akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int isprime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0 && (i % 7 == 1 || i % 7 == 6) && (n / i % 7 == 1 || n / i % 7 == 6)) {
            return false;
        }
    }
    return true;
}

int toint(string s) {
    string b;
    copy_if(all(s), back_inserter(b), [](char c) { return c != ':'; });
    return stoi(b);
}

struct P { ll p, a, b, c, d, e, f, s, m; string nm; };

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    const int dir[6][2] = {{1, 1}, {1, 0}, {0, -1}, {-1, -1}, {-1, 0}, {0, 1}};

    for (;;) {
        int t, n; cin >> t >> n;
        if (!t) break;

        map<int, map<int, int>> dist;

        rep(i, 0, n) {
            int x, y; cin >> x >> y;
            dist[x][y] = -1;
        }

        queue<pair<int, int>> q;
        int sx, sy;
        cin >> sx >> sy;

        dist[sx][sy] = 1;
        q.push({sx, sy});

        int ans = 1;

        while (!q.empty()) {
            int x, y;
            tie(x, y) = q.front(); q.pop();
            if (dist[x][y] > t) break;
            for (int i = 0; i < 6; i++) {
                int nx = x + dir[i][0], ny = y + dir[i][1];
                if (dist[nx][ny] == 0) {
                    ans++;
                    dist[nx][ny] = dist[x][y] + 1;
                    q.push({nx, ny});
                }
            }
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 3304
a = list(input())
b = list(input())
c = list(input())
dum = a.pop(0)
for i in range(300):
    if dum == "a":
        if len(a) != 0:
            dum = a.pop(0)
        else:
            print("A")
            exit()
    elif dum == "b":
        if len(b) != 0:
            dum = b.pop(0)
        else:
            print("B")
            exit()
    else:
        if len(c) != 0:
            dum = c.pop(0)
        else:
            print("C")
            exit()


Measured memory_bytes: 3064
#include<stdio.h>
typedef long long ll;
ll a,b,c;
int main(){
	scanf("%lld %lld %lld",&a,&b,&c);
	if(b >= c && b >= a) {ll tmp = a; a = b; b = tmp;}
	else if(c >= b && c >= a) {ll tmp = a; a = c; c = tmp;}
	
	int cnt = 0;
	while(b <= a-2) b += 2,cnt++;	
	while(c <= a-2) c += 2,cnt++;
	
	if(a == b && b == c)printf("%d",cnt);
	else if(b <a && c < a) printf("%d",cnt+1);
	else printf("%d",cnt+2);
}


Measured memory_bytes: 128
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int A=sc.nextInt();
        int B=sc.nextInt();
        int m=sc.nextInt();
        int a[]=sc.nextIntArray(A);
        int b[]=sc.nextIntArray(B);
        int r=1<<28;
        for (int i = 0,x,y,c; i < m; i++) {
			x=sc.nextInt()-1;
			y=sc.nextInt()-1;
			c=sc.nextInt();
			r=min(r,a[x]+b[y]-c);
		}
        sort(a);
        sort(b);
        r=min(r,a[0]+b[0]);
    
        out.println(r);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int i,x,r,f;
    P(int i,int x,int r,int f) {
    	this.i=i;
    	this.x=x;
    	this.r=r;
    	this.f=f;
    }

    public int compareTo(P p){
    	if(-this.r+p.r==0) {
    		return -this.x+p.x;
    	}
        return -this.r+p.r;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 52708
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  if(n<10){
    cout<<n<<endl;
  }else if(n<100){
    cout<<9<<endl;
  }else if(n<1000){
    cout<<9+(n-99)<<endl;
  }else if(n<10000){
    cout<<909<<endl;
  }else if(n<100000){
    cout<<909+(n-9999)<<endl;
  }else{
    cout<<90909<<endl;
  }



  return 0;
}


Measured memory_bytes: 256
n,m=map(int, input().split())
a=[1]*n
b=[1]+[0]*(n-1)
for i in range(m):
    x,y=map(int, input().split())
    a[x-1]-=1
    a[y-1]+=1
    if b[x-1]==1:b[y-1]=1
    if a[x-1]==0:b[x-1]=0
print(sum(b))

Measured memory_bytes: 5364
def dist(x, y):
    d = 0.0
    for i in range(len(x)):
        d += (x[i] - y[i]) ** 2
    return d ** 0.5

n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(tuple(map(int, input().split())))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        d = dist(x[i], x[j])
        if abs(d - int(d)) < 1e-6:
            ans += 1
print(ans)


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; 
  long long k;
  cin >> n >> k;
  vector<long long> s(1e5 + 10, 0);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    s[a] += b;
  }
  long long cnt = 0;
  for (int i = 0; i < 1e5 + 10; i++) {
    cnt += s[i];
    if (k <= cnt) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
-- Your code here!
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
 
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    a <- getInt
    
    print $ 3*a*a

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

int main(){
	string s;
	cin >> s;
	rep(i, 3) if(s[i] == '7'){
		cout << "Yes" << endl;
		return 0;
	} 
	cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


int W, N;
int tv[1010];
int tw[1010];
int dp[1010][1010];


void input(){
	string s;
	stringstream ss;
	cin >> N;
	rep(i, 1, N+1){
		cin >> s;
		replace(s.begin(), s.end(), ',', ' ');
		ss.clear();
		ss << s;
		ss >> tv[i] >> tw[i];
	}
}


void makeDP(){
	rep(i, 0, N){
		rep(j, 0, W+1){
			if(tw[i+1] > j) dp[i+1][j] = dp[i][j];
			else dp[i+1][j] = max(dp[i][j-tw[i+1]] + tv[i+1], dp[i][j]);
		}
	}
}

int main(){
	int d = 0;
	while(d++, cin >> W, W){
		input();
		makeDP();
		auto v = max_element(&dp[N][0], &dp[N][W+1]);
		auto w = v - &dp[N][0];

		cout << "Case " << d << ':' << endl;
		cout << *v << endl;
		cout << w << endl;
	}

	return 0;
}

Measured memory_bytes: 7136
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var swr = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(swr);
            var line = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
            string s = Console.ReadLine();
            var ss = s.Trim().Split('-');
            if (ss[0].Length == line[0] && ss[1].Length == line[1])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }


            Console.Out.Flush();
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

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

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {

    map<int, pair<int, int> > memo;
    map<int, vector<int>> pos;
    for (int i = 0; i < B.size(); i++) {
        memo[B[i]].second++;
    }
    for (int i = 0; i < A.size(); i++) {
        memo[A[i]].first++;
        pos[A[i]].push_back(i);
    }
    vector<pair<int, pair<int, int>>> c;
    for (auto i : memo) {
        c.push_back({i.first, i.second});
    }


    int rot = 0;
    auto f = [&](){
        vector<pair<int, int> > matchings;
        multiset<int> cands;
        for (auto y : c) {
            if (y.second.second + y.second.first > N) {
                cout << "No" << endl;
                exit(0);
            }
            for (int i = 0; i < y.second.first; i++) {
                cands.insert(y.first);
            }
        }

        sort(c.begin(), c.end(), [&](pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
            return max(a.second.first, a.second.second) > max(b.second.first, b.second.second);
        });
        auto it = cands.begin();

        rotate(c.begin(), c.begin() + rot, c.end());
        for (auto y : c) {
            int crash = 0;
            int fail = 0;
            for (int i = 0; i < y.second.second; i++) {
                if (it == cands.end()) {
                    it = cands.begin();
                    crash++;
                    if (crash > 3) {
                        return;
                    }
                }
                if (*it != y.first) {
                    matchings.push_back({*it, y.first});
                    it = cands.erase(it);
                } else {
                    ++it;
                    --i;
                }
            }
        }

        vector<int> BX(N);
        for (auto i : matchings) {
            BX[pos[i.first].back()] = i.second;
            pos[i.first].pop_back();
        }
        cout << "Yes" << endl;
        for (auto i : BX) {
            cout << i << " ";
        }
        cout << endl;
        exit(0);
    };

    while (true) {
        f();
        rot++;
    }


}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    std::vector<long long> B(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


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

int main() {

    ll X, Y;
    cin >> X >> Y;

    ll ans = 0, now = X;
    while (now <= Y) {
        now *= 2;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;
int f(int);

int main(){

	int x, d;
	long int sum;

	while(cin >> d){
		sum = 0;

		for(int i=1 ; i*d<600 ; i++){
		sum += f(600 - i*d) * d;
		}

		cout << sum << endl;
	}

	return 0;
}

int f(int x){
	return x*x;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void){
  int N;
  scanf("%d", &N);
  //printf("N=%d\n", N);

  int a,i;
  int grade[9]={0};
  for (i=0;i<N;i++){
    scanf("%d", &a);
    // printf("%d",a);
    if(grade[0]==0 && a<400){
      grade[0]=1;
    }else if(grade[1]==0 && a>399 && a<800){
      grade[1]=1;
    }else if(grade[2]==0 && a>799 && a<1200){
      grade[2]=1;
    }else if(grade[3]==0 && a>1199 && a<1600){
      grade[3]=1;
    }else if(grade[4]==0 && a>1599 && a<2000){
      grade[4]=1;
    }else if(grade[5]==0 && a>1999 && a<2400){
      grade[5]=1;
    }else if(grade[6]==0 && a>2399 && a<2800){
      grade[6]=1;
    }else if(grade[7]==0 && a>2799 && a<3200){
      grade[7]=1;
    }else if(a>3199){
      grade[8]+=1;
    }
  }
  //printf("%d\n", i);

  //printf("%d\n", grade[8]);

  int max=0,min=0;
  for(i=0;i<8;i++){
    min+=grade[i];
  }



  /*if(grade[8]+min>8){
    max=8;
  }else{
    max=grade[8]+min;
  }*/

  max=min+grade[8];

  if(min==0){
    min=1;
  }

  printf("%d %d\n", min, max);

  return 0;

}


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

int main(){
  int x,s1,s2,s3;
  cin >> x;
  s1=x/100;
  s2=(x-s1*100)/10;
  s3=(x-s1*100-s2*10)/1;
  cout << s1+s2+s3 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class CXYetAnotherDieGame {
public:
	void solve(istream& in, ostream& out) {
        ll x;
        in >> x;
        if(x <= 6) out << 1 << endl;
        else if(x % 11 > 6) out << (x / 11) * 2 + 2 << endl;
        else if(x % 11 <= 6 && x % 11 != 0) out << (x / 11) * 2 + 1 << endl;
        else if(x % 11 == 0) out << (x / 11) * 2 << endl;
	}
};

int main() {
	CXYetAnotherDieGame solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var k = int.Parse(input[2]);

            var list = new List<int>();

            var z = 0;

            if (a < b)
            {
                z = a;
            }
            else
            {
                z = b;
            }
            for (int i = 1; i <= z; i++)
            {
                if(a%i==0 && b % i == 0)
                {
                    list.Add(i);
                }
            }
           
            var x = list.Count - k;
            Console.WriteLine(list[x]);
            
        }
    }
}


Measured memory_bytes: 11092
from collections import Counter
import numpy as np


def solve(n, a_list):
    count_a = Counter(a_list)
    res = 0
    # sieve
    sieve = np.ones(10 ** 6 + 1)
    for i in range(10 ** 6 + 1):
        if sieve[i]:
            if count_a[i] > 0:
                sieve[i::i] = 0
            if count_a[i] == 1:
                res += 1
    return res


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(5, [24, 11, 8, 3, 16]) == 3
    assert solve(4, [5, 5, 5, 5]) == 0
    assert solve(10, [33, 18, 45, 28, 8, 19, 89, 86, 2, 4]) == 5


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 56716
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=405;
int f[N][N],c[N][N];
int n,m,a,b,ans;

int main(){
	read(n),read(m);
	rep(i,1,n) f[i][i]=1;
	rep(i,1,m){
		read(a),read(b);
		rep(u,1,n) f[u][a]=f[u][b]=min(2,f[u][a]+f[u][b]);
	}
	rep(i,1,n) rep(x,1,n) rep(y,x+1,n)
		if(f[i][x]+f[i][y]>=2) c[x][y]++;
	rep(i,1,n) rep(j,i+1,n)
		if(c[i][j]==0) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1536
a, op, b = input().split()
a = int(a)
b = int(b)
while op != '?':
    if op == '/':
        print(a // b)
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    else:
        print(a * b)
    a, op, b = input().split()
    a = int(a)
    b = int(b)


Measured memory_bytes: 5592
#include<iostream>
  
using namespace std;
 
int main()
{
  int N, num[101];
  cin >> N;
  for(int i = 0; i < N; i++)
    cin >> num[i];
 
  long long dp[101][21] = {{0}};
  dp[0][num[0]] = 1;
  for(int i = 1; i < N-1; i++){
    for(int j = 0; j <= 20; j++){
      if(j - num[i] >= 0)
	dp[i][j - num[i]] += dp[i-1][j];
      
      if(j + num[i] <= 20)
	dp[i][j + num[i]] += dp[i-1][j];
    }
  }
 
  cout << dp[N-2][num[N-1]] << endl;

}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)
 
#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;
 
const int INF = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	vi prefix_r(n, 0);
	vi prefix_g(n, 0);
	vi prefix_b(n, 0);
	
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			prefix_r[i] = prefix_r[i-1];
			prefix_b[i] = prefix_b[i-1];
			prefix_g[i] = prefix_g[i-1];
		}
			if (s[i] == 'R') prefix_r[i] += 1;
			if (s[i] == 'G') prefix_g[i] += 1;
			if (s[i] == 'B') prefix_b[i] += 1;
		
		
	}
	//debugn(prefix_r);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+2; j < n; j++) {
			if (s[i] != s[j]) {
				if (s[i] == 'R' && s[j] == 'G') {
					ans += prefix_b[j-1]-prefix_b[i];
					if ((j-i+1)&1) {
						if (s[(i+j)/2] == 'B') ans--;
					}
				}
				if (s[i] == 'G' && s[j] == 'R') {
					ans += prefix_b[j-1]-prefix_b[i];
					if ((j-i+1)&1) {
						if (s[(i+j)/2] == 'B') ans--;
					}				
				}
				if (s[i] == 'R' && s[j] == 'B') {
					ans += prefix_g[j-1]-prefix_g[i];
					if ((j-i+1)&1) {
						if (s[(i+j)/2] == 'G') ans--;
					}				
				}
				if (s[i] == 'B' && s[j] == 'R') {
					ans += prefix_g[j-1]-prefix_g[i];
					if ((j-i+1)&1) {
						if (s[(i+j)/2] == 'G') ans--;
					}				
				}
				if (s[i] == 'B' && s[j] == 'G') {
					ans += prefix_r[j-1]-prefix_r[i];
					if ((j-i+1)&1) {
						if (s[(i+j)/2] == 'R') ans--;
					}				
				}
				if (s[i] == 'G' && s[j] == 'B') {
					ans += prefix_r[j-1]-prefix_r[i];
					if ((j-i+1)&1) {
						if (s[(i+j)/2] == 'R') ans--;
					}	
				}
			}
			//debug2(s[i], s[j]);
			//debug(ans);
		}
	}
	cout << ans << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined



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

const int mod = 1000000007;

int H, W;
int ok[1009][1009];
int dp[1009][1009];

int main() {
    cin >> H >> W;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++) {
            char c;
            cin >> c;
            ok[i][j] = (c == '.'); // 壁なら 0, そうでないなら 1
        }

    dp[0][0] = 1;
    for(int i = 0; i < H; i++) {
        for(int j = !i; j < W; j++) {
            if(i) dp[i][j] += dp[i - 1][j];
            if(j) dp[i][j] += dp[i][j - 1];
            dp[i][j] *= ok[i][j];
            if(dp[i][j] >= mod) dp[i][j] -= mod;
        }
    }

    cout << dp[H - 1][W - 1] << endl;

    return 0;
}

