akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int factor(int x){
  int res=0;
  for(int i=2;i*i<=x;i++){
    if(x%i==0){
      int z=x/i;
      if(z==i) res++;
      else res+=2;
    }
  }
  return res;
}

int sum[100010];
int check[100010];

int main(){
  for(int i=2;i<=100000;i++){
    sum[i]+=sum[i-1];
    if(check[i]==1){
      sum[i]++;
      continue;
    }

    int num=factor(i);
    if(num>=3){
      sum[i]++;
      for(int j=2;i*j<=100000;j++){
        check[i*j]=1;
      }
    }
  }

  int Q;
  cin>>Q;
  vector<int> ans(Q,0);
  for(int i=0;i<Q;i++){
    int n;
    cin>>n;
    ans[i]=sum[n];
  }
  for(int i=0;i<Q;i++){
    cout<<ans[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 3976
//12252024832524
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; 

typedef long long LL;
const int MAXN = 200005;
int n;
map<int,int> m;

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(LL x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(LL x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = Read();
	LL ans = 0;
	for(int i = 1;i <= n;++ i)
	{
		int dz = Read();
		ans += m[i-dz];
		m[dz+i]++;
	}
	Put(ans);
	return 0;
}

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

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

	if (s.size() > t.size())
	{
		for (int i = t.size(); i > 0; --i)
		{
			bool flag = true; //OK_
			int hoi = 0;
			for (int j = s.size() - i; j < s.size(); ++j)
			{
		
				if (s[j] != t[hoi])
				{
					flag = false; //NO
					break;
				}
				
				++hoi;
			}
			if (flag)
			{
				cout << s.size() + t.size() - i << endl;
				exit(0);
			}
		}
		cout << s.size() + t.size() << endl;
	}
	else
	{
		for (int i = s.size(); i > 0; --i)
		{
			bool flag = true;
			int hoi = s.size() - i;
			for (int j = 0; j < i; ++j)
			{
				if (s[hoi] != t[j])
				{
					flag = false;
					break;
				}
				++hoi;
			}
			if (flag)
			{
				cout << s.size() + t.size() - i << endl;
				exit(0);
			}
		}
		cout << s.size() + t.size() << endl;
	}

}

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

int main() {
	int n, r, l = 0;
	cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		r += w[i];
	}
	int d, m = 99;
	for (int j = 0; j < n; j++) {
		r -= w[j];
		l += w[j];
		d = abs(r - l);
		m = min(d, m);
	} 
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nab = readInts()
    let n = nab[0]
    let a = nab[1]
    let b = nab[2]
    
    if n * a > b {
        print(b)
    } else {
        print(n * a)
    }
}

main()


Measured memory_bytes: 8240
#include<cstdio>
#include<cstring>

int main(){
    char str[1001];
    
    while(1){
        scanf("%s", str);
        if( str[0]=='0') break;
        int sum=0;
        for(int i=0; i<strlen(str); i++){
            sum+= (str[i]-'0');
        }
        
        printf("%d\n",sum);
        
    }
    return 0;
}



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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct SetUp {
    SetUp() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} setUp;

int N;
vint G[220000];
pint dfs(int idx, int par) {
    int m = 0;
    vint a;
    a.push_back(0), a.push_back(0);
    rep(i, G[idx].size()) {
        if (G[idx][i] == par) { continue; }
        pint cur = dfs(G[idx][i], idx);
        chmax(m, cur.first);
        a.push_back(cur.second);
    }
    sort(all(a)), reverse(all(a));
    pint ret = {max(a[0] + a[1] + 1, m), a[0] + 1};
    return ret;
}
signed main() {
    cin >> N;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if (dfs(1, 0).first % 3 == 2) { cout << "Second" << endl; }
    else { cout << "First" << endl; }
}

Measured memory_bytes: 41600
#include<bits/stdc++.h>
using namespace std; 
int main(){
  int A;int B; cin>>A>>B;
  int M=0;
  if(A==1){
    M+=300000;
    if(B==1)
      M+=700000;
    else if(B==2)
      M+=200000;
    else if(B==3)
      M+=100000;
    else M+=0;
  }
  else if(A==2){
    M+=200000;
    if(B==1)
      M+=300000;
    else if(B==2)
      M+=200000;
    else if(B==3)
      M+=100000;
    else M+=0;
  }
  else if(A==3){
M+=100000;
     if(B==1)
      M+=300000;
    else if(B==2)
      M+=200000;
    else if(B==3)
      M+=100000;
    else M+=0;
  }
  else{
   if(B==1)
      M+=300000;
    else if(B==2)
      M+=200000;
    else if(B==3)
      M+=100000;
    else M+=0;
  }
  cout<<M<<endl;
}

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

int main() {
  long long n, k, r, s, p, ans = 0;
  cin >> n >> k >> r >> s >> p;
  string T;
  cin >> T;

  vector<long> A(n);
  for (int i = 0; i < k; i++) {
    if (T.at(i) == 'r')
      A.at(i) = p;
    else if (T.at(i) == 's')
      A.at(i) = r;
    else
      A.at(i) = s;
  }

  for (int i = k; i < n; i++) {
    if ((T.at(i - k) == T.at(i)) & (A.at(i - k) > 0)) {
      A.at(i) = 0;
    } else {
      if (T.at(i) == 'r')
        A.at(i) = p;
      else if (T.at(i) == 's')
        A.at(i) = r;
      else
        A.at(i) = s;
    }
  }

  for (int i = 0; i < n; i++) {
    ans += A.at(i);
  }

  cout << ans << endl;
  return 0;
}


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

int main() {
    ll n, bn = INT64_MAX;
    cin >> n;
    rep(i, 5) {
        ll tmp;
        cin >> tmp;
        bn = min(bn, tmp);
    }

    ll ans = 5LL + (n - 1LL) / bn;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int digit(int n){
    int ret = 0;
    while (n>0)
    {
        n/=10;
        ret++;
    }
    return ret;
}
int main(){
    int n,Ans = 0;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++){
        if(digit(i)&1) Ans++;
    }
    printf("%d\n",Ans);
    return 0;
}

Measured memory_bytes: 128
import math
N=int(input())
ans=[0 for _ in range(10**4+1)]
for x in range(1, math.floor(math.sqrt(10**4))+1):
    for y in range(1, math.floor(math.sqrt(10**4))+1):
        for z in range(1, math.floor(math.sqrt(10**4))+1):
            if x*x + y*y + z*z + x*y + y*z + z*x <= 10**4:
                ans[x*x + y*y + z*z + x*y + y*z + z*x]+=1
for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 69656
#include<bits/stdc++.h>
#define eps 0.000000001
using namespace std;
typedef double ld;
typedef pair<int,int> p;
typedef pair<ld,p> P;

int n;
ld px[200],py[200],pz[200],vx[200],vy[200],vz[200],r[200],vr[200];

ld getlen(int a,int b,ld M){
  ld ax=px[a]+vx[a]*M,ay=py[a]+vy[a]*M,az=pz[a]+vz[a]*M,ar=r[a]-vr[a]*M;
  ld bx=px[b]+vx[b]*M,by=py[b]+vy[b]*M,bz=pz[b]+vz[b]*M,br=r[b]-vr[b]*M;
  ld dx=ax-bx,dy=ay-by,dz=az-bz;
  return sqrt(dx*dx+dy*dy+dz*dz)-(ar+br);
}

ld check(int a,int b){
  ld L=0,R=100,M;
  int s=0;
  while(s++<50){
    M=(L+R)/2;
    ld len=getlen(a,b,M),len1=getlen(a,b,M+eps);
    if(len<len1||len<0)R=M;
    else L=M;
  }
  if(getlen(a,b,R)>0)return 100;
  return R;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++)
      cin>>px[i]>>py[i]>>pz[i]>>vx[i]>>vy[i]>>vz[i]>>r[i]>>vr[i];
    priority_queue<P,vector<P>,greater<P> > q;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++)
	q.push(P(check(i,j),p(i,j)));
      q.push(P(r[i]/vr[i],p(i,i)));
    }
    ld used[200]={};
    while(!q.empty()){
      ld t=q.top().first;
      int a=q.top().second.first,b=q.top().second.second;
      q.pop();
      if(used[a]||used[b])continue;
      used[a]=used[b]=t;
    }
    for(int i=0;i<n;i++)printf("%.10lf\n",used[i]);
  }
  return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	
