akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main() {
  char S[101];
  int K;
  scanf("%d",&K);
  scanf("%s",S);
  int size = strlen(S);
  if(size<=K) {
    printf("%s",S);
  }else {
    for(int i=0;i<K;i++) {
      printf("%c",S[i]);
    }
    printf("...");
  }
  return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;
#define mxn 100005
vector<ll> a[mxn+1],h(mxn+1);
vector<bool> vis(mxn+1);
void dfs(int u)
{
    vis[u] = 1;
    for(int i: a[u])
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
}
int main()
{
    FLASH
    ll n,m;
    cin >> n >>m;
    for(int i = 0;i <= n ;i++)vis[i] =0;
    for(int i = 0;i < n;i++)
        cin >> h[i];
    for(int i = 0;i <  m;i++)
    {
        int u,v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    ll cc = 0;
    for(int i = 1; i<= n;i++)
    {
        bool ok =true;
        for(int j : a[i])
        {
            if(h[i - 1] <= h[j -1])
            {
                ok = false;
                break;
            }
        }
        if(ok)
            cc++;
    }
    /*for(int i = 1; i <= n;++i)
    {
        if(!vis[i])
        {
            dfs(i);
            cc++;
        }
    }*/
    cout << cc;
    return 0;
}



Measured memory_bytes: 9800
s = int(input())
aa = [s]
for i in range(10000):
	if s%2 == 0:
		s = s//2
	elif s%2 ==1:
		s = 3*s + 1
		
	if s in aa:
		print(i+2)
		break
	
	aa.append(s)
	

Measured memory_bytes: 3188
N,M,P = map(int,input().split())

edge_dic = {}

for _ in range(M):
    A,B,C = map(int,input().split())
    if not A - 1 in edge_dic:
        edge_dic[A-1] = [[B-1,C-P]]
    else:
        edge_dic[A-1].append([B-1,C-P])

# print(edge_dic)

INF = 10 ** 10

ans_array = [-INF] * N
can_visit = [0] * N
ans_array[0] = 0
can_visit[0] = 1 
last_ans_change = -1

for i in range(N*2):
    change_flag = 0
    for key, value in edge_dic.items():
        if can_visit[key] == 0:
            continue
        for v in value:
            goal, cost = v
            if ans_array[goal] < ans_array[key] + cost:
                ans_array[goal] = ans_array[key] + cost
                if i >= N:
                    ans_array[goal] = INF
                can_visit[goal] = 1
                change_flag = 1
                if goal == N - 1:
                    last_ans_change = i
                    if i >= N:
                        print(-1)
                        exit()
    if change_flag == 0:
        break


ans = max(0,ans_array[N-1])

print(ans)

Measured memory_bytes: 54744
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;


int main(){
	int dirs[4][3] = {
		{1,0,1},{0,1,1},{-1,0,1},{0,-1,1}
	};

	int W,H;
	cin>>H>>W;
	vector<vector<int> > dfst(H, vector<int>(W,-1));
	
	queue<pair<int,int> > qpii;
	for(int i =0;i<H;i++){
		string s;
		cin>>s;
		for (int j =0 ;j<W;j++){
			if(s[j]=='#'){
				qpii.push(make_pair(i,j));
				dfst[i][j] = 0;
			}
		}
	}
	int ans = 0;
	while(!qpii.empty()){
		pair<int,int> pii = qpii.front();
		qpii.pop();
		for (int didx = 0;didx<4;didx++){
			int ny = pii.first+dirs[didx][0];
			int nx = pii.second+dirs[didx][1];
			int nt = dfst[pii.first][pii.second]+1;
			if (ny<0 || ny>=H || nx<0 || nx>=W)
				continue;
			if(dfst[ny][nx]!=-1)continue;
			qpii.push(make_pair(ny,nx));
			dfst[ny][nx] = nt;
			ans = max(ans,nt);
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 12432
unittest
{
	assert( [ "4", "3 1 3 2" ].parse.expand.solve == 1 );
	assert( [ "6", "105 119 105 119 105 119" ].parse.expand.solve == 0 );
	assert( [ "4", "1 1 1 1" ].parse.expand.solve == 2 );
	
	assert( [ "10", "1 1 1 1 1 1 3 2 3 4" ].parse.expand.solve == 5 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto vs = input.front.split.to!( long[] );
	return tuple( vs );
}

auto solve( long[] vs )
{
	auto r = 0L;
	
	// 偶数番目と奇数番目で別々に数をカウント
	long[ long ] es;
	long[ long ] os;
	foreach( i, v; vs )
	{
		if( i % 2 == 0 )
		{
			if( v !in es ) es[ v ] = 1;
			else           es[ v ]++;
		}
		else
		{
			if( v !in os ) os[ v ] = 1;
			else           os[ v ]++;
		} 
	}
	
	// それぞれで一番多い数と二番目に多い数を検索
	auto es_m1k = 0L;
	auto es_m1c = 0L;
	auto es_m2k = 0L;
	auto es_m2c = 0L;
	foreach( k, e; es )
	{
		if( es_m1c < e )
		{
			es_m2k = es_m1k;
			es_m2c = es_m1c;
			es_m1k = k;
			es_m1c = e;
		}
		else if( es_m2c < e )
		{
			es_m2k = k;
			es_m2c = e;
		}
	}
	
	auto os_m1k = 0L;
	auto os_m1c = 0L;
	auto os_m2k = 0L;
	auto os_m2c = 0L;
	foreach( k, e; os )
	{
		if( os_m1c < e )
		{
			os_m2k = os_m1k;
			os_m2c = os_m1c;
			os_m1k = k;
			os_m1c = e;
		}
		else if( os_m2c < e )
		{
			os_m2k = k;
			os_m2c = e;
		}
	}
	
	// 一番多い数が同じだったら二番目に多い数を使う
	if( es_m1k == os_m1k )
	{
		if( es_m1c + os_m2c < es_m2c + os_m1c )
		{
			es_m1k = es_m2k;
			es_m1c = es_m2c;
		}
		else
		{
			os_m1k = os_m2k;
			os_m1c = os_m2c;
		}
	}
	
	// 書き換え対象の数を計算
	r = vs.length - es_m1c - os_m1c;
	
	return r;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt[n] = {};
    rep(i, n * (n - 1) / 2) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        if (c > d) cnt[a] += 3;
        else if (c == d) {
            cnt[a]++;
            cnt[b]++;
        }
        else cnt[b] += 3;
    }
    int score[305] = {};
    rep(i, n) score[cnt[i]]++;
    int total[305] = {};
    rrep2(i, 303, 0) {
        total[i] = total[i + 1] + score[i];
    }   
    rep(i, n) {
        cout << total[cnt[i]] - score[cnt[i]] + 1 << endl;
    }
}

Measured memory_bytes: 3196
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>
const ll INF = (ll)(1e12);

ll dp[101][101][305];
ll n, w;
vi arr, h;

ll solve(ll i, ll j, ll mg) {
    if (mg > 300) {
        return -INF;
    } else if (mg > w - (j * arr[0])) {
        return -INF;
    }

    if (i == n) {
        return 0;
    }

    if (dp[i][j][mg] == -1) {
        dp[i][j][mg] = max(solve(i + 1, j, mg),
                           solve(i + 1, j + 1, mg + arr[i] - arr[0]) + h[i]);
    }
    return dp[i][j][mg];
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    memset(dp, -1, sizeof(dp));
    cin >> n >> w;
    arr.resize(n), h.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> arr[i] >> h[i];
    }

    cout << solve(0, 0, 0) << "\n";
}


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

using namespace std;

int main(){
  bool flag=true;
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s.at(i)!='h'){
        flag=false;
        break;
      }
    }
    else{
      if(s.at(i)!='i'){
        flag=false;
        break;
      }
    }
  }
  if(s.size()%2 != 0){
    flag=false;
  }
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int W, H, x, y, r;
	
	cin >> W >> H >> x >> y >> r;
	
	if(x >= r && x <= W - r && y >= r && y <= H - r)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	
	
	return 0;
}


Measured memory_bytes: 3116
def main(argv)
  n = gets.chomp.to_i
  
  flag = false
  (1..9).each do |a|
    if n % a == 0 and n / a <= 9 then
      flag = true
    end
  end
  
  puts (flag ? 'Yes' : 'No')
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
int N ,M ,sum=0, count=0;
scanf("%d%d",&N,&M);
int A[M];
for(int i=0;i<M;i++) {
    scanf("%d",&A[i]);
    sum+=A[i];
}
if(N-sum<0) printf("-1\n");
else printf("%d\n",N-sum);
return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    auto k = vector<int>(n,0);
    auto a = vector<vector<int> >(n,vector<int>(m,0));

    for (int i = 0; i < n; i++)
    {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++)
        {
            cin >> a[i][j];
        }
    }
    
    auto v = vector<int>(m+1,0);

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < k[i]; j++)
        {
            v[a[i][j]]++;
        }
        
    }

    cout << count_if(v.begin(),v.end(),[&n](int i){
        return n == i;
    });

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }

