akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
char mp[405][405];
//bool vis[405][405];
int belong[405][405];
pair<int, int> S[160010];
int Scnt;
int h, w;
void dfs(int x, int y, int s)
{
	belong[x][y] = s;
	if (mp[x][y] == '#')
		++S[s].first;
	else
		++S[s].second;
	for (int i = 0; i < 4; ++i)
	{
		int nx = x + dx[i], ny = y + dy[i];
		if (nx > 0 && nx <= h && ny > 0 && ny <= w && mp[x][y] != mp[nx][ny] && belong[nx][ny] == 0)
		{
			dfs(nx, ny, s);
		}
	}
}
void input()
{
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
	{
		cin >> (mp[i] + 1);
	}
}

void solve()
{
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			if (!belong[i][j])
				dfs(i, j, ++Scnt);
	long long ans = 0;
	for (int i = 1; i <= Scnt; ++i)
		ans += 1LL * S[i].first * S[i].second;
	cout << ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	input();
	solve();
	return 0;
}


Measured memory_bytes: 11008
const main = (input) => {
  const args = input.split('\n')
  const k = Number(args[0])
  const s = args[1]
  if(s.length <= k) {
    console.log(s)
  } else {
    console.log(`${s.slice(0, k)}...`)
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    static int ans[4];
    for (int i = 0; i < N; ++i) {
        string S;
        cin >> S;
        if (S == "AC")
            ans[0]++;
        if (S == "WA")
            ans[1]++;
        if (S == "TLE")
            ans[2]++;
        if (S == "RE")
            ans[3]++;
    }

    cout << "AC x " << ans[0] << '\n';
    cout << "WA x " << ans[1] << '\n';
    cout << "TLE x " << ans[2] << '\n';
    cout << "RE x " << ans[3] << '\n';

    return 0;
}


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

long long int n, k, a[200012], ans;

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n - k; i++) {
		ans += a[i];
	}
	cout << ans;
	return 0;
}

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

using namespace std;

long long n,m;
long long p[100005],a[100005],b[100005],c[100005],d[100005];
long long kq;


main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for (long long i=1;i<=m;i++)
        cin>>p[i];
    for (long long i=1;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for (long long i=1;i<m;i++)
    {
        if (p[i+1]>p[i])
        {
            for (long long j=p[i];j<p[i+1];j++)
                d[j]++;
        }
        else
        {
            for (long long j=p[i]-1;j>=p[i+1];j--)
                d[j]++;
        }
    }
    for (long long i=1;i<=n;i++)
        kq+=min(c[i]+b[i]*d[i],a[i]*d[i]);
    cout<<kq<<"\n";



}

Measured memory_bytes: 7068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, T, A;
        public int[] H;
        public long MOD = 1000000007;
        public int[] used;
        public long[,] DP;

        public void Run()
        {
            N = Input.ReadInt();
            {
                var line = Input.ReadIntArray();
                T = line[0];
                A = line[1];
            }
            H = Input.ReadIntArray();

            T *= 1000;
            A *= 1000;

            int ret = -1;
            int dif = int.MaxValue;
            for (int i = 0; i < N; i++)
            {
                int d = Math.Abs(T - 6 * H[i] - A);

                if (d < dif)
                {
                    ret = i;
                    dif = d;
                }

            }

            Console.WriteLine(ret + 1);

        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13332
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

map<pii,int> mp;
vector<int> G[200005];
int c[200005];

int Q(int u,int x,int f)
{
	auto p=mp.find(MP(u,x));
	if(p!=mp.end()) return p->S;
	int re=0;
	for(int i:G[u])
		if(i!=f&&i<x)
			re+=Q(i,x,u)+1;
	return mp[MP(u,x)]=re;
}

void dfs(int u,int f,int m)
{
	int mv=max(m,f);
	if(u>m) c[u]=c[f]+Q(u,mv,f)+1;
	else c[u]=c[f]+Q(u,mv,f)-Q(u,m,f);
	for(int i:G[u])
		if(i!=f)
			dfs(i,u,mv);
}

int main()
{jizz
	int n,a,b;
	cin >> n;
	for(int i=1;i<n;++i)
		cin >> a >> b,G[a].pb(b),G[b].pb(a);
	for(int i:G[1])
		dfs(i,1,-1);
	for(int i=2;i<=n;++i)
		cout << c[i] << " \n"[i==n];
}


Measured memory_bytes: 41472
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n,x = map(int,input().split())
# 配列入力の受け取り
arrL = list(map(int,input().split()))

ans = [0]
junpzahyou = 0
i = 1
for i in arrL:
    junpzahyou += i
    if junpzahyou <= x:
        ans += [junpzahyou]
    else:
        continue

print(len(ans))
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000000; // = 10^20
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる
  ll cost; // e.costでその辺の重みにアクセスできる
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  ll ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  ll N;
  cin >> N;
  if (N % 2 == 1) {
    cout << 0 << endl;
  }
  else {
    N /= 2;
    ll ans = 0;
    for (int i = 1; i < N; i++) {
      if (N < modpow(5, i, LINF)) {
        break;
      }
      else {
        ans += (N / modpow(5, i, LINF));
      }
    }
    cout << ans << endl;
  }
}

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

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

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> Q[i];
  }
  
  // 昇順の配列
  vector<int> vec(N);
  for (int i = 0; i < N; i++) vec[i] = i+1;
  
  int a = 0;
  int i = 0;
  do {
    if (vec == P) {
      a = i;
      break;
    }
    i++;
    next_permutation(begin(vec), end(vec));
  } while (i < facctorialMethod(N));
  
  for (int i = 0; i < N; i++) vec[i] = i+1;
  int b = 0;
  i = 0;
  do {
    if (vec == Q) {
      b = i;
      break;
    }
    i++;
    next_permutation(begin(vec), end(vec));
  } while (i < facctorialMethod(N));
  
  if (a >= b) cout << a-b << endl;
  else cout << b-a << endl;
  
  return 0; 
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC168
{
    class B
    {
        static void Main(string[] args)
        {
            //var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var abcd = Enumerable.Repeat(0, (int)Q).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var K = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            if (S.Length <= K)
                Console.WriteLine(S);
            else
                Console.WriteLine(S.Substring(0, K) + "...");
        }
    }
}