constexpr ll INF = static_cast<ll>(1e18);


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b;
	ci2(a,b);
	int ans =-1;
	for(int i= b*10; i<((b+1)*10);i++){
		if(floor(i*0.08)==a){
			ans=i;
			break;
		}
	}
	co(ans);
}


Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
d = dict()
for st in s:
    if st not in d:
        d[st] = 1
    else:
        d[st] += 1
m = max(d.values())
ans = set()
for k, v in d.items():
    if v == m:
        ans.add(k)
ans = sorted(ans)
for st in ans:
    print(st)


Measured memory_bytes: 103540
#include <stdio.h>

int main()
{
        double xa1, ya1, xa2, ya2;
        double xb1, yb1, xb2, yb2;
        int tmp;

        while ( scanf( "%lf %lf %lf %lf %lf %lf %lf %lf",
                        &xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2 ) == 8 ) {

                if ( xa2 < xb1 || xb2 < xa1 || ya2 < yb1 || yb2 < ya1 ) {
                        printf( "NO\n" );
                } else {
                        printf( "YES\n" );
                }
        }

        return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define pii pair<int,int>
#define prec(n) fixed<<setprecision(n)
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int n;cin>>n;
    vi v(n);cin>>v;
    sort(all(v));

    vector<double> ans(n-1);

    ans[0]=(v[0]+v[1])/2.0;

    for(int i=1;i<n-1;i++){
        ans[i]=(ans[i-1]+v[i+1])/2.0;
    }

    cout<<ans[n-2];

}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        xs: [(i64, i64); n],
    }
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] + xs[i].1;
    }
    const INF: i64 = 1 << 50;
    let mut ma = 0;
    let mut mi = INF;
    // acc[r + 1] - x[r] - acc[l] + x[l] (l <= r)
    for i in 0..n {
        mi = min(mi, acc[i] - xs[i].0);
        ma = max(ma, acc[i + 1] - xs[i].0 - mi);
    }
    puts!("{}\n", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

namespace AtCoder
{
  class Program
  {
    private static int n, a, b, c;
    private static int[] l;
    private static readonly char[] elements = { 'a', 'b', 'c', 'x' };
    private static int ans = -1;

    static void Main(string[] args)
    {
      n = ConsoleInput.ReadAsInt();
      a = ConsoleInput.ReadAsInt();
      b = ConsoleInput.ReadAsInt();
      c = ConsoleInput.ReadAsInt();
      l = ConsoleInput.ReadAsIntArray(n);

      DFS(new List<char>());
      Console.WriteLine(ans);
    }
    private static void DFS(List<char> pattern)
    {
      if (pattern.Count < n)
      {
        foreach (var e in elements)
        {
          var list = new List<char>(pattern);
          list.Add(e);
          DFS(list);
        }
      }
      else
      {
        Calc(pattern);
      }
    }

    private static void Calc(List<char> pattern)
    {
      var aLength = 0;
      var bLength = 0;
      var cLength = 0;
      var mp = -30;

      for (int i = 0; i < pattern.Count; i++)
      {
        switch (pattern[i])
        {
          case 'a':
            aLength += l[i];
            mp += 10;
            break;
          case 'b':
            bLength += l[i];
            mp += 10;
            break;
          case 'c':
            cLength += l[i];
            mp += 10;
            break;
          case 'x':
            break;
        }
      }

      if (aLength != 0 && bLength != 0 && cLength != 0)
      {
        mp += Math.Abs(a - aLength) + Math.Abs(b - bLength) + Math.Abs(c - cLength);

        if (ans == -1 || mp < ans)
        {
          ans = mp;
        }
      }
    }
  }

  class ConsoleInput
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadAsInt() => int.Parse(Read());
    public static long ReadAsLong() => long.Parse(Read());
    public static double ReadAsDouble() => double.Parse(Read());

    public static string[] ReadAsStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadAsIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadAsInt();
      }

      return array;
    }

    public static long[] ReadAsLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadAsLong();
      }

      return array;
    }
    public static double[] ReadAsDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadAsDouble();
      }

      return array;
    }
  }
}


