akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n;
    cin >> n;
    ll a[3 * n];
    ll pre = 0LL, pos = 0LL;
    priority_queue<ll, vector<ll>, greater<ll> > q1;
    priority_queue<ll> q2;
    for (int i = 0; i < 3 * n; i++) {
        cin >> a[i];
        if (i < n) {
            q1.push(a[i]);
            pre += a[i];
        } else if (i >= 2 * n) {
            q2.push(a[i]);
            pos += a[i];
        }
    }

    ll cost[n + 1];
    cost[0] = pre;
    for (int i = n; i < 2*n; i++) {
        q1.push(a[i]);
        pre += a[i] - q1.top();
        q1.pop();
        cost[i-n+1] = pre;
    }

    cost[n] -= pos;
    for (int i = 2*n-1; i >= n; i--) {
        q2.push(a[i]);
        pos += a[i] - q2.top();
        q2.pop();
        cost[i-n] -= pos;
    }

    cout << *max_element(cost, cost+n+1) << "\n";
    return 0;
}

Measured memory_bytes: 5108
#include <stdio.h>

int main(){
	//input
	int i,n,weight,min;
	if(scanf("%d",&n)==-1){
		return 1;
	}
	int w[n];
	for(i=0;i<n;i++){
		scanf("%d",&weight);
		w[i]=weight;
	}
	
	//sum
	int sum=0;
	for(i=0;i<n;i++){
		sum+=w[i];
	}
	
	int t=0;
	int diff=sum;
	while(t<n-1&&diff-2*w[t]>0){
		diff=diff-2*w[t];
		t++;
	}
	
	int diff2=2*w[t]-diff;
	if(diff<=diff2){
		printf("%d",diff);
	}
	else{
		printf("%d",diff2);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int num500, num100, num50, price;
	cin >> num500;
	cin >> num100;
	cin >> num50;
	cin >> price;
	int pat = 0;
	for (int i = 0; i <= num500; ++i) {
		for (int ii = 0; ii <= num100; ++ii) {
			int left = price - 500 * i - 100 * ii;
			if (left <= 50 * num50 && left >= 0) {
				pat++;
			}
		}
	}
	cout << pat << endl;
	return 0;
}


Measured memory_bytes: 256
/*input

*/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <iomanip>
#include <utility>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

int main()
{
  ifalse;
  ll l, r;
  cin >> l >> r;
  ll n = 2019;
  vector < ll > v;
  map < ll, ll > mp;
  for(ll i = l; i <= r; i ++) {
    ll d = i % n;
    mp[d] ++;
    if(mp[d] == 3) {
      continue;
    }
    v.push_back(d);
    if(v.size() == 2 * n) {
      break;
    }
  }
  ll ans = ((l % n) * (r % n)) % n; 
  for(int i = 0; i < v.size(); i ++) {
    for(int j = i + 1; j < v.size(); j ++) {
      ans = min(ans, (v[i] * v[j]) % n);
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int", c:"int"):
    for j in a[i]:
        if not visited[j[0]]:
            visited[j[0]]=1
            if j[1]%2==0:
                col[j[0]]=c
            else:
                col[j[0]]=c*-1
            dfs(j[0], col[j[0]])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1].append([v-1, d])
        a[v-1].append([u-1, d])
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

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

const int MAXN = (int) 2e5;

int n;

int A[MAXN + 5], S = 0;
int B[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) A[i] = read<int>(), S ^= A[i];
	for(int i = 1; i <= n; ++i) B[i] = read<int>();
}

inline bool check()
{
	static int a[MAXN + 5], b[MAXN + 5];

	a[n + 1] = b[n + 1] = 0;
	for(int i = 1; i <= n; ++i)
	{
		a[i] = A[i], a[n + 1] ^= a[i];
		b[i] = B[i], b[n + 1] ^= b[i];
	}

	sort(a + 1, a + n + 1 + 1);
	sort(b + 1, b + n + 1 + 1);
	for(int i = 1; i <= n + 1; ++i) if(a[i] != b[i]) return 0;
	return 1;
}

int N = 0;

inline void discrete()
{
	static int val[MAXN + 5];
	for(int i = 1; i <= n; ++i) if(A[i] != B[i]) val[N++] = A[i], val[N++] = B[i];
	val[N++] = S;
	sort(val, val + N), N = unique(val, val + N) - val;
	for(int i = 1; i <= n; ++i) if(A[i] != B[i])
	{
		A[i] = lower_bound(val, val + N, A[i]) - val + 1;
		B[i] = lower_bound(val, val + N, B[i]) - val + 1;
	}
	S = lower_bound(val, val + N, S) - val + 1;
}

namespace DSU
{
	int fa[MAXN + 5];

	inline void init() { for(int i = 1; i <= N; ++i) fa[i] = i; }
	inline int get_fa(int u) { return u == fa[u] ? u : fa[u] = get_fa(fa[u]); }
	inline void link(int u, int v) { fa[get_fa(u)] = get_fa(fa[v]); }
}

inline void solve()
{
	if(!check()) { puts("-1"); return; }

	discrete();
	DSU::init();
	for(int i = 1; i <= n; ++i) if(A[i] != B[i]) DSU::link(A[i], B[i]);

	int ans = 0;
	for(int i = 1; i <= n; ++i) ans += A[i] != B[i];
	for(int i = 1; i <= N; ++i) ans += i == DSU::fa[i];
	printf("%d\n", ans - 1);
}

int main()
{
	input();
	solve();

	return 0;
}



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

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

int main(){
	int N;
	cin >> N;
	vector<vector<int>> G(N);
	map<P,int> d;
	rep(i,N-1){
		int u,v,w;
		cin >> u >> v >> w;
		u--; v--; w%=2;
		d[P(u,v)] = d[P(v,u)] = w;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	vector<int> used(N,-1);
	used[0] = 1;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int x = que.front(); que.pop();
		for(int u : G[x]){
			if(used[u]==-1){
				used[u] = used[x] + d[P(x,u)];
				que.push(u);
			}
		}
	}

	for(int u : used)cout << u%2 << endl;
}


Measured memory_bytes: 18816
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    string S;
    cin >> S;
    rep(i, S.size())
    {
        if (S[i] == '1')
        {
            cout << 9;
        }
        else if (S[i] == '9')
        {
            cout << 1;
        }
        else
        {
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[]args){
		Scanner s = new Scanner(System.in);
		int[] a = new int[10];
		for(int i=0; i<10; i++) a[i] = s.nextInt();
		Arrays.sort(a);
		for(int i=9; i>6; i--){
			System.out.println(a[i]);
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "/Users/swad/Desktop/CP/debug.h"
#endif

// const int N = int(1e5) + 10;
const int MOD = int(1e9) + 7;

int n;
string s;
vector<vector<int>> dp;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> n >> s;

	dp = vector<vector<int>>(n, vector<int>(n, 0));
	dp[n - 1][0] = 1;

	for (int i = n - 2; i >= 0; i--) {
		int st, en, inc;
		if (s[i] == '>') st = 1, en = n - i, inc = 1;
		else st = n - i - 2, en = -1, inc = -1;

		for (int d = st; d != en; d += inc) {
			dp[i][d] = dp[i][d - inc] + dp[i + 1][d - (inc == 1)];
			if (dp[i][d] > MOD) dp[i][d] -= MOD;
		}
	}

	int ans = 0;
	for (int d = 0; d < n; d++) {
		ans += dp[0][d];
		if (ans > MOD) ans -= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<pair<int,int> >L[N],R[N];
bool vis[N];
int pos[N],ans=1;
void dfs(int u)
{
    vis[u]=1;
    for(int i=0;i<L[u].size();i++){
        int v=L[u][i].first,d=L[u][i].second;
        if(vis[v]){
            if(pos[v]!=pos[u]-d) ans=0;
        }
        else{
            pos[v]=pos[u]-d;
            dfs(v);
        }
    }
    for(int i=0;i<R[u].size();i++){
        int v=R[u][i].first,d=R[u][i].second;
        if(vis[v]){
            if(pos[v]!=pos[u]+d) ans=0;
        }
        else{
            pos[v]=pos[u]+d;
            dfs(v);
        }
    }
}
int main()
{
    int n,m,l,r,d;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&l,&r,&d);
        L[r].push_back(make_pair(l,d));
        R[l].push_back(make_pair(r,d));
    }
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        pos[i]=0;
        dfs(i);
    }
    printf("%s\n",ans?"Yes":"No");

    return 0;
}


Measured memory_bytes: 16128
def solve():
    r,g,b,n = map(int,input().split())
    ans = 0
    for i in range(n+1):
        if r*i>n:
            break
        for j in range(n+1):
            if g*j+r*i>n:
                break
            if (n-g*j-r*i)%b==0:
                ans+=1
    print(ans)
if __name__=='__main__':
    solve()

Measured memory_bytes: 3060
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);

    int cnt=0;
    int i;
    for(i=a; i<=b; i++) {
        if(c%i==0) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 2760
/*
  AOJ 0567
  Title:Best Pizza
  @kankichi573
*/
#include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <math.h>
#include <float.h>
// #include <stdlib.h>
int N;
int A,B,C,D[10000];

int comp_(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int solve()
{
        int i;
        int totalcal,totalamount;
        double ratio1,ratio2;

        totalcal=C;totalamount=A;

        for(i=0;i<N;i++)
        {
                ratio1=((double)totalcal)/((double)totalamount);
                ratio2=((double)D[i])/((double)B);

                //printf("%f %f\n",ratio1,ratio2);

                if(ratio2<=ratio1)
                        break;
                totalcal+=D[i];
                totalamount+=B;
        }
        return((int)ratio1);
}
main()
{
        int i,j,ret;

        scanf("%d",&N);
        scanf("%d %d",&A,&B);
        scanf("%d",&C);

        for(i=0;i<N;i++)
        {
                scanf("%d",&D[i]);
        }
        qsort(D,N,sizeof(int),comp_);
        ret=solve();
        printf("%d\n",ret);
  return(0);
}

Measured memory_bytes: 604
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:noConvert	1:singleNum	2:spaceList	3:newLineList
//4:spaceNumList	5:newLineNumList	6:oneCharList	7:oneCharNumList
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4).sort(function(a,b){
  	return b - a;
  });
  var alice = 0;
  var bob = 0;
  for(var i = 0; i < list.length; i++){
    if(i % 2 == 0){
       alice += list[i];
       }else{
       bob += list[i];
       }
  }
  myout(alice - bob);
}

Main(myin());


Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

#define ll long long
#define p pair<ll,ll>
#define mp(a,b) make_pair(a,b)
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<p> sushi(n);
	for (int i = 0; i < n; i++)
	{
		ll t, d;
		cin >> t >> d;
		sushi[i] = mp(d,t);
	}
	sort(sushi.begin(), sushi.end());
	reverse(sushi.begin(), sushi.end());
	ll sum = 0;
	set<int> kind;
	priority_queue<ll, vector<ll>, greater<>> doub;
	for (int i = 0; i < k; i++)
	{
		sum += sushi[i].first;
		if (kind.find(sushi[i].second) != kind.end())doub.push(sushi[i].first);
		else kind.insert(sushi[i].second);
	}
	ll ret = sum + kind.size() * kind.size();
	for (int i = k; i < n; i++)
	{
		if (kind.find(sushi[i].second) != kind.end())continue;
		if (doub.empty())break;
		sum += sushi[i].first - doub.top();
		doub.pop();
		kind.insert(sushi[i].second);
		if (ret < sum + kind.size() * kind.size())
			ret = sum + kind.size() * kind.size();
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define mod 1000000007

using namespace std;

int main(){

  int n;

  //入力を受け取る
  cin >> n;
  int b[n-1];

  rep(i,0,n-2)cin >> b[i];
  
  long long ans = b[0];
  rep(i,1,n-2){
  //b_i, b_{i+1}のうち小さい方がA_iの最大値となる
  ans += min(b[i-1],b[i]);
  }
  ans += b[n-2];
  
  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int p=__gcd(n,360);
    cout<<360/p<<endl;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner

case class Input(as: List[Int]) {
  def heightMap = Input.heightMap(this.as)
  def heightRegions = this.heightMap.toList.sortWith({ case (a, b) => a._1 < b._1 })
  def solved: Output = {
    val n = as.length
    var hasSinked = Array.fill(n)(false)
    def updateSinked(regions: List[(Int, Int)]): Int = {
      var d = 0
      for ((from, to) <- regions) {
        var k = 1
        if ((from == 0) || hasSinked(from-1)) k -= 1
        if ((to == n-1) || hasSinked(to+1)) k -= 1
        d += k
        (from to to).foreach(hasSinked(_) = true)
      }
      d
    }
    var hr = this.heightRegions
    var m = 1
    if (hr.head._1 == 0) {
      m += updateSinked(hr.head._2)
      hr = hr.tail
    }
    var max = m
    for ((_, rs) <- hr) {
      val d = updateSinked(rs)
      m += d
      max = math.max(m, max)
    }
    Output(max)
  }
}

object Input {
  def mapAux(as: List[Int]): Map[Int, List[Int]] = {
    val m = scala.collection.mutable.Map[Int,List[Int]]()
      .withDefaultValue(List())
    as.zipWithIndex.foreach({ case (a, i) => m(a) = i :: m(a) })
    m.map({ case (a, l) => (a, l.reverse) }).toMap
  }
  def split(l: List[Int]): List[(Int, Int)] = {
    def aux(prev: Int, from: Int, acc: List[(Int, Int)], l: List[Int]): List[(Int, Int)] = l match {
      case Nil => (from, prev) :: acc
      case hd :: tl => if (prev+1 == hd) aux(hd, from, acc, tl)
                       else aux(hd, hd, (from, prev)::acc, tl)
    }
    aux(l.head-1, l.head, Nil, l).reverse
  }
  def heightMap(as: List[Int]): Map[Int, List[(Int, Int)]] = {
    val h2l = mapAux(as)
    h2l.map({ case (a, l) => (a -> split(l)) })
  }
  def fromStdin(): Input = {
    val sc = new Scanner(System.in)
    Input(List.fill(sc.nextInt())(sc.nextInt))
  }
}

case class Output(v: Int) {
  override def toString(): String = {
    v.toString()
  }

  def print() = println(this.toString())
}

object Main extends App {
  Input.fromStdin().solved.print()
}



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

int main()
{
    string s;

    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    long double a,b,x,y;
    cin >> a >> b >> x >> y;
    cout <<fixed << setprecision(9) <<  double(a)*double(b) / 2 <<" " <<  (x+x==a && y+y==b);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    void solve() {
        int sum = sc.nextInt() + sc.nextInt();
        if (sum >= 10) System.out.println("error");
        else System.out.println(sum);
    }
}

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

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

	ll n,k;
	cin >> n >> k;
	vector<ll> a;
	for(ll i=0; i<n; i++){
		ll num; cin >> num;
		a.push_back(num);
	}
	sort(a.rbegin(), a.rend());
	ll ans = 0;
	for(ll i=k; i<n; i++){
		ans += a[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3444
import itertools

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [i for i in range(n)]

def add(k, x):
  while k <= n:
    data[k] += x
    k += k & -k
def get(k):
  s = 0
  while k:
    s += data[k]
    k -= k & -k
  return s
ans = 10 ** 18
for i in itertools.combinations(c,n//2):
  j = list(set(c)-set(i))
  even = sorted([(a[k],k+1) if k % 2 else (b[k],k+1) for k in i])
  odd = sorted([(b[k],k+1) if k % 2 else (a[k],k+1) for k in j])
  prev = -1
  A = []
  for x in range(n):
    Y,X = divmod(x,2)
    if X % 2:
      now0,now1 = even[Y][0],even[Y][1]
    else:
      now0,now1 = odd[Y][0],odd[Y][1]
    if prev > now0:
      break
    else:
      A.append(now1)
    prev = now0
  else:
    data = [0]*(n+1)
    tmp = 0
    for i,z in enumerate(A):
      tmp += (n-1-i) - get(z)
      add(z,1)
    ans = min(ans,tmp)
if ans == 10 ** 18:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 60632
#include <bits/stdc++.h>
using namespace std;
#ifdef _LOCAL //
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout   \
	if (false) \
	cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif //
#define next asdnext
#define prev asdprev
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define vrep(i, v) for (auto &i : v)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力
#define vecin(v,n)	\
	vec(v,n);		\
	vin(v);
#define vec(v, n) vector<int> v(n, 0);
#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define _n "\n"



void Main()
{
	int X,N;
	cin>>X>>N;
	vec(v,N);
	vin(v);
	int dev_min=1000;
	int ans = -1;
	for(int i = 0; i <= 101; i++){
		bool flag = false;
		rep(k,N){
			if(i==v[k]){
			flag = true;
			break;
			}
		}
	if(flag)continue;
		if(dev_min>abs(i-X)){
			dev_min = abs(i-X);
		ans = i;
		}
	}
	cout<<ans<<_n;
}

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


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include<stdio.h>
#include<functional>
#include <math.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
int s=0;
int main() {
    int N;
    int num=0;
    int t=0;
    int ans=0;
    cin >> N;
    s+=N;
    while(N!=0){
        N/=10;
        num+=1;}
    if (num%2==0){
        t=num/2;
        for (int i=0; i<t;++i){
        ans+=9*pow(10,i*2);
    }}
    else{
        t=int(num/2);
        for (int i=0; i<t;++i){
        ans+=9*pow(10,i*2);
    }
    ans+=s-pow(10,num-1)+1;
    }
    cout << ans<< endl;
    return 0;

}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1073741824")
#pragma GCC optimize("Ofast")

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<deque>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<fstream>
#include<iterator>
#include<functional>
#include<bitset>
#include<memory>
#include<sstream>
#include<new>
#include<cassert>
#include<iomanip>
#include<list>

using namespace std;
using namespace placeholders;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<bool, bool> pbb;
typedef pair<ld, ld> pdd;

const int inf = (int)1e9 + 9;
const ll linf = (ll) 1e18;
const ld eps = 1e-9;
const int mod = (int) 1e9 + 7;
const int smod = 16769023;
const ll lmod = 27644437;
const ld pi = acos(-1);

#define it(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define scn second
#define sgn(x) (x > 0 ? 1 : (x == 0 ? 0 : -1))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<char>> mat(n, vector<char>(m));
	int w = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> mat[i][j];
			if (mat[i][j] == '.')
			{
				w++;
			}
		}
	}
	list<pii> q = { mp(0, 0) };
	vector<vb> used(n, vb(m, false));
	vector<vi> dist(n, vi(m, inf));
	used[0][0] = true;
	dist[0][0] = 0;
	vi dx = { 0, 0, 1, -1 };
	vi dy = { -1, 1, 0, 0 };
	while (q.size())
	{
		pii pos = q.front();
		q.pop_front();
		for (int i = 0; i < 4; i++)
		{
			pii cur = mp(pos.fst + dy[i], pos.scn + dx[i]);
			if (cur.fst >= 0 && cur.fst < n && cur.scn >= 0 && cur.scn < m && !used[cur.fst][cur.scn]
				&& mat[cur.fst][cur.scn] == '.')
			{
				used[cur.fst][cur.scn] = true;
				q.pb(cur);
				dist[cur.fst][cur.scn] = dist[pos.fst][pos.scn] + 1;
			}
		}
		if (pos.fst == n - 1 && pos.scn == m - 1)
		{
			cout << w - dist[pos.fst][pos.scn] - 1;
			return 0;
		}
	}
	cout << -1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        vector<string> v = {"AC", "WA", "TLE", "RE"};
        int n;
        cin >> n;
        map<string, int> cnt;
        while(n--){
            string s;
            cin >> s;
            cnt[s]++;
        }
        for(auto &it : v){
            cout << it << ' ' << "x " << cnt[it] << '\n';
        }
    }
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n;
    cin >> n;
    vector<P> a(n);
    vector<P> b(n);
    rep(i,n) cin >> a[i].first >> a[i].second;
    rep(i,n){
        b[i].first=a[i].first+a[i].second;
        b[i].second=i;
    }
    sort(b.rbegin(),b.rend());
    ll taka=0,ao=0;
    rep(i,n){
        if(i%2==0){
            taka+=a[b[i].second].first;
        }else{
            ao+=a[b[i].second].second;
        }
    }
    
    cout << taka-ao << endl;
    
    
    return 0;
}











Measured memory_bytes: 3328
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	o := n
	m := map[int]int{}
	for n > 1 {
		d := div(n)
		m[d] = 1
		n /= d
	}
	mm := make([]int, 0)
	for v := range m {
		mm = append(mm, v)
	}
	l := len(mm)
	var ans int
	ans = o
	for i := uint32(1); i < 1<<uint(l); i++ {
		d := 1
		for b := 0; b < l; b++ {
			if (i>>uint(b))&1 == 0 {
				continue
			}
			d *= mm[b]
		}
		if bits.OnesCount32(i)&1 == 1 {
			ans -= o / d
			continue
		}
		ans += o / d
	}
	fmt.Fprintln(writer, ans)
}
func div(x int) int {
	for i := 2; i*i < x+1; i++ {
		if x%i == 0 {
			return i
		}
	}
	return x
}



Measured memory_bytes: 1184
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;

const int inf = 1e9 + 10;
int main()
{
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> arr[i];
  }
  int dp[n];
  dp[n-1] = 0;
  dp[n-2] = abs(arr[n-2] - arr[n-1]);

  for (int i = n-3; i >= 0; --i)
  {
     int minm = inf;
     for (int kk = 1; kk <= k; ++kk)
     {
       if(i + kk >= n) break;
        minm = min(minm, dp[i + kk] + abs(arr[i] - arr[i + kk]));
     }
     dp[i] = minm;
  }
  cout << dp[0];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define S second
#define F first
#define pi =3.14159265358979323846264338327950L;
typedef long long int ll;
vector<int> graph[200010];
vector<bool> vis(200010,false);
vector<int> dis(200010,-1);

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//~ freopen("input.txt", "r", stdin); 
    //~ freopen("output.txt", "w", stdout); 
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	queue<pair<int,int>> q;
	q.push({1,0});
	vis[1]=true;
	while(!q.empty()){
		int v=q.front().first;
		int d=q.front().second;
		q.pop();
		dis[v]=d;
		for(int i:graph[v]){
			if(!vis[i]){
				vis[i]=true;
				q.push({i,v});
			}
		}
	}
	bool flag=true;
	for(int i=1;i<=n;i++){
		if(dis[i]==-1) {
			flag=false;
			break;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++){
			cout<<dis[i]<<endl;
		}
	}
	else cout<<"No"<<endl;
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int count =0;
    for ( int i=1; i<=N; ++i ){
        int n = to_string(i).length();
        if( n%2 == 1 ) ++count;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);

int main () {
       int a,b,c;
       cin>>a>>b>>c;
       swap(a,b);
       swap(a,c);
       cout<<a<<" "<<b<<" "<<c;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
 int N,k=0,d,s=0;
  cin>>N;
  int n=N;
  while(n){
    k++;
  	n/=10;
  }
  N-=pow(10,k-2);
  while(N){
  	d=N%10;
    s+=d;
    N/=10;
  }
  cout<<s+1<<endl;
  
}	


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

using namespace std;

int main(){
    int n, s = 0, min, k, ans = 0;
    
    cin >> n;
    vector<int> ve(n);
    for(int i = 0; i < n; i++){
        cin >> ve[i];
        s += ve[i];
    }

    if(s % 10 != 0){
        cout << s << endl;
    }else{
        sort(ve.begin(), ve.end());
        
        for(int i : ve){
            if(i % 10 != 0){
                ans = s - i;
                break;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3632
#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 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;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;

	int N, M, K;

	ll H, W;
	cin >> H >> W;

	ll ans=10000000000;
	ll Min, Max;
	
	if (H > 2) {
		Min = H / 3 * W;
		Max = (H / 3 + (H % 3 == 0 ? 0 : 1)) * W;
		ans = min(ans, Max - Min);
	}
	if (W > 2) {
		Min = W / 3 * H;
		Max = (W / 3 + (W % 3 == 0 ? 0 : 1)) * H;
		ans = min(ans, Max - Min);
	}

	int index;
	rep(i, 1, H) {
		ll a = i * W;
		ll b = (W / 2) * (H - i);
		ll c = (W / 2 + W%2) * (H - i);
		Min = min(a, min(b, c));
		Max = max(a, max(b, c));
		if (ans > Max - Min)
			index = i;
		ans = min(ans, Max - Min);
	}
	rep(i, 1, W) {
		ll a = i * H;
		ll b = (H / 2) * (W - i);
		ll c = (H / 2 + H % 2) * (W - i);
		Min = min(a, min(b, c));
		Max = max(a, max(b, c));
		if (ans > Max - Min)
			index = i;

		ans = min(ans, Max - Min);
	}

	cout << ans;
	return 0;
}

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

typedef long long LL;
int a[100000];
LL sum[100000];
int n,m;
int bo1[50001],bo2[50001],f[50001];

int check(int ans){
	memset(bo1,0,sizeof(bo1));
	memset(bo2,0,sizeof(bo2));
	memset(f,0,sizeof(f));
	f[0]=1;
	int p1=0,p2=0,ans1=0;
	for (int i=1; i<=n; ++i){
		while (p1<i && sum[i]+(LL)i*ans>=sum[p1]+(LL)p1*ans+m+ans){
			bo1[p1]=1;
			if (bo1[p1] && !bo2[p1] && f[p1]) ++ans1; 
			++p1;
		}
		while (p2<i && sum[i]+i>sum[p2]+p2+1+m) {
			bo2[p2]=1;
			if (bo1[p2] && f[p2]) --ans1;
			++p2;
		}
		if (ans1) f[i]=1;
	}
	for (int i=0; i<=n; ++i)
		if (f[i] && (sum[n]-sum[i]+n-i-1)<=m) return 1;
	return 0;
}

int main(){
	while (scanf("%d%d",&m,&n), n>0 || m>0){
		for (int i=1; i<=n; ++i) scanf("%d",&a[i]);
		memset(sum,0,sizeof(sum));
		for (int i=1; i<=n; ++i) sum[i]=sum[i-1]+a[i];
		int head=0,tail=m;
		while (head<tail-1){
			int mid=(head+tail)>>1;
			if (check(mid)) tail=mid;
			else head=mid;
			//printf("%d %d\n",head,tail);
		}
		printf("%d\n",tail);
	}
}

Measured memory_bytes: 2756
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		StringBuilder sb=new StringBuilder();
		String v=s.next();
		int w=gInt();
		
		for(int i=0;i<v.length();i+=w) {
			sb.append(v.charAt(i));
		}
		System.out.println(sb);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 21972
#include <stdio.h>
 
typedef struct{
    int p;
    int left;
    int right;
}Tree;
 
void preparse(int);
void inparse(int);
void postparse(int);
 
Tree tree[100];
int n;
 
int main(){
    int i,root,p,left,right;
 
    scanf("%d",&n);
    for(i=0;i<n;i++){
        tree[i].p = -1;
    }
    for(i=0;i<n;i++){
        scanf("%d%d%d",&p,&left,&right);
        tree[p].left = left;
        tree[p].right = right;
        if(left != -1)tree[left].p = p;
        if(right != -1)tree[right].p = p;
    }
 
    for(i=0;i<n;i++){
        if(tree[i].p == -1)root = i;
    }
 
    printf("Preorder\n");
    preparse(root);
    printf("\nInorder\n");
    inparse(root);
    printf("\nPostorder\n");
    postparse(root);
    printf("\n");
    return 0;
}
 
void preparse(int u){
    if(u== -1)return ;
    printf(" %d", u);
    preparse(tree[u].left);
    preparse(tree[u].right);
}
 
void inparse(int u){
    if(u==-1)return ;
    inparse(tree[u].left);
    printf(" %d",u);
    inparse(tree[u].right);
}
 
void postparse(int u){
    if(u==-1)return ;
 
        postparse(tree[u].left);
        postparse(tree[u].right);
        printf(" %d", u);
     
}

Measured memory_bytes: 616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			int num = i;
			int sumDig = 0;
			while (num > 0) {
				sumDig += num % 10;
				num /= 10;
			}
			
			if (a <= sumDig && sumDig <= b) sum += i;
		}
		
		System.out.println(sum);
		
		sc.close();
	}
}




Measured memory_bytes: 27068
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] rSum = new int[n + 1];
        int[] gSum = new int[n + 1];
        int[] bSum = new int[n + 1];
        for (int i = n - 1; i >= 0; i--) {
            rSum[i] += rSum[i + 1];
            gSum[i] += gSum[i + 1];
            bSum[i] += bSum[i + 1];
            if (arr[i] == 'R') {
                rSum[i]++;
            } else if (arr[i] == 'G') {
                gSum[i]++;
            } else if (arr[i] == 'B') {
                bSum[i]++;
            }
        }
        long total = 0;
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                if (arr[i] == arr[j]) {
                    continue;
                }
                if ((arr[i] == 'R' && arr[j] == 'G') || (arr[i] == 'G' && arr[j] == 'R')) {
                    total += bSum[j + 1];
                    if (j + (j - i) < n && arr[j + (j - i)] == 'B') {
                        total--;
                    }
                } else  if ((arr[i] == 'G' && arr[j] == 'B') || (arr[i] == 'B' && arr[j] == 'G')) {
                    total += rSum[j + 1];
                    if (j + (j - i) < n && arr[j + (j - i)] == 'R') {
                        total--;
                    }
                } else  if ((arr[i] == 'R' && arr[j] == 'B') || (arr[i] == 'B' && arr[j] == 'R')) {
                    total += gSum[j + 1];
                    if (j + (j - i) < n && arr[j + (j - i)] == 'G') {
                        total--;
                    }
                }
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 36716
# ABC166 B

def main():
    n, k = map(int, input().split())
    
    sunuke = [0] * n

    for i in range(k):
        d = int(input())
        A = list(map(int, input().split()))

        for j in A:
            sunuke[j-1] += 1
    
    print(sunuke.count(0))



if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include <iostream>
#include <bits/stdc++.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <math.h>
#define ll long long int
using namespace std;

ll mod = 998244353;

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll modInverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin >> n >> k;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin >> arr[i];
    int dp[k+1];
    for(int i=0;i<=k;i++)
        dp[i] = 2;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i-arr[j]<0)
                continue;
            else
            {
                if(dp[i-arr[j]]==2)
                    dp[i] = 1;
            }
        }
    }
    if(dp[k]==1)
        cout << "First";
    else
        cout << "Second";
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n,t;
cin>>n>>t;
ll a,b;
ll ans=infll;
for(int i=0;i<n;i++){
    cin>>a>>b;
    if(b<=t){
        chmin(ans,a);
    }
}
if(ans==infll){
    cout<<"TLE"<<endl;
}else{
    cout<<ans<<endl;
}
}












Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		String linea = in.readLine();
		while(linea!=null&&!linea.trim().equals("")){
			int n=Integer.parseInt(linea);
			int arr[]=new int [n];
			StringTokenizer toks = new StringTokenizer(in.readLine());
			for (int i = 0; i < n; i++) 
				arr[i]=Integer.parseInt(toks.nextToken());
			boolean crece=false;
			boolean decrece=false;
			int tam=1;
			int cont=0;
			for (int i = 0; i < arr.length-1; i++) {
				if(crece){
					if(arr[i]<=arr[i+1]){
						tam++;
					}else{
						cont++;
						crece=false;
						//decrece=true;
						tam=0;
						if(i==arr.length-2){
							
						}
						//i++;
					}
				}else if(decrece){
					if(arr[i]>=arr[i+1]){
						tam++;
					}else{
						cont++;
						decrece=false;
						//crece=true;
						tam=0;
						//i++;
					}
				}else{
					if(arr[i]<arr[i+1]){
						crece=true;
						tam++;
					}else if(arr[i]>arr[i+1]){
						decrece=true;
						tam++;
					}else tam++;
				}
			}
			
//			if(crece){
//				if(arr[arr.length-2]<=arr[arr.length-1]){
//					tam++;
//				}else{
//					cont++;
//					crece=false;
//					//decrece=true;
//					tam=0;
//					//i++;
//				}
//			}else if(decrece){
//				if(arr[i]>=arr[i+1]){
//					tam++;
//				}else{
//					cont++;
//					decrece=false;
//					//crece=true;
//					tam=0;
//					//i++;
//				}
//			}else{
//				if(arr[i]<arr[i+1]){
//					crece=true;
//					tam++;
//				}else if(arr[i]>arr[i+1]){
//					decrece=true;
//					tam++;
//				}else tam++;
//			}
//			//if(arr[arr.length-2])
//			if(tam>0)cont++;
			
			out.println(++cont);
			linea=in.readLine();
		}
		
		in.close();
		out.close();
	}
}


Measured memory_bytes: 36616
n=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        if 4*i*j-n*i-n*j>0 and i*j*n%(4*i*j-n*i-n*j)==0:
            print(i,j,i*j*n//(4*i*j-n*i-n*j))
            exit()

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

long long calc(long long k){
    if(k%2==0) return (k/2%2)^k;
    else return (k+1)/2%2;
}

int main(void){
    long long A,B;
    cin>>A>>B;
    
    cout<<(calc(A-1)^calc(B))<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    S = input()
    T = input()

    ans = 0
    for s, t in zip(S, T):
        if s != t:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9312
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    n = int(input())
    a_list = list(map(int, input().split()))


    ans_list = []
    ans_list.append(0)
    for i in range(len(a_list)):
        ans_list.append(0)

    for ai in a_list:
        ans_list[ai-1] += 1

    for answer in ans_list:
        print(answer)




if __name__ == "__main__":
    resolve()



Measured memory_bytes: 99876
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
	long long int n, a[110], cnt = 0, ans = 1e9;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = a[0]; i <= a[n - 1]; i++) {
		for (int j = 0; j < n; j++) {
			cnt += pow(a[j] - i, 2);
		}
		ans = min(ans, cnt);
		cnt = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256