Measured memory_bytes: 27544
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int num[58];
int main()
{
	int n,m,a,b;
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b;a--;b--;num[a]++;num[b]++;
	}
	rep(i,n) cout<<num[i]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char c[12];
	int a,b,i;
	scanf("%d%d",&a,&b);
	scanf("%s",c);
	if(c[a]!='-'||strlen(c)!=a+b+1)
	{
		printf("No");
		return 0;
	}
	else
	{
		for(i=0;i<strlen(c);i++)
		{
			if(i==a)
				continue;
			if(!(c[i]>='0'&&c[i]<='9'))
			{
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes");
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  double a,b;
  scanf("%lf", &a);
  scanf("%lf", &b);
  if(a>b)
    printf("GREATER\n");

  else if(b>a)
    printf("LESS\n");

  else
    printf("EQUAL\n");

  return 0;
}


Measured memory_bytes: 128
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
xt = 0
BC = A
for i in range(1, N):
	xt += x
	A = [A[-1]] + A[0:-1] 
	BC = [v if v < BC[i] else BC[i] for (i, v) in enumerate(A)]
	tempcost = xt + sum(BC)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
vector<P> to[100001];
ll d[100001]={};
void dfs(ll i,ll par){
    for(auto x:to[i]){
        if(x.first!=par){
            d[x.first]=d[i]+x.second;
            dfs(x.first,i);
        }
    }
}

int main(void){
    ll n,q,k;
    cin>>n;
    for(int i=0;i<n-1;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        to[a].push_back(make_pair(b,c));
        to[b].push_back(make_pair(a,c));
    }
    cin>>q>>k;
    dfs(k,-1);
    for(int i=0;i<q;i++){
        ll x,y;
        scanf("%d%d",&x,&y);
        printf("%lld\n",d[x]+d[y]);
    }
}

Measured memory_bytes: 14336
def main():
    s = input()

    rs, ls = 0, 0
    prev = ''
    A = [0] * len(s)
    for ci, c in enumerate(s):
        if c == 'R':
            if prev == 'l':
                A[ci - ls - 1] = rs//2 + ls//2 if rs % 2 == 0 \
                    else rs//2 + 1 + ls//2
                A[ci - ls] = rs//2 + ls//2 if ls % 2 == 0 \
                    else rs//2 + ls//2 + 1
                rs, ls = 0, 0

            rs += 1
            prev = 'r'
        else:
            ls += 1
            prev = 'l'

    A[-ls - 1] = rs//2 + ls//2 if rs % 2 == 0 \
        else rs//2 + 1 + ls//2
    A[-ls] = rs//2 + ls//2 if ls % 2 == 0 \
        else rs//2 + ls//2 + 1

    print(' '.join([str(a) for a in A]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 49136
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
vector< int > L;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, X;
  cin >> N >> X;
  REP(i, N) {
    int tmp;
    cin >> tmp;
    L.push_back(tmp);
  }
  int dis = 0, ans = 1;
  REP(i, N) {
    if (dis + L[i] > X) {
      break;
    } else {
      dis += L[i];
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  ll N;
  cin>>N;
  vector<P> vec(N);
  for(ll i=0;i<N;i++){
    ll a;
    cin>>a;
    vec.at(i)=make_pair(a,i+1);
  }
  sort(vec.begin(),vec.end());
  for(ll i=0;i<N;i++){
    cout<<vec.at(i).second<<" ";
  }
}

Measured memory_bytes: 2432
import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val n = sc.nextInt()
        val nodes = Array(n) { BinaryNode() }
        for (i in 0 until n) {
            val id = sc.nextInt()
            val left = sc.nextInt()
            val right = sc.nextInt()
            nodes[id].left = left
            nodes[id].right = right
            if (left != -1) {
                nodes[left].parent = id
            }
            if (right != -1) {
                nodes[right].parent = id
            }
        }

        var rootId = -1
        for (i in nodes.indices) {
            if (nodes[i].parent == -1) {
                rootId = i
            }
        }
        val hs = IntArray(n) { -1 }
        setHeights(rootId, hs, nodes)
        val ds = IntArray(n) { -1 }
        setDepths(rootId, ds, nodes, 0)

        for (i in 0 until n) {
            val node = nodes[i]
            val sibling = when {
                node.parent == -1 -> -1
                nodes[node.parent].left == i -> nodes[node.parent].right
                else -> nodes[node.parent].left
            }
            val type =
                    if (node.parent == -1) "root"
                    else if (node.left != -1 || node.right != -1) "internal node"
                    else "leaf"
            var degree = 0
            if (node.left != -1) ++degree
            if (node.right != -1) ++degree
            println("node $i: parent = ${node.parent}, " +
                    "sibling = $sibling, degree = $degree, " +
                    "depth = ${ds[i]}, height = ${hs[i]}, $type")
        }
    } catch (e: Exception) {
        println(e)
    }
}

fun setHeights(id: Int, hs: IntArray, nodes: Array<BinaryNode>): Int {
    var h1 = 0
    var h2 = 0
    if (nodes[id].left != -1) {
        h1 = setHeights(nodes[id].left, hs, nodes) + 1
    }
    if (nodes[id].right != -1) {
        h2 = setHeights(nodes[id].right, hs, nodes) + 1
    }
    hs[id] = Math.max(h1, h2)
    return hs[id]
}

fun setDepths(id: Int, ds: IntArray, nodes: Array<BinaryNode>, d: Int): IntArray {
    if (id == -1) return ds
    ds[id] = d
    setDepths(nodes[id].left, ds, nodes, d + 1)
    setDepths(nodes[id].right, ds, nodes, d + 1)
    return ds
}

class BinaryNode(
        var parent: Int = -1,
        var left: Int = -1,
        var right: Int = -1
)




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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (int)(1000000007)
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 1000005
#define mxnn 2000005
int dp[mxn];
int32_t main(){
sp;
int n,k;
cin >>n >>k;
int arr[n+1];
for(int i = 1;i<=n;i++) cin >>arr[i];
for(int i = 1;i<=k;i++){
    int x = 0;
    for(int j = 1;j<=n;j++) if(i-arr[j]>=0) if(dp[i-arr[j]] == 0) x = 1;
    dp[i] = x;
}
if(dp[k]) cout<<"First";
else cout<<"Second";
return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
ans = []
if S > K:
  for i in range(K+1):
    s_z = S - i
    if s_z < 0:
      pass
    elif K < s_z:
      if (K + 1) > (s_z - K):
        ans.append(K*2 - s_z + 1)
    else:
      ans.append(s_z + 1)

else:
  for i in range(S+1):
    s_z = S - i
    if s_z < 0:
      pass
    elif K < s_z:
      if (K + 1) > (s_z - K):
        ans.append(K*2 - s_z + 1)
    else:
      ans.append(s_z + 1)

print(sum(ans))

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.141592653589793238

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main(){
	ll a, b, h, m;
	cin >> a >> b >> h >> m;
	double hr = h * 60 + m;
	hr = hr * 0.5;
	double mn = m * 6;
	double theta = abs(hr - mn);
	theta = theta * (PI/180);
	trace(cos(theta), theta);
	cout << setprecision(15) << sqrt(a*a + b*b - 2*a*b*cos(theta)) << endl;
}

Measured memory_bytes: 4184
"use strict"

function main(input) {
  input = input.split(/\n|\s/)

  const words = input.slice(1, -1)

  let ans = "Yes"
  let prevword = words[0]
  let sets = new Set()
  sets.add(words[0])
  for (let i = 1; i < words.length; i++) {
    if (words[i][0] != prevword[prevword.length - 1] || sets.has(words[i])) {
      ans = "No"
      break
    }
    prevword = words[i]
    sets.add(words[i])
  }

  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7500
#include<stdio.h>

int main(){
  int tate,yoko;
  while(1){
    scanf("%d %d",&tate,&yoko);
    if(tate == 0&&yoko == 0){
      break;
    }else{
      for(int i = 1;i <= tate;i++){
        for(int k = 1;k <= yoko;k++){
          printf("#");
        }
        printf("\n");
      }
      printf("\n");
    }
  
  }
  return 0;
}

Measured memory_bytes: 1812
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    char[][] grid = new char[H][W];

    for (int i = 0; i < H; i++) {
      grid[i] = scanner.next().toCharArray();
    }

    int[][] ds = new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (grid[i][j] == '#') {
          boolean valid = false;
          for (int[] d : ds) {
            int y = i + d[0];
            int x = j + d[1];
            if (y >= 0 && y < H && x >= 0 && x < W && grid[y][x] == '#') valid = true;
          }
          if (!valid) {
            System.out.println("No");
            return;
          }
        }
      }
    }
    System.out.println("Yes");
  }
}


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

int main() {
	int N, i, tmp = 0;
	cin >> N;
	for (i = 0; i < N; ++i) {
		string S;
		cin >> S;
		if (S == "A") ++tmp;
		else {
			if (!tmp) break;
			--tmp;
		}
	}
	if (N != i || tmp) cout << "NO";
	else cout << "YES";
	cout << endl;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,x;
    cin >> n >> x;
    vector <long long> a(n);
    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    long long ans = 0;
    for(long long i = 0; i < (n-1); i++){
        if((x-a[i])>=0){
            x-=a[i];
            ans++;
        }else{
            break;
        }
    }
    if(x==a[n-1]){
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  vector<vector<int>> A(3,vector<int>(3));
  cin >> A[0][0] >> A[0][1] >> A[0][2];
  cin >> A[1][0] >> A[1][1] >> A[1][2];
  cin >> A[2][0] >> A[2][1] >> A[2][2];
  int N;
  cin >> N;
  bool ans=false;
  vector<int> b(N);
  vector<vector<int>> B(3,vector<int>(3,0));
  for(int i=0;i<N;++i) cin >> b[i];
  for(int k=0;k<N;++k){
    for(int i=0;i<3;++i){
      for(int j=0;j<3;++j){
        if(A[i][j]==b[k]) B[i][j]=1;
      }
    }
  }
  for(int i=0;i<3;++i){
    if((B[i][0] * B[i][1] * B[i][2]) == 1) ans = true;
    if((B[0][i] * B[1][i] * B[2][i]) == 1) ans = true;
  }
  if(B[0][0]*B[1][1]*B[2][2]==1) ans = true;
  if(B[0][2]*B[1][1]*B[2][0]==1) ans = true;
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
s = int(input())

import math

ans = float('inf')

if s == n:
    print(n+1)
    exit()

for b in range(2, 10**6):
    res = n
    tmp = 0
    while res > 0:
        tmp += res % b
        res = (res-res % b)//b
    if tmp == s:
        ans = min(ans, b)

if n < 10**6:
    print(ans if ans != float('inf') else -1)
    exit()

for p in range(1, 10**6):
    if (n-s) % p != 0:
        continue
    else:
        b = (n-s)//p + 1
        if p < b and n % b == s-p:
            ans = min(ans, b)
        
print(ans if ans != float('inf') else -1)


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

using namespace std;

inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int a[100000];

int main(){
	int n=read(),ma=0,mi=0;
	for(int i=1;i<=n;i++){
		a[i]=read();
		ma=max(ma,a[i]);
	}
	for(int i=1;i<=n;i++){
		if(abs(a[i]*2-ma)<abs(mi*2-ma)){
			mi=a[i];
		}
	}
	printf("%d %d\n",ma,mi);
	return 0;
}


Measured memory_bytes: 640
# import collections


def main():
    _ = int(input())
    A = list(map(int, input().split()))

    A.sort()

    # sames = 0
    # C = collections.Counter(A)
    # for v in C.values():
    #     if v > 1:
    #         sames += 1

    a_max = A[-1]
    dp = [0] * (a_max + 1)
    # dp = [True] * a_max
    # A = set(A)

    for a in A:
        if dp[a] != 0:
            dp[a] = 2
            continue

        i = a
        while i < a_max + 1:
            dp[i] += 1
            i += a

    r = 0
    for a in A:
        if dp[a] == 1:
            r += 1

    print(r)

    #     if dp[a - 1]:
    #         tmp_a = a * 2
    #         while tmp_a < a_max + 1:
    #             dp[tmp_a - 1] = False
    #             tmp_a += a

    # r = 0
    # for a in A:
    #     if dp[a - 1]:
    #         r += 1

    # print(r - sames)


if __name__ == '__main__':
    main()

Measured memory_bytes: 33016
h1, m1, h2, m2, k = map(int,input().split())
st = h1*60 + m1
sto = h2*60 + m2

if st < sto:
    if sto-st-k > 0:
        print(sto-st-k)
    else:
        print(0)

else:
    if sto+24*60 - st -k > 0:
        print(sto+24*60 - st -k)
    else:
        print(0)

Measured memory_bytes: 9184
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, M; string s[55], t[55];
int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> s[i];
	for (int i = 0; i < M; i++) cin >> t[i];
	bool flag = false;
	for (int i = 0; i <= N - M; i++) {
		for (int j = 0; j <= N - M; j++) {
			bool f = true;
			for (int k = 0; k < M; k++) {
				for (int l = 0; l < M; l++) {
					if (s[i + k][j + l] != t[k][l]) f = false;
				}
			}
			if (f) flag = true;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}

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

int main() {
    int n;cin>>n;
    vector<string>a;
    string tmp;
    for(int i=0;i<n;++i){
        cin>>tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end());
    
    int ans=1;
    for(int i=1;i<n;++i){
        if(a[i]!=a[i-1])ans++;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11656
W,H,N=map(int,input().split())
data=[list(map(int,input().split())) for i in range(N)]
_W=0
_H=0
for i in data:
    if i[2]==1:
        _W=max(i[0],_W)
    if i[2]==2:
        W=min(W,i[0])
    if i[2]==3:
        _H=max(i[1],_H)
    if i[2]==4:
        H=min(H,i[1])

if W-_W<=0 or H-_H<=0:
    print(0)
    exit()
a=int((W-_W)*(H-_H))
if a>0:
    print(a)
else:
    print(0)


Measured memory_bytes: 3064
import numpy as np
h,w=map(int,input().split())
s=[input() for i in range(h)]
flag=False
ans="Yes"
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            flag=False
            for k in[-1,1]:
                if(i+k<h and 0<=i+k and s[i+k][j]=="#"):
                    flag=True
                    break
                if(j+k<w and 0<=j+k and s[i][j+k]=="#"):
                    flag=True
                    break
            if(flag==False):
                ans="No"
                break
        
print(ans)        

Measured memory_bytes: 12488
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

bool comp(pair<int, int> a, pair<int, int> b) {
  return a.second > b.second;
}

int main() {

  while(1) {
    long long n,m;
    cin >> n >> m;
    if(!(n||m)) break;

    vector<pair<int, int> > vp;
    for(int i = 0; i < n; i++) {
      int d, p;
      cin >> d >> p;
      vp.push_back(pair<int, int>(d,p));
    }
    sort(vp.begin(), vp.end(), comp);

    int num = 0, ans = 0;
    for(int i = 0; i < vp.size(); i++) {
      for(int j = 0; j < vp[i].first; j++) {
        if(num >= m) ans += vp[i].second;
        num++;
      }
    }
    cout << ans << endl;

  }

	return 0;
}

Measured memory_bytes: 1336
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var dist, graph, INF = 1e9;

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var p = o.a();
  graph = xArray("[]",n);
  for(var i = 0; i < m; i++){
    var t = o.l(), a = t[0]-1, b = t[1]-1, c = t[2];
    graph[a].push({to:b,cost:p-c});
  }
  bellmanFord(n);
  if(dist[n-1] === INF)return -1;
  if(dist[n-1] >= 0)return 0;
  return 0-dist[n-1];
}

function bellmanFord(n){
  dist = xArray(INF,n);
  dist[0] = 0;
  for (var i = 0; i < n*2; i++) {
    for (var v = 0; v < n; v++) {
      for (var k = 0; k < graph[v].length; k++) {
        var e = graph[v][k];
        if (dist[v] !== INF && dist[e.to] > dist[v] + e.cost) {
          if(e.to === n-1 && i >= n-1)return dist[n-1] = INF;
          dist[e.to] = dist[v] + e.cost;
        }
      }
    }
  }
}

Measured memory_bytes: 12688
#!/usr/bin/perl
my $n = scalar(<STDIN>) - 0;
my $mx = -1;
my $tot = 0;
foreach(1..$n){
  my $a = scalar(<STDIN>) - 0;
  $tot += $a;
  $mx = $a if $a > $mx;
}
$tot -= ($mx / 2);
print "$tot\n";



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll n;
ll a[3100];
ll dp[3100][3100], visit[3100][3100];
ll inf = 1LL<<60;
ll rec(ll L, ll R) {
    if (L > R) return 0;
    if (visit[L][R] == 1) return dp[L][R];
    visit[L][R] = 1;
    
    ll diff = n - (R - L + 1);

    ll res = 0;
    if (diff % 2 == 0) {
        res = -inf;
        chmax(res, rec(L+1, R) + a[L]);
        chmax(res, rec(L, R-1) + a[R]);
    } else {
        res = inf;
        chmin(res, rec(L+1, R) - a[L]);
        chmin(res, rec(L, R-1) - a[R]);
    }
    return dp[L][R] = res;
}

int main() {
    cin >> n;
    rep (i, n) cin >> a[i];
    cout << rec(0, n-1) << endl; 
}

Measured memory_bytes: 149888
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))


l = 0
r = 2*10**9

while r - l > 1:
    m = (l+r)//2
    count = 0
    for a in A:
        count += (a+m-1)//m-1
    if count <= K:
        r = m
    else:
        l = m
    
print(r)

Measured memory_bytes: 91992
isprimes = [True]*(10**5+1)
isprimes[0] = False
isprimes[1] = False
for i in range(2, 10**5+1):
  if isprimes[i]:
    j = i**2
    while j < 10**5+1:
      isprimes[j] = False
      j += i
islikes = [False]*(10**5+1)
for i in range(3, 10**5+1, 2):
  if isprimes[i] and isprimes[(i+1)//2]:
    islikes[i] = True
ruiseki = [0]*(10**5+1)
for i in range(1, 10**5+1):
  ruiseki[i] = ruiseki[i-1]+(1 if islikes[i] else 0)
Q = int(input())
for _ in range(Q):
  l, r = map(int, input().split())
  print(ruiseki[r]-ruiseki[l-1])


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, s.size()) mp[s[i]]++;

    for (auto x : mp)
    {
        if (x.second % 2 == 1)
        {
            OP("No");
            return 0;
        }
    }
    OP("Yes");

    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	h,n = readline() |> split |> parseMap
	a = zeros(Int,n,2)
	for i in 1:n
		a[i,:] = readline() |> split |> parseMap
	end
	dp = 10^18*ones(Int,n+1,h+1)
	dp[1,1] = 0
	for i in 1:n
		for j in 1:h+1
			dp[i+1,j] = min(dp[i+1,j],dp[i,j])
			if j+a[i,1]<h+1
				dp[i+1,j+a[i,1]]=min(dp[i+1,j+a[i,1]],dp[i,j+a[i,1]],dp[i+1,j]+a[i,2],dp[i,j]+a[i,2])
			else
				dp[i+1,h+1]=min(dp[i+1,h+1],dp[i,h+1],dp[i+1,j]+a[i,2],dp[i,j]+a[i,2])
			end
		end
	end
	println(dp[n+1,h+1])
end

main()

Measured memory_bytes: 270736
N = [int(e) for e in input().split()]
nums = [int(t) for t in input().split()]
count=[]
k = 0
check = []
t = nums[0]
for i in range(N[0]):
    count.append(0)
while count[t-1] == 0:
    check.append(t)
    count[t-1] += 1
    k = t -1
    t = nums[k]

s = check.index(t) + 1
if(N[1] < s):
    print(check[N[1] - 1])
else:
    ans = (N[1] - s)%(len(check)+1-s)
    ans1 = check.index(t) + ans
    print(check[ans1])

Measured memory_bytes: 106828
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

char str[100005];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    int n=strlen(str);

    int i;
    for(i=1; i<n; i++) {
        if(str[i-1]==str[i]) {
            printf("%d %d\n", i, i+1); return 0;
        }
    }
    for(i=2; i<n; i++) {
        if(str[i-2]==str[i]) {
            printf("%d %d\n", i-1, i+1); return 0;
        }
    }
    printf("-1 -1\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int a,anser;

    scanf("%d", &a); 

    if(a <= 10){
        anser = a + (a*a) + (a*a*a);
        printf("%d\n", anser);
    }

    return 0;
}


Measured memory_bytes: 1728
//15
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int y;
    cin>>y;
    double m=0;
    int bn;
    for(int i=1;i<=n;i++){
      int b,r,t;
      cin>>b>>r>>t;
      double cm=((t==1)?1+y*r/100.:pow(1+r/100.,y));
      if(cm>m){
	m=cm;
	bn=b;
      }
    }
    cout<<bn<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
a,b,c,d=map(int,input().split())

if a<=c<=b:
    if d<=b:
        print(d-c)
    else:
        print(b-c)
elif c<=a<=d:
    if b<=d:
        print(b-a)
    else:
        print(d-a)
else:
    print(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;

typedef pair<int, int> p;

namespace SCC{
    vector<int> g[1 << 17], r[1 << 17], dfn;
    int chk[1 << 17], pv;
    void dfs(int v){
        chk[v] = 1;
        for(auto i : g[v]){
            if(!chk[i]) dfs(i);
        }
        dfn.push_back(v);
    }
    void rdfs(int v, int color){
        chk[v] = color;
        for(auto i : r[v]){
            if(!chk[i]) rdfs(i, color);
        }
    }
    void getSCC(int n){
        memset(chk, 0, sizeof chk); dfn.clear();
        for(int i=0; i<n; i++) if(!chk[i]) dfs(i);
        memset(chk, 0, sizeof chk); pv = 0; reverse(all(dfn));
        for(auto i : dfn) if(!chk[i]) rdfs(i, ++pv);
    }
    void init(){
        for(int i=0; i<(1 << 17); i++){
            g[i].clear(), r[i].clear();
        }
    }
    void addEdge(int s, int e){
        g[s].push_back(e); r[e].push_back(s);
    }
};
using namespace SCC;

const int sz = 1 << 16, inv = 1 << 15;
int n, x[101010], y[101010], id[101010][2];
vector<p> pt;

void connect(int now, int l, int r, int node = 1, int s = 0, int e = sz){ //[l, r)
    if(l >= r) return;
    if(r <= s || e <= l) return;
    if(l <= s && e <= r){
        addEdge(now, node); return;
    }
    int m = s + e >> 1;
    connect(now, l, r, node << 1, s, m);
    connect(now, l, r, node << 1 | 1, m, e);
}

int solve(int m){
    init();
    for(int i=1; i<(1 << 16); i++){
        addEdge(i, i << 1);
        addEdge(i, i << 1 | 1);
    }
    for(int i=0; i<n; i++){
        addEdge(id[i][0] | sz | inv, id[i][1] | sz);
        addEdge(id[i][1] | sz | inv, id[i][0] | sz);
    }
    for(int i=0; i<n; i++){
        int a = lower_bound(all(pt), p(x[i]-m+1, -1)) - pt.begin();
        int b = lower_bound(all(pt), p(x[i]+m, -1)) - pt.begin();
        connect(id[i][0] | sz, a | inv, id[i][0] | inv);
        connect(id[i][0] | sz, id[i][0]+1|inv, b | inv);
        a = lower_bound(all(pt), p(y[i]-m+1, -1)) - pt.begin();
        b = lower_bound(all(pt), p(y[i]+m, -1)) - pt.begin();
        connect(id[i][1] | sz, a | inv, id[i][1] | inv);
        connect(id[i][1] | sz, id[i][1]+1|inv, b | inv);
    }
    getSCC(1 << 17);
    for(int i=0; i<inv; i++) if(chk[i | sz] == chk[i | sz | inv]) return 0;
    return 1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
        if(x[i] > y[i]) swap(x[i], y[i]);
        pt.push_back({x[i], i});
        pt.push_back({y[i], i+n});
    }
    sort(all(pt));
    for(int i=0; i<n; i++){
        id[i][0] = lower_bound(all(pt), p(x[i], i)) - pt.begin();
        id[i][1] = lower_bound(all(pt), p(y[i], i+n)) - pt.begin();
    }
    int l = 0, r = 1e9+7;
    while(l < r){
        int m = l + r + 1 >> 1;
        if(solve(m)) l = m;
        else r = m - 1;
    }
    cout << l;
}

Measured memory_bytes: 27672
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, x;
    cin >> a >> b >> x;
    if(a <= x && x <= a + b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[50],b[50],c[50];
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	for(int i=1;i<n;i++)c[i]=read();
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(i!=1 && a[i]-1==a[i-1])ans+=c[a[i-1]];
	}pr2(ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int nCk(int n,int k){
    if(n<k) return 0;
    int ret=1;
    for(int i=1; i<=k; i++){
        ret*=n-i+1;
        ret/=i;
    }
    return ret;
}
int main(){
    string str;
    cin >> str;
    int N=str.length();
    int a[N],b[N];
    for(int i=0; i<N; i++){
        a[i]=str.at(N-1-i)-'0';
    }
    int base=10;
    b[0]=a[0];
    for(int i=1; i<N; i++){
        b[i]=(b[i-1]+base*a[i])%2019;
        base*=10;
        base%=2019;
    }
    int c[2019];
    c[0]=1;
    for(int i=1; i<2019; i++){
        c[i]=0;
    }
    for(int i=0; i<N; i++){
        c[b[i]]++;
    }
    int ans=0;
    for(int i=0; i<2019; i++){
        ans+=nCk(c[i],2);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5276
#include<bits/stdc++.h>
#define MN 3000
#define MM 10000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
bool f[MM+5];
int n,K,len[MN+5],p[MM*2+5];
string st[MN+5],ans,S;
bitset<10003> b[MN+5];
void ExKMP()
{
    int m=S.length()-1;p[1]=m;
    for(int i=2,l=1,r=1;i<=m;++i)
    {
        if(r>=i) p[i]=min(r-i+1,p[i-l+1]); else p[i]=0;
        while(i+p[i]<=m&&S[i+p[i]]==S[p[i]+1]) ++p[i];
        if(i+p[i]-1>r) l=i,r=i+p[i]-1;
    }
}
int Small(int x,int y,int l)
{
    if(x+l<=y) 
    {
        int L=p[l+x+2];
        if(L>=l) return 0;
        else  return S[L+1]>S[l+x+L+2]?1:-1;
    }
    int L1=p[l+x+2];
    if(L1<y-x) return S[L1+1]>S[l+x+L1+2]?1:-1;
    int L2=p[y-x+1];
    if(L2>=l-(y-x)) return 0;
    else return S[y-x+L2+1]>S[L2+1]?1:-1;
}
int main()
{  
	//freopen("aba.in","r",stdin);
	//freopen("aba.out","w",stdout);
    n=read();K=read();b[n+1][K]=1;f[0]=1;
    for(int i=1;i<=n;++i) cin>>st[i],len[i]=st[i].length();
    for(int i=n;i>=1;--i) b[i]=b[i+1]|(b[i+1]>>len[i]);
    for(int i=1;i<=n;++i)
    {
        S='*'+st[i]+'@'+ans;ExKMP();int mn=-1,LL=ans.length();
        for(int j=0;j<=LL&&j+len[i]<=K;++j) if(f[j]&&b[i+1][j+len[i]])
        {
            if(mn==-1)
            {
                if(j==LL) mn=j;
                else
                {
                    int L=p[len[i]+j+2];
                    if(L<len[i]&&(j+L==LL||S[L+1]<S[len[i]+j+L+2])) mn=j;
                }
                continue;
            }
            if(Small(mn,j,len[i])>=0) mn=j;
        }
        if(mn==-1)
        {
            for(int j=LL-len[i];j>=0;--j)
                if(f[j]&&p[len[i]+j+2]==len[i]&&b[i+1][j+len[i]]) f[j+len[i]]=1;
            continue;
        }
        memset(f+mn+len[i]+1,0,sizeof(bool)*(K-mn-len[i]+3));
        for(int j=mn+len[i];~j;--j) 
        {
            if((j<=mn||p[len[i]+mn+2]>=j-mn)&&f[j]&&b[i+1][j]) f[j]=1;
            else if(j>=len[i]&&f[j-len[i]]&&b[i+1][j]&&(j-len[i]==mn||Small(j-len[i],mn,len[i])==0)) f[j]=1;
            else f[j]=0;
        }
        ans=ans.substr(0,mn)+st[i];
	}
    cout<<ans;
    return 0;
}


Measured memory_bytes: 7876
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N;
vector<int>a;

int dfs(int n, int b, int c){
  if(n == 10) return 1;

  if(b < a[n] && dfs(n+1, a[n], c)) return 1;
  if(c < a[n] && dfs(n+1, b, a[n])) return 1;
  return 0;
}

int main(){
  scanf("%d", &N);
  rep(i, N){
    a.clear();
    int b;
    rep(i, 10){
      scanf("%d", &b);
      a.PB(b);
    }

    printf("%s\n", dfs(0, 0, 0)?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 1188
def coins():
	a = int(input())
	b = int(input())
	c = int(input())
	x = int(input())
	count = 0
	for ai in range(0, a + 1):
		for bi in range(0, b + 1):
			for ci in range(0, c + 1):
				if (500 * ai + 100 * bi + 50 * ci) == x:
					count += 1
	print(count)

coins()

Measured memory_bytes: 38896
#include<stdio.h>
#include<stdbool.h>

int main(void) {
    int n;
    int ans=2;
    scanf("%d",&n);
    if (n < 2) {
        printf("%d\n",n);
        return 0;
    }
    while(true) {
        ans *= 2;
        if (ans > n) {
            break;
        }
    }
    printf("%d\n",ans/2);
    return 0;
}


Measured memory_bytes: 128
def main():
    L,R = list(map(int,input().split()))

    ans = float('inf')
    if R-L >= 672:
        ans = 0
        print(ans)
        return
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans = min(ans, i*j%2019)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  int m;
  cin>>m;
  cout<<48-m;

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int[] d = new int[n + 1];
        d[0] = 0;
        for (int i = 1; i < n + 1; i++) {
            d[i] = d[i - 1] + l[i - 1];
            if (d[i] <= x) count++;
        }
        System.out.println(count + 1);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d; int j=c/b; int k=a/d;
  bool f =true;
  if(c%b!=0) j++;
  if(a%d!=0) k++;
  
  if(j<=k) cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    int a,b,c;

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

    if(a==b && b==c){
        printf("No\n");
    }else if(a!=b && b!=c && c!=a){
        printf("No\n");

    } else {
        printf("Yes\n");
    }




    return 0;
}


Measured memory_bytes: 128