const ll MOD = 1e9 + 7;

int n;
ll a[200001];
ll psum[200001];

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

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		psum[i] = psum[i - 1] + a[i];
		psum[i];
	}

	ll ans = 0;
	for (int i = 1; i < n; i++)
	{
		ans += a[i] * ((psum[n] - psum[i]) % MOD) % MOD;
		ans %= MOD;
	}

	cout << ans;
}

Measured memory_bytes: 6776
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    for(int i = 0; i < 1000; i++) {
        if(max(H, W) * i >= N) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>

using namespace std;

int main()
{
  int A, B, T;
  cin >> A >> B >> T;
  cout << (T / A) * B << endl;
  return 0;
}


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

using lint = int64_t;
#define bit(n) (lint(1) << n)
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);

        cout << fixed << setprecision(12);
    }
} iosetup;

lint mpow(lint n, lint p) {
    lint res = 1;
    while (p) {
        if (p % 2) res = res * n % MOD;
        n = n * n % MOD;
        p /= 2;
    }
    return res;
}

int main() {
    string num;
    cin >> num;
    lint n = num.size();

    lint ans = 0;
    lint one = 0;
    for (int i = 0; i < n; i++) {
        if (num[i] == '1') {
            ans = (ans + mpow(lint(2), one) * mpow(lint(3), n - i - 1) % MOD) % MOD;
            one++;
        }
    }
        ans += mpow(lint(2), one);
        ans %= MOD;

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

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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

const int N = 100000 + 5;
long long a[N], b[N], c[N], d[N], e[N];
int main() {
    //freopen("c.in", "r", stdin);
    long long n, k;
    cin >> n >> k;
    rep(i,0,n) {
        cin >> a[i] >> b[i];
        c[i] = a[i];
    }
    sort(c, c+n);
    int m = unique(c, c+n) - c;
    int cnt = 0;
    rep(i,0,n) {
        int pos = lower_bound(c, c+m, a[i]) - c;
        d[pos] += b[i];
        e[pos] = a[i];
    }
    rep(i,0,m) {
        if(k - d[i]<= 0) {
            cout << e[i] << endl;
            break;
        }
        k -= d[i];
    }
    return 0;
}


Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int[] antenas = new int[5];
        for (int i = 0; i < 5; i++) {
            antenas[i] = kbd.nextInt();
        }
        int k = kbd.nextInt();
        System.out.println(tushin(antenas, k));
    }

    static String tushin(int[] antenas, int k) {
        for (int i = 0; i < 5; i++) {
            for (int j = i + 1; j < 5; j++) {
                if (antenas[j] - antenas[i] > k) {
                    return ":(";
                }
            }
        }
        return "Yay!";
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<utility>

int const MAXN = 2e5;
int const MAXNN = 1<<18;
int64_t MOD = 998244353;

std::pair<int, int> XD[MAXN];
int N, NN;

int dat[MAXNN*2-1];

void init() {
  for(NN = 2; NN < N; NN<<=1);
  std::fill_n(dat, NN*2-1, -1);
}

int query_in(int a, int b, int k, int l, int r) {
  if(r <= a || b <= l) return -1;
  if(a <= l && r <= b) return dat[k];
  int m = (l+r)/2;
  int vl = query_in(a, b, k*2+1, l, m);
  int vr = query_in(a, b, k*2+2, m, r);
  return std::max(vl, vr);
}

void update(int k, int v) {
  k += NN-1;
  dat[k] = v;
  while(k > 0) {
    k = (k-1)/2;
    dat[k] = std::max(dat[k*2+1], dat[k*2+2]);
  }
}

int query(int a, int b) { return query_in(a, b, 0, 0, NN); }
int query(int a) { return dat[a+NN-1]; }

int64_t dp[MAXN];

int64_t calc(int i) {
  if(i >= N) return 1;
  if(dp[i] > 0) return dp[i];
  int64_t res = (calc(i+1) + calc(query(i)+1))%MOD;
  return dp[i] = res;
}

int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> XD[i].first >> XD[i].second;
  std::sort(XD, XD+N);
  init();

  update(N-1, N-1);
  for(int i = N-2; i >= 0; --i) {
    int reach = XD[i].first + XD[i].second;
    int j = std::partition_point(XD+i, XD+N,
      [reach](std::pair<int, int>& x){ return x.first < reach; }) - XD;
    update(i, i);
    update(i, query(i, j));
  }
  std::fill_n(dp, N, 0);
  std::cout << calc(0) << std::endl;
  return 0;
}


