akhauriyash/Code-Regression huggingface dataset:
book_num, arg_num, dest = map(int, input().split(" "))
Cs = []
As = []
ans = []
for _ in range(book_num):
    li = list(map(int, input().split(" ")))
    Cs.append(li[0])
    As.append(li[1:])
for i in range(2 ** book_num):
    ja = [0]*arg_num
    cost = 0
    for j in range(book_num):
        if ((i >> j) & 1):
            for s in range(arg_num):
                ja[s] += As[j][s]
            cost += Cs[j]
    flag = 0
    for j in ja:
        if j < dest:
            flag = 1
    if flag == 0:
        ans.append(cost)
if ans:
    print(min(ans))
else:
    print(-1)

Measured memory_bytes: 9240
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner teclado = new Scanner(System.in);
		int N = teclado.nextInt();
		int A = teclado.nextInt();
		int B = teclado.nextInt();
		int total = A * N;
		if (total <= B) {
			System.out.println(total);
		}
		
		else {
			System.out.println(B);
		}
		
		teclado.close();
		
	}
}

Measured memory_bytes: 21844
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;
string num;
int dp[105][4][2];
int solve(int index, int nz, int small) {

	//db3(index, nz, small);
	if (index == num.length()) {
		return dp[index][nz][small] = (nz==0);
	}
	//if (index >= 10) return 0;
	if (dp[index][nz][small] != -1)
		return dp[index][nz][small];
	int limit  = (small ==  1 ? 9 : (num[index]-'0'));
	int res = 0;
	for (int i=0; i<=limit; i++) {
		int z = nz;
		if (i > 0) {
			if (z > 0) z--;
			else continue;
		}

		int s = small;
		if (s==0 && i < limit) s=1;

		res += solve(index+1, z, s);
	}
	return dp[index][nz][small] = res;
}

void testcase() {
	int K;
	cin >> num >> K;

	rep (i, 0, 104)
	rep (j, 0, 3)
	rep (k, 0, 1)
		dp[i][j][k] = -1;
    cout << solve(0, K, 0)  << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string x;
  cin>>k>>x;
  if(x.size()<=k){
    cout<<x<<endl;
  }
  else{
    for(int i=0;i<k;i++){
      cout<<x[i];
    }
    cout<<"..."<<endl;
  }

}

Measured memory_bytes: 3604
N = int(input())
A = list(map(int, input().split()))
lis = set()
A.sort()
ans = 0
for i in range(N):
    if not A[i] in lis:
        if i == N-1:
            ans += 1
        else:
            if A[i] == A[i+1]:
                cnt = 1
                while A[i] * cnt <= int(1e6):
                    lis.add(A[i] * cnt)
                    cnt += 1
            else:
                ans += 1
                cnt = 1
                while A[i] * cnt <= int(1e6):
                    lis.add(A[i] * cnt)
                    cnt += 1
print(ans)


Measured memory_bytes: 86676
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  char alpha;
  cin >> alpha;

  if((alpha - 'a' >= 0) && (alpha - 'a' <= 25))
    cout << "a\n";
  else
    cout << "A\n";
  
  return 0;
}


Measured memory_bytes: 3636
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)

x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)

print(x3, y3, x4, y4)


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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int n;
    cin >> n;

    vi p(102);
    REP(i, n) cin >> p[i] >> p[i+1];
    vvi dp(102, vi(102, 0));

    FOR(l, 2, n+1){           // 対象とする行列の数
        FOR(i, 1, n-l+2){     
            int j = i + l - 1;   
            dp[i][j] = (1 << 20); // dp[i][j] := [Mi, Mj]の最小回数
            FOR(k, i, j){
	            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1] * p[k] * p[j]);
            }
        }
    }

  cout << dp[1][n] << endl;

    
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}

int main(void){
    IN(A)IN(B)IN(C)
    printf("%d\n",C-min(A-B,C));
    return 0;
}


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

int main(void){
    int n, m;
    char str[255];
    map<string, int> red, blue;

    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%s", str);
        string s(str);
        if (red.count(s)==false) red[s]=0;
        red[s]++;
    }
    scanf("%d", &m);
    for (int i=0; i<m; i++){
        scanf("%s", str);
        string s(str);
        if (blue.count(s)==false) blue[s]=0;
        blue[s]++;
    }

    int ma=0;
    for (map<string, int>::iterator it=red.begin(); it!=red.end(); it++){
        if (blue.count(it->first)) ma=max(ma, it->second-blue[it->first]);
        else ma=max(ma, it->second);
    }printf("%d\n", ma);

    return 0;
}


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