Measured memory_bytes: 17480
#クラスカル法 最小全域木を求める

#union-find木
#クラスカル法にはUnion-find木が必要
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)] #親
        self.rank = [0 for _ in range(n)] #根の深さ

    #xの属する木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    #xとyの属する集合のマージ
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    #xとyが同じ集合に属するかを判定
    def same(self, x, y):
        return self.find(x) == self.find(y)


#クラスカル法
# V: 頂点集合(リスト) E: 辺集合[始点, 終点, 重み](リスト)
class kruskal():
    def __init__(self, V, E):
        self.V = V
        self.E = E
        self.E.sort(key=lambda x: x[2]) #辺の重みでソート

    def weight(self):
        UF = UnionFind(len(V)) #頂点数でUnion Find Treeを初期化
        res = 0
        for i in range(len(self.E)):
            e = self.E[i]
            
            if (UF.same(e[0], e[1])) == False:
                UF.unite(e[0], e[1])
                res += e[2]
                
        return res

    def edge(self):
        UF = UnionFind(len(V)) #頂点数でUnion Find Treeを初期化
        res_E = []
        for i in range(len(E)):
            e = E[i]
            
            if (UF.same(e[0], e[1])) == False:
                UF.unite(e[0], e[1])
                res_E.append(e)

        return res_E

    def node(self):
        UF = UnionFind(len(V)) #頂点数でUnion Find Treeを初期化
        res_V = []
        for i in range(len(E)):
            e = E[i]
            
            if (UF.same(e[0], e[1])) == False:
                UF.unite(e[0], e[1])
                res_V.append(e[0])
                res_V.append(e[1])

        return list(set(res_V))
        