Measured memory_bytes: 8192
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	S := make([]string, H+2)
	for i := 0; i < H+2; i++ {
		if i == 0 || i == H+1 {
			var t []rune
			for j := 0; j < W+2; j++ {
				t = append(t, '.')
			}
			S[i] = string(t)
		} else {

			var t string
			fmt.Scan(&t)
			S[i] = "." + t + "."
		}
	}
	for i := 1; i <= H; i++ {
		for j := 1; j <= W; j++ {
			if S[i][j] == '#' {
				fmt.Print("#")
			} else {
				b := 0
				if S[i-1][j-1] == '#' {
					b++
				}
				if S[i-1][j] == '#' {
					b++
				}
				if S[i-1][j+1] == '#' {
					b++
				}
				if S[i][j-1] == '#' {
					b++
				}
				if S[i][j] == '#' {
					b++
				}
				if S[i][j+1] == '#' {
					b++
				}
				if S[i+1][j-1] == '#' {
					b++
				}
				if S[i+1][j] == '#' {
					b++
				}
				if S[i+1][j+1] == '#' {
					b++
				}
				fmt.Print(b)
			}

		}
		fmt.Println()
	}
}



Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int x = cin.nextInt();
        int[] a = cin.ArrayInt(N);
        long ans = 0;
        for (int i = 0; i < N - 1; i++)
        {
            int dec = Math.Min(a[i + 1], Math.Max(0, a[i] + a[i + 1] - x));
            a[i + 1] -= dec;
            ans += dec;
        }
        if(a[0]+a[1] > x)
        {
            ans += (a[0] + a[1]) - x;
        }
        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' '};

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 25056
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    string s, t;
    cin >> s >> t;

    ll ans = inf;

    for(ll i = 0; i < s.length(); i++) {
        ll last = i + t.length() - 1;
        if(last >= s.length())
            break;

        ll diff = 0;
        for(ll j = 0, k = i; j < t.length(); j++, k++)
            diff += (s[k] != t[j]);

        ans = min(ans, diff);
    }

    cout << ans << EL;

    return 0;
}