int main(void){
    // Your code here!
    string S,T;
    cin >> S >> T;
    
    int M = 0;
    int cnt;
    for(int i=0;i<S.size()-T.size()+1;i++){
        cnt = 0;
        for(int j=0;j<T.size();j++){
            if(S[i+j]==T[j]) cnt++;
        }
        M = max(cnt,M);
    }
    cout << T.size()-M << endl;
}

Measured memory_bytes: 3624
s = gets.chomp
q = gets.to_i
queries = q.times.map { gets.split }

s1 = ''
reversed = false

queries.each do |t, f, c|
  if t.to_i == 1
    reversed = !reversed
    next
  end

  if (f.to_i == 1 && reversed) || (f.to_i == 2 && !reversed)
    s << c
  else
    s1 << c
  end
end

if reversed
  puts s.reverse! << s1
else
  puts s1.reverse! << s
end


Measured memory_bytes: 43132
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    long[][] a = new long[n][2];
    long[][] c = new long[m][2];

    for (int i = 0; i < n; i++) {
      a[i][0] = sc.nextLong();
      a[i][1] = sc.nextLong();
    }

    for (int i = 0; i < m; i++) {
      c[i][0] = sc.nextLong();
      c[i][1] = sc.nextLong();
    }

    for (int i = 0; i < n; i++) {
      long min = Integer.MAX_VALUE;
      int index = 0;
      for (int j = 0; j < m; j++) {
        if (min > Math.abs(a[i][0] - c[j][0]) + Math.abs(a[i][1] - c[j][1])) {
          min = Math.abs(a[i][0] - c[j][0]) + Math.abs(a[i][1] - c[j][1]);
          index = j + 1;
        }
      }
      System.out.println(index);
    }

  }
}

Measured memory_bytes: 36212
s = int(input())
a_list = []
m = 1
a_list.append(s)
t = s
while s > 0:
  if t%2 == 0:
    t = t//2
  else:
    t = 3*t+1
  m += 1
  if t in a_list:
    break
  a_list.append(t)
  
print(m)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

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

  vector<int> a(N);
  
  for(int i=0;i<N;i++) cin>>a[i];
    
  int cost_min=INT_MAX;
  for(int x=-100;x<=100;x++){
    int cost=0;
    for(int i=0;i<N;i++) cost+=(a[i]-x)*(a[i]-x);
    cost_min=min(cost,cost_min);
  }
  
  cout<<cost_min<<endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    vector<ll> ans(2 * N + 1);
    int j = 1;
    for(int i = 0; i < N; i++) {
        if(i == 0) ans[0] = 0;
        else if(i == 1) ans[1] = A[0];
        else if(i % 2 == 0) ans[i] = ans[i - 1] + A[j];
        else {
            ans[i] = ans[i - 1] + A[j];
            j++;
        }
    }
    cout << ans[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 7992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H;
		int W;
		int count;
		int[] detaH = new int[300];
		int[] detaW = new int[300];
		for (count = 0; true; count++) {
			H = sc.nextInt();
			W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			detaH[count] = H;
			detaW[count] = W;
		}
		for (int i = 0; i < count; i++) {
			for (int i2 = 0; i2 < detaH[i]; i2++) {
				for (int i3 = 0; i3 < detaW[i]; i3++) {
					System.out.print("#");
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
		sc.close();
	}
}


Measured memory_bytes: 36880
#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int digit(int x){
	int res = 0;
	while(x != 0){
		res++;
		x /= 10;
	}
	return res;
}

int main(void) {
	int a, b;
	while(cin >> a >> b){
		cout << digit(a + b) << endl;
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

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

  ll red = 0;
  ll white = 0;

  string S;
  cin >> S;

  for (ll i = 0; i < N; i++)
  {
    if (S[i] == 'R'){ 
      red += 1;
    } else {
      white += 1;
    }
  }


  if (red == 0) {
    cout << 0 << endl;
  } else {
    string risou = "";
    for (ll i = 0; i < red; i++)
    {
      risou.push_back('R');
    }
    for (ll i = 0; i < white; i++)
    {
      risou.push_back('W');
    }
    
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
      if (S[i] != risou[i]) {
        ans += 1;
      }
    }
    cout << (ans / 2) << endl;
  }
}

Measured memory_bytes: 3920
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
c = list(input())

ans = 0
l = 0
r = N-1
while l <= r:
    flag = False
    for i in range(l,N):
        if c[i] == 'W':
            l = i
            flag = True
            break
    if not flag:
        l = N

    flag = False
    for i in range(r+1)[::-1]:
        if c[i] == 'R':
            r = i
            flag = True
            break
    if not flag:
        r = -1

    if r < l:
        break
    
    c[l] = 'R'
    c[r] = 'W'
    ans += 1

print(ans)

Measured memory_bytes: 77820
import sys

def S(): return sys.stdin.readline().rstrip()

H,W,K = map(int,S().split())
mod = 10**9+7

if W == 1:
    print(1)
    exit()

fib = [1,1,2,3,5,8,13,21]  # fib[i] = i本の縦線に横線を引く方法の数(同じ高さ)

dp = [[0]*(W+1) for _ in range(H+1)]  # dp[i][j] = i行目にjに達する横線の引き方

for i in range(H+1):
    for j in range(W+1):
        if i == 0:
            if j == 1:
                dp[i][j] = 1
        else:
            if j == 1:
                dp[i][j] = dp[i-1][j]*fib[W-1] + dp[i-1][j+1]*fib[W-2]
                dp[i][j] %= mod
            elif j == W:
                dp[i][j] = dp[i-1][j-1]*fib[W-2] + dp[i-1][j]*fib[W-1]
                dp[i][j] %= mod
            elif 2 <= j <= W-1:
                dp[i][j] = dp[i-1][j-1]*(fib[j-2]*fib[W-j]) + dp[i-1][j]*(fib[j-1]*fib[W-j]) + dp[i-1][j+1]*(fib[j-1]*fib[W-j-1])
                dp[i][j] %= mod

print(dp[H][K])

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

using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll, ll>;
using PLD=pair<ld, ld>;
using VPLL=vector<PLL>;
#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i, n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i, a, b) for(ll i=(a);i<=(b);i++)
#define FORD(i, a, b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x, a) fill(x.begin(),x.end(),a)
#define EACH(i, x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const int INF = 1 << 30;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;

template<class T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last) {
	reverse(middle, last);
	return next_permutation(first, last);
}

