akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
from itertools import permutations
INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.V = list(range(N))
        self.E = [[] for _ in range(N)]

    def add_edge(self, edge):
        """辺を加える。edgeは(始点, 終点、重み)からなるリスト
        重みがなければ、重み1とする。
        """
        if len(edge) == 2:
            edge.append(1)
        elif len(edge) != 3:
            print("error in add_edge")
            pass

        s, t, w = edge
        self.E[s].append([t, w])
        self.E[t].append([s, w])  # 無向グラフを仮定。逆向きにも辺を張る

        pass


def Warshall_Floyd(g: Graph):
    """ワーシャルフロイド法により、全節点対の最短距離を求める。O(V^3)
    https://ja.wikipedia.org/wiki/%E3%83%AF%E3%83%BC%E3%82%B7%E3%83%A3%E3%83%AB%E2%80%93%E3%83%95%E3%83%AD%E3%82%A4%E3%83%89%E6%B3%95
    """
    N = g.N
    dist = [[INF]*N for _ in range(N)]
    for from_, toweights in enumerate(g.E):
        for to_, w in toweights:
            dist[from_][to_] = w

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist


def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"):

    g = Graph(N)
    for a, b, c in zip(A, B, C):
        g.add_edge([a-1, b-1, c])

    B = Warshall_Floyd(g)

    m = INF
    for order in permutations(r, R):
        counter = 0
        for i in range(R-1):
            counter += B[order[i]-1][order[i+1]-1]
        m = min(m, counter)
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    r = [int(next(tokens)) for _ in range(R)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, R, r, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58460
#include<iostream>
#include<vector>
#include<string>

const int MAX = 1e5 + 10;

int main(){
    int n, m;
    std::cin >> n >> m;
    std::vector<int> ID(MAX, 0);
    for(int i = 0; i < m; i++){
        int l, r;
        std::cin >> l >> r;
        ID[l]++;
        ID[r + 1]--;
    }

    // imos
    int cnt = 0;
    for(int i = 1; i < MAX; i++){
        ID[i] += ID[i - 1];
        if(ID[i] == m) cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>

const int INF = 1000 * 1000 * 1000 + 1000;
int N, M, D[1123], C[1123];
int memo[1123][1123], ans = 0;

//dp(i,j) == ??????i+1?????§j+1??\??\???????????£?????????????°?????????´???
//dp(0,????????§???) == 0
//dp(i,j) == min( dp(i-1,j-1)+D[i]*C[j],dp(i,j-1)) 

int dp(int i, int j) {
	if (i > j) { return INF; }
	if (i == -1) { return 0; }
	else {
		if (memo[i][j] != -1) { return memo[i][j]; }
		return memo[i][j] = std::min(dp(i - 1, j - 1) + D[i] * C[j], dp(i, j - 1));
	}
}

int main(void) {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) { scanf("%d", &D[i]); }
	for (int i = 0; i < M; ++i) { scanf("%d", &C[i]); }

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

	printf("%d\n", dp(N - 1, M - 1));
	return 0;
}

Measured memory_bytes: 6228
from collections import deque

h, w = map(int, input().split())

maze = [list(input()) for _ in range(h)]
step = [[0] * w for _ in range(h)]
direction = [[1,0],[-1,0],[0,1],[0,-1]]

def bfs(maze,h,w):
    start = [0,0]
    #キューで座標保存
    q = deque([start])
    while q:
        x, y = q.popleft()
        for d in direction:
            nx = x + d[0]
            ny = y + d[1]
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] == "." and step[nx][ny] == 0:
                q.append([nx,ny])
                step[nx][ny] = step[x][y] + 1
        if step[h-1][w-1] != 0:
            return step[h-1][w-1]
    return -1

#壁の数
wall = 0
for i in maze:
    for j in i:
        if j == "#":
            wall += 1
if bfs(maze,h,w) >= 0:
    ans = h * w - wall - (bfs(maze,h,w) + 1)
else:
    ans = -1
print(ans)


Measured memory_bytes: 73784
let is_prime n =
  if n = 2 || n = 3 || n = 5 then true
  else if n mod 2 = 0 || n mod 3 = 0 || n mod 5 = 0 then false
  else
    let rec loop i =
      if i*i > n then true
      else if n mod i = 0 then false
      else if n mod (i+2) = 0 then false
      else loop (i+6);
    in loop 5

let () =
  let n = read_int () in
  let rec read ct = function
      0 -> ct
    | i ->
       let m = read_int () in
       read (if is_prime m then ct+1 else ct) (i-1)
  in
  Printf.printf "%d\n" (read 0 n)

Measured memory_bytes: 3092
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 5000100;
int a[N], s[N], s1[N], s2[N], n, m, Q;
inline int P(int i, int j) {
	if(i == 0 || j == 0) return N-1;
	return i*m+j;
}
int main() {
	scanf("%d%d%d", &n, &m, &Q);
	for(int i = 1; i <= n; i ++ ) for(int j = 1; j <= m; j ++ ) scanf("%1d", &a[P(i, j)]);
	for(int i = 1; i <= n; i ++ ) for(int j = 1; j <= m; j ++ ) {
		// printf("I : %d, J : %d, P(i, j) : %d\ns[P(i-1, j)] : %d, s[P(i, j-1)] : %d, a[P(i, j)] : %d, s[P(i-1, j-1)] :%d\n", i, j, P(i, j), s[P(i-1, j)], s[P(i, j-1)], a[P(i, j)], s[P(i-1, j-1)]);
		s[P(i, j)] = s[P(i-1, j)]+s[P(i, j-1)]+a[P(i, j)]-s[P(i-1, j-1)];
		s1[P(i, j)] = s1[P(i-1, j)]+s1[P(i, j-1)]+(a[P(i, j)] && a[P(i-1, j)])-s1[P(i-1, j-1)];
		s2[P(i, j)] = s2[P(i-1, j)]+s2[P(i, j-1)]+(a[P(i, j)] && a[P(i, j-1)])-s2[P(i-1, j-1)];
	}
	// for(int i = 1; i <= n; i ++, puts("")) for(int j = 1; j <= m; j ++ ) printf("%d ", s1[P(i, j)]);
	while(Q -- ) {
		int x1, x2, y1, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		int ans = s[P(x2, y2)]+s[P(x1-1, y1-1)]-s[P(x1-1, y2)]-s[P(x2, y1-1)];
		x1 ++;
		ans -= s1[P(x2, y2)]+s1[P(x1-1, y1-1)]-s1[P(x1-1, y2)]-s1[P(x2, y1-1)];
		x1 --, y1 ++;
		ans -= s2[P(x2, y2)]+s2[P(x1-1, y1-1)]-s2[P(x1-1, y2)]-s2[P(x2, y1-1)];
		printf("%d\n", ans);
	}
	getchar(), getchar();
	return 0;
}


Measured memory_bytes: 71424
local bit=require"bit"
local function reada(n,m)m=m or 1 r={}for i=1,m do r[i]={}end for i=1,n do for j=1,m do r[j][i]=io.read"*n"end end return unpack(r)end 
N=io.read"*n"
a=reada(N)
s=0
for i=1,N do
	s=bit.bxor(a[i],s)
end
for i=1,N do
	print(bit.bxor(a[i],s))
end

Measured memory_bytes: 4744
def main():
    S = int(input())
    mod = 10 ** 9 + 7

    dp = [0] * (S + 1)
    dp[0] = 1
    for i in range(1, S+1):
        for j in range(0, (i-3)+1):
            dp[i] += dp[j]
            dp[i] %= mod
    print(dp[S])


if __name__ == '__main__':
    main()


Measured memory_bytes: 64652
#include <stdio.h>

using namespace std;

void QSort(int x[], int left, int right)
{
	int i, j;
	int pivot;

	i = left;                      /* ソートする配列の一番小さい要素の添字 */
	j = right;                     /* ソートする配列の一番大きい要素の添字 */

	pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

	while (1) {                    /* 無限ループ */
		while (x[i] > pivot)       /* pivot より大きい値が */
			i++;                   /* 出るまで i を増加させる */

		while (pivot > x[j])       /* pivot より小さい値が */
			j--;                   /*  出るまで j を減少させる */
		if (i >= j)                /* i >= j なら */
			break;                 /* 無限ループから抜ける */

		int temp;
		temp = x[i];
		x[i] = x[j];
		x[j] = temp;
		
		i++;                       /* 次のデータ */
		j--;
	}
	if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
		QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
	if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
		QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

int main()
{
	int n;
	long sum = 0;
	int a[100000];
	int b[100000];

	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &a[i], &b[i]);
		a[i] += b[i];
	}

	QSort(a, 0, n - 1);
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) sum += a[i] - b[i];
		else sum -= b[i];
	}
	printf("%ld\n", sum);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >>A>>B;
  if(A<=5){
    cout <<0<<endl;
  }else if(A>=6&&A<=12){
    cout <<B/2<<endl;
  }else if(A>=13){
    cout <<B<<endl;
  }
}

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

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))