Measured memory_bytes: 3600
// I - Coins
#include <bits/stdc++.h>
using namespace std;
using dl = double;

vector<dl> dp(2999+2);

int main(){
	int N; scanf("%d",&N);
	int C = (N+1)/2;
	dp[1] = 1.;
	for(int lv=1; lv<=N; lv++){
		dl p; scanf("%lf",&p);
		dl q = 1.-p;
		int e = max(1, lv-C+2);
		for(int i=lv+1; i>=e; i--) dp[i] = q*dp[i] + p*dp[i-1];
	}
	dl a = 0; for(int i=N+1; i>C; i--) a += dp[i];
	printf("%.10g\n",a);
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	cout<<n*(n+1)/2-n/3*(n/3+1)/2*3-n/5*(n/5+1)/2*5+n/15*(n/15+1)/2*15<<endl;
}












Measured memory_bytes: 3612
N=int(input())
c=list(input())
x=0
M=N
for i in range(N):
  if c[i]=="W":
    for j in range(N):
      if i==M-1-j:
        M=i
        break
      elif c[M-1-j]=="R":
        x+=1
        c[M-1-j]="W"
        M=M-j
        break
  if i==M:
    break
print(x)

Measured memory_bytes: 10780
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            String str = String.valueOf(i);
            if (str.length() % 2 == 1) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 28244