A, B = map(int, input().split())
E = [list(map(int, input().split())) for _ in range(B)]

V = [i for i in range(A)]

kl = kruskal(V, E)

print(kl.weight())





Measured memory_bytes: 28596
#include<iostream>
using namespace std;
int main(){
int a,b,c,n,s=0;
cin>>a>>b>>c>>n;
for(int i=0;i<=a;i++)
for(int j=0;j<=b;j++)
for(int k=0;k<=c;k++)
if(i*500+j*100+k*50==n)
s++;
cout<<s;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < 0 && a[i + 1] < 0) {
      a[i] *= -1;
      a[i + 1] *= -1;
    }
    if (a[i] < 0 && a[i + 1] >= 0 && abs(a[i]) > a[i + 1]) {
      a[i] *= -1;
      a[i + 1] *= -1;
    }
  }
  cout << accumulate(a.begin(),a .end(), 0LL) << '\n';
  return 0;
}


Measured memory_bytes: 640
k, x = map(int,input().split())

maxv = x + (k-1)
minv = x - (k-1)
if maxv > 1000000:
  maxv = 1000000
  
if minv < -1000000:
  minv =  -1000000

ans = ''
for i in range(maxv-minv+1):
  ans += ' ' + str(minv+i) 
  
ans = ans.strip()
print(ans)

Measured memory_bytes: 3060
from collections import Counter

N = int(input())
C = list(input())

cnt = Counter(C)
ans1 = min(cnt["R"], cnt["W"])

ans2 = 0
l, r = 0, N-1
while l < r:
    if C[l] == "W" and C[r] == "R":
        ans2 += 1
        l += 1
        r -= 1
    else:
        if C[l] == "R":
            l += 1
        if C[r] == "W":
            r -= 1

ans = min(ans1, ans2)
print(ans)




Measured memory_bytes: 84476
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
         line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ans = int.MaxValue;
        for (int i = 0; i <=  n -k; i++)
        {
            var b = Math.Abs(a[i + k - 1] - a[i]);
            if (a[i + k - 1] <= 0) b += -a[i + k - 1];
            else if (a[i] >= 0) b += a[i];
            else b += Math.Min(-a[i], a[i + k - 1]);
            ans = Math.Min(ans, b);
        }
        Console.WriteLine(ans);
    }
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int a,b;
    cin >> a >> b;

    int c=a+b;
    if (c&1){
        cout << "IMPOSSIBLE" << el;
        return 0;
    }

    cout << c/2 << el;

    return 0;
}

Measured memory_bytes: 256
C = [list(map(int, input().split())) for _ in range(3)]
A = [0] * 3
B = [0] * 3
for i in range(3):
    B[i] = C[0][i] - A[0]
for j in range(1, 3):
    A[j] = C[j][0] - B[0]
ans = 'Yes'
for k in range(3):
    for l in range(3):
        if C[k][l] != A[k] + B[l]:
            ans = 'No'
            print(ans)
            exit()
print(ans)

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