#define COUT(x) cout<<x<<"\n"

void Main() {
	ll N;
	ll mini=0;
	ll maxi = 0;
	ll result=0;
	cin >> N;
	VI ai(N);
	REP(i, N) cin >> ai[i];
	SORT(ai);
	vector<bool> b(8, false);
	REP(i, N) {
		ll a = ai[i];
		REP(j, 8) {
			ll mul = 400;
			if (mul * j <= a && a <= mul * (j + 1) - 1&&b[j]==false) {
				mini++;
				maxi++;
				b[j] = true;
			}
			else if(a>=3200){
				if(mini==0) mini++;
				maxi++;
				break;//8回判定しているため
			}
		}
	}

	cout << mini<<" "<<maxi << "\n";
	return;
}

int main() {
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

vector<int> x, y;

double dist(int i, int y1, int y2)
{
    if(y1 == y2)
        return 0.0;
    return abs(sqrt(pow(y[i]-y[i+1], 2.0) + pow(x[i]-x[i+1], 2.0)) * (y1-y2) / (y[i]-y[i+1]));
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        x.assign(n+2, -1);
        y.assign(n+2, -1);
        for(int i=1; i<=n; ++i)
            cin >> x[i] >> y[i];

        vector<vector<double> > dp(n+2, vector<double>(n+2, DBL_MAX));;
        dp[1][n] = 0.0;
        multimap<double, pair<int, int> > mm;
        mm.insert(make_pair(0.0, make_pair(1, n)));

        for(;;){
            double len = mm.begin()->first;
            int a = mm.begin()->second.first;
            int b = mm.begin()->second.second;
            mm.erase(mm.begin());
            if(len > dp[a][b] + EPS)
                continue;
            if(a == b){
                printf("%.10f\n", len);
                break;
            }

            int currY = y[a];

            for(int i=0; i<2; ++i){
                for(int j=0; j<2; ++j){
                    int a1 = a + j - 1;
                    int b1 = b + i;
                    int nextY = y[b1];
                    if(a1 < 1 || a1 > n || b1 < 1 || b1 > n)
                        continue;
                    if(min(y[a1],y[a1+1]) <= nextY && nextY <= max(y[a1],y[a1+1])){
                        double len2 = len + dist(a1, currY, nextY) + dist(b, currY, nextY);
                        if(b1 != b && y[b] == y[b1])
                            len2 += abs(x[b1] - x[b]);
                        if(a1 != a && y[a] == y[a1])
                            len2 += abs(x[a1] - x[a]);
                        if(len2 < dp[b1][a1] - EPS){
                            dp[b1][a1] = len2;
                            mm.insert(make_pair(len2, make_pair(b1, a1)));
                        }
                    }
                }
            }

            for(int i=0; i<2; ++i){
                int a1 = a + 2*i - 1;
                int nextY = y[a1];
                if(a1 < 1 || a1 > n)
                    continue;
                if(min(y[b],y[b+1]) <= nextY && nextY <= max(y[b],y[b+1])){
                    double len2 = len + dist(a-1+i, currY, nextY) + dist(b, currY, nextY);
                    if(currY == nextY)
                        len2 += abs(x[a1] - x[a]);
                    if(len2 < dp[a1][b] - EPS){
                        dp[a1][b] = len2;
                        mm.insert(make_pair(len2, make_pair(a1, b)));
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 0
import math
from decimal import Decimal, ROUND_HALF_UP
def run(n):
    if len(pos)>=n:return(pos[n-1])
    else:run(n-1)
    x,y=pos[-1]
    d=math.degrees(math.atan(y/x))
    xi=x+math.cos(math.radians(d+[90,270][x<0]))
    yi=y+math.sin(math.radians(d+[90,270][x<0]))
    pos.append([xi,yi])
pos=[[1.0,0.0],[1.0,1.0]]
while 1:
    n=int(input())
    if n==-1:break
    run(n)
    print(Decimal(pos[n-1][0]).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP))
    print(Decimal(pos[n-1][1]).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP))


Measured memory_bytes: 7084
s=input()
t=input()

sl=len(s)
tl=len(t)

c=[]

for i in range(sl-tl+1):
    cnt=0
    for j in range(tl):
        if s[i+j]==t[j]:
            cnt+=1
    c.append(cnt)
    cnt=0

print(tl-max(c))

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

INF = 2147483647
M = [[INF for j in range(n)] for i in range(n)]
check, dist = [0 for i in range(n)], [INF for i in range(n)]


def dijkstra(s):
    p = [-1 for i in range(n)]
    dist[s] = 0

    while True:
        min_cost = INF
        for i in range(n):
            if check[i] != 2 and dist[i] < min_cost:
                min_cost = dist[i]
                u = i

        if min_cost == INF:
            break

        check[u] = 2

        for v in range(n):
            if check[v] != 2 and M[u][v] != INF:
                if dist[u] + M[u][v] < dist[v]:
                    dist[v], p[v] = dist[u] + M[u][v], u
                    check[v] = 1


def main():
    for i in range(n):
        data = list(map(int, input().split()))
        for j in range(data[1]):
            M[data[0]][data[2*(j+1)]] = data[2*(j+1)+1]

    dijkstra(0)

    for i in range(n):
        print(i, dist[i])


if __name__ == '__main__':
    main()



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

int solve(){
    int n, m;
    cin >> n >> m;
    if(n==0) return 1;
    vector<int> a(n), b(m);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    int ans = 0;
    for(int i=0,j=0;i<n||j<m;){
        if(i==n){
            while(j<m) ans += b[j++];
            break;
        }
        if(j==m){
            while(i<n) ans += a[i++];
            break;
        }
        if(a[i]<b[j]){
            ans += b[j];
            j++;
        }else if(a[i]>b[j]){
            ans += a[i];
            i++;
        }else{
            ans += a[i];
            i++;
            j++;
        }
    }
    cout << ans << endl;
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}



Measured memory_bytes: 3116
# coding: utf-8
# Your code here!

s = input()
w = input().split()
sum = 0
for i in range(int(s)):
    sum += int(w[i])
average = sum / int(s)
limit = 100
index = 0
for i in range(int(s)):
    if abs(int(w[i]) - average) < limit:
        limit = abs(int(w[i]) - average)
        index = i
print(index)


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
cnt=[0,0]
for i in range(n):
    if a[i]%2==0:
        if a[i]%4==0:
            cnt[1]+=1
        else:
            cnt[0]+=1
if cnt[0]==0 and cnt[1]!=0:
    if 2*cnt[1]+1>=n:
        print("Yes")
    else:
        print("No")
elif cnt[0]+2*cnt[1]>=n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n;cin >> n;
    vl cnt(n,0);
    ll ans=1;
    rep(i,n){
        ll a;cin >> a;
        if(a==0)ans*=3-cnt[0];
        else ans*=cnt[a-1]-cnt[a];
        cnt[a]++;
        ans%=MOD;
    }
    cout << ans%MOD <<endl;
}


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

using namespace std;

int main(){
	int n,a[4]{};
	string s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin  >> s;
		if (s == "P")a[0]++;
		if (s == "W")a[1]++;
		if (s == "G")a[2]++;
		if (s == "Y")a[3]++;
	}
	if (a[3] > 0)
		cout << "Four" << endl;
	else
		cout << "Three" << endl;

 	return 0;
}



Measured memory_bytes: 256
main(i,j){
	int a[10];
	while(1){
		for(i=0;i<10;i++)	a[i]=getchar()-'0';
		if(getchar()==-1)	break;
		for(i=9;i>=1;i--){
			for(j=0;j<i;j++){
				a[j]=(a[j]+a[j+1])%10;
			}
		}
		printf("%d\n",a[0]);
	}
	exit(0);
}

Measured memory_bytes: 0
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.Maybe (fromMaybe)
import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Class (lift)
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

-- 有向グラフに閉路があるか判定し、閉路があれば Nothing を返す。
-- 閉路がなければ最長路の長さを返す。
solve :: V.Vector [Int] -> Maybe Int
solve edges = fmap U.maximum $ runST $ runMaybeT $ do
  let !n = V.length edges  -- 頂点の個数
  vec <- UM.replicate n (-2 :: Int) -- -2: new, -1: DFSの最中, 正: チェック済み
  let dfs !x = do
        s <- UM.read vec x
        case s of
          -2 -> do
            -- x を通る閉路があるかチェックする
            UM.write vec x (-1)
            v <- foldM (\ !a y -> max a <$> dfs y) 0 (edges V.! x)
            let !v' = v + 1
            UM.write vec x v'
            return v'
          -1 -> mzero  -- コールスタックのどこかで dfs x が呼ばれている。閉路
          v -> return v
  mapM_ dfs [0..n-1]
  U.unsafeFreeze vec

main = do
  n <- readLn
  xs <- V.replicateM n $ do
    U.map (subtract 1) . U.unfoldrN (n-1) (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let m = n * (n - 1) `quot` 2  -- グラフの頂点数
  let -- (i,j) (0 <= i < j < n) を 0 以上 m 未満の整数値にコードする
      makePair :: Int -> Int -> Int
      makePair i j | i' < j' = n * i' - (i' + 1) * i' `quot` 2 + j' - i' - 1
                   | otherwise = undefined
        where i' = min i j; j' = max i j
  -- 「試合 (i,j) よりも試合 (i',j') の方を後に行う場合に辺 makePair i j → makePair i' j' が存在する」ようなグラフを作る
  let edges :: V.Vector [Int]
      edges = V.create $ do
        e <- VM.replicate m []
        V.forM_ (V.indexed xs) $ \(i,ys) -> do
          U.forM_ (U.zip ys (U.tail ys)) $ \(a,b) -> do
            -- (i,a) -> (i,b)
            let !b' = makePair i b
            -- VM.modify e (b' :) (makePair i a)
            t <- VM.read e (makePair i a)
            VM.write e (makePair i a) $! b' : t
        return e
  print $ fromMaybe (-1) $ solve edges


Measured memory_bytes: 103036
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>

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

    std::vector< std::pair<std::pair<std::string, int>, int> > sp (n);

    for (int i = 0; i < n; i++) {
        std::cin >> sp[i].first.first >> sp[i].first.second;
        sp[i].first.second *= -1;
        sp[i].second = i + 1;
    }

    std::sort(sp.begin(), sp.end());

    for(int i = 0; i < n; i++) {
        std::cout << sp[i].second << std::endl;

    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i;
    ll s[N];
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s[i];
        s[i]*=2;
    } 
    ll a[N];
    ll f = 0;
    for(i=0;i<n;i++){
        if(i%2==0) f+=s[i];
        else f-=s[i];
    }
    a[0]=f/2;
    for(i=0;i<n-1;i++){
        a[i+1]=s[i]-a[i];
    }
    for(i=0;i<n;i++) cout << a[i] << " ";
    cout << endl;


 
    return 0;
}

Measured memory_bytes: 2944
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            int[] ar = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
            Console.WriteLine(IsRightTriangle(ar) ? "YES" : "NO");
        }
    }

    static bool IsRightTriangle(int[] ar)
    {
        return ar[0] * ar[0] + ar[1] * ar[1] == ar[2] * ar[2];
    }
}


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