#include<bits/stdc++.h>
using namespace std;
vector<int> graph[105];
bool vis[105];
int lvl[105];
int i;
void bfs(int rt)
{
    int src,adj;
    src=rt;
    deque<int>dq;
    vis[src]=1;
    lvl[src]=1;
    dq.push_back(src);
    while(!dq.empty())
    {
        src=dq.front();
        dq.pop_front();
        for(i=0; i<graph[src].size(); i++)
        {
            adj=graph[src][i];
            if(vis[adj]==0)
            {
                vis[adj]=1;
                lvl[adj]=lvl[src]+1;
                dq.push_back(adj);
            }
        }
    }
}
int main()
{
    int nodes,x,v;
    cin >> nodes;
    int u[200];
    memset(vis,0,sizeof(vis));
    memset(lvl,0,sizeof(lvl));
    for(i=1;i<=nodes;i++)
    {
        cin >> u[i];
        cin >> x;
        for(int j=0;j<x;j++)
        {
            cin >> v;
            graph[u[i]].push_back(v);
        }
    }
    bfs(1);
    for(i=1;i<=nodes;i++)
    {
        cout << u[i] << " " << lvl[u[i]]-1 << endl;
    }
}



Measured memory_bytes: 3168
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 5100;

int n;
vector<int> a;
vector<vector<int>> g;