Measured memory_bytes: 11648
K = int(input())
lunlun = [i for i in range(1,10)]
while True:
    if len(lunlun) >= K:
        break
    K -= len(lunlun)
    new = []
    for lun in lunlun:
        last_digit = lun %10
        for diff in range(-1, 2):
            if last_digit +diff >9 or last_digit +diff <0:
                continue
            new.append(10*lun +last_digit +diff)
    lunlun = new
print(lunlun[K-1])


Measured memory_bytes: 10688
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int ones(int e) {
    int ans = 0;
    while (e) {
        e &= (e - 1);
        ans++;
    }

    return ans;
}

void f() {
    int q;
    cin >> q;
    set<int> s;
    ll even = 0, odd = 0;
    int e;
    cin >> e;
    q--;
    int p = e;
    int on = ones(e);
    while (q--) {
        int e;
        cin >> e;


    }
}


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    ll d[n];
    for (int i = 0; i < n; i++) cin >> d[i];


    ll m[n];
    m[0] = 0;
    for (int i = 1; i < n; i++) {
        m[i] = d[i - 1] - m[i - 1];
    }

    if (m[n - 1] < d[n - 1]) {
        int dif = d[n - 1] - m[n - 1];
        m[0] += dif / 2;
//        m[n - 1] += dif / 2;
    }

    for (int i = 1; i < n; i++) {
        m[i] = d[i - 1] - m[i - 1];
    }


    for (ll e : m) {
        cout << 2 * e << ' ';
    }

}



