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

int h, w;
vector<string> S;

const int MAXI = 410;
long long black, white;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

bool seen[MAXI][MAXI];

void dfs(int x, int y){
    seen[x][y] = true;
    if(S[x][y] == '#') black++;
    else white++;
    
    for(int i = 0; i < 4; i++){
        int nx, ny;
        nx = x + dx[i];
        ny = y + dy[i];
        if(nx < 0 or ny < 0 or nx >= h or ny >= w){
            continue;
        }
        if(S[x][y] == S[nx][ny]){
            continue;
        }
        if(seen[nx][ny]){
            continue;
        }
        dfs(nx, ny);
    }

}

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

    cin >> h >> w;
    S.resize(h);

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

    long long ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(S[i][j] == '.') continue;
            if(seen[i][j]) continue;
            black = 0, white = 0;
            dfs(i, j);
            ans += black * white;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int a[3]; rep(i,3) cin>>a[i];
    sort(a,a+3);
    cout<<a[2]-a[0]<<endl;
    return 0;
}


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

int main() {
  int k, x;
  cin >> k >> x;
  
//  cout << x - k + 1 << ", " << k + x << endl;
  
  int start = x - k + 1;
  int end = x + k;
  
  for(int i = start; i<end; i++)
  {
    cout << i << " ";
  }
  
  return 0;
}

Measured memory_bytes: 256
"""
制約
1≦N≦100
Nは整数
"""

#入力
N = int(input())

#九九リストの作成
list = []
for i in range(1, 10):
  for j in range(1, 10):
    list.append(i * j) #リストに追加　list.append()

#リスト内にNが存在するかどうかで判別＆出力
if N in list:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>
#include<chrono>
#include<random>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

long double constexpr pi = 3.141592653589793;

template<class T>
constexpr T sigma1(T i, T n){
    return (n - i + 1) * (i + n) / 2;
}

template<class T>
constexpr T sigma2(T i, T n){
    return (i == 1 ? n * (n + 1) * (2 * n + 1) / 6 :
            sigma2(1, n) - sigma2(1, i - 1));
}

template<class T>
constexpr T sigma3(T i, T n){
    if (i == 1) {
        auto temp = sigma1(i, n);
        return temp * temp;
    }
    return sigma2(1, n) - sigma2(1, i - 1);
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    cout << min(a, k) + (k - a - b > 0 ? -(k - a - b) : 0)<< "\n";

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

const int INF = 100100100;
const int MOD = 1e9 + 7;

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

    int N;
    llong A[300000];
    cin >> N;

    REP(i, N) {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
    }

    int l = 0;
    int r = N - 1;
    while (l < r) {
        if (A[l] < A[r]) {
            A[r] -= A[l];
            l++;

        } else if (A[l] == A[r]) {
            l++;
            r--;
        } else if (A[l] > A[r]) {
            A[l] -= A[r];
            r--;
        }
    }

    if (r < l) {
        cout << 0 << "\n";
        return 0;
    } else {
        cout << A[r] << "\n";
        return 0;
    }

    return 0;
}


Measured memory_bytes: 2560
n=int(input())
A=list(map(int,input().split()))
f=True
if n%2==0:
  if 0 in A or len(set(A))!=n//2:f=False
else:
  if len([0 for a in A if a==0])!=1 or len(set(A))!=n//2+1:f=False