int num[MAX];
int dp[MAX][MAX][2];
int sdp[MAX][2];

void rec(int v, int p) {
	num[v] = 1;
	for(int nv: g[v]) {
		if(nv == p) continue;
		rec(nv, v);
		num[v] += num[nv];
	}

	for(int i = 0; i <= num[v]; ++ i) {
		sdp[i][0] = sdp[i][1] = INF;
	}

	sdp[0][0] = a[v];
	if(a[v] > 0) sdp[0][1] = a[v];

	int cur = 0;
	for(int nv: g[v]) {
		if(nv == p) continue;
		for(int i = cur; i >= 0; -- i) {
			int tmp0 = sdp[i][0], tmp1 = sdp[i][1];
			sdp[i][0] = INF, sdp[i][1] = INF;
			for(int j = 0; j <= num[nv]; ++ j) {
				chmin(sdp[i + j][0], tmp0 + dp[nv][j][0]);
				if(dp[nv][j][0] < 0 || dp[nv][j][1] < INF) chmin(sdp[i + j + 1][0], tmp0);
				if(a[v] > 0) {
					chmin(sdp[i + j][1], tmp1 + dp[nv][j][1]);
					if(dp[nv][j][0] < 0 || dp[nv][j][1] < INF) chmin(sdp[i + j + 1][1], tmp1);
				}
			}
		}
		cur += num[nv];
	}

	for(int i = 0; i <= num[v]; ++ i) {
		dp[v][i][0] = sdp[i][0];
		dp[v][i][1] = sdp[i][1];
	}
}

