akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    cout<<
    (s=="Sunny"?"Cloudy"
        :(s=="Cloudy"?"Rainy"
            :"Sunny"))<<endl;
}/*
./problem.exe
*/

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long ans = 0;
		long mod = (long) 1e9 + 7;
		/*
		long cc = 0;
		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
				cc += A[i] ^ A[j];
			}
		}
		*/
		//Console.WriteLine(cc);
		
		for(int i=0;i<60;i++){
			
			long cnt = 0;
			for(int j=0;j<N;j++){
				if((A[j] >> i) % 2 == 1) cnt++;
			}
			long zero = N - cnt;
			long part = (cnt * zero);
			part %= mod;
			long b = ((long)1) << i;
			b %= mod;
			long v = part * b % mod;
			ans += v;
			ans %= mod;
		}
		
		Console.WriteLine(ans);
		
		
		
		
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 53780
import numpy as np

N, M, X = map(int, input().split())

C = [0]*N
A = np.array([[0]*M for i in range(N)])

for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] = tmp[0]
    A[i] = tmp[1:]

min_ans = 10**10
flg = False
for i in range(2**N):
    tmp_A = np.array([0] * M)
    tmp_C = 0
    for j in range(N):
        if ((i >> j) & 1):
            tmp_A += A[j]
            tmp_C += C[j]
    if (tmp_A >= X).sum() == M and tmp_C < min_ans:
        min_ans = tmp_C
        flg = True

if flg:
    print(min_ans)
else:
    print("-1")