int main()
{
    int n;
    string s;
    cin>>n>>s;
    int r=0,w=0;
    for(int i=0;i<n;i++){
        r+=(s[i]=='R');
        w+=(s[i]=='W');
    }
    int ans=r,c=0;
    for(int i=0;i<r;i++) c+=(s[i]=='R');
    ans=min(ans,r-c);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3744
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

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

int main() {
    int n = 0;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string res = "";
    for (int i=0; i<n; i++) {
        res.push_back(s.at(i));
        res.push_back(t.at(i));
    }
    cout << res << endl;
    return 0;
}


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

int main() {
	int r, c;
	cin >> r >> c;
	vector<vector<int>> table(r, vector<int>(c));
	for(int i = 0; i < r; i++) {
		for(int j = 0; j < c; j++) {
			cin >> table.at(i).at(j);
		}
	}
	int sum = 0;
	int all_sum = 0;
	for(int i = 0; i < r; i++) {
		for(int j = 0; j < c; j++) {
			cout << table.at(i).at(j) << " ";
			sum += table.at(i).at(j);
			all_sum += table.at(i).at(j);
		}
		cout << sum << endl;
		sum = 0;
	}
	for(int j = 0; j < c; j++) {
		for(int i = 0; i < r; i++) {
			sum += table.at(i).at(j);
		}
		cout << sum << " ";
		sum = 0;
	}
	cout << all_sum << endl;
}


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


int main() {

    int n;
    cin >> n;
    double ans = 0;
    rep(i,n) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") ans += x;
        else if (u == "BTC") ans += x * 380000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

int main(){
    int n;cin>>n;
    vector<int> P(n);
    for(int i=0;i<n;i++) cin>>P[i];
    
    int count=0;
    int m=n+1;
    for(int i=0;i<n;i++){
        if(m>P[i]){
            count++;
            m=P[i];
        } 
    }

    cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    string s, t;
    cin >> s >> t;
    map<char, int> sa, ta;
    int s_v = 1;
    for (char c : s) if (!sa[c]) sa[c] = s_v++;
    int t_v = 1;
    for (char c : t) if (!ta[c]) ta[c] = t_v++;
    bool cond = true;
    for (int i = 0; i < (int)s.length(); i++) {
        if (sa[s[i]] != ta[t[i]]) {
            cond = false;
            break;
        }
    }
    cout << (cond ? "Yes" : "No") << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
//constexpr ll mod = 1e9 + 7;
constexpr ll mod = 2019;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
    ans = 2019;
    cin >> L >> R;
    if (R - L + 1 >= 2019) {
        cout << 0 << endl;
    } else {
        for (int i = L; i <= R; i++) {
            for (int j = i + 1; j <= R; j++) {
                int ii = i % mod;
                int jj = j % mod;
                ans = min((ii * jj) % mod, ans);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9+5
int main() {
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	for(auto &i : v) {
		i.resize(3);
	}
	
	for(auto &ve : v) {
		for(int &i : ve) {
			cin>>i;
		}
	}
	
	vector<vector<int> > dp(n);
	for(auto &ve : dp) {
		ve.resize(3);
	}
		
	dp[0][0] = v[0][0];
	dp[0][1] = v[0][1];
	dp[0][2] = v[0][2];
		
	for(int i=1;i<n;i++) {
		for(int j=0;j<3;j++) {
			dp[i][j] = max(dp[i-1][(j+1)%3] + v[i][j], dp[i-1][(j+2)%3] + v[i][j]);
		}
	}
	
	int ma = 0;
	for(int i=0;i<3;i++) {
		ma = max(ma,dp[n-1][i]);
	}
	cout<<ma;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}

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

int a[999];

int main(){
    string s;
    cin >> s;
    for(char c: s) a[(int)c]++;
    for(int i='a'; i<='z'; i++){
        if(a[i] == 0){
            cout << (char)i << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans =0;
    string S;
    cin >> S;
    REP(i,4){
        if(S[i]=='+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
//#include <algorithm>

#include <stdio.h>
using namespace std;

void swap(int &a, int &b) {
    int tmp = b;
    b = a;
    a = tmp;
}

int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = true;
    int i = 0;
    while (flag) {
        flag = false;
        for (int j = N - 1; j > i; j--) {
            if (A[j] < A[j - 1]) {
                flag = true;
//				cout << j << " " << A[j - 1] << " " << A[j] << endl;
                swap(A[j], A[j - 1]);
//				cout << j << " " << A[j - 1] << " " << A[j] << endl;
                sw++;
            }
        }
		i++;
    }

    return sw;
}

int main(void) {
	int N;
    int sw;
	int A[100];
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
    sw = bubbleSort(A, N);


	for (int i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}



Measured memory_bytes: 3072
import random
import time

start = time.time()
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]


def main():
    best_score = 0
    best_ans = [0] * 26
    base = list(range(26))
    ans = [0] * 26
    while time.time() - start < 1.8:
        random.shuffle(base)
        score = calc_score(base)
        if score > best_score:
            best_score = score
            ans = base[:]

    for d in range(D):
        print(ans[d % 26] + 1)


def calc_score(T):
    score = 0
    last_day = [-1] * 26
    for d in range(D):
        t = T[d % 26]
        score += S[d][t]
        last_day[t] = d
        for c, ld in zip(C, last_day):
            score -= c * (d - ld)
    return score


if __name__ == "__main__":
    main()


Measured memory_bytes: 79624
#include<cstdio>
#include<iostream>
int main(){
    while(1){
        int x;
        int coin,n=0;
        scanf("%d",&x);
        if(x==0)
            break;
        x=1000-x;
        for(int i=0;i<6;i++){
            if(i==0)
                coin=500;
            else if(i==1)
                coin=100;
            else if(i==2)
                coin=50;
            else if(i==3)
                coin=10;
            else if(i==4)
                coin=5;
            else
                coin=1;
            for(;x>=coin;){
                x-=coin;
                n++;
            }
        }
        printf("%d\n",n);
    }
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 998244353;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
ll p[200009],p1[200009];
template<class T>
struct segtree
{
	vector<T> t;
	vector<T> lazy;
	segtree(int a, T val)
	{
		t.assign(4*a,val);
		lazy.assign(4*a,0);
	}
	
	void build(int a[], int v, int tl, int tr) 
	{
		if (tl == tr) t[v] = a[tl];
		else 
        {
			int tm = (tl + tr) / 2;
			build(a, v*2, tl, tm);
			build(a, v*2+1, tm+1, tr);
			t[v] = (p[tr-tm]*t[v*2]%mod + t[v*2+1])%mod;
			//cout<<t[v]<<' '<<tl<<' '<<tr<<'\n';
		}
	}
	
	T query(int v, int tl, int tr, int l, int r) 
	{
		if (l > r) return 0;
		if (l == tl && r == tr) return t[v];
		int tm = (tl + tr) / 2;
		push(v,tl,tr);
		return (p[tr-tm]*query(v*2, tl, tm, l, min(r, tm))%mod + 
		 query(v*2+1, tm+1, tr, max(l, tm+1), r))%mod;
	}
	
	void push(int v, int tl, int tr)
	{
		if(lazy[v]==0) return;
		int tm = (tl+tr)/2;
		t[v*2] = lazy[v]*p1[tm-tl+1]%mod;
		t[v*2+1] = lazy[v]*p1[tr-tm]%mod;
		lazy[v*2]=lazy[v*2+1]=lazy[v];
		lazy[v]=0;
	}
	
	void update(int v, int tl, int tr, int l, int r, T new_val) 
	{
		if(l>r) return;
		if (tl == l && tr == r)
		{
			t[v] = new_val*p1[tr-tl+1]%mod;
			lazy[v]=new_val;
		}
		else 
		{	
			push(v,tl,tr);
			int tm = (tl + tr) / 2;
			update(v*2, tl, tm, l, min(r,tm), new_val);
			update(v*2+1, tm+1, tr, max(l,tm+1), r, new_val);
			t[v] = (p[tr-tm]*t[v*2] + t[v*2+1]%mod)%mod;
		}
	}
};
segtree<ll> T(200009,0);
int a[200009];
void solve()
{
	p[0]=1;
	for(int i=1;i<=200000;i++) p[i]=p[i-1]*10%mod;
	for(int i=1;i<=200000;i++) p1[i]=(p1[i-1]*10%mod+1)%mod;
	
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++) a[i]=1;
	T.build(a,1,1,n);
	int l,r,d;
	//T.update(1,1,n,1,1,2);
	//cout<<T.t[1]<<'\n';
	while(q--)
	{
		cin>>l>>r>>d;
		T.update(1,1,n,l,r,d);
		cout<<T.t[1]<<'\n';
	}
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 19576
s = gets.chomp

s.chars.each_with_index do |char, i|
  if i%2 == 0
    unless ["R", "U", "D"].include?(char)
      puts "No"
      exit
    end
  else
    unless ["L", "U", "D"].include?(char)
      puts "No"
      exit
    end
  end
end

puts "Yes"


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end



int main(){
    int n,m; scanf("%d%d",&n,&m);
    int l; scanf("%d",&l);
    ll dist[310][310]; Fill(dist,INF);
    ll dist2[310][310]; Fill(dist2,INF);
    rep(i,0,n)dist[i][i]=dist2[i][i]=0;
    rep(i,0,m){
        int a,b,c; scanf("%d%d%d",&a,&b,&c);
        a--; b--;
        if(c<=l)dist[a][b]=dist[b][a]=c,dist2[a][b]=dist2[b][a]=1;
    }
    rep(k,0,n)rep(i,0,n)rep(j,0,n)chmin(dist[i][j],dist[i][k]+dist[k][j]);
    rep(i,0,n)rep(j,0,n)if(dist[i][j]!=INF){
        if(dist[i][j]<=l)dist2[i][j]=1;
    }
    rep(k,0,n)rep(i,0,n)rep(j,0,n)chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
    int q; scanf("%d",&q);
    rep(rot,0,q){
        int a,b; scanf("%d%d",&a,&b); a--; b--;
        printf(dist2[a][b]==INF?"-1\n":"%lld\n",dist2[a][b]-1);
    }
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main()
{
 int h,a,s=0;
 cin>>h>>a;
 while(1)
 {
     h=h-a;
     s++;
     if(h<=0)
     {
         break;
     }
 }
 cout<<s<<endl;
    return 0;


}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b/a) << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

class Program
{

    public static void Main()
    {
        long N = int.Parse(Console.ReadLine());

        //たくさん確保
        long[] a = new long[1000000];

        a[0] = 3;
        a[1] = 5;
        a[2] = 7;

        for (int i = 0; a[3 * (i - 1) + 5] <= N; i++)
        {
            a[3 * i + 3] = a[i] * 10 + 3;
            a[3 * i + 4] = a[i] * 10 + 5;
            a[3 * i + 5] = a[i] * 10 + 7;
//            (a[3 * i + 3],
//                a[3 * i + 4],
//                a[3 * i + 5]) = sgs(a[i]);
        }

        int count = 0;

        //全てのa[i]に対して、条件を満たすか調べる
        for (int i = 0; a[i] <= N; i++)
        {
            //            Console.WriteLine(a[i]);
            int check3 = 0;
            int check5 = 0;
            int check7 = 0;
            long tmp;

            tmp = a[i];

            //全ての桁に対して、数値を調べる
            for (int j = 0; j < 10; j++)
            {
                //                Console.WriteLine(tmp);
                if (tmp % 10 == 3)
                {
                    check3++; tmp /= 10;
                }
                else if (tmp % 10 == 5)
                {
                    check5++; tmp /= 10;
                }
                else if (tmp % 10 == 7)
                {
                    check7++; tmp /= 10;
                }

            }

            /*            Console.WriteLine("{0} {1} {2} {3}",
                                check3,
                                check5,
                                check7,
                                N);
            */
            if (check3 > 0
                && check5 > 0
                && check7 > 0
                && a[i] <= N)
            {
                count++;

            }
        }

        Console.WriteLine(count);
        //        (a[3], a[4], a[5]) = sgs(a[0]);
        //        (a[6], a[7], a[8]) = sgs(a[1]);
        //        (a[9], a[10], a[11]) = sgs(a[2]);
    }

/*    static public (long a, long b, long c) sgs(long d)
    {
        long a = d * 10 + 3;
        long b = d * 10 + 5;
        long c = d * 10 + 7;

        return (a, b, c);
    }
    */
}


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


signed main() {
  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> p;
  string simei;
  int tensu;
  int suzi;
  for( int i = 0; i < N; i++ ){
    cin >> simei;
    cin >> tensu;
    suzi = i+1;
    tensu *= -1;
    p.push_back(make_tuple(simei, tensu, suzi));
  }
  
  sort(p.begin(), p.end());
  
  for( auto zyun : p ){
    tie(simei, tensu, suzi) = zyun;
    cout << suzi << endl;
  }

  
}


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



int main() {


int n; cin >> n;
string s; cin >> s;
int red  =0;
int blue = 0;
for(int i = 0; i < n; i++){
  if(s[i] == 'R')red++;
  if(s[i] == 'B') blue++;
}

if(red > blue)
cout <<  "Yes";
else
cout << "No";





}


	


Measured memory_bytes: 256
def main():
    X = int(input())
    candidates = [1]
    c_append = candidates.append
    max_range = int(X**0.5) + 1
    for i in range(2, max_range):
        for j in range(2, max_range):
            powered = i ** j
            if powered > X:
                break
            else:
                c_append(powered)
    ans = max(candidates)
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll c[n],s[n],f[n];
  rep(i,0,n-1)cin>>c[i]>>s[i]>>f[i];
  c[n-1]=0,s[n-1]=0,f[n-1]=0;

  rep(i,0,n-1){
    ll sum=c[i]+s[i];
    rep(j,i+1,n){
      if(j==n-1){
        out(sum);
        break;
      }
      if(sum>s[j]){
        if((sum-s[j])%f[j]!=0){
          sum=s[j]+f[j]*ceil((double)(sum-s[j])/f[j])+c[j];
        }else sum+=c[j];

      }else{
        sum=s[j]+c[j];
      }
    }
  }
  out(0);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back

int r, c;
char grid[1111][1111];
pair<int,int> bg, ed;
int dist[1111][1111];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0 ,-1, 0};

void solve()
{
    memset(dist, 0x3F, sizeof dist);

    cin>>r>>c;
    cin>>bg.f>>bg.s;
    --bg.f,--bg.s;
    cin>>ed.f>>ed.s;
    --ed.f,--ed.s;
    forn(i, r) forn(j, c) cin>>grid[i][j];
    
    deque<pair<int,int>> dq;
    
    dist[bg.f][bg.s] = 0;
    dq.push_front(mp(bg.f, bg.s));
    while(sz(dq))
    {
        pair<int,int> now = dq.front(); dq.pop_front();
        forn(i, 4)
        {
            pair<int,int> nxt = mp(now.f + dx[i], now.s + dy[i]);
            if (nxt.f < 0 || nxt.f >= r) continue;
            if (nxt.s < 0 || nxt.s >= c) continue;
            if (grid[nxt.f][nxt.s] == '#') continue;
            if (dist[nxt.f][nxt.s] > dist[now.f][now.s])
            {
                dist[nxt.f][nxt.s] = dist[now.f][now.s];
                dq.push_front(nxt);
            }
        }
        for (int d1 = -2; d1<=2;++d1) for (int d2 = -2; d2 <= 2; ++d2)
        {
            pair<int,int> nxt = mp(now.f + d1, now.s + d2);
            if (nxt.f < 0 || nxt.f >= r) continue;
            if (nxt.s < 0 || nxt.s >= c) continue;
            if (grid[nxt.f][nxt.s] == '#') continue;
            if (dist[nxt.f][nxt.s] > dist[now.f][now.s] + 1)
            {
                dist[nxt.f][nxt.s] = dist[now.f][now.s] + 1;
                dq.push_back(nxt);
            }
        }
    }
    if (dist[ed.f][ed.s] >= 1e9) cout << -1 << '\n';
    else cout << dist[ed.f][ed.s] <<'\n';
}

signed main(void)
{
    int T = 1;
    // cout << fixed;
    // cout.precision(44);
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 14444
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

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

    int64_t n, x;
    cin >> n >> x;

    vector<int64_t> as(n);
    for (auto &a:as)
        cin >> a;

    int64_t ans = 0;
    for (int i = 0; i + 1 < n; i++) {
        int64_t over = as[i] + as[i + 1] - x;
        if (over > 0) {
            int64_t s = min(over, as[i + 1]);
            as[i + 1] -= s;
            ans += s;
        }

        over = as[i] + as[i + 1] - x;
        if (over > 0) {
            as[i] -= over;
            ans += over;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>

const int MAX_N = 3000;
long long f[MAX_N + 1][MAX_N + 1][2];
int a[MAX_N + 1];

long long dp(int l, int r, int d) {
  auto &ret = f[l][r][d];
  if (ret != -4485090715960753727ll) return ret;
  if (l == r) return ret = d ? a[l] : -a[l];
  if (d == 0) {
    ret = std::min(dp(l + 1, r, !d) - a[l], dp(l, r - 1, !d) - a[r]);
  } else {
    ret = std::max(dp(l + 1, r, !d) + a[l], dp(l, r - 1, !d) + a[r]);
  }
  return ret;
}

int main() {
  memset(f, -0x3f, sizeof(f));
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  std::cout << dp(1, n, 1);
  return 0;
}

Measured memory_bytes: 141056
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
string s;

int main() {
	cin >> n;
	VI a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	VI mae(n+1);VI usi(n+1);
	mae[0] = 0;
	for (int i = 0; i < n; i++)
	{
		mae[i + 1] = max(mae[i], a[i]);
	}
	usi[n] = 0;
	for (int i = 0; i < n; i++)
	{
		usi[n - i-1] = max(usi[n - i], a[n - i - 1]);
	}
	for (int i = 0; i < n; i++)
	{
		cout << max(mae[i], usi[i + 1])<<endl;
	}
}

Measured memory_bytes: 3968
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

int run(istream& in, ostream& out) {
    ll H, N;
    in >> H >> N;
    vector<ll> A(N), B(N);
    REP(i, N) {
        in >> A[i] >> B[i];
    }
    ll ans = 0;

    vector<vector<ll>> dp(N, vector<ll>(H+1));
    REP(j, H+1) {
        if (j == 0) {
            dp[0][j] = 0;
            continue;
        }
        dp[0][j] = (j + A[0] - 1) / A[0] * B[0];
    }
    REP(i, N-1) REP(j, H+1) {
        if (j == 0) {
            dp[i+1][j] = 0;
        } else if (j < A[i+1]) {
            dp[i+1][j] = min(dp[i][j], B[i+1]);
        } else {
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i+1]]+B[i+1]);
        }
    }
    ans = dp[N-1][H];
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 78464
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);++(i))
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);--(i))
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    stack<char> sc;
    REP(i,0,n){
        if (sc.empty() || s[i] == 'S' || sc.top() == 'T' && s[i] == 'T') sc.push(s[i]);
        else if (sc.top() == 'S') sc.pop();
    }

    cout << sc.size() << endl;

    return 0;
}

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

int main(){

    int r,c;
    long table[101][101];
    cin >> r >> c;

    for (int i = 0; i < r; i++){
        for (int j = 0; j < c; j++){
            cin >> table[i][j];
        }
    }

    for (int i = 0; i <= r; i++){
        table[i][c] = 0;
    }

    for (int j = 0; j <= c; j++){
        table[r][j] = 0;
    }

    for (int i = 0; i < r; i++){
        for (int j = 0; j < c; j++){
            table[i][c] += table[i][j];
            table[r][j] += table[i][j];
            table[r][c] += table[i][j];
        }
    }

    for (int s = 0; s <= r; s++){
        for (int t = 0; t <= c; t++){
            if (t != 0){
                cout << " " << table[s][t];
            } else {
                cout << table[s][t];
            }
        }
        cout << endl;
    }
    //cout << endl;
    return 0;

}


Measured memory_bytes: 3132