akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//const int maxx = 100010;
const int inf = 0x3f3f3f3f;
int n,m,sum=0,cnt=0,flag=0,x1,y5;
char a[10][10];
int vis[10][10];
int dis[2][2]= {{0,1},{1,0}};
void dfs(int p,int q)
{
    cnt++;
    if(cnt==sum)
    {
        flag=1;
        printf("Possible\n");
        return;
    }
    for(int i=0; i<2; i++)
    {
        if(a[p+dis[i][0]][q+dis[i][1]]=='#'&&p+dis[i][0]<=n&&q+dis[i][1]<=m)
        {
            dfs(p+dis[i][0],q+dis[i][1]);
            cnt--;
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            scanf(" %c",&a[i][j]);
            if(a[i][j]=='#') sum++;
        }
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            if(a[i][j]=='#')
            {
                dfs(i,j);
                if(flag==0) printf("Impossible\n");
                return 0;
            }

    return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がline1, 2行目がline2, …に入る
  var tmp = input.split("\n");
  var line0 = tmp[0].split(" ");
  //var line1 = tmp[1].split(" ");
  //var line2 = tmp[2].split(" ");
  //var line3 = tmp[3].split(" ");

  var input1 = Number(line0[0]);
  var input2 = Number(line0[1]);
  var input3 = Number(line0[2]);
  var a = input1;
  var b = input2;
  var c = input3;

  var ans = 0;

  //console.log( line0 +" "+ a +" "+ b +" "+ c)

  var min = Math.min.apply(null, line0);
  var max = Math.max.apply(null, line0);
  
  //line0.splice(index, 1);
  




  console.log(max - min);

  


}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 25288
void main() {
    int n = readln.chomp.to!int;
    writeln(n * (n + 1) / 2);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
key = [False]*n
for i in range(n):
    if i >= k:
        if t[i] == t[i-k] and key[i-k] == False:
            key[i] = True
            continue
    if t[i] == "r":
        ans += p
    if t[i] == "s":
        ans += r
    if t[i] == "p":
        ans += s
print(ans)

Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 

using namespace std;

int main() {
    int N, Y;
    int count_x = -1;
    int count_y = -1;
    int count_z = -1;
    cin >> N >> Y;

    for (int x = 0; x <= N; x++) {
        for (int y = 0; x + y <= N; y++) {
            int z = N - x - y;
            int total = 10000 * x + 5000 * y + 1000 * z;
            if (total == Y) {
                count_x = x;
                count_y = y;
                count_z = z;
            }
        }
    }

    cout << count_x << " " << count_y << " " << count_z << endl;
    return 0;
}


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

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

    if (S == "AAA"){
        cout << "No" << endl;
    } else if (S == "BBB"){
        cout << "No" << endl;
    } else {
        cout << "Yes" <<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

/* Prototype declaration */
int solve(int, int);

/* Global variables */
int n, A[20], m[200];

int main() {
  int i, q;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &m[i]);
    if( solve(0, m[i]) ) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int solve(int i, int m) {
  if( m == 0 ) return 1;
  if( i >= n ) return 0;

  if( solve(i + 1, m) || solve(i + 1 ,m - A[i]) ) return 1;
  else return 0;
}

Measured memory_bytes: 580
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()


# ===CODE===
def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    n, m = map(int, input().split())

    d = []
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        d.append((a, b))

    d.reverse()
    ans = []
    a = n*(n-1)//2
    que = UnionFind(n)

    for i in range(m):
        ans.append(a)
        x,y = d[i]
        if not que.same(x,y):
            a -= que.size(x)*que.size(y)
            que.union(x,y)

    ans.reverse()
    for tmp_a in ans:
        print(tmp_a)


if __name__ == '__main__':
    main()


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

int main () {
  int N;
  string n;
  cin >> N;
  for (int i=0;i<N;i++) {
    cin >> n;
    if ( n == "Y" ) {
      cout << "Four" << endl;
      break;
    }
    if ( i == N-1 ) {
      if ( n != "Y" ) {
      cout << "Three" << endl;}
    }
  }
}

Measured memory_bytes: 3628
#coding:UTF-8
def iS(N,A,g,cnt):
    for i in range(g,N):
        v=A[i]
        j=i-g
        while j>=0 and A[j]>v:
            A[j+g]=A[j]
            j=j-g
            cnt+=1
        A[j+g]=v
    return(cnt)


def sS(N,A):
    cnt=0
    G=[]
    h=1
    while h <= N:
        G.append(h)
        h=3*h+1
    m=len(G)
    print(m)
    G.reverse()
    for i in range(m):
        cnt=iS(N,A,G[i],cnt)
    for i in range(len(G)):
        G[i]=str(G[i])
    print(" ".join(G))
    print(cnt)
    for i in range(len(A)):
        print(A[i])

        
if __name__=="__main__":
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sS(N,A)

Measured memory_bytes: 47424
def is_palindrome(s):
    for i in range(len(s) // 2):
        if s[i] != s[-i - 1]:
            return False
    return True


s = input()
n = len(s)
ans = "Yes"
if (
    not is_palindrome(s)
    or not is_palindrome(s[0 : (n - 1) // 2])
    or not is_palindrome(s[(n + 3 - 1) // 2 :])
):
    ans = "No"
print(ans)


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

using namespace std;

const int MAX_NOMBRE = 100, MAX_CAILLOU = 1e5+42;

int main()
{
    int nbCoup, nbCaillou;
    cin >> nbCoup >> nbCaillou;

    int coup[nbCoup];

    for(int iCin = 0; iCin < nbCoup; iCin++) {
        cin >> coup[iCin];
    }

    int vainqueur[nbCaillou][2];

    for(int fin = 0; fin < coup[0]; fin++) {
        vainqueur[fin][0] = 0;
        vainqueur[fin][1] = 0;
    }

    for(int caillou = coup[0]; caillou <= nbCaillou; caillou++) {
        for(int joueur = 0; joueur < 2; joueur++) {
            int meilleur = 0;
            for(int idCoup = 0; idCoup < nbCoup; idCoup++) {
                if(coup[idCoup] <= caillou) {
                    meilleur = max(meilleur, 1-vainqueur[caillou-coup[idCoup]][1-joueur]);
                }
            }
            vainqueur[caillou][joueur] = meilleur;
        }
    }

    if(vainqueur[nbCaillou][0]) {
        cout << "First";
    }
    else {
        cout << "Second";
    }

    return 0;
}


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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 300333;
char s[300333];

int main() {
    ios::sync_with_stdio(false);

    scanf("%s", s + 1);
    s[0] = '1';
    int n = strlen(s);
    s[n] = '1';
    ++n;

    static ll d[N][2][3];
    d[1][1][0] = 1;
    for (int i = 2; i <= n; ++i) {
        if (s[i-1] == '0' || s[i-1] == '?') {
            (d[i][0][0] = d[i-1][0][0] + d[i-1][1][0]) %= MOD;
            (d[i][0][1] = d[i-1][0][1] + d[i-1][1][1]) %= MOD;
            (d[i][0][2] = d[i-1][0][2] + d[i-1][1][2]) %= MOD;
        }
        if (s[i-1] == '1' || s[i-1] == '?') {
            if (i % 2 == 0) {
                (d[i][1][0] = d[i-1][0][0]) %= MOD;
                (d[i][1][1] = d[i-1][1][0] + d[i-1][1][1] + d[i-1][0][1]) %= MOD;
                (d[i][1][2] = d[i-1][1][2] + d[i-1][0][2]) %= MOD;
            } else {
                (d[i][1][0] = d[i-1][0][0] + d[i-1][1][0]) %= MOD;
                (d[i][1][1] = d[i-1][0][1]) %= MOD;
                (d[i][1][2] = d[i-1][0][2] + d[i-1][1][1] + d[i-1][1][2]) %= MOD;
            }
        }
    }
    cout << d[n][1][2] << "\n";

    return 0;
}


Measured memory_bytes: 14592
use proconio::input;

fn main() {
  
  let mut _n : usize ;
  let mut _d : String ;
 

  

    input! {
     
      mut n : usize ,
      mut d : String ,
    }

     let  length = d.len();

      if length > n{
        let s = &d[0..n];
      println!("{}...",s);

     }else   {

      println!("{}",d);

     }

   
    
}



Measured memory_bytes: 2132
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    x, y = MI()
    to_x_y = [[], []]
    deleted = False
    for i,s in enumerate(S):
        if s == "T":
            S = S[i:]
            deleted = True
            break
        else:
            x -= 1
    if not deleted:
        S=""
    toY = False
    contin = False
    #run length 
    for i, s in enumerate(S):
        if s == "F":
            if contin:
                to_x_y[toY][-1] += 1
            else:
                to_x_y[toY].append(1)
                contin = True
        else:
            toY = not toY
            contin = False

    #print((x,y),*to_x_y,sep="\n")

    #xについてdp
    now_x = set([0])
    for distanse in to_x_y[0]:    
        next_x = set()
        for i, X in enumerate(now_x):
            next_x.add(X + distanse)
            next_x.add(X - distanse)
        now_x = next_x
    
    #yについてdp
    now_y = set([0])
    for distanse in to_x_y[1]:    
        next_y = set()
        for i, Y in enumerate(now_y):
            next_y.add(Y + distanse)
            next_y.add(Y - distanse)
        now_y = next_y

    #print(now_x,now_y)
    print("YNeos"[x not in now_x or y not in now_y::2] )


if __name__ == '__main__':
    main()

Measured memory_bytes: 47836
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
hs = Hash.new(0)
a.each do |x|
  hs[x] += 1
end

res = 0
hs.each do |_, v|
  res += v * (v - 1) / 2
end

n.times do |k|
  puts res - hs[a[k]] + 1
end


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

int main(void) {
	int N, M; cin >> N >> M;
	vector<int> A(N);

	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}

	double border = sum / (4.0 * M);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] >= border) cnt++;
	}

	if (cnt >= M) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3616
//==========================================
// ABC132b Ordinary NUmber
//
// 2019/08/16
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n;
  cin >> n;

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

  int cnt=0;
  for(int i=1; i<n-1; i++)
  {
    if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1]))
    {
      cnt++;
    }
  }
  cout << cnt << endl;


  return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
S = LIST()
T = LIST()

dp = []
for i in range(N+1):
	dp.append([0]*(M+1))
# print(dp)

for i in range(1, N+1):
	for j in range(1, M+1):
		if S[i-1] == T[j-1]:
			dp[i][j] = (1 + dp[i-1][j] + dp[i][j-1]) % mod
		else:
			dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod
ans = (dp[-1][-1] + 1) % mod
print(ans)


Measured memory_bytes: 94296
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;


int main()   {
    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, 1000);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(k);
        vector<int> a;
        forr(i,0,n) {
            readint(kk); a.push_back(kk);
        }
        sort(a.begin(), a.end());
        cout << accumulate(a.begin(), a.begin()+k, 0) << endl;
    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 3636
//ΔAGC034E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 2222;
const int inf = 1e9;
int n,a[N],b[N],t[N],f[N],ans;
char s[N];
vector<int> v[N];
void dfs(int u,int fa){
	int i,x,o=0;
	b[u]=0;
	t[u]=0;
	for(i=0;i<v[u].size();i=i+1){
		x=v[u][i];
		if(x==fa)
			continue;
		dfs(x,u);
		t[x]+=b[x];
		f[x]+=b[x];
		b[u]+=b[x];
		t[u]+=t[x];
		o=max(o,f[x]+t[x]);
	}
	if(o>t[u])
		f[u]=o-t[u];
	else
		f[u]=t[u]&1;
	b[u]+=a[u];
}
int main()
{
	int i,x,y;
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n;i=i+1)
		a[i]=s[i]-'0';
	for(i=1;i<n;i=i+1){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	ans=inf;
	for(i=1;i<=n;i=i+1){
		dfs(i,0);
		if(!f[i])
			ans=min(ans,t[i]);
	}
	if(ans>=inf)
		ans=-1;
	else
		ans/=2;
	cout<<ans;
	return 0;
}

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

using namespace std;

int main(){

	int n;cin >> n;
	int p = 1e9+7;
	vector<vector<int>> arr(n,vector<int>(n,0));
	int mask = (1<<n);
	vector<vector<int>> dp(n,vector<int>(mask,0));
	for(int i = 0;i<n;i++){
		for(int j = 0;j<n;j++){
			cin >> arr[i][j];
		}
	}
	for(int i = 0;i<n;i++){
		if(arr[n-1][i] == 0)continue;
		dp[n-1][(1<<i)] = 1;
	}
	int ans = 0;
	for(int i = n-2;i>=0;i--){
		for(int j = n-1;j>=0;j--){
			if(arr[i][j] == 0)continue;
			for(int k = 0;k<mask;k++){
				if(((k)&(1<<j)) == 0){
					dp[i][(1<<j)+(k)] = (dp[i][(1<<j)+(k)]+dp[i+1][k])%p;
				}
			}
		}
	}
	for(int i = 0;i<mask;i++){
		ans+=dp[0][i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 180608
import java.util.Scanner;

public class Main {
	public static void main(String[] atgs){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){
			//A???????????????
			int A = sc.nextInt();
			//??????????????????
			String operator = sc.next();
			//B???????????????
			int B = sc.nextInt();
			//????????¨???????????°??????
			if(operator.equals("?")){
			 break;
			}
			//????¨??¨????
			switch(operator){
			case "+":
				System.out.println(A + B);
				break;
			case "-":
				System.out.println(A - B);
				break;
			case"*":
				System.out.println(A * B);
				break;
			case"/":
				System.out.println(A / B);
				break;

			default:
				break;
				}
		}
	}
}

Measured memory_bytes: 26108
n, m, k = map(int, input().split())
is_black = False

for i in range(n+1):
  for j in range(m+1):
    if i * (m - j) + j * (n - i) == k:
      is_black = True
      break

if is_black:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
b = inpl()
dif = sum(a) - sum(b)
if dif < 0:
    print(-1)
else:
    m_cnt = 0
    m_num = 0
    p = []
    for i in range(n):
        if a[i] - b[i] > 0:
            p.append(a[i] - b[i])
        elif a[i] - b[i] < 0:
            m_cnt += 1
            m_num += b[i] - a[i]
    cnt = 0
    p.sort()
    while m_num > 0:
        cnt += 1
        tmp = p.pop()
        m_num -= tmp
    print(m_cnt + cnt)

Measured memory_bytes: 75932
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, a, b = map(int, input().split())
sum = 0
sumsum = 0
for i in range(1, n+1):
    x = str(i)
    sum = 0
    for j in range(len(x)):
        sum += int(x[j])

    if a <= sum and sum <= b:
        sumsum += i
print(sumsum)


Measured memory_bytes: 3832
import scala.io.StdIn.{readLine, readInt};
import scala.collection.immutable.Queue;
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val graph: Array[List[Int]] = new Array[List[Int]](n + 1);
        for (i <- (1 to n)) {
            graph(i) = readLine.split(" ").drop(2).map(_.toInt).toList;
        }
        val ret: Array[Int] = bfs(1, n + 1, graph);
        for (i <- (1 to n)) {println("%d %d".format(i, ret(i)))}
    }
    def bfs(start: Int, size: Int, graph: Array[List[Int]]): Array[Int] = {
        val status = new Array[Int](size).map(a => -1);
        def go(q: Queue[Int]): Unit = {
            q.dequeueOption match {
                case None => ();
                case Some((src, rest)) => {
                    val newQ = graph(src).foldLeft(rest) { (nq, dst) =>
                        if (status(dst) == -1) {
                            status(dst) = status(src) + 1;
                            nq.enqueue(dst);
                        } else {
                            nq;
                        }
                    }
                    go(newQ);
                }
            }
        }
        status(start) = 0;
        go(Queue[Int](start));
        status;
    }
}


Measured memory_bytes: 44628
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 20000
typedef pair<int,int> pii;
 
map<pii,int> id;
map<int,pii> mp;
int color[MAX][2],tmp[MAX][2];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
 
struct State{
    int v,p,col;
    State(int v,int p,int col) :
	v(v),p(p),col(col) {}
};
 
bool bfs(int v,int p){
    queue<State> Q;
    Q.push(State(v,p,0));
    Q.push(State(v+1,1-p,1));
   
    while(!Q.empty()){
	State s = Q.front(); Q.pop();
	pii np = mp[s.v];
	if(color[s.v/2][s.p] >= 0){
	    if(color[s.v/2][s.p] != s.col){
		return false;
	    }
	    continue;
	}
	color[s.v/2][s.p] = s.col;
	for(int i = 0 ; i < 4 ; i++){
	    int nx = np.first+dx[i],ny = np.second+dy[i];
	    if(id.find(pii(nx,ny)) != id.end()){
		int x = id[pii(nx,ny)]%2;
		if(id[np]/2 == id[pii(nx,ny)]/2){
		    Q.push(State(id[pii(nx,ny)],1-s.p,1-s.col));
		}else{
		    Q.push(State(id[pii(nx,ny)],(x&1?1:0),s.col));
		}
	    }
	}
    }
    return true;
}
 
void init(){
    mp.clear();
    id.clear();
    memset(color,-1,sizeof(color));
}
 
int main(){
    int N,x,y;
    char ch;
    while(cin >> N,N){
	init();
	for(int i = 0 ; i < N ; i++){
	    cin >> x >> y >> ch;
	    int j = i*2;
	    if(ch == 'x'){
		mp[j] = pii(x,y); mp[j+1] = pii(x+1,y);
		id[pii(x,y)] = j; id[pii(x+1,y)] = j+1;
	    }else{
		mp[j] = pii(x,y); mp[j+1] = pii(x,y+1);
		id[pii(x,y)] = j; id[pii(x,y+1)] = j+1;
	    }
	}
	bool can = true;
	for(int i = 0 ; i < 2*N ; i+=2){
	    if(color[i/2][0] >= 0) continue;
	    for(int j = 0 ; j < N ; j++){
		for(int k = 0 ; k < 2 ; k++){
		    tmp[j][k] = color[j][k];
		}
	    }
	    if(!bfs(i,0)) can = false;
	    if(!can){
		can = true;
		for(int j = 0 ; j < N ; j++){
		    for(int k = 0 ; k < 2 ; k++){
			color[j][k] = tmp[j][k];
		    }
		}
		if(!bfs(i,1)){
		    can = false;
		    break;
		}
	    }
	}
	cout << (can ? "Yes" : "No") << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  rep(i,N) cin>>vec.at(i);
  sort(vec.begin(),vec.end());
  int count=1;
  int ans,num;
  ans=num=0;
  rep(i,N-1){
    if(i+ans>N-1||vec.at(i)+2<vec.at(i+ans)) continue;
    for(int j=i;j<N-1;j++){
      if(vec.at(i)>=vec.at(j+1)-2) {
        count++;
        if(vec.at(i)==vec.at(j+1)) num++;
      }
      else {
        ans=max(ans,count);
        count=1;
        i+=num;
        num=0;
        break;
      }
    }
    ans=max(ans,count);
    count=1;
  }
  cout<<max(ans,count)<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;
typedef pair<int, char> ICpair;

int N, K;


int main() {
	ios_base::sync_with_stdio(false);
	cin >> N >> K;
	LL ret = 0LL;
	ffor (a, 1, N + 1) {
		int toAdd = K - a % K;
		if ((2 * toAdd) % K != 0)
			continue;
		LL mul = N / K;
		LL cnt = 0LL;
		if (mul * K + toAdd <= N)
			cnt = mul + 1;
		else
			cnt = mul;
		
		ret += cnt * cnt;
	}
	
	cout << ret << endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

int color[9];

void solve()
{
    int N;
    cin >> N;
    REP0(i, N)
    {
        int a;
        cin >> a;
        color[min(a / 400, 8)]++;
    }
    int ans = 0;
    REP0(i, 8)
    {
        ans += (color[i] > 0);
    }
    cout << max(ans, 1) << " " << ans + color[8] << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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

int main(int argc, char const* argv[]) {
	const double PI = 3.14159265358979;
	double r;
	std::cin >> r;
	std::cout << std::fixed << std::setprecision(8);
	std::cout << r * r * PI << " " ;
	std::cout << 2 * r * PI << std::endl ;
	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >>n; int ans=0;
  vector<vector<int>>v(n,vector<int>(2*n-2,0));
  for(int i=0; i<n; i++){
    int a; cin >>a;
    for(int j=0; j<a; j++){
      cin >>v[i][2*j] >>v[i][2*j+1];
    }
  }
  for(int i=1; i<(1<<n); i++){
    bool shit=1; vector<bool>b(n,0);
    int ii=i,sum=0;
    for(int j=0; j<n; j++){
      if(!ii) break;
      if(ii%2){b[j]=1; sum++;}
      ii/=2;
    }
    for(int j=0; j<n; j++){
      for(int k=0; k<n-1; k++){
        if(v[j][2*k]&&b[j]&&b[v[j][2*k]-1]!=v[j][2*k+1])
        {shit=0; break;}
      }
      if(!shit) break;
    }
    if(shit) ans=max(ans,sum);
  }
  cout <<ans;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int sum = 0;
  sort(a.begin(), a.end());
  for(int i = 0; i < k; i++){
    sum += a[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int R, G, B, N;
	cin >> R >> G >> B >> N;

	int kotae = 0;
	rep(i, 3001) {
		rep(j, 3001) {
			int k = i * R + j * G;
			if (N >= k && (N - k) % B == 0) kotae++;


		}
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define oo 999999999

using namespace std;

int n,m;
int a[N],b[N];
int l=oo,r;
int ans;

bool check(int);

int main(){
	scanf("%d",&n);m=2*n-1;
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]),l=min(l,a[i]),r=max(r,a[i]);	
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)) l=mid+1,ans=mid;
		else r=mid-1;
	}
	cout<<l-1<<endl;
	return 0;
}
bool check(int x){
	memset(b,0,sizeof(b));	
	int z=oo,sum=0,y;
	for(int i=1;i<=m;i++)
		if(a[i]>=x)
			b[i]=1,sum++;
	for(int i=n;i>1;i--)
		if(b[i]==b[i-1]&&z>n-i){	
			z=n-i;
			y=b[i];
		}
	for(int i=n;i<m;i++)
		if(b[i]==b[i+1]&&z>i-n){
			z=i-n+1;
			y=b[i];
		}
	if(z==oo)
		return sum<m-sum?false:true;
	return y?true:false;
}


Measured memory_bytes: 6528
from functools import lru_cache

n = int(input())
A = [int(i) for i in input().split()]

@lru_cache(maxsize=1000000)
def solveBruteForce(p, t):
    if t == 0:
        return True
    elif t < 0:
        return False
    elif p == n:
        return False
    elif solveBruteForce(p+1, t-A[p]):
        return True
    elif solveBruteForce(p+1, t):
        return True
    else:
        return False

M = int(input())
q = [int(i) for i in input().split()]
for mi in range(M):
    if solveBruteForce(0, q[mi]):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 12312
import bisect

n,k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1-i):
    if i > n-j:
      break
    now = sorted(v[:i]+v[n-j:])
    tmp = min(k-i-j,bisect.bisect_left(now, 0))
    ans = max(ans,sum(now[tmp:]))
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<long>a(n);
  for(int i=0; i<n; i++)cin >> a[i];
  cout << max(long(-1), n-accumulate(a.begin(), a.end(), 0L)) << endl;
  return 0;
}


Measured memory_bytes: 10732
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<utility>
#include<algorithm>

using namespace std;

typedef double Real;
typedef complex<Real> Point;
typedef complex<Real> Vector;
typedef pair<Point,Point> Line;
typedef pair<Point,Point> Segment;
typedef vector<Point> Polygon;

const Real eps=1e-8;
const Real PI=acos(-1.0);

Real doP(Point a,Point b){
	return (conj(a)*b).real();
}

Real crP(Point a,Point b){
	return (conj(a)*b).imag();
}

Point proj(Point p,Vector b){
	return b*doP(p,b)/norm(b);
}

Point proj(Point p,Line l){
	Point p1=l.first,p2=l.second;
	return p1+proj(p-p1,p2-p1);
}

Point refl(Point p,Vector b){
	Point h=proj(p,b);
	return h*2.0-p;
}

Point refl(Point p,Line l){
	Point h=proj(p,l);
	return h*2.0-p;
}

Real arg(Point p){
	return atan2(p.imag(),p.real());
}

Polygon reflPoly(Polygon poly,Line l){
	Polygon res;
	for(int i=0;i<poly.size();i++){
		res.push_back(refl(poly[i],l));
	}
	return res;
}

Polygon poly;

Polygon polys[10];
int N;

void input(){
	scanf("%d",&N);
	if(N==0) exit(0);
	int sx,sy;
	scanf("%d%d",&sx,&sy);
	poly.clear();
	for(int i=0;i<N;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x-=sx;
		y-=sy;
		poly.push_back(Point(x,y));
	}
	poly.push_back(poly[0]);
}

typedef pair<Real,int> P;

vector<P> ps;

void ins(Real a,Real b){
	if(a>b) return;
	ps.push_back(P(a+eps,1));
	ps.push_back(P(b-eps,-1));
}

bool check(int *ord){
	ps.clear();
	for(int i=0;i<N;i++){
		int id=ord[i];
		Point p1=polys[i][id];
		Point p2=polys[i][id+1];
		if(crP(p1,p2)<0){
			swap(p1,p2);
		}
		if(abs(crP(p1,p2))<eps) return false;
		Real ang1=arg(p1);
		Real ang2=arg(p2);
		if(ang2-ang1<0){
			ins(-PI,ang2);
			ins(ang1,PI);
		}else{
			ins(ang1,ang2);
		}
	}
	sort(ps.begin(),ps.end());
	int cnt=0;
	for(int i=0;i<ps.size();i++){
		cnt+=ps[i].second;
		if(cnt==N) return true;
	}
	return false;
}

void gen(int *a){
	for(int i=0;i<N;i++) polys[i].clear();
	polys[0]=poly;
	for(int i=0;i<N-1;i++){
		int id=a[i];
		Point p1=polys[i][id];
		Point p2=polys[i][id+1];
		Line l=Line(p1,p2);
		polys[i+1]=reflPoly(polys[i],l);
	}
}

int solve(){
	int res=0;
	int ord[10];
	for(int i=0;i<N;i++) ord[i]=i;
	do{
		gen(ord);
		bool flg=check(ord);
		if(flg){
		//	for(int i=0;i<N;i++) printf("%d ",ord[i]);
		//	printf("\n");
			res++;
		}
	}while(next_permutation(ord,ord+N));
	return res;
}

int main(){
	while(true){
		input();
		int ans=solve();
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1136
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}


int main() {
	const double PI = 3.14159265358979323846;
	int i, j, k;
	
	int N, M, K;

	cin >> N >> M;

	vector<int> A[100001];
	int d[100001] = { 0 };
	int next[100001] = { 0 };
	
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		A[a].push_back(b);
		A[b].push_back(a);
	}

	queue<int> Q;
	Q.push(1);
	d[1] = 1;
	while (!Q.empty()) {
		int x = Q.front();
		Q.pop();
		for (auto y : A[x]) {
			if (d[y] != 0)
				continue;

			d[y] = d[x] + 1;
			next[y] = x;
			Q.push(y);
		}
	}
	vector<int> ans;
	rep(i, 2, N+1) {
		if (next[i] == 0) {
			cout << "No";
			return 0;
		}
		ans.push_back(next[i]);
	}
	cout << "Yes" << endl;
	for (auto x : ans) {
		cout << x << endl;
	}
	return 0;

}

Measured memory_bytes: 11164
while True:
    N, M, P = map(int, input().split())
    if N == 0 and M == 0 and P == 0:
        break
    X = [int(input()) for _ in range(N)]
    win = X[M - 1]
    if win == 0:
        print(0)
    else:
        print(int(round(sum(X) * 100 * (1 - P / 100) / win, 10)))




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

#define INF 2147483647
int n, k, island[100][100];

int solve(int s, int g){
    int i, j;
    int a;
    int m;
    int decided[100] = {0};
    while(true){
        m = INF;
        for(i=0;i<n;i++){
            if(island[s][i] < m && !decided[i]){
                m = island[s][i];
                a = i;
            }
        }
        decided[a] = 1;
        if(a == g) return island[s][g];
        if(m == INF) return -1;
        for(i=0;i<n;i++){
            if(island[a][i]!=INF){
                island[s][i] = min(island[s][a]+island[a][i], island[s][i]);
            }
        }
    }
}

int main(){
    int i, j, t, a, b, cost;
    cin >> n >> k;
    while(n || k){
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                island[i][j] = INF;
            }
            island[i][i] = 0;
        }
        for(i=0;i<k;i++){
            cin >> t >> a >> b;
            a--; b--;
            if(t){
                cin >> cost;
                if(cost < island[a][b]){
                    island[a][b] = cost;
                    island[b][a] = cost;
                }
            }else{
                cout << solve(a, b) << endl;
            }
        }
        cin >> n >> k;
    }
}

Measured memory_bytes: 900
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

const int dx[]={0,1,-1,0};
const int dy[]={1,0,0,-1};
char field[8][9];

void dfs(int sy,int sx,int d=0,int depth=0){
    if(field[sy][sx]=='0'){
        if(depth==3){
            return;
        }
        if(sy+dy[d]>=0 && sy+dy[d]<8 && sx+dx[d]>=0 && sx+dx[d]<8){
            dfs(sy+dy[d],sx+dx[d],d,depth+1);
        }
    }else{
        field[sy][sx]='0';
        for(int dir=0;dir<4;dir++){
            if(sy+dy[dir]>=0 && sy+dy[dir]<8 && sx+dx[dir]>=0 && sx+dx[dir]<8){
                dfs(sy+dy[dir],sx+dx[dir],dir,1);
            }
        }
    }
}

int main(){
    int ds;
    int num=1;

    cin>>ds;

    while(ds--){
        int sx,sy;

        cin.ignore(2);
        for(int i=0;i<8;i++){
            cin>>field[i];
        }

        cin>>sx>>sy;

        dfs(sy-1,sx-1);

        cout<<"Data "<<num++<<":"<<endl;

        for(int i=0;i<8;i++){
            cout<<field[i]<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
using namespace::std;

int main(){
    int n,k,i,a;
    int cnt = 0;
    cin >> n >> k;
    for(i = 0;i < n;i++){
        cin >> a;
        if(a >= k) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
-----------------------
local S = (read.l()):totable()
local T = (read.l()):totable()
local c = 0
for i=1, #S do
    if S[i] ~= T[i] then
        c = c + 1
    end
end
print(c)

Measured memory_bytes: 11060
#include <bits/stdc++.h>
using namespace std;
 
string solve(string S){
  bool result = true;
  
  for(int i = 1; i < 4; i++){
    if(S[i-1] == S[i]){
      result = false;
    }
  }

  if(result){
    return "Good";
  }
  else{
    return "Bad";
  }
}

int main() {
  string S;
  cin >> S;
  cout << solve(S) << endl;
}


Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var output = [];
  for(var i = 0; i < N; i++){
    if(N % 2 == 0){
      if(i % 2 == 0){
        output.push(list[i]);
      }else{
        output.unshift(list[i]);
      }
    }else{
      if(i % 2 == 1){
        output.push(list[i]);
      }else{
        output.unshift(list[i]);
      }
    }
  }
  myout(myconv(output, 8));
}


Measured memory_bytes: 67052
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

void solve() {
	int n;
	cin >> n;
	n -= 400;
	n /= 200;
	cout << 8 - n;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 3652
//23
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int c[1000]={};
    int ans=0;
    for(int i=0;i<n;i++){
      char l[1001];
      cin>>l;
      int cl[1000];
      for(int j=0;j<n;j++){
	cl[j]=(l[j]=='*')?0:c[j]+1;
      }
      for(int j=ans+1;j<=n;j++){
	int ms=0,cs=0;
	for(int k=0;k<n;k++){
	  if(cl[k]>=j){
	    cs++;
	    ms=max(ms,cs);
	  }else{
	    cs=0;
	  }
	}
	if(ms<j)break;
	ans=max(ans,j);
      }
      memcpy(c,cl,sizeof(c));
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 880
// 173

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main(){
    int n, r_c=0, w_c=0, count=0;
    cin >> n;
    char c;
    vector<bool> v(n);
    for(int i=0; i<n; i++){
        cin >> c;
        if(c == 'R') {v.at(i) = true; r_c++;}
        else if(c == 'W') {v.at(i) = false; w_c++;}
    }
    for(int i=0; i<r_c; i++){
        if(!v.at(i)) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n, k, s;
  cin>>n>>k>>s;
  int a[n];
  REP(i,n){
    if(i < k){
      a[i] = s;
    }else{
      a[i] = s + 1;
    }
  }
  if(s == 1000'000'000){
    REP(i,n){
      if(i >= k){
        a[i] = 1;
      }
    }
  }
  REP(i,n){
    cout<<a[i]<<' ';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std; // 575
const int INF = 1073741823; // 10^30-1、使わない辺とかに用いる

int square(int N) { // 2乗を返すだけ
	return N * N;
}

int main() {
	int N, M;
	while (true) {
		cin >> N >> M;
		if (N == 0) break;
		int dp[20001][256]; // dp[i][j]は第i番目まで見てy[i]=jになってる時の最小誤差
		for (int i = 0;i < 20001;++ i) for (int j = 0;j < 256;++ j) dp[i][j] = INF;
		dp[0][128] = 0;
		int C[16], x[20000];
		for (int i = 0;i < M;++ i) cin >> C[i];
		for (int i = 0;i < N;++ i) cin >> x[i];
		
		for (int i = 0;i < N;++ i) {
			for (int j = 0;j < 256;++ j) {
				for (int k = 0;k < M;++ k) {
					int next = max(0, min(255, j + C[k])); // 次にC[k]を選んだ時の遷移先
					dp[i + 1][next] = min(dp[i + 1][next], dp[i][j] + square(x[i] - next));
				}
			}
		}
		int ans = dp[N][0]; // 最悪ケース: 誤差255が全部=1300500500、intに入る
		for (int j = 1;j < 256;++ j) ans = min(ans, dp[N][j]);
		cout << ans << endl;
	}
	return 0;
}


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



int main()
{
   int A, B, C, K;
   cin >> A >> B >> C >> K;
   int ans = 0;
   ans += min(A, K);
   K -= ans;
   if(K)
     K -= min(B, K);

    if(K)
        ans -= min(C, K);

   cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

const int MAX = (int) pow(10., 9.);
const int MIN = 1;

int main(int argc, char const *argv[])
{
	int input_size, num, temp, num_min;
	int sub_max = MIN - MAX;
	cin >> input_size;

	for (int i = 0; i < input_size; ++i)
	{
		cin >> num;
		if(i == 0)
		{
			num_min = num;
			continue;
		}
		temp = num - num_min;
		if(sub_max < temp) sub_max = temp;
		if(num_min > num) num_min = num;
	}

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

	return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int n, m[505], ans = 1e9, t;
bool e[505], f[505], ok;
char a[505];
int main(){
	scanf("%d", &n);
	fill(f,f+n,true);
	rep(i,n){
		scanf("\n%s", a);
		rep(j,n){
			if(a[j] == '#'){
				e[j] = true;
				ok = true;
			}else{
				m[i]++;
				if(f[j]) t++;
				f[j] = false;
			}
		}
	}
	if(!ok) return 0*puts("-1");
	rep(i,n) ans = min(ans, m[i]+1-e[i]);
	printf("%d\n", ans + t);
}

Measured memory_bytes: 256
import { readFileSync } from 'fs'
function main() {
  const input = readFileSync('/dev/stdin', 'utf8')
  const [n, b] = input.trim().split('\n').map(v => v.trim().split(' ').map(string => parseInt(string))) 
  let a = 0  
  for (let i = 0; i < n[0]; i++) {
    if (i === 0) {
      a += b[i]
    } else if (i === n[0] - 1) {
      a += b[i - 1]
    } else {
      a += Math.min(b[i], b[i - 1])
    }
  }
  console.log(a)
}
main()

Measured memory_bytes: 7500