using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

int main(){
string Taro;
string Hanako;
int n;
int scoreTaro=0;
int scoreHanako=0;
cin>>n;
REP(i,n){
    cin>>Taro>>Hanako;
    if(Taro>Hanako)scoreTaro+=3;
    else if(Taro<Hanako)scoreHanako+=3;
    else{
    scoreTaro++;
    scoreHanako++;
    }
}
cout<<scoreTaro<<" "<<scoreHanako<<endl;
}


Measured memory_bytes: 3188
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> k >> a >> b;
  tmp = k;
  if (k >= a + 1) {
    ans = b;
    k -= a + 1;
    ans += k / 2 * (b - a);
    ans += k % 2;
  }
  ans = max(ans, 1 + tmp);
  Cout(ans);
  return 0;
}

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

int main(){
  int num=0;
  while(cin>>num){
    if(num>0){
      int count = 0;
      for(int i=1;i<=num;i++){
	for(int j=i+1;j<=num;j++){
	  if((double)(j-i+1)*(i+j)/2 == num) count++;
	}
      }
      cout<<count<<endl;
    }else
      break;
  }
  return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Two Switches
	var A, B, C, D float64
	fmt.Scanf("%f %f %f %f", &A, &B, &C, &D)

	ans := math.Min(B, D) - math.Max(A, C)
	if ans >= 0 {
		fmt.Println(ans)
	} else {
		fmt.Println("0")
	}
}