Measured memory_bytes: 2944
"use strict";

const main = arg => {
    // 標準入力の不要な空白と改行を削除し、配列に格納する
    const input = arg.trim().split(" ");
    const target = parseInt(input[0], 10);
    const dig = parseInt(input[1], 10);

    const parsedNum = target.toString(dig);

    console.log(parsedNum.length);
}

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

Measured memory_bytes: 21064
n=int(input())

w=[]
ans=0

for i in range(n):
    a=input()
    w.append(a)
    if i>0:
        if w[i][0]==w[i-1][-1]:
            ans+=1

li=list(set(w))
l=len(li)

if l==n and ans==n-1:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3060
N, C = map(int, input().split())
ch = [[0]*(10**5+1) for _ in range(C)]

for _ in range(N):
  s, t, c = map(int, input().split())
  ch[c-1][s] += 1
  ch[c-1][t] -= 1

for c in range(C):
  for i in range(10**5):
    if ch[c][i+1] == 1:
      ch[c][i+1] = ch[c][i+1] + ch[c][i]
      ch[c][i] = 1
    else:
      ch[c][i+1] = ch[c][i+1] + ch[c][i]

ans = 0
for i in range(10**5):
  temp = 0
  for c in range(C):
    temp += ch[c][i+1]
  ans = max(ans, temp)

print(ans)

Measured memory_bytes: 32564
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
	int i,a;
	for (i = 1;; ++i){
		scanf("%d", &a);
		if (a == 0) break;
		printf("Case %d: %d\n",i,a);
	}
	return 0;
}

Measured memory_bytes: 596
// problem: "https://atcoder.jp/contests/agc043/tasks/agc043_a"

#include<bits/stdc++.h>

using namespace std;

int valOf(vector<string>&M,int i,int j,vector<vector<int>>&V)
{
    if(i-1 >= 0 && j-1 >= 0)
    {
        if(M[i][j] == '.')
            return min(V[i-1][j],V[i][j-1]);
        else
        {
            int x,y;

            if(M[i-1][j] == '.')
                x = V[i-1][j]+1;
            else
                x = V[i-1][j];

            if(M[i][j-1] == '.')
                y = V[i][j-1]+1;
            else
                y = V[i][j-1];

            return min(x,y);
        }
    }
    else if(j == 0 && i != 0)
    {
        if(M[i][j] == '.')
            return V[i-1][j];
        else
        {
            if(M[i-1][j] == '.')
                return V[i-1][j]+1;
            else
                return V[i-1][j];
        }
    }
    else if(j != 0 && i == 0)
    {
        if(M[i][j] == '.')
            return V[i][j-1];
        else
        {
            if(M[i][j-1] == '.')
                return V[i][j-1]+1;
            else
                return V[i][j-1];
        }
    }

    if(M[i][j] == '.')
        return 0;

    return 1;
}

int minFlips(vector<string>&M,int h,int w)
{
    vector<vector<int>>V(h,vector<int>(w,0));
    int i,j;

    for(i=0;i!=h;i++)
        for(j=0;j!=w;j++)
            V[i][j] = valOf(M,i,j,V);         // define

    return V[h-1][w-1];
}