print(2**(n//2)%(10**9+7) if f else 0)

Measured memory_bytes: 14008
import sys
import math
import collections
from collections import deque
import heapq
n = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

s = str(n)
for i in range(len(s)):
    if s[i] == "7":
        print("Yes")
        sys.exit()

print("No")
            




    


Measured memory_bytes: 9476
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


a_num, b_num, a_time, b_time = 0, 0, 0, 0

for n,b in enumerate(B):
  b_time += b
  b_num += 1
  if b_time > K:
    b_time -= b
    b_num -= 1
    break
    
ans = b_num

for n,a in enumerate(A):
  a_time += a
  a_num += 1
  time = a_time + b_time
  while time > K and b_num > 0:
    b_time -= B[b_num - 1]
    b_num -= 1
    time = a_time + b_time
  if time > K:
    break
  ans = max(ans, a_num + b_num)

print(ans)

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

#define FAST        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll          long long
#define ull         unsigned long long
#define all(a)      a.begin(), a.end()
#define rall(a)     a.rbegin(), a.rend()
#define pii         pair<int, int>
#define mod         1000000007
#define PI          acos(-1)

using namespace std;



int main (){
    //FAST;
    //freopen("input.txt", "r", stdin);

    ull n;
    cin>>n;
    ull ans = n+ (n*n) + (n*n*n);
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll ans=0;
    char s[100100];
    scanf("%s", s);
    for(ll i=0; s[i+1]!='\0'; i++) if(s[i]!=s[i+1]) ans++;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int p, m, c;
    cin >> p >> m >> c;
    cout << (p + m + c) << endl;
}



Measured memory_bytes: 3180
n, m = gets.split.map(&:to_i)

ss = m.times.with_object([]) do |_, arr|
  _, *s = gets.split.map(&:to_i)
  arr.push(s)
end
ps = gets.split.map(&:to_i)

ans = 0

(1 << n).times do |bit|
  valid = true

  m.times do |i|
    next if ss[i].count { |s| bit[s - 1] == 1 } % 2 == ps[i]

    valid = false
    break
  end

  ans += 1 if valid
end

puts ans


Measured memory_bytes: 1788
package main

import (
  "io"
  "bufio"
  "strings"
  "fmt"
  "os"
)
 
func nextDate(date string) (d int) {
  switch date {
    case "SUN":
      d = 7
    case "MON":
      d = 6
    case "TUE":
      d = 5
    case "WED":
      d = 4
    case "THU":
      d = 3
    case "FRI":
      d = 2
    case "SAT":
      d = 1
    default:
      d = 0
  }
  return
}
 
func main() {
  buf := bufio.NewReaderSize(os.Stdin, 1024)
  date := readLine(buf)
  fmt.Fprintf(os.Stdout, "%v\n", nextDate(date))
}
 
func readLine(reader *bufio.Reader) string {
  str, _, err := reader.ReadLine()
  if err == io.EOF {
    return ""
  }
  return strings.TrimRight(string(str), "\r\n")
}
 
func checkErr(err error) {
  panic(err)
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

vll dis;
void dfs(vvpll &graph, ll i, ll dist){
  dis[i] = dist;
  vrep(j, graph[i]){
    if(dis[j.first] == -1){
      dfs(graph, j.first, dist + j.second);
    }
  }
}

int main(){
  ll n;
  cin >> n;
  vvpll graph(n);
  rep(i, 0, n - 1){
    ll u, v, w;
    cin >> u >> v >> w;
    graph[u - 1].push_back(make_pair(v - 1, w));
    graph[v - 1].push_back(make_pair(u - 1, w));
  }
  dis.assign(n, -1);
  dfs(graph, 0, 0);
  vrep(i, dis) cout << (i % 2 ? 0 : 1) << endl;
}

Measured memory_bytes: 9984
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

#define pb push_back

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N;
int a[50];

int main(int argc, char* argv[])
{
	scanf("%d", &N);
	int index;
	int M = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		if (M <= abs(a[i])) {
			M = abs(a[i]);
			index = i;
		}
	}

	if (a[index] < 0) {
		printf("%d\n", 2 * N);
		printf("%d %d\n", index + 1, N);
		printf("%d %d\n", index + 1, N);
		for (int i = N; i >= 2; i--) {
			printf("%d %d\n", i, i - 1);
			printf("%d %d\n", i, i - 1);
		}
	}
	else {
		printf("%d\n", 2 * N);
		printf("%d %d\n", index + 1, 1);
		printf("%d %d\n", index + 1, 1);
		for (int i = 1; i <= N - 1; i++) {
			printf("%d %d\n", i, i + 1);
			printf("%d %d\n", i, i + 1);
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	int N, tmp,i;
	bool flag = false;
	vector<int> A;
	int max = -100, max2 = -200;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &tmp);
		A.push_back(tmp);
		if (max == tmp) {//一緒なら
			max2 = tmp;
			flag = true;
		}
		else if (max < tmp) {//でかいなら
			flag = false;
			max2 = max;
			max = tmp;
		}
		else if(max2 < tmp){//2番目よりでかいなら
			flag = false;
			max2 = tmp;
		}
	}
	if (flag) {//フラグ立ってるなら最大値2つあるので全部それ
		for (i = 0; i < N; i++) {
			printf("%d\n", max);
		}
	}
	else {
		for (i = 0; i < N; i++) {
			if (max == A.at(i)) {
				printf("%d\n", max2);
			}
			else {
				printf("%d\n", max);
			}
		}
	}
	
	

	
	return 0;
}

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


left_white = 0
right_black = 0

for ss in s:
    if ss == '.':
        left_white += 1
min_sum = left_white + right_black


for ss in s:
    if ss == '.':
        left_white -= 1
    else:
        right_black += 1
    min_sum = min(min_sum, left_white + right_black)
print(min_sum)



Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int x,y,z;
   cin >> x >> y >> z;
   swap(x,y);
   swap(x,z);
   cout << x << ' ' << y << ' ' << z << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace ::std;

int main(){
	string S;
	cin >> S;
	
	bool tap1 = true;
	bool tap2 = true;
	for(int i = 0; i < S.size(); ++i){
		if(i%2 == 0){
			if(S[i] == 'L'){
				tap1 = false;
				break;
			}
		}
		else{
			if(S[i] == 'R'){
				tap2 = false;
				break;
			}
		}
	}

	if(tap1 && tap2){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;

	}

	return 0;
	
}  


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.1415926535897932


void solve()
{
       ll n, m;
       cin>>n>>m;
       vl op;
       ll tm=m;
       for(ll i=1; i*i<=m; i++){
              if(tm%i==0){
                     //cout<<i<<endl;
                     op.pb(i);
                     if(tm/i!=i) op.pb(tm/i);
              }

       }
       sort(op.rbegin(), op.rend());
       //for(ll x:op) cout<<x<<" ";
       //cout<<endl;
       for(ll x:op){
              if(m/x >= n){
                     cout<<x;
                     return ;
              }
       }
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = Console.ReadLine();
            var s = Console.ReadLine();
            if(s.Length <= int.Parse(k))
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine(s.Substring(0, int.Parse(k)) + "...");
            }
        }
    }
}