int main() {
  int Ac, Bc, X, Y, check;
  cin >>Ac >>Bc >>X >>Y;
  vector<int> Acs(Ac);
  for(int i=0;i<Ac;i++){
    cin >>Acs.at(i);
  }  
  vector<int> Bcs(Bc);
  for(int i=0;i<Bc;i++){
    cin >>Bcs.at(i);
  }  
  
  sort(Acs.begin(), Acs.end());
  sort(Bcs.begin(), Bcs.end());
    
  if(max(Acs.at(Ac-1),X) < min(Bcs.at(0),Y)){
    cout << "No War" <<endl;
  }
  else{
    cout << "War" <<endl;
  }  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>
#include <bitset>

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::vector<long long int>> lower(static_cast<int>(std::sqrt(n)) + 1);
	for (auto i = 0; i < lower.size(); ++i) lower[i] = std::vector<long long int>(i + 1, 0);
	std::vector<long long int> all(n, 0);
	for (auto _i = 0; _i < m; ++_i) {
		int a, b; std::cin >> a >> b;
		if (b <= lower.size()) {
			for (auto j = 0; j < b; ++j) {
				lower[b - 1][j] += (a + j + 1) % b;
			}
		}
		else {
			all[0] += a + 1;
			all[1] -= a;
			for (auto j = b - a - 1; j < n; j += b) {
				all[j] -= b;
				if (j + 1 < n) all[j + 1] += b;
			}
		}
	}
	for (auto i = 1; i < n; ++i) all[i] += all[i - 1];
	for (auto i = 1; i < n; ++i) all[i] += all[i - 1];
	for (auto i = 0; i < n; ++i) {
		long long int sum = 0LL;
		for (const auto& l : lower) sum += l[i % l.size()];
		std::cout << all[i] + sum << '\n';
	}
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  if (N % 2 == 0) {
    cout << N << "\n";
  }
  else {
    cout << 2 * N << "\n";
  }
}