int main()
{
    int h,w;
    cin>>h>>w;

    vector<string>M(h);
    int i;
    for(i=0;i!=h;i++)
        cin>>M[i];

    cout<<minFlips(M,h,w);      // define

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int n;
        cin >> n;
        cout << n * n << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

#define NL '\n'
#define sz(x) x.size()
#define INF LONG_MAX
#define IINF LLONG_MAX
#define PI (2.0*acos(0.0))

#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define sfd2(x,y) scanf("%lf %lf",&x,&y);

#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))

#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Rof(i, j, k) for(int i = j; i >= k; i--)
#define all(x) x.begin(),x.end()
#define asort(x) sort(all(x));
#define dsort(x) sort(all(x), greater<int>())
#define unq(x) x.erase(unique(x.begin(),x.end()),x.end())

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair <int,int> PII;
typedef pair <LL,LL> PLL;

LL gcd(LL a,LL b) { return b==0 ? a : gcd(b,a%b); }
LL lcm(LL a,LL b) { return (a/gcd(a,b))*b; }

int main() {
	int X,Y;
	cin>>X>>Y;
	if(Y%2==0){
		if(Y<2*X||Y>4*X){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}else
		cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3636
import bisect
primes = []
def SieveOfEratosthenes(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    for p in range(2, n): 
        if prime[p]: 
            primes.append(p)
SieveOfEratosthenes(10**5+30)
x = int(input())
print(primes[bisect.bisect_left(primes, x)])

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    string s,t,u; cin >> s >> t >> u;
    cout << "A" << t[0] << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n,ans=0;
        
        n = sc.nextInt();
        
        Set<String> set = new HashSet<String>();
        
        for(int i = 0; i < n; i++){
            
            String prize;
            prize = sc.next();
            
            set.add(prize);
        }
        
        System.out.println(set.size());
    }
}


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

int main(){
  int N;
  cin >> N;
  if(N==2){
    int B;
    cin >> B;
    cout << 2*B << endl;
  }else{
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin >> B.at(i);
  }
    int count = B.at(0)+B.at(N-2);
    for(int i=0;i<N-2;i++){
      count+=min(B.at(i),B.at(i+1));
    }
    cout << count << endl;
  }
  
}



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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

const int mod = 1e9 + 7;
mt19937 rng( (int)chrono::steady_clock::now().time_since_epoch().count() );

struct Mint {
  int a;
  Mint(int _a = 0) : a(_a) {}
  friend ostream& operator << (ostream &out, const Mint &_) {
    out << _.a;
    return out;
  }

  bool operator == (const Mint &_) const { return a == _.a; }
  bool operator ! () const { return !a; }

  Mint operator + (const Mint &_) const {
    int ret = a + _.a;
    return ret < mod ? Mint(ret) : Mint(ret - mod);
  }
  Mint operator - (const Mint &_) const { return *this + Mint(mod - _.a); }
  Mint operator * (const Mint &_) const { return Mint( (int)( (LL)a * _.a % mod) ); }
  friend Mint& operator += (Mint &a, const Mint &b) { return a = a + b; }
  friend Mint& operator -= (Mint &a, const Mint &b) { return a = a - b; }
  friend Mint& operator *= (Mint &a, const Mint &b) { return a = a * b; }
  Mint& operator ++ () { return *this = *this + Mint(1); }
  Mint& operator -- () { return *this = *this - Mint(1); }

  template<class T> Mint binPow(T exp) const {
    Mint ret(1), c = *this;
    for (; exp; exp >>= 1, c *= c) if (exp & 1) ret *= c;
    return ret;
  }
};

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

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafClover

  int n, a, b, c, d; cin >> n >> a >> b >> c >> d;

  vector<Mint> inv(n + 1); inv[1] = Mint(1);
  for (int i = 2; i < sz(inv); ++i) inv[i] = inv[mod % i] * Mint(mod - mod / i);
  vector<Mint> invFact(n + 1); invFact[0] = 1;
  for (int i = 1; i < sz(invFact); ++i) invFact[i] = invFact[i - 1] * inv[i];

  vector<vector<Mint> > f(n + 1, vector<Mint>(1) );
  f[0][0] = Mint(1);
  for (int i = a; i <= b; ++i) {
    vector<vector<Mint> > nF(n + 1, vector<Mint>(min(d, n / i) + 1) );
    for (int j = 0; j < sz(f); ++j) nF[j][0] = f[j][0] + (c < sz(f[j]) ? accumulate(f[j].begin() + c, f[j].end(), Mint() ) : 0);
    f.swap(nF);

//    cerr << "i = " << i << '\n';
//    for (int j = 0; j < sz(f); ++j) {
//      for (int k = 0; k < sz(f[j]); ++k) if (f[j][k].a) cout << j << ' ' << k << ' ' << f[j][k] << '\n';
//    }
//    cerr << "====\n";

    for (int j = 0; j + i < sz(f); ++j) {
      for (int k = 0; k + 1 < sz(f[j]); ++k) f[j + i][k + 1] += f[j][k] * inv[k + 1] * invFact[i];
    }

//    cerr << "i = " << i << '\n';
//    for (int j = 0; j < sz(f); ++j) {
//      for (int k = 0; k < sz(f[j]); ++k) if (f[j][k].a) cout << j << ' ' << k << ' ' << f[j][k] << '\n';
//    }
  }

  Mint ans = f[n][0] + (c < sz(f[n]) ? accumulate(f[n].begin() + c, f[n].end(), Mint() ) : 0);
  for (int i = 1; i <= n; ++i) ans *= Mint(i);

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int  a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d){
		cout<<"Left"<<endl;
	}else if(a+b<c+d){
		cout<<"Right"<<endl;
	}else{
		cout<<"Balanced"<<endl;
	}
	return 0;
}


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