Measured memory_bytes: 27300
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[2][20010],gx,gy,len,n[2],kk;
char s[20010];
bool f[2][2][20010];
int main()
{
	scanf("%s",s+1);
	scanf("%d%d",&gx,&gy);
	len=strlen(s+1);
	int tmp;
	for(tmp=1;tmp<=len&&s[tmp]=='F';tmp++);
	 	
	kk=0;
	for(int i=tmp;i<=len;i++)
		if(s[i]=='F') a[kk][n[kk]+1]++;
		else n[kk]++,kk^=1;
	n[kk]++;
	//cout<<n[0]<<' '<<n[1]<<endl;
	f[0][0][8000+tmp-1]=f[0][1][8000]=1;
	for(int k=0;k<=1;k++)
		for(int i=1;i<=n[k];i++)
		{
			memset(f[i&1][k],0,sizeof(f[i&1][k]));
			//cout<<k<<' '<<i<<' '<<a[k][i]<<endl;
			for(int j=-8000;j<=8000;j++)
			{
				if(f[(i&1)^1][k][j+8000]==1) 
				{	
					f[i&1][k][j-a[k][i]+8000]=f[i&1][k][j+a[k][i]+8000]=1;
					//cout<<i<<' '<<k<<' '<<j+8000<<' '<<f[(i&1)^1][k][j+8000]<<endl;
					//cout<<j-a[k][i]+8000<<' '<<j+a[k][i]+8000<<endl;
				}
			}
		}
	if(f[n[0]&1][0][gx+8000]&&f[n[1]&1][1][gy+8000]) printf("Yes");
	else printf("No");			 	
	return 0;
}
/*FFFTTFFFTTFFFF
10 0*/
/*TTTT
0 0*/
/*FTFFTFFFTFF
4 2*/
/*FFFFFFF
3 -2*/

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		for (int i = 0; i < N; ++i) {
			x[i] = sc.nextInt() % (2 * K);
			y[i] = sc.nextInt() % (2 * K);
			if (sc.next().equals("W")) {
				y[i] += K;
				y[i] %= 2 * K;
			}
			int[] p = pos(x[i], y[i], K);
			x[i] = p[0];
			y[i] = p[1];
		}
		int[][] cnt = new int[2 * K][3 * K];
		for (int i = 0; i < N; ++i) {
			++cnt[y[i]][x[i]];
			--cnt[y[i]][x[i] + K];
			--cnt[y[i] + K][x[i]];
			++cnt[y[i] + K][x[i] + K];
		}
		for (int i = 0; i < cnt.length; ++i) {
			for (int j = 1; j < cnt[i].length; ++j) {
				cnt[i][j] += cnt[i][j - 1];
			}
		}
		for (int j = 0; j < cnt[0].length; ++j) {
			for (int i = 1; i < cnt.length; ++i) {
				cnt[i][j] += cnt[i - 1][j];
			}
		}
		for (int i = 0; i < cnt.length; ++i) {
			for (int j = 0; j < cnt[i].length; ++j) {
				if (j < 2 * K && i < K)
					continue;
				int[] pos = pos(j, i, K);
				cnt[pos[1]][pos[0]] += cnt[i][j];
			}
		}
		int ans = 0;
		for (int i = 0; i < K; ++i) {
			for (int j = 0; j < 2 * K; ++j) {
				ans = Math.max(ans, cnt[i][j]);
			}
		}
		System.out.println(ans);
	}

	int[] pos(int x, int y, int K) {
		x %= 2 * K;
		y %= 2 * K;
		if (y >= K) {
			x += K;
			y += K;
			x %= 2 * K;
			y %= 2 * K;
		}
		if (!(0 <= y && y < K && 0 <= x && x < 2 * K))
			throw new AssertionError();
		return new int[] { x, y };
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 120388
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
#include<bits/extc++.h>
using namespace __gnu_pbds;
using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 1<<21, mod = 1e9 + 7;
ll n;
set<ll> a;
void check(ll d) {
	if(d==1) return;
	ll t = n;
	while(t%d == 0) t/=d;
	if(t%d==1) a.insert(d);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	n--;
	for(ll d = 1; d*d <= n; d++) {
		if(n%d) continue;
		a.insert(d), a.insert(n/d);
	}
	n++;
	if(a.count(1)) a.erase(1);
	for(ll d = 1; d*d <= n; d++) {
		if(n%d) continue;
		check(d), check(n/d);
	}
	cout << a.size() << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll func(ll i, ll dp[], vector <ll> v[]) {
  if(dp[i] != -1) {
    return dp[i];
  }
  ll r = 0;
  for(ll x = 0; x < v[i].size(); x++) {
    r = max(r, func(v[i][x], dp, v));
  }
  return (dp[i] = r + 1);
}
            
int main() {
  ll n, m;
  cin >> n >> m;
  vector <ll> v[n+1];
  for(ll x = 0; x < m; x++) {
  	ll a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  ll dp[n+1];
  memset(dp, -1, sizeof(dp));
  ll ans= 0;
  for(ll x = 1; x <= n; x++) {
    dp[x] = func(x, dp, v);
    ans = max(ans, dp[x]);
  }
  cout << ans-1;
}

Measured memory_bytes: 12360
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int main() {
	int n, a[100005], as[100005];
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		as[i] = a[i];
	}

	long long ans1 = 0, ans2 = 0;

	//先頭を正とした場合
	int pn = 1;//正=1,負=-1
	long long sum = 0;//ここまでの和を保存
	REP(i, n) {
		sum += a[i];
		if (sum * pn <= 0) {
			ans1 = ans1 + pn * (pn - sum);
			sum = pn;
		}
		pn *= -1;
	}

	//先頭を負とした場合
	pn = -1;
	sum = 0;
	REP(i, n) {
		sum += a[i];
		if (sum * pn <= 0) {
			ans2 = ans2 + pn * (pn - sum);
			sum = pn;
		}
		pn *= -1;
	}

	cout << min(ans1, ans2) << endl;

	return 0;
}

Measured memory_bytes: 640
import math
h,w = map(int,input().split())
#h 縦
#w 横
if w == 1 or h == 1 :
    print("1")
elif (h * w ) % 2 == 0:
    result = h * w /2
    result = math.ceil(result)
    print(str(result))
elif (h * w )% 2 != 0:
    result = ((h * w) // 2 )+ 1
    result = math.ceil(result)
    print(str(result))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int xx = Integer.MIN_VALUE;//最小値
    int yy = Integer.MAX_VALUE;//最大値
    int num;
    for(int i=0; i<n; i++){
      num = sc.nextInt();
      if(num>xx){
        xx = num;
      }
    }

    for(int i=0; i<m; i++){
      num = sc.nextInt();
      if(num<yy){
        yy = num;
      }
    }

    //判定
    if(xx>=yy){
      System.out.println("War");//war
    }else{
      if(x<yy&&y>xx){
        System.out.println("No War");//No war
      }else{
        System.out.println("War");//war
      }
    }
  }
}

Measured memory_bytes: 21972
function Main(input) {
  var ans = false;
  for(var i=0;i<3;i++){
    for(var j=1;j<3;j++){
      if(input[i]!=input[j]) ans=true;
    }
  }
  if(ans){
    console.log("Yes");
  }else{
    console.log("No");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	double a;
	vector<double> r;
	while(cin >> a)
	{
		double sum = 0;
		for (int i=0; i<10; i++)
		{
			sum+=a;
			if (i%2)
			{
				a/=3;
			} else {
				a*=2;
			}
		}
		r.push_back(sum);
	}
	cout << setprecision(10);
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
}

Measured memory_bytes: 0
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    VIN(ll, a, n);
    ll r = 1;
    ll p = a[0];
    ll c = 0;
    rep(l, n)
    {
        while (r < n && (r <= l || !(a[r] & p)))
        {
            p ^= a[r];
            ++r;
        }
        c += r - l;
        if (l == r) ++r;
        else p ^= a[l];
    }
    cout << c << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 1792
N,M = (int(x) for x in input().split())
A = list(map(int,input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x:-x[1])
i = 0
for b,c in BC:
  tmp = 0
  while(tmp < b and i < N):
    if(A[i] > c):
      break
    else:
      A[i] = c
      tmp += 1
      i += 1
      
print(sum(A))

Measured memory_bytes: 25300
//============================================================================
// Name        : ATcoder.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int N;

int main() {
	cin>>N;
	int n1;
	int t1=0;
	for(int i=0;i<N;++i){
		cin>>n1;
		if(n1%2>0)t1++;
	}
	if(t1%2>0){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
S = gets.chomp
T = gets.chomp

SW = Hash.new{|h, k| h[k] = Array.new}
(0...S.size).each{|i| SW[S[i]] << i}

ans = 0
po = 0
(0...T.size).each{|i|
  (ans = -1; po = 0; break) if not SW.key?(T[i])
  a = SW[T[i]].bsearch{|x| po <= x}
  if a.nil? then
    ans += S.size
    po = SW[T[i]][0] + 1
  else
    po = a + 1
  end
}

puts ans + po


Measured memory_bytes: 3324
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int a,b;
  cin>>a>>b;
  cout<<a*b<<endl;

  return 0;
}




Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


ll dp[21111];
int main(){   
    int h,n;
    cin>>h>>n;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,21111)dp[i] = INF ;
    dp[0] = 0;//代入されるのはコスト

    rep(i,n){
        rep(j,20010){
            if(j - a[i] >= 0){
                //dpテーブル更新
                dp[j] = min(dp[j] , dp[j - a[i]] + b[i]);
                               
            }
        }
    }
    ll ans = INF;
    for(int i = 20001;i >=h;i--)ans = min(ans,dp[i]);
    cout<<ans<<endl;
}


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

int main() {
  int H,W; cin >> H >> W;
  string A[H];string s;
  for (int i = 0; i<H; i++) cin >> A[i];
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  bool flg;
  for (int i = 0; i<H; i++) {
    for (int j = 0; j<W; j++) {
      if(A[i][j]=='#') {
        flg = false;
        for (int k = 0; k<4; k++) {
          if(i+dy[k]>=0 && i+dy[k]<H && j+dx[k]>=0 && j+dx[k]<W) {
            if(A[i+dy[k]][j+dx[k]]=='#') flg = true;
          }
        }
        if(flg==false) {cout << "No" << "\n"; return 0;}
      }
    }
  }
  cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#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;

void Main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  REP(i, n)
  cin >> a[i];
  
  for(int i = 0; i < n; i++){
    b[a[i]-1] = i + 1;
  }
  REP(i,n)
    printf("%d ", b[i]);
}

int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

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

int main()
{
    int n;
    cin >> n;
    long long ans;
    vector<long long> a(n + 1), b(n);
    for (int i = 0; i < n + 1; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    for (int i = 0; i < n; i++)
    {
        long long c = min(a[i], b[i]);
        b[i] -= c;
        a[i] -= c;
        ans += c;
        c = min(a[i + 1], b[i]);
        b[i] -= c;
        a[i + 1] -= c;
        ans += c;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int N;
    cin >> N;

    vector<pair<int, int>> s(N);
    int Xi, Li;
    for (int i = 0; i < N; i++)
    {
        cin >> Xi >> Li;
        s.at(i) = make_pair(Xi + Li, Xi - Li);
    }
    sort(s.begin(), s.end());

    int res = 0;
    int mx = -1e9;
    for (int i = 0; i < N; i++)
    {
        int li = s.at(i).second, ri = s.at(i).first;
        if (mx <= li)
        {
            res++;
            mx = ri;
        }
    }
    cout << res << endl;
}

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

ll calc(ll v) {
	if (v == 1) return 1;
	else return 2 * calc(v/2) + 1;
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	ll tmp;
	while (cin >> tmp) {
		cout << calc(tmp) << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int n,m;
    cin>>n>>m;
    int like[m];
    for(int i = 0; i < m; i++){
        like[i] = 0;
    }
    for(int i = 0; i < n; i++){
        int k;
        cin>>k;
        for(int j = 0; j<k; j++){
            int a;
            cin>>a;
            like[a-1]++;
        }
    }
    int sum = 0;
    for(int i = 0; i < m; i++){
        if(like[i] == n) sum++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const ll n_max=3000;
ll a[n_max];
ll dp[n_max][n_max];


ll dfs(ll l, ll r){
  if(r==l){
    dp[r][r]=a[r];
    return a[r]; 
  }
  else{
    ll tl,tr;
    if(dp[l+1][r]==-1){
      tl=dfs(l+1,r);
    }
    else tl=dp[l+1][r];
    if(dp[l][r-1]==-1){
      tr=dfs(l,r-1);
    }
    else tr=dp[l][r-1];
    dp[l][r]= max(a[l]-tl,a[r]-tr);
    return max(a[l]-tl,a[r]-tr);
  }
}

int main(){
  rep(i,n_max) rep(j,n_max) dp[i][j]=-1;
  
  ll n;
  cin >> n;
  rep(i,n) cin >> a[i];
  cout << dfs(0,n-1) << endl;
  
  
  return 0;

}


Measured memory_bytes: 70656
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 200005;

int main()
{
	vector<pll> L;
	ll mul = 1, i;
	while(mul <= 1e15){
		for(i = mul/10-1; i <= mul; i += max(mul/1000000, 1ll)){
			if(i <= 0 || i == mul/10-1) continue;
			ll cur = i, t = 0;
			while(cur) t += cur%10, cur /= 10;
			pll p = pll(i, t);
			while(L.size() && (ll)L.back().first * p.second > (ll)L.back().second * p.first) L.pop_back();
			L.push_back(p);
		}
		mul *= 10;
	}

	int K;
	scanf("%d", &K);
	ll cur = 2, m = 1;
	for(int i = 1; i <= K; i++) printf("%lld\n", L[i].first);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){

	int a,b;
	char name[20];

	for(int i=0; i < 9; i++){
		scanf("%s %d %d",name,&a,&b);
		printf("%s %d %d\n",name,a+b,200*a+300*b);
	}

    return 0;
}



Measured memory_bytes: 2684
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 1e18;
    rep(i, 2e5+10) {
        ll tmp = i*c;
        tmp += max(0LL, x - i/2) * a;
        tmp += max(0LL, y - i/2) * b;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

#define MAX_N 8
bool used[MAX_N+1] = {0};
int perm[MAX_N+1];
int cmat[MAX_N+1][MAX_N+1];
int count = 0;

bool check_onepath(int n) {
    int p = 1;
    bool flag = false;
    for (int i = 2; i < n+1; i++) {
        if (cmat[p][perm[i]] < 1) break;
        p = perm[i];
        if (i == n) flag = true;
    }
    return flag;
}

int permutation(int pos, int n) {
    if (pos == n+1) {
        // for (int i = 1; i < n+1; i++) cout << perm[i];
        // cout << endl;
        if (check_onepath(n)) count++;
        return 0;
    }
    for (int i = 2; i < n+1; i++) {
        if (!used[i]) {
            perm[pos] = i;
            used[i] = true;
            permutation(pos+1, n);
            used[i] = false;
        }
    }
    return 0;
}


int main() {
    fill((int*)cmat, (int*)(cmat+MAX_N+1), 0);
    // (N-1)! 通りの通り方を全部試す (2<=N<=8)
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        cmat[u][v] = 1;
        cmat[v][u] = 1;
    }
    // 順列
    perm[1] = 1;
    used[1] = true;
    if (N == 1) count++;
    else permutation(2, N);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main( ){
  int i,j,N,flag,tmp,count=0;
  int A[100];

  scanf("%d",&N);
  if((N > 100) &&(N < 0)){
    printf("N is error\n");
  }
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }

 
  flag = 1;
  while(flag){
    flag = 0;
    for(i = N-1; i > 0; i--){
      if(A[i]<A[i-1]){
	tmp = A[i];
	A[i]=A[i-1];
	A[i-1]=tmp;
	flag = 1;
	count++;
      }
    }
  }

  for(j = 0; j < N; j++){
    if(j > 0){
      printf(" ");
    }
    printf("%d",A[j]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2124
/*
[jsc2019-qual] B - Kleene Inversion
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 2000;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf operator-(const gf x) const { return gf((n - x.n + MOD) % MOD); }
    gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
    gf& operator+=(const gf x) { return *this = (*this + x); }
    gf& operator-=(const gf x) { return *this = (*this - x); }
    gf& operator*=(const gf x) { return *this = (*this * x); }
};

const gf inv2 = 5e8 + 4;

int N;
ll K;
int A[MAX_N];

ll solve() {
    ll cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (A[i] < A[j]) {
                cnt0++;
            } else if (A[i] > A[j]) {
                cnt1++;
            }
        }
    }

    gf ans = inv2 * cnt0 * K * (K - 1) + inv2 * cnt1 * K * (K + 1);

    return ans.n;
}

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

    cout << solve() << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


vector<ll> P;
void prime(const ll N) {
    for(ll i = 2; i <= N; i++) {
        bool flag = true;
        for(ll j = 2; j * j <= i; j++) {
            if(i % j == 0) {
                flag = false;
                break;
            }
        }
        if(flag) P.emplace_back( i );
    }
}

int main() {
    ll x; cin >> x;
    prime(200000);

    auto itr = lower_bound(P.begin(), P.end(), x);
    ll index = itr - P.begin();
    
    
    cout << P[index] << endl;


    return 0;
}



Measured memory_bytes: 640
### ABC104C - All Green
def rec(score: int, idx: int) -> int:
    if idx == 0:
        return float("inf")
    point, (num, bonus) = idx * 100, A[idx]
    cnt = min(score // point, num)
    cur_score = cnt * point + bonus if cnt == num else cnt * point
    rest = score - cur_score
    if rest > 0:
        cnt += rec(rest, idx - 1)
    return min(cnt, rec(score, idx - 1))


def main():
    global A
    D, G = map(int, input().split())
    A = [(0, 0)] + [tuple(map(int, input().split())) for _ in range(D)]
    ans = rec(G, D)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
parseInt(x) = parse(Int,x)

function main()
  (N,X) = map(parseInt,split(readline()))
  L = map(parseInt,split(readline()))
  D = zeros(Int64,N+1)
  for i=1:N
    D[i+1] = D[i]+L[i]
  end
  j = 0 
  for i = 1:(N+1)
    if X >= D[i]
      j = i 
    end
  end
  println(j)
end
  
main()

Measured memory_bytes: 171300
N = int(input())
A = list(map(int,input().split()))

def dfs(sign):
  cnt = 0
  tmp = 0
  for a in A:
    tmp += a
    if(tmp*sign >= 0):
      cnt += abs(tmp) + 1
      tmp = -sign
    sign *= -1
  return cnt

print(min(dfs(1), dfs(-1)))

Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long 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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n;cin >> n;
    string s,t;cin >> s >> t;
    string a = "";
    for (int i = 0; i < n; i++) {
        a += s[i];
        a += t[i];
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int B, W;
	scanf("%d %d", &B, &W);
	
	int i, N = B + W;
	long long fact[200001], fact_inv[200001], pow[200001], pow_inv[200001];
	for (i = 1, fact[0] = 1, pow[0] = 1; i <= N; i++) {
		fact[i] = fact[i-1] * i % Mod;
		pow[i] = pow[i-1] * 2 % Mod;
	}
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod), pow_inv[N] = div_mod(1, pow[N], Mod); i >= 0; i--) {
		fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
		pow_inv[i] = pow_inv[i+1] * 2 % Mod;
	}
	
	long long b = 0, w = 0;
	for (i = 1; i <= N; i++) {
		if (i > B) b = (b + fact[i-2] * fact_inv[B-1] % Mod * fact_inv[i-B-1] % Mod * pow_inv[i-1]) % Mod;
		if (i > W) w = (w + fact[i-2] * fact_inv[W-1] % Mod * fact_inv[i-W-1] % Mod * pow_inv[i-1]) % Mod;
		printf("%lld\n", (w + (1 - b - w + Mod * 2) * pow_inv[1]) % Mod);
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 8504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int N; cin >>N;
  long double sum=0;
  vector<long long int>A(N);
  vector<long long int>B(N);
  for(long long int i=0;i<N;i++){
    cin>>A.at(i);
    sum+=A.at(i);
    if(i==0){
      B.at(i)=A.at(i);
    }else{
      B.at(i)=B.at(i-1)+A.at(i);
    }
  }
  long long int k=0;
  for(long long int i=0;i<N;i++){
    if(2*B.at(i)>=sum){
      k=i;
      break;
    }
  }  
  if(2*B.at(k)==sum){
    cout<<0<<endl;
  }else{
    cout<<fixed<<setprecision(0)<<min(abs(sum-2*B.at(k)),abs(sum-2*B.at(k-1)))<<endl;
  }
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100000;

int n, k, q;
ll dist[maxn];
bool used[maxn];
vector<pair<int, int>> p;
vector<vector<pair<ll, ll>>> v(maxn);  //行先とコスト

int main() {

	cin >> n;
	rep(i, n - 1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		v[a].push_back(pair<ll, ll>(b, c));
		v[b].push_back(pair<ll, ll>(a, c));
	}

	cin >> q >> k;

	rep(i, q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		p.push_back(pair<int, int>(a, b));
	}

	fill(used, used + n, false);
	fill(dist, dist + n, INF);
	dist[k - 1] = 0; used[k - 1] = true;

	queue<int> que;
	que.push(k - 1);

	while (que.size()) {
		int t = que.front(); que.pop();
		for (int i = 0; i < v[t].size(); i++) {
			if (!used[v[t][i].first]) {
				dist[v[t][i].first] = dist[t] + v[t][i].second;
				used[v[t][i].first] = true;
				que.push(v[t][i].first);
			}
		}
	}

	rep(i, p.size()) {
		cout << dist[p[i].first] + dist[p[i].second] << endl;
	}

	return 0;
}

Measured memory_bytes: 11000
#include <iostream>
#include <cstdio>
#define ll long long
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 << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 5100,inf = 2e9;
int n,tot,ans;
char s[N];
int head[N],val[N];
int f[N],siz[N],dis[N];
struct node{int nex,to;}a[N << 1];
void add(int f,int t) {a[++ tot].nex = head[f]; a[tot].to = t; head[f] = tot;}
void dfs(int now,int fa)
{
	siz[now] = val[now]; int QAQ = 0;
	for(int i = head[now],to;i;i = a[i].nex)
	{
		to = a[i].to; if(to == fa) continue; dfs(to,now);
		siz[now] += siz[to]; dis[to] += siz[to];
		dis[now] += dis[to]; if(dis[QAQ] < dis[to]) QAQ = to;
	}
	if(!QAQ) {f[now] = 0; return;}
	if(dis[QAQ] * 2 <= dis[now]) f[now] = dis[now] / 2;
	else f[now] = dis[now] - dis[QAQ] + min(f[QAQ], (2 * dis[QAQ] - dis[now]) / 2);
}
int main()
{
	ans = inf; n = read(); cin >> s;
	for(int i = 0;i < n;i ++) val[i + 1] = s[i] - '0';
	for(int i = 1,x,y;i < n;i ++)
	{
		x = read(); y = read();
		add(x,y); add(y,x);
	}
	for(int i = 1;i <= n;i ++)
	{
		for(int j = 1;j <= n;j ++) f[j] = siz[j] = dis[j] = 0;
		dfs(i,0); if(dis[i] & 1) continue;
		if(f[i] * 2 >= dis[i]) ans = min(ans,dis[i] / 2);
	}
	cout << (ans == inf ? -1 : ans) << "\n";
}

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

using namespace std;
using i64 = int64_t;

struct UnionFind{
    int m;
    vector<int> par;
    UnionFind(int n, int m) : par(n, -1), m(m){}
    int Find(int x){return par[x] < 0 ? x : Find(par[x]);}
    bool Unite(int x, int y){
        x = Find(x);
        y = Find(y);
        if(x == y)
            return true;
        if(x < m && y < m)
            return false;
        if(x > y)
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
};

signed main(){
    
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind u(n + m, m);
    for(int i = 0; i < k; ++i){
        int t, a, b;
        cin >> t >> a >> b;
        --a, --b;
        if(t == 1){
            a += m;
            b += m;
            if(!u.Unite(a, b)){
                cout << i + 1 << endl;
                return 0;
            }
        }else{
            a += m;
            if(!u.Unite(a, b)){
                cout << i + 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include<string>
using namespace std;
int a[100000];
int main(void){
    int n,x,i;
    long long int ans=0;
    cin>>n>>x;
    for(i=0;i<n;i++)cin>>a[i];
    if(a[0]>x){
        ans+=a[0]-x;
        a[0]=x;
    }
    for(i=1;i<n;i++){
        if(a[i-1]+a[i]>x){
            ans+=a[i-1]+a[i]-x;
            a[i]=x-a[i-1];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 640
import math

n = int(input())
s = int(input())
f = None
for i in range(2, math.ceil(math.sqrt(n))):
    c = 0
    k = n
    while k > 0:
        c += k % i
        k //= i
    if c == s:
        f = i
        break
if f is None:
    for i in range(int(math.sqrt(n)), 1, -1):
        b = n // i
        k = n
        c = 0
        while k > 0:
            c += k % b
            k //= b
        if s >= c and (s - c) % i == 0 and b - (s - c) // i > n // (i + 1):
            f = b - (s - c) // i
            break
if f is None:
    if s == n: f = n + 1
    elif s <= (n + 1) // 2: f = n - s + 1
    elif s == 1: f = n
if f is None: print(-1)
else: print(f)


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

int main(void){
  long long int N, ans = LLONG_MAX;
  cin >> N;
  for(long long int i = 1; i <= (long long int)ceil(sqrt(N)); i++){
    if(N%i == 0){
      ans = min(i-1+N/i-1, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(q)]

ans = (n - 2)** 2
cnt, wh = [n - 2, n - 2], [[None] * (n - 2), [None] * (n - 2)]
for num, x in query:
    num, x = num - 1, x - 2
    if cnt[num] > x:
        for i in range(x, cnt[num]):
            wh[num][i] = cnt[1 - num]
        cnt[num] = x
    ans -= wh[num][x]
    wh[num][x] = 0
print(ans)


Measured memory_bytes: 113532
#include<iostream>
#define ll long long
using namespace std;
ll a,b,n;
ll f(ll x)
{
	return a*x/b-a*(x/b);
}
int main()
{
	cin>>a>>b>>n;
	ll l=0,r=n;
	ll ans=0;
	while(r-l>=100000)
	{
		ll lmid=l+(r-l)/3;
		ll rmid=r-(r-l)/3;
		if(f(lmid)>f(rmid)) r=rmid;
		else l=lmid;
	}
	while(l<=r&&l<=n)
	{
		ans=max(ans,f(l));
		l++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};

mint dp[61][2][2][2];
bool used[61][2][2][2];
ll L, R;

mint f (ll digit, ll x, ll y, ll msb) {
    if (digit == -1) return mint(1);
    if (used[digit][x][y][msb]) return dp[digit][x][y][msb];
    mint ret(0);

    ll l = (L >> digit) & 1;
    ll r = (R >> digit) & 1;

    if (x or !l) {
        ret += f(digit-1, x, r?1:y, msb);
    }
    if ((x or !l) and (y or r) and msb) {
        ret += f(digit-1, x, y, msb);
    }
    if (y or r) {
        ret += f(digit-1, l==0?1:x, y, 1);
    }

    dp[digit][x][y][msb] = ret;
    used[digit][x][y][msb] = true;
    return ret;
}

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

    cin >> L >> R;
    cout << f(60, 0, 0, 0) << endl;
}

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

using namespace std;

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

    int ans = T.size();

    for(int i = 0; i <= S.size() - T.size(); i++) {
        int diff = 0;
        for(int j = 0; j < T.size(); j++) {
            if(T[j] != S[i + j]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
function main(input) {
  input = input.split(' ');
  var k = parseInt(input[0]);
  var s = parseInt(input[1]);
  var count = 0;
  for(var x = 0; x <= k; x++) {
    for(var y = 0; y <= k; y++) {
      var z = (s - parseInt(x) - parseInt(y));
      if (0 <= z && z <= k) {
        count++;
      }
    }
  }
  console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7616
#include <stdio.h>
#include <string.h>

int main(void)
{
    int i,j;
    int H,W;
    int ans=1;
    char s[50][50];
    char t[3]=".#";
    scanf("%d",&H);
    scanf("%d",&W);
    for(i=0;i<H;i++){
            scanf("%s",&s[i]);
    }
    #if 0
    for(i=0;i<H;i++){
        for(j=0;j<H;j++){
            printf(s[i][j]);
        }
        printf("\n");
    }
   #endif
//   printf("\n%s\n",s[0][1]);
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if(s[i][j]==t[1]){
                if(i!=0 && s[i-1][j]==t[1]) {
                    ans=1;
                }else if(j!=0 && s[i][j-1]==t[1]){
                    ans=1;
                }else if(i!=H-1 && s[i+1][j]==t[1]){
                    ans=1;
                }else if(j!=W-1 && s[i][j+1]==t[1]){
                    ans=1;
                }else{
                    ans=0;
                    break;
                }
            }
        }
        if(ans==0) break;
    }
    if(ans==1){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

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

int main() {
  int N,M,sum=0;
  cin >> N >> M;
  for (int i=0;i<M;i++){
    int A;
    cin >> A;
    sum += A;
  }
  cout << max(N-sum,-1) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <iomanip>
#include <locale>

using namespace std;

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

	int ret = c - (a - b);

	cout << (ret > 0 ? ret : 0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N, M, R;
vector<int> r;
ll d[210][210];

int main () {
  cin >> N >> M >> R;
  Rep(i, R) {
    int tmp;
    cin >> tmp;
    r.push_back(tmp);
  }

  rep(i, N) {
    rep(j, N) {
      if (i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }

  Rep(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;

    if (d[a][b] > c) d[a][b] = d[b][a] = c;
  }

  rep(k, N) {
    rep(i, N) {
      rep(j, N) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  ll ans = LINF;

  sort(All(r));

  do {
    ll tmp = 0;

    Rep(i, R-1) {
      tmp += d[r[i]][r[i+1]];
    }

    ans = min(tmp, ans);
  } while (next_permutation(All(r)));

  cout << ans << "\n";
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll X,Y,Z;
    cin>>X>>Y>>Z;
    
    ll ans=(X-Z)/(Y+Z);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define alll(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define endl '\n'

ll f(ll x)
{
    int ret=0;
    while(x)
    {
        ret+=x%10;
        x/=10;
    }
    return ret;
}
ll nxt(ll x)
{
    string s = to_string(x);
    ll ret = x;
    double mx = 1.0 * x / f(x);
    for(int i=s.size()-1;i>=0;--i) {
        s[i] = '9';
        ll x2 = stoll(s);
        double tmp = 1.0 * x2 / f(x2);
        if(tmp < mx) ret = x2, mx = tmp;
    }
    return ret;
}
int main()
{
    int n;
    cin>>n;
    ll cur = 1;
    for(int i=1;i<=n;++i)
    {
        cout << cur << endl;
        cur = nxt(cur + 1);
    }
}


Measured memory_bytes: 256
def main():
    sx, sy, tx, ty = map(int, input().split())

    print(''.join(solve(sx, sy, tx, ty)))

def solve(sx, sy, tx, ty):
    for s in vertical(sx, sy, tx, ty): yield s
    for s in vertical(tx, ty, sx, sy): yield s
    yield 'L'
    for s in vertical(sx - 1, sy, tx, ty + 1): yield s
    yield 'D'
    yield 'R'
    for s in vertical(tx + 1, ty, sx, sy - 1): yield s
    yield 'U'

def vertical(sx, sy, tx, ty):
    yield move(ty - sy, 'U', 'D')
    yield move(tx - sx, 'R', 'L')

def move(q, up, down):
    if q > 0:
        return up * q
    else:
        return down * (-q)

main()


Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: i64,
      a: i64,
      b: i64,
      c: i64,
      d: i64,
    }

    for up in 0..n {
        let down = n-1-up;
        let upper = a + up*d - c*down;
        let lower = a + up*c - d*down;
        if lower <= b && b <= upper {
            println!("{}", "YES");
            return;
        }
    }
    println!("{}", "NO");
}


Measured memory_bytes: 4352