Measured memory_bytes: 1840
# n, m, lを受け取る
n, m, l = map(int, input().split())

# 行列Aを受け取る
A = []
for i in range(n):
    A.append(list(map(int, input().split())))

# 行列Bを受け取る
B = []
for j in range(m):
    B.append(list(map(int, input().split())))

# 行列Cの元となる行列を作成
C = [[0 for a in range(l)] for b in range(n)]

# 処理実行
for c in range(n):
    for d in range(l):
        result = 0
        for e in range(m):
            result += A[c][e] * B[e][d]
        C[c][d] = result
for f in C:
    print(" ".join(map(str, f)))



Measured memory_bytes: 6888
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, A);
    IN(ll, B);
    IN(ll, N);
    auto f = [&](ll x) {
        return A * x / B - A * (x / B);
    };
    OUT(f(min(B - 1, N)));
}

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

using lint = long long;
using pint = pair<lint, lint>;
#define x first
#define y second

const int maxn = 100004, maxm = 200004, mod = 1000000007;
int n, m, s, t;
lint d1[maxn], d2[maxn];
int c1[maxn], c2[maxn], a[2*maxm], b[2*maxm], d[2*maxm];
vector<pint> g[maxn];

int sum(int x, int y) { return (x+y) % mod; }
int mul(int x, int y) { return (x*(lint)y) % mod; }
int sq(int x) { return mul(x, x); }