int main() {
    long long L, R; cin >> L >> R;
    if (R - L > 3000) cout << 0 << endl;
    else {
        long long res = 2018;
        for (long long i = L; i < R; ++i)
            for (long long j = i+1; j <= R; ++j)
                res = min(res, (i * j) % 2019);
        cout << res << endl;
    }
}

Measured memory_bytes: 256
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)*}
    };
}

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)*}
    };

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

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

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

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [usize; m]
    }
    let s: usize = v.iter().sum();
    if s > n {
        println!("-1");
    } else {
        println!("{}", n - s);
    }
}


Measured memory_bytes: 2164
#include <stdio.h>

int main()
{
	char s[101];
	scanf("%s", &s);
	
	int i, j, max[26] = {}, min = 101, tmp;
	for (i = 0; i < 26; i++) {
		tmp = 0;
		for (j = 0; s[j] != 0; j++) {
			if (s[j] != 'a' + i) tmp++;
			else {
				if (tmp > max[i]) max[i] = tmp;
				tmp = 0;
			}
		}
		if (tmp > max[i]) max[i] = tmp;
	}
	for (i = 0; i < 26; i++) if (max[i] < min) min = max[i];
	
	printf("%d\n", min);
	fflush(stdout);
	return 0;
}

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

using namespace std;

#define REPEAT(i, N) for (int i = 0; i < (N); i++)

int main() {
  int N;
  
  cin >> N;
  
  vector<int> A(N + 1, 0);
  
  REPEAT(i, N - 1) {
    int _in;
    
    cin >> _in;
    
    A[_in]++;
  }
  
  REPEAT(i, N) {
    cout << A[i + 1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4044
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int* P = new int[N];
    for(int i = 0; i < N; ++i) {
        cin >> P[i];
    }
    sort(P, P + N);
    int result = 0;
    for(int i = 0; i < K; ++i) {
        result += P[i];
    }
    cout << result << endl;
    return 0;
}

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

const int MAX_S = 100000;
bool p[MAX_S];


void prime() {
  fill(p, p+MAX_S, true);
  p[0] = p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
        p[i*j] = false;
      }
    }
  }
}

int main() {
  int x;
  prime();
  while(cin >> x) {
    int n = 2;
    bool b = false;
    for(int i = 3; i < MAX_S; i++) {
      if(b && n > x) {
        cout << n << endl;
        break;
      }

      if(i == x) {
        cout << n << ' ';
        b = true;
      }

      if(p[i]) n = i;
    }
  }
}

Measured memory_bytes: 1260
import sys

A, B = map(int, sys.stdin.readline().rstrip().split())
c = 1e-10
d = 1 - c
A_min = int(A * (100 / 8.) + d)
A_max = int((A + d) * (100 / 8.))
B_min = int(B * 10.)
B_max = int((B + d) * 10.)

if min(A_max, B_max) - max(A_min, B_min) >= 0:
    print(max(A_min, B_min))
else:
    print('-1')

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

const int N=200005;

int n,a[N],ans[N];
std::vector<int> e[N],vec[2];

void dfs(int x,int fa,int d)
{
	vec[d].pb(x);
	for (int to:e[x])
		if (to!=fa) dfs(to,x,d^1);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		e[x].pb(y);e[y].pb(x);
	}
	dfs(1,0,0);
	int k1=n/3,k2=n/3;
	if (n%3==1) k1++;
	else if (n%3==2) k1++,k2++;
	if (vec[0].size()>vec[1].size()) std::swap(vec[0],vec[1]);
	if (k1<=vec[0].size()&&k2<=vec[1].size())
	{
		for (int i=0;i<k1;i++) ans[vec[0][i]]=1;
		for (int i=0;i<k2;i++) ans[vec[1][i]]=2;
	}
	else
	{
		for (int i=0;i<k1;i++) ans[vec[1][i]]=1;
		for (int i=k1;i<k1+k2;i++) ans[vec[1][i]]=2;
	}
	int now0=3,now1=1,now2=2;
	for (int i=1;i<=n;i++)
		if (!ans[i]) a[i]=now0,now0+=3;
		else if (ans[i]==1) a[i]=now1,now1+=3;
		else a[i]=now2,now2+=3;
	for (int i=1;i<=n;i++) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 22516
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
string trans(int N)
{
        string S;
        while (N != 0)
        {
                if (N % 2 == 1)
                {
                        N--;
                        S = '1' + S;
                }
                else
                {
                        S = '0' + S;
                }
                N /= 2;
        }
        return S;
}