void solve() {
	cin >> n;
	a.resize(n);
	rep(i, n) {
		cin >> a[i];
	}
	g.assign(n, vector<int>());
	rep(i, n - 1) {
		int u, v; cin >> u >> v; 
		-- u, -- v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 0; i < n; ++ i) {
		for(int j = 0; j <= MAX; ++ j) {
			dp[i][j][0] = dp[i][j][1] = INF;
		}
	}
	rec(0, -1);
	int ans = n;
	for(int j = n; j >= 0; -- j) {
		if(dp[0][j][0] < 0) ans = j;
		if(dp[0][j][1] < INF) ans = j;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 400512
#include<iostream>
#include<vector>
using namespace std;
bool check[100001];
vector<int> v[100001];
void dfs(int idx)
{
	if (check[idx])
		return;
	check[idx] = true;
	int v_size = v[idx].size();
	for (int i = 0; i < v_size; i++)
		if(!check[v[idx][i]])
			dfs(v[idx][i]);
}
int main()
{
	int n, m;
	cin >> n >> m;
	int x, y, z;
	for (int i = 0; i < m; i++)
	{
		cin >> x >> y >> z;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (!check[i])
		{
			dfs(i);
			cnt++;
		}
	}
	cout << cnt << '\n';
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  // dream, dreamer, erase, eraser
  string tmp_s = s;
  
  string usiro1;
  string usiro2;
  string usiro3;
  // 後ろから取っていく
  while(true){ 
    if (tmp_s.size()<6){
      usiro1 = tmp_s.substr(tmp_s.size()-5, 5);
    } else if (tmp_s.size()==6){
      usiro1 = tmp_s.substr(tmp_s.size()-5, 5);
      usiro2 = tmp_s.substr(tmp_s.size()-6, 6);
    } else {
      usiro1 = tmp_s.substr(tmp_s.size()-5, 5);
      usiro2 = tmp_s.substr(tmp_s.size()-6, 6);
      usiro3 = tmp_s.substr(tmp_s.size()-7, 7);
    }
    
    if ((usiro1=="dream") || (usiro1=="erase")){ 
      tmp_s = tmp_s.substr(0, tmp_s.size()-5);
    } else if (usiro2=="eraser"){ 
      tmp_s = tmp_s.substr(0, tmp_s.size()-6);
    } else if (usiro3=="dreamer"){ 
      tmp_s = tmp_s.substr(0, tmp_s.size()-7);
    } else { 
      cout << "NO" << endl;
      return 0;
    }
    
    if (tmp_s.size()==0){ 
      cout << "YES" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 512
process.stdin.resume();
process.stdin.setEncoding('utf8');
     
process.stdin.on('data', function (chunk) {
    var numbers = chunk.toString().split(" ");
	var S = parseInt(numbers.pop()), K = parseInt(numbers.pop());
	
	var c=0;
	for (var X=0; X <= K; X++)
		for (var Y=0; Y <= K; Y++){
			var Z = S - X - Y;
			if (Z >= 0 && Z <= K){
				c++;
			}
		}
	
    process.stdout.write(c.toString());    
     
    process.exit();
});

Measured memory_bytes: 11468
#include <iostream>
#include <stdio.h>
#include <iomanip>

using namespace std;

int main(){
    double a,b,c,d,e,f;
    double x,y;
    while(cin>>a>>b>>c>>d>>e>>f) {
        y = (c*d - a*f)/(b*d - a*e);
        x = (c*e - f*b)/(a*e - b*d);
        if(x == 0) {x = 0;}
        if(y == 0) {y = 0;}
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = k; i < n; i++) {
        if (a[i] > a[i - k]) printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 4064
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);	/*最大公約数*/
int lcm(int x, int y);	/*最小公倍数*/

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/



/*ここからmain関数*/

int main()
{
	int x, y, z;
	cin >> x >> y >> z;

	if (x == y && y == z)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

/*2数の大きい方を返す*/
int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

/*2数の小さい方を返す*/
int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

/*2数の最大公約数を返す*/
int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

/*2数の最小公倍数を返す*/
int lcm(int x, int y)
{
	int m;

	for (int i = 1;i <= y;i++)
	{
		if ((x*i) % y == 0) {
			m = x * i;
			break;
		}
	}

	return m;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> a;
ll foo(int i,vector<int> &dp){
    

    if(i==a.size()-1) return 0;

    if(i>=a.size()) return INT_MAX;
    
    if(dp[i]!=-1) return dp[i];

    ll l = foo(i+1,dp)+abs(a[i+1]-a[i]);
    ll r = foo(i+2,dp)+abs(a[i+2]-a[i]);

    return dp[i]=min(l,r);

}
int main(){

      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      int n;
      cin>>n;
      for(int i=0;i<n;i++)
      {
          int x;
          cin>>x;
          a.push_back(x);
      }
      vector<int> dp(n,-1);
      cout<<foo(0,dp)<<"\n";
}

Measured memory_bytes: 5880
#include<stdio.h>

int main(void){


    int a, b, d, r;


    double f;


    scanf("%d %d", &a, &b);


	d=a/b; r=a%b; f=(double)a/(double)b;


    printf("%d %d %lf\n", d, r, f);

    return 0;

} 

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long k, n;
long long v[200003];
long long maxx, aux;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> k >> n;
	
	for (int i = 1; i <= n; i++)
	{
		cin >> v[i];
		if (v[i] - v[i - 1] > maxx)
			maxx = v[i] - v[i - 1];
	}
	maxx = max(maxx,v[1] + k - v[n]);
	cout << k - maxx;
	return 0;
}

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


int main(void) {
	int N;
	std::cin >> N;
	std::vector<int> A(N);
	for (int i = 1; i <= N; i++) {
		int a;
		std::cin >> a;
		A[a-1]++;
	}
	std::sort(A.begin(), A.end());

	std::vector<int> Sum(N+1);
	for (int i = 0; i < N; i++) {
		Sum[i+1] = Sum[i]+A[i];
	}

	for (int K = 1; K <= N; K++) {
		int l = 0, r = N/K+1;
		while(l+1 < r) {
			int c = (l+r)/2;
			bool ok = [&](int c) {
				int i = std::lower_bound(A.begin(), A.end(), c) - A.begin();
				int sum = c*(N-i) + Sum[i];
				return (sum >= c*K);
			}(c);
		if (ok) l = c; else r = c;
		}
		std::cout << l << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3200
num = int(input())
inps = input().split()
num_list = [int(i) for i in inps]
smallest = num_list[0]
largest = num_list[0]
total = 0
for i in num_list:
    if i > largest:
        largest = i
    if i < smallest:
        smallest = i
    total += i
print("{} {} {}".format(smallest, largest, total))

Measured memory_bytes: 8728
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n + 1];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		for (int i = 0; i < k; i++) {
			int[] b = new int[n + 1];
			for (int j = 0; j < n; j++) {
				int l = Math.max(j - a[j], 0);
				int r = Math.min(j + a[j] + 1, n);
				b[l]++;
				b[r]--;
			}
			for (int j = 1; j < b.length; j++) {
				b[j] += b[j - 1];
			}
			a = b;

			boolean all = true;
			for (int j = 0; j < n; j++) {
				if (a[j] < n) {
					all = false;
					break;
				}
			}
			if (all) {
				break;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(a[i]).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 62860
n = gets.chomp.to_i
ar = []
n.times do |num|
  ar << gets.chomp.to_i
end
min_num = 10000000000000000
d = -10000000000000000000000000
ar.each do |i|
  num = i.to_i
  a = num - min_num 
  d = a if a > d
  min_num = num if min_num > num 
end
p d

Measured memory_bytes: 10464
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

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

    vector<int>pos[256];
    for(int i=0; i<s.size(); i++)
        pos[s[i]].push_back(i);

    reverse(pos['W'].begin(),pos['W'].end());

    int res = 0;
    while(!pos['W'].empty() && !pos['R'].empty()){
        if(pos['W'].back() > pos['R'].back())break;
        pos['W'].pop_back();
        pos['R'].pop_back();
        res++;
    }

    cout<<res;
}


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


Measured memory_bytes: 5172
#include <iostream>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;

    int c = a*b;

    if(c % 2 == 0)
        cout << "Even" << endl;
    if(c % 2 == 1)
        cout << "Odd" << endl;

    return 0;
}

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

const int maxn = 202000;
int n, q, lb, rb;
char s[maxn], t[maxn], d[maxn];

int main() {
    scanf("%d %d\n%s\n", &n, &q, s + 1);
    lb = 0, rb = n + 1; // (lb, rb) available
    rep(i, q) scanf("%c %c\n", &t[i], &d[i]);

    for(int i = q; i ; --i) {
        if(s[lb+1]==t[i] && d[i]=='L') lb++;
        if(s[rb-1]==t[i] && d[i]=='R') rb--;

        if(s[lb]==t[i] && d[i]=='R') lb--;
        if(s[rb]==t[i] && d[i]=='L') rb++;
    }

    printf("%d\n", rb - lb - 1);

    return 0;
}

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

int main() {
    ll A, B, K; cin >> A >> B >> K;
    if (A >= K) cout << A-K << " " << B << endl;
    else {
        ll K_ = K - A;
        if (B >= K_) cout << 0 << " " << B-K_ << endl;
        else cout << 0 << " " << 0 << endl;
    }
}

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

using namespace std;

int main() {
    int N;
    long long int K;
    cin >> N >> K;
    
    vector<long long int> A(N);
    vector<long long int> F(N);
    for(int n=0; n<N; n++) {
        cin >> A[n];
    }
    for(int n=0; n<N; n++) {
        cin >> F[n];
    }
    
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<long long int>());
    vector<long long int> vec(N);
    long long int r=0;
    for(int n=0; n<N; n++) {
        vec[n] = A[n]*F[n];
        if(r<vec[n]) {
            r = vec[n];
        }
    }
    long long int l=0;
    long long int mid;
    while(abs(r-l)>1) {
        long long int k=0;
        mid = (l+r)/2;
        for(int n=0; n<N; n++) {
            if(vec[n]<=mid) continue;

            k += (vec[n]-mid)/F[n];
            if((vec[n]-mid)%F[n]!=0) {
                k++;
            }
        }
        
        if(k<=K) {
            r = mid;
        } else {
            l = mid;
        }
    }

    long long int tmp=0;
    for(int n=0; n<N; n++) {
        if(vec[n]<=l) continue;

        tmp += (vec[n]-l)/F[n];
        if((vec[n]-l)%F[n]!=0) {
            tmp++;
        }
    }

    if(tmp<=K) {
        cout << l << endl;
    } else {
        cout << r << endl;
    }

    return 0;
    
}

Measured memory_bytes: 4992
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    from collections import defaultdict
    import bisect
    p = [list(map(int,input().split())) for _ in range(m)]
    a = defaultdict(list)
    for x,y in sorted(p):
        a[x] += [y]
    for x,y in p:
        z = bisect.bisect_right(a[x],y)
        print("%06d%06d"%(x,z))
if __name__ == '__main__':
  main()


Measured memory_bytes: 43320
n=int(input())
s=0

l=len(str(n))
for i in range(0,l-1):
    if i%2==0:
        s=s+(10**(i+1)-10**(i))
    else:
        continue
if l%2==1:
    m=n-10**(l-1)+1
    print(m+s)
else:
    print(s)

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

vector<vector<int>> v;

int w,h;
void dfs(int y, int x, vector<vector<bool>> &used){
    for(int dy=-1;dy<=1;dy++){
        for(int dx=-1;dx<=1;dx++){
            if(dy==0 && dx==0)continue;
            int ddy = y+dy, ddx = x+dx;
            if(ddx<0 || ddy<0 || ddx>=w || ddy>=h)continue;
            if(v[ddy][ddx]!=1 || used[ddy][ddx]==true)continue;
            used[ddy][ddx] = true;
            dfs(ddy,ddx,used);
        }
    }
}

int main(){
    while(cin>>w>>h&&(w||h)){
        
        v.clear();
        v.resize(h,vector<int>(w));
        rep(i,h)rep(j,w)cin>>v[i][j];
        
        int ans = 0;
        vector<vector<bool>> used(h,vector<bool>(w,false));
        rep(i,h){
            rep(j,w){
                if(used[i][j]==false && v[i][j]==1){
                    used[i][j] = true;
                    dfs(i,j,used);
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3436
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
	char a[5];
	int sum = 1;
	scanf("%s",a);
	for(int i=0;i<4;i++)
	{
		if(a[0]==a[1])
		{
			if(a[1]==a[2])
			{
				printf("Yes\n");break;
			}
			else
			{
				printf("No\n");break;
			}
		}
		if(a[0]!=a[1])
		{
			if(a[1]==a[2])
			{
				if(a[2]==a[3])
				{
					printf("Yes\n");break;
				}
				else
				{
					printf("No\n");break;
				}
			}
			else
			{
				printf("No\n");break;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 256
a = input()
b = input()
c = input()

abc = a[0]
a = a[1:]

while 1:
	if abc == "a":
		if not a:
			print("A")
			break
		abc = a[0]
		a = a[1:]
	elif abc == "b":
		if not b:
			print("B")
			break
		abc = b[0]
		b = b[1:]
	else:
		if not c:
			print("C")
			break
		abc = c[0]
		c = c[1:]

Measured memory_bytes: 3064