Measured memory_bytes: 256
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
def solve(N,A):
    dic=defaultdict(lambda: 0)
    for a in A: dic[a]+=1
    m=max(A)
    for i in range((m+1)//2,m+1):
        if m%2==0 and i==m//2:
            dic[i]-=1
        else:
            dic[i]-=2
    return not any([cnt<0 or (n<((m-m//2)+1) and cnt>0) for n,cnt in dic.items()])

print("Possible" if solve(N,A) else "Impossible")


Measured memory_bytes: 38384
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
a = inputlist()

xor = 0
for i in range(N):
    xor = xor ^ a[i]

ans = [0]*N
for i in range(N):
    ans[i] = a[i]^xor
print(*ans)

Measured memory_bytes: 105604
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;
 
int N,M;
vector<ll> A;
vector<ll> B,C;
 
int main(){
  cin>>N>>M;
  A.resize(N);
  B.resize(M);
  C.resize(M);
  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=0;i<M;i++) cin>>B[i]>>C[i];
 
  sort(A.begin(),A.end());
  vector<pair<ll,int>> v;
  for(int i=0;i<M;i++) v.push_back(mkp(C[i],i));
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
 
  int it=0;
  for(int i=0;i<M;i++){
    if(A[it]<v[i].first){
      int tmp=B[v[i].second];
      while(tmp>0&&it<N&&A[it]<v[i].first){
        A[it]=v[i].first;
        it++;
        tmp--;
      }
    }
  }
 
  ll ans=0;
  for(int i=0;i<N;i++) ans+=A[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 4724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long a = in.nextLong();
			long b = in.nextLong();

			String ans = "";
			if (a * b <= 0) {
				ans = "Zero";
			} else if (a > 0 && b > 0) {
				ans = "Positive";
			} else if (a < 0 && b < 0) {
				if ((Math.abs(b) - Math.abs(a) + 1) % 2 != 0) {
					ans = "Negative";
				} else {
					ans = "Positive";
				}
			}
			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 23380
#include<cstdio>
#include<algorithm>
#include<map>
const int maxn=2010,S=10000;
int n,a[maxn],b[maxn],vt;
bool used[maxn],ban[maxn];
std::map<int,int>M;
struct edge{int to;edge*next;}E[maxn*20],*ne=E,*fir[maxn*10];
int vis[maxn*10];
void cmin(int&a,int b){b<a?a=b:1;}
void cmax(int&a,int b){b>a?a=b:1;}
int pid(int x){return M.count(x)?M[x]:M[x]=vt++;}
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
int dfs(int i,int x){
	int mv=i<n&&!ban[i]?i:n;
	vis[i]=x;
	for(edge*e=fir[i];e;e=e->next){
		if((e->to>=n||!used[e->to])&&vis[e->to]!=x)cmin(mv,dfs(e->to,x));
	}
	return mv;
}
int pr[S+1],pc;
bool com[S+1];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	std::sort(a,a+n);
	vt=n;
	for(int i=2;i<=S;i++){
		if(!com[i])pr[pc++]=i;
		for(int j=0;j<pc&&i*pr[j]<=S;j++){
			com[i*pr[j]]=1;
			if(i%pr[j]==0)break;
		}
	}
	for(int i=0;i<n;i++){
		int x=a[i];
		for(int j=0;j<pc&&pr[j]*pr[j]<=x;j++)if(x%pr[j]==0){
			int t=pid(pr[j]);
			link(i,t);link(t,i);
			while(x%pr[j]==0)x/=pr[j];
		}
		if(x>1){
			int t=pid(x);
			link(i,t);link(t,i);
		}
	}
	for(int i=1;i<=n;i++){
		int mv=0;
		for(int j=0;j<n;j++)if(!used[j]&&vis[j]!=i)cmax(mv,dfs(j,i));
		printf("%d%c",a[mv]," \n"[i==n]);
		used[mv]=1;
		for(edge*e=fir[mv];e;e=e->next)
			for(edge*f=fir[e->to];f;f=f->next)
				if(!used[f->to])
					ban[f->to]=0,vis[f->to]=-1;
		for(int j=n;j--&&a[j]>a[mv];)if(!used[j]&&vis[j]!=-1)ban[j]=1;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int fa[100005];
int find(int x){
   return x==fa[x]?fa[x]:fa[x]=find(fa[x]);
}
void combine(int x,int y){
   int f1=find(x);
   int f2=find(y);
   if(f1!=f2)fa[f1]=f2;
}
int n,m;
vector<int>vec[100005];
int vis[100005];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=n;i++){
      int k;
      cin>>k;
      for(int j=1;j<=k;j++){
        int x;
        cin>>x;
        vis[x]=1;
        vec[x].push_back(i);
      }
    }
    for(int i=1;i<=m;i++){
      for(int j=1;j<vec[i].size();j++){
        combine(vec[i][0],vec[i][j]);
      }
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        if(fa[i]==i) {sum++;}
    }
   // cout<<sum<<"\n";
    if(sum==1)cout<<"YES\n";
    else cout<<"NO\n";
}


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

int gcd(int a, int b){
    for(int i = a; i >= 1; --i){
        if(a%i == 0 && b%i == 0){
            return i;
        }
    }
}

int main(){
    int a,b;
    cin >> a >> b;
    ll ans = ll(a)*b / gcd(a,b);
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  
  std::map<string, string> S;

  for(int n=0; n<N; n++)
  { string SS;
    cin >> SS;
   
    if(S.find(SS)==S.end())
    {
      S.insert(std::make_pair(SS, SS));
    }
  }
  
  cout << S.size() << endl;
}


Measured memory_bytes: 25308
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool f = (S == "AAA" or S == "BBB");
  cout << (!f ? YES : NO) << endl;
}

signed main(){
  std::string S;
  std::cin >> S;
  solve(S);
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 200'000 + 5;


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    i64 n;
    cin >> n;

    const i64 maxn = 10000;
    vector<i64> R(n + 1);

    for (i64 x = 1; x <= maxn; x++) {
        for (i64 y = 1; y <= maxn; y++) {
            i64 vxy = sqr(x) + sqr(y) + x * y;
            if (vxy > n) {
                break;
            }
            for (i64 z = 1; z <= maxn; z++) {
                i64 v = sqr(x) + sqr(y) + sqr(z) + x * y + x * z + y * z;
                if (v > n) {
                    break;
                }
                R[v] += 1;
            }
        }
    }
    stringstream ss;
    for (i64 i = 1; i <= n; i++) {
        ss << R[i] << endl;
    }
    cout << ss.str() << endl;

    return 0;
}


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

int main(void) {
  ll A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> S(A), T(B), X(Q);
  REP(i, 0, A) cin >> S[i];
  REP(i, 0, B) cin >> T[i];
  REP(i, 0, Q) cin >> X[i];

  REP(i, 0, Q) {
    ll x = X[i];

    auto s = lower_bound(S.begin(), S.end(), x);
    auto t = lower_bound(T.begin(), T.end(), x);

    ll ans = 1LL << 60;
    if (s != S.end() && t != T.end()) {
      ans = min(ans, max(*s, *t) - x);
    }
    if (s != S.end() && t != T.begin()) {
      ans = min(ans, min(*s - x, x - *(t - 1)) + (*s - *(t - 1)));
    }
    if (s != S.begin() && t != T.end()) {
      ans = min(ans, min(*t - x, x - *(s - 1)) + (*t - *(s - 1)));
    }
    if (s != S.begin() && t != T.begin()) {
      ans = min(ans, x - min(*(s - 1), *(t - 1)));
    }
    cout << ans << endl;
  }
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    map<string, int> mp;
    mp["SUN"] =  7;
    mp["MON"] =  6;
    mp["TUE"] =  5;
    mp["WED"] =  4;
    mp["THU"] =  3;
    mp["FRI"] =  2;
    mp["SAT"] =  1;

    string s; cin >> s;
    cout << mp[s] << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

cand = [0] * 10**5

for i in range(len(A)):
    cand[A[i]] += 1
    if A[i] < len(A)-1:
        cand[A[i]+1] += 1
    if A[i] > 0:
        cand[A[i]-1] += 1

print(max(cand))

Measured memory_bytes: 13964
#include <iostream>

int main()
{
    char b;

    std::cin >> b;

    if (b == 'A') {
        std::cout << 'T';
    } else if (b == 'T') {
        std::cout << 'A';
    } else if (b == 'C') {
        std::cout << 'G';
    } else if (b == 'G') {
        std::cout << 'C';
    }
    std::cout << std::endl;

    return 0;
}

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

int A,B;

int main(){
  cin >> A >> B;
  if(0 <= A && A < 6) cout << 0 << endl;
  else if(5 < A &&  A < 13) cout << B/2 << endl;
  else cout << B << endl;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
    int x = n / 111;
    if(111 * x == n)
        cout << 111 * x << endl;
    else
        cout << 111 * (x + 1) << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k, x, y;std::cin >> n >> k >> x >> y;
  ll ans = 0;
  for(int i=0;i<min(n, k);i++) ans += x;
  if(k<n) for(int i=k;i<n;i++) ans += y;
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

ll gcd(ll a, ll b) { return b==0 ? a : gcd(b, a%b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    ll ans = 1;
    rep(i, n) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> now;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        now.push_back(make_pair(a, b));
    }
    vector<pair<int, int>> cp;
    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        cp.push_back(make_pair(c, d));
    }

    vector<int> to(55);
    for (int i = 0; i < n; i++) {
        int min_dist = 2000000000;
        for (int j = 0; j < m; j++) {
            int dist = abs(now[i].first - cp[j].first) + abs(now[i].second - cp[j].second);
            if (dist < min_dist) {
                min_dist = dist;
                to[i] = j;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << to[i] + 1 << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  int N, M;
  
  cin >> N >> M;
  
  vector<ll> H(N + 1, 0);
  vector<ll> H_max(N + 1, -1);
  vector<bool> H_dup(N + 1, false);
  
  for (int i = 1; i <= N; i++) {
    ll H_i;
    
    cin >> H_i;
    
    H[i] = H_i;
  }
  
  for (int i = 0; i < M; i++) {
    int in1, in2;
    
    cin >> in1 >> in2;
    
    H_max[in1] = max(H_max[in1], max(H[in1], H[in2]));
    H_max[in2] = max(H_max[in2], max(H[in1], H[in2]));
    
    if (!H_dup[in1] && H[in1] == H[in2]) {
      H_dup[in1] = true;
    }
    
    if (!H_dup[in2] && H[in1] == H[in2]) {
      H_dup[in2] = true;
    }
  }
  
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if ((H_max[i] == -1 || H_max[i] == H[i]) && !H_dup[i]) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main() {
	int N,M;
	cin >>N>>M;
	vector<int> s(M+1),c(M+1);
	vector<int> a(N+1);
	for(int i=1;i<=N;i++){
		a[i]=0;
	}
	for(int i=1;i<=M;i++){
		cin >>s[i]>>c[i];
		a[s[i]]=c[i];
	}
	int p;
	p=0;
	for(int i=1;i<=M;i++){
		if((N>=2&&s[i]==1)&&c[i]==0){
				p=-1;
			}
		for(int k=i+1;k<=M;k++){
			if(s[i]==s[k]&&c[i]!=c[k]){
				p=-1;
			}
		}
	}
	if(p==-1){
		cout <<-1;
	}
	else{
		p=0;
		if(N>1&&a[1]==0){
			a[1]=1;
		}
		for(int i=1;i<=N;i++){
			p+=a[i]*pow(10,N-i);
		}
		cout <<p;
	}


	




}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    string S; cin>>S;
    int rcnt=0;
    rep(i,N)if(S[i]=='R') rcnt++;
    int ans=0;
    rep(i,rcnt)if(S[i]=='W') ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656