bool binary(vector<int> vec, int key)
{
        int left = 0;
        int right = vec.size();

        while (left < right)
        {
                int mid = (left + right) / 2;
                if (vec[mid] == key)
                {
                        return true;
                }
                else if (vec[mid] > key)
                {
                        right = mid;
                }
                else
                {
                        left = mid + 1;
                }
        }
        return false;
}

int main() //input->compute->output
{
        int N;
        cin >> N;

        if (N <= 9)
        {
                cout << N << endl;
        }
        else if (N <= 99)
        {
                cout << 9 << endl;
        }
        else if (N <= 999)
        {
                cout << 9 + (N - 99) << endl;
        }
        else if (N <= 9999)
        {
                cout << 909 << endl;
        }
        else if (N <= 99999)
        {
                cout << 9 + 900 + (N - 9999) << endl;
        }
        else
        {
                cout << 90909 << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,m;
    cin>>n>>m;
    int road[m][2],ans[n];
     for(int i=0;i<n;i++){
      ans[i]=0;
    }
    for(int i=0;i<m;i++){
    cin>>road[i][0]>>road[i][1];
      ans[(road[i][0]-1)]++;
      ans[(road[i][1])-1]++;
    }
    for(int i=0;i<n;i++){
      cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 256
N = int(input())
alist = list(map(int, input().split()))

alice = 0
bob = 0
for i in range(N):
  if i % 2 == 0:
    alice += alist.pop(alist.index(max(alist)))
  else:
    bob += alist.pop(alist.index(max(alist)))
    
print(alice-bob)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> m;

int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(m[a]==0){
			m[a]=1;
			ans++;
		}else{
			m[a]=0;
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if((s[2]==s[3]) && s.length()==6)
    {
        if(s[4]==s[5])
        {
            cout<<"Yes"<<endl;
        }
        
        else
        
    

         {
             cout<<"No"<<endl;
         }
        
        
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
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 (b<a) { a=b; return 1; } return 0; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

int main() {
    cout<<fixed<<setprecision(10);
    string s; cin>>s;

    map<string,string> m;
    m["ABC"] = "ARC";
    m["ARC"] = "ABC";

    cout<<m[s]<<endl;

    return 0;

}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int h,w,q,m[2001][2001];
int sb[2001][2001],sx[2001][2001],sy[2001][2001];
main()
{
	cin>>h>>w>>q;
	for(int i=0;i<h;i++)
	{
		string s;cin>>s;
		for(int j=0;j<w;j++)m[i+1][j+1]=s[j]-'0';
	}
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)
		sb[i][j]=sb[i-1][j]+sb[i][j-1]-sb[i-1][j-1]+m[i][j];
	for(int i=2;i<=h;i++)for(int j=1;j<=w;j++)
		sx[i][j]=sx[i-1][j]+sx[i][j-1]-sx[i-1][j-1]+(m[i][j]&&m[i-1][j]);
	for(int i=1;i<=h;i++)for(int j=2;j<=w;j++)
		sy[i][j]=sy[i-1][j]+sy[i][j-1]-sy[i-1][j-1]+(m[i][j]&&m[i][j-1]);
	for(;q--;)
	{
		int a,b,c,d;cin>>a>>b>>c>>d;
		cout<<(sb[c][d]-sb[a-1][d]-sb[c][b-1]+sb[a-1][b-1])
			-(sx[c][d]-sx[a][d]-sx[c][b-1]+sx[a][b-1])
			-(sy[c][d]-sy[a-1][d]-sy[c][b]+sy[a-1][b])<<endl;
	}
}

Measured memory_bytes: 64384
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;


int main(void) {
  ll N;
  cin >> N;
  string s;
  cin >> s;
  ll i;
  
  ll cnt=0;
  for(i=0; i<N; i++) {
    if(s[i]=='.') cnt++;
  }
  
  ll ans=cnt;
  for(i=0; i<N; i++) {
    if(s[i]=='#') cnt++;
    if(s[i]=='.') cnt--;
    
    chmin(ans, cnt);
  }
  
  pt(ans);
}






Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int A,B,M;
 cin>>A>>B>>M;
 int a[A];

 int mina=INT_MAX;int minb=INT_MAX ;int minc=INT_MAX;

 for(int i=0;i<A;i++)
 {
     cin>>a[i];
     if(a[i]<mina)
         mina=a[i];
 }
 int b[B];
 for(int i=0;i<B;i++)
 {
     cin>>b[i];
     if(b[i]<minb)
         minb=b[i];
 }
 int c[M];
 for(int i=0;i<M;i++)
 {
     int x,y,t;
     cin>>x>>y>>t;
     c[i]=a[x-1]+b[y-1]-t;
     if(minc>c[i])
         minc=c[i];
 }
 cout<<min(mina+minb,minc);
}

Measured memory_bytes: 1408
N = int(input())
ans = 0
for i in range(1,N+1,1):
    count = 0
    if i%2==0:
        continue
    for j in range(1,i+1,1):
        if i%j==0:
            count = count + 1
    if count == 8:
        ans = ans + 1

print(ans)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
	long long int n, m, t;
	cin >> n >> m >> t;
	long long int a;
	long long int sum = 0;
	long long int tt = 0;
	cin >> a;
	sum += a-m;
	tt = a;
	for (long long int i = 1; i < n; i++) {
		cin >> a;
		if (a > tt+m*2) {
			sum += a-(tt+m*2);
		}
		tt = a;
	}
	if (t > tt+m) {
		sum += t-(tt+m);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3104
N, M = map(int, input().split())
KS = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

pattern_count = 0
for n in range(2 ** N):
	for i, ks in enumerate(KS):
		switch_count = 0
		for s in ks[1:]:
			if n >> (s - 1) & 1:
				switch_count += 1
		else:
			if switch_count % 2 != P[i]:
				break
	else:
		pattern_count += 1
print(pattern_count)


Measured memory_bytes: 3188
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

int n,tot=1,ans,val[1000010];
string s[200010];
vector<pair<int,int> > v[1000010];

inline void dfs(int x,int pr,int id,int lvl)
{
	if(lvl<0){
		val[x]++;return;
	}
	bool flag=false;
	for(int i=0;i<v[x].size();i++) if(v[x][i].first!=pr){
		if(v[x][i].second==s[id][lvl]-'a'){
			flag=true;
			dfs(v[x][i].first,x,id,lvl-1);
			break;
		}
	}
	if(!flag){
		tot++;
		v[x].push_back(make_pair(tot,s[id][lvl]-'a'));
		v[tot].push_back(make_pair(x,s[id][lvl]-'a'));
		dfs(tot,x,id,lvl-1);
	}
}

inline void solve(int x,int pr,int sum,vector<int> col)
{
	if(val[x]){
		ans+=sum;
		sum++;
	}
	vector<int> nw;nw.resize(26,0);
	for(int i=0;i<26;i++) nw[i]=col[i];
	for(int i=0;i<v[x].size();i++) if(v[x][i].first!=pr){
		if(val[v[x][i].first]) nw[v[x][i].second]++;
	}
	for(int i=0;i<v[x].size();i++) if(v[x][i].first!=pr){
		int pre=nw[v[x][i].second];
		sum+=nw[v[x][i].second]-val[v[x][i].first];nw[v[x][i].second]=0;
		solve(v[x][i].first,x,sum,nw);
		nw[v[x][i].second]=pre;sum-=nw[v[x][i].second]-val[v[x][i].first];
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=n;i++){
		dfs(1,-1,i,s[i].size()-1);
	}
	vector<int> xx;xx.resize(26,0);
	solve(1,-1,0,xx);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 686800
N=int(input())
S=input()
count=0
nocount=0
Rcount=0
Gcount=0
Bcount=0
for k in range(N):
    if S[k]=="R":
        Rcount+=1
    if S[k]=="G":
        Gcount+=1
Bcount = N -Rcount-Gcount
count=Rcount*Gcount*Bcount
for k in range(3,N+1):
    if k%2==1:
        for i in range(1,k-1,2):
            if S[i-1]!=S[k-1]:
                j=(i+k)//2
                if S[i-1]!=S[j-1] and S[k-1]!=S[j-1]:
                    nocount+=1
    if k%2==0:
        for i in range(2,k-1,2):
            if S[i-1]!=S[k-1]:
                j=(i+k)//2
                if S[i-1]!=S[j-1] and S[k-1]!=S[j-1]:
                    nocount+=1
print(count-nocount)


Measured memory_bytes: 9256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                count += 1
print(count)

Measured memory_bytes: 3060
let solve = (input) => {
  const [N, ls] = input.split("\n")
  const ll = ls.split(" ").map(Number)

  const m = Math.max(...ll)
  const sum = ll.reduce((c, n) => c + n, 0)
  const rest = sum - m
  return rest - m > 0 ? "Yes" : "No"
}
const input = require("fs").readFileSync("/dev/stdin", "utf8")
console.log(solve(input.trim()))


Measured memory_bytes: 7372