Measured memory_bytes: 27524
#import numpy

N = int(input())

C = [int(i) for i in input().split()] 
V = [int(i) for i in input().split()]

ans = []
for i in range(N):
	if(C[i]-V[i]>0):
		ans.append(C[i]-V[i])
		ans.sort(reverse=True)

#x = numpy.prod(ans)
print(sum(ans))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ii pair<int,int>
#define ll long long
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define orta ((bas+son)>>1)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define inf 100000000
#define N 505
#define MOD 998244353
using namespace std;

int main() {

	int a,b,c;
	ll k;

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

	if(k&1) printf("%d",b-a);
	else printf("%d",a-b);

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



int main() {
	ll n, m;
	cin >> n >> m;
	ll ans = m * 1900 + (n - m) * 100;
	ll k = 1;
	rep(i, m) k *= 2;
	ans *= k;
	cout << ans << endl;
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define double long double

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

  double A,B,H,M;
  cin>>A>>B>>H>>M;
  double a=H*1.*360/12+M*1.*30/60;
  double b=M*1.*360/60;
  double d=abs(a-b);
  if(d>180){
    while(d<=180)d-=180;
  }
  d=d*1./180*M_PI;
  double ans=A*A+B*B-2*A*B*cos(d);
  cout<<fixed<<setprecision(20)<<sqrt(ans)<<endl;
  return 0;
}


Measured memory_bytes: 4096
S = [input() for _ in range(3)]
i = [0,0,0]
t = 0
while True:
    if i[t] == len(S[t]):
        print(chr(t+ord('A')))
        exit()
    i[t] += 1
    t = ord(S[t][i[t]-1]) - ord('a')


Measured memory_bytes: 61992
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def read_is(n=1):
    return [read_i() for _ in range(n)]


class Graph:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.edges = [[] for _ in range(n_nodes)]

    def add_edge(self, s, t, d=None, undirected=False):
        if d is not None:
            self.edges[s].append((t, d))
        else:
            self.edges[s].append(t)
        if undirected:
            self.add_edge(t, s, d)


class FloydWarshall:
    def __init__(self, graph):
        self.graph = graph
        self.distances = [[float('inf')] * graph.n_nodes
                          for _ in range(graph.n_nodes)]
        self.nexts = [[None] * graph.n_nodes for _ in range(graph.n_nodes)]
        self._init()

    def _init(self):
        for x in range(self.graph.n_nodes):
            self.distances[x][x] = 0
        for source in range(self.graph.n_nodes):
            for destination, distance in self.graph.edges[source]:
                self.distances[source][destination] = distance
                self.nexts[source][destination] = destination

    def compute_shortest_path_lengths(self):
        for k in range(self.graph.n_nodes):
            for i in range(self.graph.n_nodes):
                for j in range(self.graph.n_nodes):
                    s = self.distances[i][k] + self.distances[k][j]
                    if s < self.distances[i][j]:
                        self.distances[i][j] = s
                        self.nexts[i][j] = self.nexts[i][k]


n, m, l = read_i()
graph = Graph(n)
for _ in range(m):
    a, b, c = read_i()
    if c > l:
        continue
    graph.add_edge(a - 1, b - 1, d=c, undirected=True)
fw = FloydWarshall(graph)
fw.compute_shortest_path_lengths()

graph2 = Graph(n)
for s in range(n):
    for t in range(n):
        if s >= t:
            continue
        if fw.distances[s][t] > l:
            continue
        graph2.add_edge(s, t, d=1, undirected=True)
fw = FloydWarshall(graph2)
fw.compute_shortest_path_lengths()

q = int(input())
for _ in range(q):
    s, t = read_i()
    s -= 1
    t -= 1
    d = fw.distances[s][t] - 1
    if d == float('inf'):
        print(-1)
    else:
        print(d)

Measured memory_bytes: 88668
N = int(input())
S = list(input().strip())

l = 0
r = N-1
ans = 0
while l < r:
    if S[l] == 'W' and S[r] == 'R':
        ans += 1
        l += 1
        r -= 1
    while l < N and S[l] != 'W':
        l += 1
    while r >= 0 and S[r] != 'R':
        r -= 1

print(ans)

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

int main(){
while(1){
	int n;
	scanf("%d",&n); if(n==0)break;
	int a[100002],b[100002],c,k=0; a[0]=-1;

	for(int i=1;i<=n;i++){
		scanf("%d",&c);
		if(i%2==1){
			if(a[k]==c)b[k]++;
			else {
				k++;
				a[k]=c;
				b[k]=1;
			}
		}
		else {
			if(a[k]==c)b[k]++;
			else {
				if(k==1){ a[k]=1-a[k]; b[k]++; }
				else {
					k--;
					b[k]+=b[k+1]+1;
				}
			}
		}
	}

	int ret=0;
	for(int i=1;i<=k;i++){
		if(a[i]==0)ret+=b[i];
	}

	printf("%d\n",ret);
}
}

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

map <pair<int, int>, int> mp;


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

int get(int x, int y) {
	int sum = 0;
	for(int i = 0; i < 9; i++) {
		int ax = x + dx[i], ay = y + dy[i];
		sum += mp.count(make_pair(ax, ay));
	}
	return sum;
}


set <pair <int, int> > st[10];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int h, w, n; cin >> h >> w >> n;
	vector <pair <int, int> > v;
	for(int i = 1; i <= n; i++) {
		int x, y; cin >> x >> y;
		v.push_back(make_pair(x, y));
		mp[make_pair(x, y)] = 1;
	}


	for(auto z: v) { 
		int x, y; tie(x, y) = z; 
		for(int i = 0; i < 9; i++) {
			int ax = x + dx[i], ay = y + dy[i];
			if(ax > 1 && ax < h && ay > 1 && ay < w) {
				st[get(ax, ay)].insert(make_pair(ax, ay));
			}
		}
	}

	int x = (h - 2) * (w - 2);

	for(int i = 1; i <= 9; i++) x -= (int)st[i].size();

	cout << x << endl;
	for(int i = 1; i <= 9; i++) {
		cout << st[i].size() << endl;
	}
}

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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int k, x;
    cin >> k >> x;
    if(500 * k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define MAXN 100001
using namespace std;
char s[MAXN];
int main()
{
	int judge=0;
	scanf("%s",s+1);
	int lenth=strlen(s+1);
	for(int i=1;i<=lenth;i++)
	{
		if(judge==0)
		{
			if(s[i]=='C')
			{
				judge=1;
				continue;
			}
			else
			{
				continue;
			}
		}
		else
		{
			if(s[i]=='F')
			{
				judge=2;
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

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

using vi = vector<int>;

int dfs(const vi& v, int turn)
{
    if(v[0] < 2 && v[1] < 2) return !turn;

    for(int i = 0; i < 2; i++)
    for(int j = 1; j * 2 <= v[i]; j++)
    {
        int r = dfs({v[i] - j * 2, v[!i] + j}, !turn);

        if(r == turn) return r;
    }

    return !turn;
}

using lli = int64_t;

int main()
{
    ios_base::sync_with_stdio(0);

    lli x, y; cin >> x >> y;

    if(llabs(x - y) <= 1) cout << "Brown" << endl;
    else                  cout << "Alice" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;

int main() {
    #ifndef LOCAL
        fastIO;
    #endif
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a>0 && c>0){
        c-=b;
        if(c<1){
            cout << "Yes" << endl;
            break;
        }
        a-=d;
        if(a<1){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3660
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  ll n;
  cin >> n;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  ll l = 1;
  loop(i,0,n) l = lcm(l, A[i]);
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 3568
using System;
using System.Linq;
 
namespace _1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = new int[n];
            A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.Write(A[0]);
            for (int i = 1; i < n; i++)
            {
                Console.Write(" " + A[i]);
            }
            Console.WriteLine();
            for (int i = 1; i < n; i++)
            {
                int v = A[i];
                int j = i - 1;
                while (j >= 0 && A[j] > v)
                {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = v;
                Console.Write(A[0]);
                for (int k = 1; k < n; k++)
                {
                    Console.Write(" " + A[k]);
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 16296
(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar nx (input-to-list (read-line)))
(defvar l (input-to-list (read-line)))

(defun sumate (l start)
  (if l
      (cons start (sumate (cdr l) (+ start (car l))))
      (list start)))

(format t "~d" (length (remove-if #'(lambda (a)
                                     (> a (cadr nx)))
                                  (sumate l 0))))

Measured memory_bytes: 11872
/*
                    NAYEEM
    Information and Communication Engineering ,
            University of Rajshahi
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define uu first
#define vv second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())
#define zero(arr,a) memset(arr,a,sizeof arr)
#define mx 1005
#define TestCase int t,cs=1;sci(t);while(t--)

//ll modPower(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
//ll power(ll a,ll b){if(b==0)return 1;ll x=power(a,b/2);x=(x*x);if(b&1)x=(x*a);return x;}

int fx[]={0,1,1,1,0,-1,-1,-1};
int fy[]={1,1,0,-1,-1,-1,0,1};



int main()
{
    //IOS
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    /*
        Check Contains Limit && Declear Counter in Long Long
        Check Array Size
    */

    ll n,k,i,j,ans;
    cin>>n>>k;
    j = n%k;
    cout<<min(j,k-j)<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int main(){
	string T;
	cin >> T;
	int i;
	myfor(i,T.length())if(T[i] == '?')T[i] = 'D';
	cout << T << endl;
	return 0;
}


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


int main() {
  int n ;
  cin >> n ;
  
  vector<int> vec(n);
  for(int i=0 ; i<n ; i++ ){
    cin >> vec.at(i);
  }
  
  int sum=0;
  for(int i=0 ;i<n ;i++ ){
    for(int j=1 ;j<n-i ;j++){
      sum+=vec.at(i)*vec.at(i+j);
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////
struct cake {
    ll a;
    ll b;
    ll c;
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<cake>x(n);
    vector<ll>sum(n);
    ll ans=0;
    rep(i,n){
        cin>>x[i].a>>x[i].b>>x[i].c;
        sum[i]=(x[i].a+x[i].b+x[i].c);
    }
    sort(all(sum),greater<ll>());
    ll tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);
    

    rep(i,n){
        
        sum[i]=(x[i].a+x[i].b-x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);
    rep(i,n){
        
        sum[i]=(x[i].a-x[i].b+x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);
    rep(i,n){
        
        sum[i]=(-x[i].a+x[i].b+x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);
    rep(i,n){
        
        sum[i]=(-x[i].a-x[i].b+x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);
    rep(i,n){
        
        sum[i]=(x[i].a-x[i].b-x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);
    rep(i,n){
        
        sum[i]=(-x[i].a+x[i].b-x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);


    rep(i,n){
        
        sum[i]=(-x[i].a-x[i].b-x[i].c);
    }
    sort(all(sum),greater<ll>());
    tmp=0;
    rep(i,m){
        tmp+=sum[i];
    }
    chmax(ans,tmp);


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

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

int main() {
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,3){
    if (s[i]==t[i]) ans++;
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    double ans = 0.0;
    for (int i = 0; i < n; i++) {
        double x;
        string s;
        cin >> x >> s;

        if (s == "BTC") {
            x *= 380000.0;
        }

        ans += x;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 167C.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(100).
01 N          PIC 9(02).
01 M          PIC 9(02).
01 X          PIC 9(06).
01 TBL1.
   03 TB      OCCURS 12.
      05 C    PIC 9(06).
      05 A    PIC 9(06) OCCURS 12.
01 TBL2.
   03 AW      PIC 9(07) OCCURS 12.
01 CW         PIC 9(07).
01 TBL3.
   03 CX      PIC 9(07) OCCURS 4096 DEPENDING ON L.
01 L          PIC 9(04) COMP. 
01 SHO        PIC 9(04) COMP. 
01 AMR        PIC 9(01) COMP. 
01 IDX        PIC 9(02).
01 I          PIC 9(04) COMP.
01 J          PIC 9(02).
01 P1         PIC 9(03) COMP.
01 P2         PIC 9(03) COMP.
01 FLG        PIC X(01).
01 CNT        PIC S9(10).
01 OUT        PIC -(10)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N M X .
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    ACCEPT INP
    MOVE 1 TO P1 
    PERFORM VARYING J FROM 1 BY 1 UNTIL J > M + 1
      PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
      END-PERFORM
      IF (J = 1)
        MOVE INP(P1:P2 - P1) TO C(I)
      ELSE
        MOVE INP(P1:P2 - P1) TO A(I J - 1)
      END-IF
      COMPUTE P1 = P2 + 1
    END-PERFORM
  END-PERFORM.
*>
  MOVE 0 TO L
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 2 ** N - 1
    MOVE ZERO TO TBL2 CW
    MOVE 1 TO IDX
    MOVE I TO SHO
    DIVIDE SHO BY 2 GIVING SHO REMAINDER AMR
    PERFORM UNTIL SHO = 0 AND AMR = 0
      IF (AMR = 1)
        ADD C(IDX)   TO CW
      END-IF
      PERFORM VARYING J FROM 1 BY 1 UNTIL J > M OR AMR = 0
        ADD A(IDX J) TO AW(J)
      END-PERFORM
*>
      DIVIDE SHO BY 2 GIVING SHO REMAINDER AMR
      ADD 1 TO IDX
    END-PERFORM
*>
    PERFORM VARYING J FROM 1 BY 1 UNTIL J > M OR AW(J) < X
    END-PERFORM
*>
    IF (J > M)
      ADD  1  TO L
      MOVE CW TO CX(L)
    END-IF
  END-PERFORM.
*>
  SORT CX ASCENDING KEY CX.
*>
  IF (L = 0)
    MOVE -1 TO OUT
  ELSE
    MOVE CX(1) TO OUT
  END-IF.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 3956
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


int main() {
	
	int x, y;
	cin >> x >> y;
	int ans = 0;
	
	if (x == 1) {
		ans += 300000;
	}
	if (x == 2) {
		ans += 200000
			;
	}
	if (x == 3) {
		ans += 100000;
	}

	if (y == 1) {
		ans += 300000;
	}
	if (y == 2) {
		ans += 200000
			;
	}
	if (y == 3) {
		ans += 100000;
	}

	if (x == 1 && y == 1) {
		ans += 400000;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include<vector>
#include<queue>

using namespace std;

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

typedef pair<int, int> P;

vector<P>v;
bool comp1(const P& p1, const P& p2) {
	if (p1.second == p2.second) {
		return p1.first > p2.first;
	}
	else return p1.second < p2.second;
}
bool comp2(const P& p1, const P& p2) {
	if (p1.first == p2.first) {
		return p1.second < p2.second;
	}
}

signed main() {
	int N, L; cin >> N >> L;
	REP(i, N) {
		int l, r; cin >> l >> r;
		v.push_back({ l,r });
	}
	sort(v.begin(), v.end());
	int pos = 0;
	int cnt = 0;
	int idx;
	priority_queue<int>que;
	REP(i, N) {
		idx = i;
		if (v[i].first > 0)break;
		que.push(v[i].second);
	}
	while (pos < L) {
		int nex = que.top();
		cnt++;
		pos = nex;
		if (nex == L) {
			break;
		}
		for (int i = idx; i < N; i++) {
			if (v[i].first > nex) {
				idx = i;
				break;
			}
			que.push(v[i].second);
		}
	}
	int x = cnt;
	cout << x << " ";

	sort(v.begin(), v.end(), comp1);
	//cout << "sorted" << endl;
	int l = 0;
	int y = 1e9;
	REP(i, N) {
		if (v[i].first <= l)l = v[i].second;
		if (l == L)y = min(y, i + 1);
	}
	cout << y << endl;
}


Measured memory_bytes: 9224
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int p=0;
    int a;
    cin>>a;
    for(int i=0;i<a;i++){
        string s;
        cin>>s;
        if(s=="Y"){
            p+=1;
        }
    }
    if (p==0){
        cout<<"Three"<<endl;
    }
    else cout<<"Four"<<endl;
}


Measured memory_bytes: 256
from itertools import combinations

N, K = map(int, input().split())
points = []
for i in range(N):
    points.append(list(map(int, input().split())))

points.sort(key=lambda p:p[0])


min_area = 10**20
for k in range(K, N+1):
    for l in range(0, N-k+1):
        points_tmp = points[l:l+k]
        points_tmp.sort(key=lambda p:p[1])
        for m in range(0, k-K+1):
            points_selected = points_tmp[m: m+K]
            ymin = points_selected[0][1]
            ymax = points_selected[-1][1]
            points_selected.sort(key=lambda p:p[0])
            xmin = points_selected[0][0]
            xmax = points_selected[-1][0]
            area = (xmax-xmin) * (ymax-ymin)
            min_area = min(area, min_area)

print(min_area)


Measured memory_bytes: 3064
import math
from sys import stdin
input = stdin.readline

n = int(input())
s = [int(input()) for _ in range(n)]

sorted_s=sorted(s)
sum_a=sum(s)
not_ans=0
if sum_a%10==0:
    for i in range(n):
        if sorted_s[i]%10!=0:
            print(sum_a-sorted_s[i])
            exit()
        else:
            continue
    print(0)
else:
    print(sum_a)

Measured memory_bytes: 3064
sx, sy, tx, ty = map(int, input().split())
print('R' * (tx - sx) + 'U' * (ty - sy), end='')
print('L' * (tx - sx) + 'D' * (ty - sy), end='')
print('D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L', end='')
print('U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R', end='')


Measured memory_bytes: 3060
n, a, b = (int(i) for i in input().split())  
mod = 1000000007
import math

def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    r = min(r, n - r)
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs *= (i % mod) * pow(j, mod - 2, mod)
        combs %= mod
    return combs

print((pow(2, n, mod) - 1 - combinations_mod(n, a) - combinations_mod(n, b))%mod)
  
  
    

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
)

func main() {
	var d, n float64
	fmt.Scan(&d, &n)
	if n <= 99 {
		fmt.Println(int(math.Pow(100, d) * n))
	} else if n == 100 {
		fmt.Println(int(math.Pow(100, d) * 101))
	}
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
    int N;
    int A[220000];
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i];
    sort(A, A + N);
    double ans = (A[0] + A[1]) / 2.0;
    for (int i = 2; i < N; i++)(ans += A[i]) /= 2.0;
    cout << fixed << setprecision(20);
    cout << ans << endl;
}


Measured memory_bytes: 256
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = new Array(N).fill(1);
  var redVisited = new Set([0]);
  var lastRed = 0;
  for(var i = 0; i < M; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1]--;
    list[tmp[1] - 1]++;
    if(redVisited.has(tmp[0] - 1)){
      	redVisited.add(tmp[1] - 1);
    }
    if(list[tmp[0] - 1] == 0){
       redVisited.delete(tmp[0] - 1);
    }
  }
  myout(redVisited.size);
}

Measured memory_bytes: 34096
#include <iostream>
#include <algorithm>

#define SIZE 200001

using namespace std;

int main() {
    long long int A,B,C,D,i,j,k,M,K,Q;
    long long int X,N,Y,Z;
  //  long long int A[100][100];

    cin >> N;

    M = N % 1000;

    if (M> 0)
        cout << 1000-M << endl;
    else
        cout << M << endl;
  return 0;

}


Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;

int keta(int x);

int main()
{
	int num;
	int a, b;
	int reverse = 0;
	int rem;
	int tmp;
	int ans = 0;

	cin >> a >> b;

	for (int i = a; i <= b; i++) {
		num = i;
		tmp = i;
		while (tmp != 0) {
			rem = tmp % 10;

			reverse = reverse * 10 + rem;

			tmp /= 10;
		}
		if (reverse == num) {
			ans++;
		}
		reverse = 0;
	}

	cout << ans << "\n";

	return (0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
ll a[100005];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    sort(a, a+n);
    ll s = a[n-1], t = 0;
    rep(i, 0, n) {
        if (abs(a[n-1] - a[i]*2) < s) {
            s = abs(a[n-1] - a[i]*2);
            t = a[i];
        }
    }
    cout << a[n-1] << " " << t << endl;
    return 0;
}


Measured memory_bytes: 1024
/*
	"We know what we are, but know not what we may be."
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

/*
	"You never know how strong you are until being strong is the only choice you have."
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
/*
	"With self-discipline most anything is possible."
*/
	
	string s, t; cin >> s >> t;
	
	long long n, m; cin >> n >> m;
	
	string u; cin >> u;
	if(u == s) n--;
	if(u == t) m--;
	
	cout << n << " " << m;
	return 0;
}

/*
	"Reach for it. Push yourself as far as you can."
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    str s; str t; str u;
    cin>>s>>t>>u;

    int d = 'A' - 'a';

    cout<<char(s[0]+d)<<char(t[0]+d)<<char(u[0]+d)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;

  ll n = s.size();

  reverse(all(s));

  map<ll, ll> mp;
  mp[0] = 1;

  ll cnt = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cnt += modpow(10, i, 2019) * (s[i] - '0');
    cnt %= 2019;

    ans += mp[cnt];
    mp[cnt]++;
  }

  cout << ans << ln;

  return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h;
    rep(i, n) {
        int d;
        cin >> d;
        h.push_back(d);
    }
    sort(all(h));
    k = min(k, n);
    rep(i, k) h.pop_back();
    ll ans = 0;
    for (int d : h) ans += d;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
using namespace std;
 
int main()
{
  int h1,s1,h2,s2;
  cin>>h1>>s1>>h2>>s2;
  int a = ((h1+s2)-1)/s2;
  int b = ((s1+h2)-1)/s1;
  
  if(a>=b)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
q, h, s, d = gets.chomp.split.map(&:to_i)
n = gets.to_i
res = 0
rest = 4 * n
while rest > 0
  c = []
  c << [1, q] if rest >= 1
  c << [2, h] if rest >= 2
  c << [4, s] if rest >= 4
  c << [8, d] if rest >= 8
  sz, v = c.sort_by! {|m, c| c.to_f / m }[0]
  cnt = rest / sz
  res += cnt * v
  rest -= cnt * sz
end
puts res

Measured memory_bytes: 1788