void dijkstra(int st, lint *d, int *c) {
    for (int i=1; i<=n; i++) d[i] = 1e17;
    c[st] = 1; d[st] = 0;

    priority_queue<pint, vector<pint>, greater<pint> > q;
    q.emplace(0ll, st);

    while (not q.empty()) {
        int k; lint di; tie(di, k) = q.top(); q.pop();
        if (di > d[k]) continue;
        d[k] = di;
        for (pint i : g[k]) {
            int nk = i.x; lint nd = di + i.y;
            if (nd < d[nk]) d[nk] = nd, c[nk] = 0, q.emplace(nd, nk);
            if (nd == d[nk]) c[nk] = sum(c[nk], c[k]);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> s >> t;

    for (int i=0; i<m; i++) {
        int x, y; lint k;
        cin >> x >> y >> k;
        a[i] = y; b[i] = x; d[i] = k;
        a[i+m] = x; b[i+m] = y; d[i+m] = k;
        g[x].emplace_back(y, k);
        g[y].emplace_back(x, k);
    }

    dijkstra(s, d1, c1);
    dijkstra(t, d2, c2);

    lint ans = 0;
    for (int i=1; i<=n; i++) if (d1[i] + d2[i] == d1[t] and d1[i] == d2[i]) ans = sum(ans, sq(mul(c1[i], c2[i])));
    for (int i=0; i<2*m; i++) if (d1[a[i]] + d[i] + d2[b[i]] == d1[t] and d1[a[i]] + d[i] > d2[b[i]] and d1[a[i]] < d[i] + d2[b[i]]) ans = sum(ans, sq(mul(c1[a[i]], c2[b[i]])));

    cout << sum(mul(c1[t], c2[s]), mod - ans) << '\n';
}

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

#define ll long long

using namespace std;

int x;

int prime(int x){
    for (int i=2; i<=sqrt(x); i++){
        if (x%i==0) return 0;
    }
    return 1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>x;
    
    for (int i=x; i; i++){
        if (prime(i)) return cout<<i,0;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
from itertools import permutations

N = int(input())
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))

ans = 0
c = 0

for p in permutations(range(N)):
    dist = 0
    x1, y1 = XY[p[0]]
    for i in p[1:]:
        x, y = XY[i]
        dist += ((x1 - x) ** 2 + (y1 - y) ** 2) ** 0.5
    ans += dist
    c += 1

print(ans / c)


Measured memory_bytes: 9456
#include<bits/stdc++.h>
using namespace std;
int n,x,arr[103],ans=1;
int main(){
    int i;
    scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        arr[i]=arr[i-1]+arr[i];
        if(arr[i]<=x) ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

LL const MAXN = 1e6 + 5, mod = 998244353;
LL frac[MAXN], invfrac[MAXN];

inline LL qpow(LL a, LL k) {
  LL re = 1;
  for (; k; k >>= 1, a = a * a % mod)
    if (k & 1) re = re * a % mod;
  return re;
}
inline LL C(LL n, LL m) { return frac[n] * invfrac[m] % mod * invfrac[n - m] % mod; }

int main() {
 // freopen("yesorno.in", "r", stdin);
//  freopen("yesorno.out", "w", stdout);
  int n, m; scanf("%d %d", &n, &m);
  if (n < m) std :: swap(n, m);
  frac[0] = 1;
  for (RI i = 1; i <= n + m; ++i) frac[i] = frac[i - 1] * i % mod;
  invfrac[n + m] = qpow(frac[n + m], mod - 2);
  for (RI i = n + m; i; --i) invfrac[i - 1] = invfrac[i] * i % mod;
  LL ans = 0;
  for (RI i = 1; i <= m; ++i)
    ans = (ans + C(n - i + m - i, n - i) * C(i + i, i) % mod) % mod;
  ans = ans * qpow(2, mod - 2) % mod * qpow(C(n + m, n), mod - 2) % mod;
  ans = (ans + n) % mod;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 15872
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 26;
const int D = 365;

int d;

int c[N];
int s[D][N];

vi ans;
vi ansbest;

int last[N];
int evaluate(const vi& t){
    memset(last, 0, sizeof last);
    int ret = 0;
    FOR(i,t.size()){
        ret += s[i][t[i]];
        last[t[i]] = i+1;

        FOR(j,N){
            ret -= c[j] * (i+1 - last[j]);
        }
    }
    return ret;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>d;
    FOR(i,N)cin>>c[i];
    FOR(i,d){
    	FOR(j,N){
    		cin>>s[i][j];
    	}
    }

    FOR(i,d){
        // bruteforce
        int best = -1, vbest = -OO;
        FOR(j,N){
            ans.pb(j);
            int v = evaluate(ans);
            if(v > vbest){
                vbest = v;
                best = j;
            }
            ans.pop_back();
        }

        ans.pb(best);
    }

    int cbest = evaluate(ans);
    ansbest = ans;

    // hill climb
    REP(i,1,10000){
        int a, b;
        a = irand(0, d-1);
        b = irand(0, N-1);

        swap(ans[a], b);
        int tv = evaluate(ans);
        // cerr << "test " << tv << endl;
        if(tv > cbest){
            cbest = tv;
            ansbest = ans;
        }else{
            // chance to still do it anyway
            int diff = cbest - tv;
            double ldiff = log(diff);
            ldiff = max(ldiff, 2.0);

            int ch = irand(1, (int)ldiff);
            if(ch == 1){ // do
                cbest = tv;
            }else{ // revert
                swap(ans[a], b);
            }
        }
    }

    FOR(i,d){
        cout << ans[i]+1 << endl;
    }


    cerr << "final: " << evaluate(ans) << endl;

    return 0;
}


Measured memory_bytes: 4024
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,d = LI()
    while 1:
        c -= b
        if c <= 0:
            break
        a -= d
        if a <= 0:
            break
    if c <= 0:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


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

const int N = 305, djq = 998244353;

char s[N];
int K, len, n, c[N], f[N][N][N], sum[N], s1[N][N], s2[N][N], ans;

int main()
{
	scanf("%s", s + 1); std::cin >> K;
	len = strlen(s + 1); n = 1;
	for (int i = 1; i <= len; i++) (s[i] == '1' ? c[n] : n)++;
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + c[i];
	f[0][0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= sum[n]; j++)
			for (int k = 0; k <= sum[n]; k++)
			{
				s1[j][k] = s2[j][k] = f[i - 1][j][k];
				if (j) s1[j][k] = (s1[j][k] + s1[j - 1][k]) % djq;
				if (j && k) s2[j][k] = (s2[j][k] + s2[j - 1][k - 1]) % djq;
			}
		for (int j = sum[i]; j <= sum[n]; j++)
			for (int k = 0; k <= j; k++)
			{
				f[i][j][k] = s1[j][k];
				if (j > c[i])
				{
					f[i][j][k] = (f[i][j][k] - s1[j - c[i] - 1][k] + djq) % djq;
					if (k) f[i][j][k] = (f[i][j][k] + s2[j - c[i] - 1][k - 1]) % djq;
				}
			}
	}
	for (int i = 0; i <= K && i <= sum[n]; i++) ans = (ans + f[n][sum[n]][i]) % djq;
	return std::cout << ans << std::endl, 0;
}

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

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

  while(1) {
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    if(x < y) {
      cout << x << " " << y << endl;
    } else {
      cout << y << " " << x << endl;
    }
  }

  return 0;
}



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

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

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int C;
        cin >> C;
        if (C != i) ans++;
    }

    if (ans <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
#define ll long long
#define P pair<int,int>
using namespace std;
const int mod = 1000000007;
//char c[MAX][MAX];
int step[MAX][MAX];
int H,W,N; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

signed main(){
    string s; cin >> s;
    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main() {

    int n, wa;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        cin >> wa;
        vec.at(wa - 1) = i;
    }
    rep(i, n){
        cout << vec.at(i) + 1 << " ";
    }
    cout << endl;

}




Measured memory_bytes: 1152
n,k = map(int,input().split(" "))

trees = []
for i in range(n):
    trees.append(int(input()))

trees = sorted(trees,reverse=True)
average = sum(trees)/len(trees)
min_dist = 1e+10
if abs(max(trees) - average) > abs(min(trees) - average):
    for i in range(n)[k-1:]:
        if min_dist > abs(trees[i] - trees[i-k+1]):

            min_dist = abs(trees[i] - trees[i-k+1])
else:
    for i in range(n-k+1):
        if min_dist > abs(trees[i+k-1] - trees[i]):
            min_dist = abs(trees[i+k-1] - trees[i])
print(min_dist)


Measured memory_bytes: 8288
#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {
    char* x = (char*)malloc(3000); 
    char* y = (char*)malloc(3000);
    scanf("%s %s", x, y);

    int N = strlen(x);
    int M = strlen(y);

    int ans[N][M];
    for (int i=0; i<N; i++)
        for (int j=0; j<M; j++)
            ans[i][j] = 0;

    // DP initialization:
    ans[0][0] = x[0] == y[0]? 1:0;
    for (int i=1; i<N; i++) {
        if (x[i] == y[0])
            ans[i][0] = 1;
        else
            ans[i][0] = ans[i-1][0];
    }      
    for (int j=1; j<M; j++) {
        if (y[j] == x[0])
            ans[0][j] = 1;
        else
            ans[0][j] = ans[0][j-1];
    }


    // DP step:
    for (int sum=2; sum<N+M-1; sum++) {
        for (int first=1; first<N; first++) {
            int second = sum - first;
            if (second < 1 || second >= M)
                continue;
            if (x[first] == y[second])
                ans[first][second] = ans[first-1][second-1] + 1;
            else
                ans[first][second] = max(ans[first-1][second], ans[first][second-1]);
        }
    }

    string ret = "";
    int i = N-1;
    int j = M-1;
    while (i >= 1 && j >= 1) {
        if (x[i] == y[j]) {
            ret = x[i] + ret;
            i--;
            j--;
        } else {
            if (ans[i-1][j] == ans[i][j]) {
                i--;
            } else {
                j--;
            }
        }
    }

    if (ret.length() != ans[N-1][M-1]) {
        if (i == 0)
            ret = x[0] + ret;
        else
            ret = y[0] + ret;
    }
        
    cout << ret << endl;

    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int a,b;
    
    cin >> a >> b;
    
    if(a >= 1 and a <= 9 and b >= 1 and b <= 9){
        cout << a * b << endl;
    } else {
        cout << "-1" << endl;
    }
}

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

void solve(long long N, long long M, std::vector<long long> a,
           std::vector<long long> b, std::vector<long long> c) {
    vector<vector<ll>> dist(N, vector<ll>(N, 1e9));
  for (int i = 0; i < N; i++) {
    dist[i][i] = 0;
  }

  for (int i = 0; i < M; i++) {
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  ll res = M;
  for (int i = 0; i < M; i++) {
    bool inPath = false;
    for (int j = 0; j < N; j++) {
      if (dist[j][a[i]] + c[i] == dist[j][b[i]]) {
        inPath = true;
      }
    }
    if (inPath) {
      res--;
    }
  }
  cout << res << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(M);
  std::vector<long long> b(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    a[i]--;
    b[i]--;
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(a), std::move(b), std::move(c));
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <string>
using namespace std;

int main(void)
{
    //float f;
    //string s;
    //int m,n,o;
    //vector <float> f(10);
    //char a,b,c;
    int i=0,sum=0;
    long long int m,n,o,total=0;
    cin>>m>>n>>o;
    if(m>=o&&n>=o)
    {
        if(m%o==0) total++;
        total+=n/o-m/o;
    }
    else if(n>=o)
    {
        total+=n/o;
        if(m==0) total++;
    }
    else if(m==0) total++;
    cout<<total;
    return 0;
}



Measured memory_bytes: 256
n=int(input())
h=[int(i) for i in input().split()]

ans=0
for i in range(len(h)-1):
    while h[i]!=0:
        
        for j in range(i+1,len(h)):
            if h[j]<h[i]:
                break
            else:
                h[j]-=1
        h[i]-=1
        ans+=1
ans += h[-1]
print(ans)
            

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    jct = {'AC': 0,
           'WA': 0,
           'TLE': 0,
           'RE': 0}
    for i in range(N):
        s = input()
        jct[s] += 1

    print(f'AC x {jct["AC"]}')
    print(f'WA x {jct["WA"]}')
    print(f'TLE x {jct["TLE"]}')
    print(f'RE x {jct["RE"]}')



if __name__ == '__main__':
    solve()


Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,k,d,l,x;
    int c=1,sum=0;
    cin>>n>>x;
    for(i=1;i<=n;i++)
    {
        cin>>l;
        sum=sum+l;
        if(sum>x)
        {
            break;
        }
        c++;

    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
d = dict()
for s in S:
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
l = sorted(d.items(), key=lambda x: x[1], reverse=True)
maxv = l[0][1]
res = []
for x in l:
    if x[1] == maxv:
        res.append(x[0])
for x in sorted(res):
    print(x)


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

constexpr int INF = 1<<30;

int main(){
    int n;
    cin >> n;
    vector<int> a, b(n);
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    int ans = INF;
    for(int t=0;t<2;t++){
        int cnt = 0;
        a = b;
        for(int i=0;i<n-2;i++){
            if((i+t)%2){
                if(a[i]<a[i+1]){
                    cnt++;
                    if(a[i]<a[i+2]) swap(a[i],a[i+1]);
                    else swap(a[i+1],a[i+2]);
                }
            }
            else{
                if(a[i]>a[i+1]){
                    cnt++;
                    if(a[i]>a[i+2]) swap(a[i],a[i+1]);
                    else swap(a[i+1],a[i+2]);
                }
            }
        }
        if((n-2+t)%2){
            if(a[n-2]<a[n-1]) cnt++;
        }else{
            if(a[n-2]>a[n-1]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3680
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder
import kotlin.math.absoluteValue
import kotlin.math.min

object CMain{
    fun solve(){
        val x = nextLong().absoluteValue
        val k = nextLong()
        val d = nextLong()

        if(x / k >= d){
            println(x - k * d)
        }else{
            val rem = k - x / d
            if(rem % 2 == 0L){
                println(x % d)
            }else{
                println(d - x % d)
            }
        }
    }





    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun NextDouble() = next().toDouble()
}

fun main(){
    CMain.solve()
}



Measured memory_bytes: 33732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		if (N % Math.max(H, W) == 0) {
			System.out.print(N / Math.max(H, W));
		} else {
			System.out.print(N / Math.max(H, W) + 1);
		}
	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll arr[n+1];
    for(ll i=1;i<=n;i++)
        cin>>arr[i];
        ll dp[n+1];
        dp[0]=0;
        dp[1]=0;
        dp[2]=abs(arr[1]-arr[2]);
        for(ll i=3;i<=n;i++)
        {
            ll min1=1000000002;
            for(ll j=k;j>=1;j--)
            {
                if(i-j>=1)
               min1=min(abs(arr[i]-arr[i-j])+dp[i-j],min1);
               else
                continue;
            }
        dp[i]=min1;
        }
    cout<<dp[n];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int x, a;
	cin >> x >> a;
	cout << (x < a ? 0 : 10) << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        string s; cin >> s;
        string abc = "ABC";
        int cnt = 0;
        for (int x = 0; x <= n-3; ++x){
            string c = s.substr(x, 3);
            //cout << c << endl;
            if (c == abc) cnt++;
        }
        cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3560
from math import sqrt


def one_twoone(a: int, b: int)->bool:
    c = int(str(a) + str(b))
    sq = int(sqrt(c))
    return c == sq * sq


if __name__ == "__main__":
    a, b = map(int, input().split())
    yes = one_twoone(a, b)
    print('Yes' if yes else 'No')


Measured memory_bytes: 3060
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            System.out.println("ABC" + s);
        }
    }
}


Measured memory_bytes: 22612
def insertion_sort(arr)
  puts arr.join("\s")
  1.upto(arr.size - 1) do |i|
    v = arr[i]
    j = i - 1
    while j >=0 && arr[j] > v
      arr[j+1] = arr[j]
      j -= 1
    end
    arr[j+1] = v
    puts arr.join("\s")
  end
end

n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
insertion_sort(arr)

Measured memory_bytes: 8836
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
#define mpi map<ll,ll>
#define  si set<ll>
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define reP(i,a,n) for(ll i=a;i<=n;i++)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define st string
#define sz size()
#define case(i,n) Case<<" "<<i<<": "<<n<<endl;
#define tc ll t;cin>>t;while(t--)
int main()
{
    ll n;cin>>n;
    for(ll i=1;i<10;i++)
    {
        if(n%i==0 and (n/i)<10)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3632
/*
 *
 */
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

//int a[100005];
pair<int, bool> p[100005];

int main(){
    //freopen("c2.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int ai;
        cin >> ai;
        p[i].first = ai;
        p[i].second = i&1;  // 0: even, 1: odd
    }
    sort(p, p + n);

    int total = 0;
    for (int i = 0; i < n; ++i) {
        if((p[i].second && !(i&1)) || (!p[i].second && (i&1))) {
            total++;
        }
    }
    cout << total / 2 << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b, x;  
  	double r;
  
  	cin >> a >> b;
  	x = (a+b)/2;
  	r = ((double)a+(double)b)/2.f;

  	if(r-x == 0)
    {
     cout << x <<endl; 
    }
  else
  {
   cout << x+1 << endl; 
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
const int MaxN = 1e6;
typedef long long LL; 

int a[MaxN + 5];
LL b[MaxN + 5]; 
vector <LL> need;
int n, K; 
int main() 
{
	while(~scanf("%d%d", &n, &K)) {
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]); 
		for (int i = 1; i <= n; i++) {
			LL sum = 0;
			for (int j = i; j <= n; j++) {
				sum += a[j]; need.push_back(sum);
			}
		}
		LL res = 0;
		for (int bit = 59; bit >= 0; bit--) {
			int t = 0, size = need.size();
			for (int j = 0; j < size; j++) if(need[j] & (1LL << bit)) t++;
			if(t < K) continue; vector <LL> tmp; tmp.clear(); 
			for (int i = 0; i < size; i++) {
				if(need[i] & (1LL << bit)) tmp.push_back(need[i]);
			}
			need = tmp; res += (1LL << bit);
		}
		printf("%lld\n", res);
	}
	return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dy[4]={0,-1,0,1};
int dx[4]={-1,0,1,0};

int H,W;
int A[1000][1000];

int type[1000][1000];

signed main(){
    scanf("%lld%lld",&H,&W);
    vpint vec;
    rep(i,H){
        rep(j,W){
            scanf("%lld",&A[i][j]);
            vec.pb({A[i][j],i*W+j});
        }
    }
    sort(all(vec));
    rep(i,vec.size()){
        int h=vec[i].fi;
        int y=vec[i].se/W,x=vec[i].se%W;

        set<int>lis;
        bool flag=false;
        rep(d,4){
            int ny=y+dy[d],nx=x+dx[d];
            if(ny<0||ny>=H||nx<0||nx>=W)continue;
            if(A[ny][nx]<h){
                if(type[ny][nx]==-1)flag=true;
                else lis.insert(type[ny][nx]);
            }
        }
        if(flag||lis.size()>1){
            type[y][x]=-1;
        }
        else if(lis.size()==1){
            type[y][x]=*lis.begin();
        }
        else{
            type[y][x]=y*W+x;
        }
    }

    int ans=0;
    rep(i,H)rep(j,W)if(type[i][j]==-1)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 34132
/*
  C - 一次元リバーシ / 1D Reversi
  <http://abc047.contest.atcoder.jp/tasks/arc063_a>
  感想
  ・文字列の長さはstrlen。
  ・strcmpは"文字列"同士の比較。そのため、引数はポインタをとる。
  ・単純な"文字"の比較なら、引き算でできる。
*/

#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
  char S[100000];
  int i;
  int c = 0;

  scanf("%s", S);
  for( i=0; i<strlen(S)-1; i++ ){
    if( (S[i]-S[i+1]) != 0 ){
      c++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[0]*n
a=list(map(int,input().split()))
left=a[0]
right=sum(a[1::])
t=abs(right-left)
for i in range(1,n):
  left+=a[i]
  right-=a[i]
  t=min(t,abs(right-left))
print(t)

Measured memory_bytes: 27596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<numeric>

#define _GLIBCXX_DEBUG
#define chinko long long

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> p(n);
	for(int i=0;i<n;i++) p[i]=i;
	
	int ans=0;
	
	bool visited[8][8]={};	
	
	for(int i=0;i<m;++i){
		int a,b;
		cin>>a>>b;
		a--; b--;
		visited[a][b]=visited[b][a]=true;
	}
	
	do{
		bool anko=true;
		for(int i=0;i<n-1;++i){
			if(visited[p[i]][p[i+1]]) continue; 
			anko=false; 
			break;
		}
		if(anko) ++ans;
	}while(next_permutation(p.begin()+1,p.end()));
	
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

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

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

	sort(a, a + n); sort(b, b + n);

	if (n % 2 == 0) {
		int l = a[n / 2] + a[(n - 1) / 2], r = b[n / 2] + b[(n - 1) / 2];
		cout << 2 * (r / 2) - 2 * ((l + 1) / 2) + 1 + (l % 2) + (r % 2);	
	}
	else {
		cout << b[n / 2] - a[(n - 1) / 2] + 1;
	}
}


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

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

static const int INF = 1145141919;
const long long INFL = 1LL<<60;

int main()
{
	int n, k;
	cin >> n >> k;
	long long int h[110000];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	long long int dp[110000];
	for (int i = 0; i < 110000; ++i)
	{
		dp[i] = INFL;
	}
	dp[0] = 0;
	for (int i = 1; i < n; ++i)
	{
		for (int j = 1; j <= min(k, i); ++j)
		{
			chmin(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
//const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}

int main() {
	ll N, K;

	cin >> N >> K;
	
	vector<ll> h(N);
	ll sum = 0;
	rep(i, N) {
		cin >> h[i];
		if (h[i] >= K)
			sum++;
	}


	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<stdio.h>
#include<stack>
using namespace std;

int main() {
	int n, m, s;
	cin >> n >> m >> s;
	int limit = 1000000000;
	if (n == m) {
		for (int i = 0; i < n - 1; i++) {
			cout << s << ' ';
		}
		cout << s;
		return 0;
	}
	if (s == limit) {

		for (int i = 0; i < m; i++) {
			cout << limit << ' ';
		}
		for (int i = 0; i < n - m - 1; i++) {
			cout << 1 << ' ';
		}
		cout << 1;
		return 0;
	}
	for (int i = 0; i < m; i++) {
		cout << s << ' ';
	}
	for (int i = 0; i < n - m - 1; i++) {
		cout << limit << ' ';
	}
	cout << limit;
	return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <atcoder/all>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using namespace atcoder;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/* g++ a.cpp -std=c++14 -I ../ */
const int MAX_A = 300005;
int op(int a, int b) { return max(a, b);}
int e() { return 0;}

signed main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    segtree<int, op, e> dp(MAX_A);
    rep(i, n){
        /* xを最後に追加したときの長さの最大値  */
        int x = a[i];
        int l = x-k, r = x+k+1;
        l = max(l, 0);
        r = min(r, MAX_A);
        int now = dp.prod(l, r)+1;
        dp.set(x, now);
    }
    int ans = dp.prod(0, MAX_A);
    cout << ans << endl;
    return 0;
}

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

int main(){
	int a, b;
	cin >> a >> b;
	int res1, res2, res3;
	res1=a+a-1;
	res2=b+b-1;
	res3=a+b;
	cout << max(max(res1, res2), res3) << endl;

}

Measured memory_bytes: 256