akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=1e6+10;
int n,m,q,a[maxn],b[maxn],c[maxn],d[maxn],sum,A[maxn],ans;
void dfs(int x,int la)
{
	if (x==n+1)
	{
		int now=0;
		for (int i=1;i<=q;i++) if (A[b[i]]-A[a[i]]==c[i]) now+=d[i];
		ans=max(ans,now);
		return;
	}
	for (int i=la;i<=m;i++) A[x]=i,dfs(x+1,i);
}
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for (int i=1;i<=q;i++) scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	dfs(1,1); printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 3848
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
MOD = 10**9+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
d = defaultdict(int)
for a in A:
    d[a] += 1
ans = 0
for i in range(1,2001):
    c = 0
    for j in range(0,i):
        c += d[j]
    ans += c*d[i]*((K-1)*K)//2
    ans %= MOD
for i in range(len(A)):
    a = A[i]
    for j in range(i+1,len(A)):
        if a > A[j]:
            ans += K
ans %= MOD
print(ans)


Measured memory_bytes: 73596
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/

vector<int> Edge[100005];
int check[100005][30];

int main() {

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

	string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int n;
	while(cin >> n,n){

		vector<char> A(n);
		
		set<char> st;

		vector<int> cnt(26,0);
		for (int i = 0; i < n; i++)
		{
			cin >> A[i];
			cnt[A[i]-'A']++;
			st.insert(A[i]);
		}
		
		int maxi = 0;
		string letter="?";

		for (int i = 0; i < 26; i++)
		{
			maxi = max(maxi,cnt[i]);
		}
		vector<int> v;
		for (int i = 0; i < 26; i++)
		{
			if(cnt[i] == maxi){
				v.push_back(i);
			}
		}
		if(v.size() > 1){
			cout << "TIE" << endl;
			continue;
		}
		//これ以降は必ず確定する

		fill_v(cnt,0);
		maxi = 0;

		for (int i = 0; i < n; i++)
		{
			cnt[A[i]-'A']++;
			int rest = n-(i+1);
			//最大値を見つける
			for (int j = 0; j < 26; j++)
			{
				if(maxi < cnt[j]){
					maxi = cnt[j];
					letter = alpha[j];
				}
			}
			//cout << maxi << " " << letter << endl;
			bool fin = false;
			//finがtrueならまだ確定できない
			for (int j = 0; j < 26; j++)
			{
				if(cnt[j] == maxi && j == (letter[0]-'A'))continue;
				fin |= (cnt[j]+ rest >= maxi);
				if(fin)break;
			}
			//cout << maxi << " " << cnt['V'-'A']<<endl;
			//cout << "i= " << i << " rest= " << rest << endl;
			if(!fin){
				cout << letter << " " << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 5464
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  while(1) {
    int W, H; cin >> W >> H;
    if(!W) break;
    vector<string> G(H);
    rep(i, 0, H) cin >> G[i];
    vector<vector<int>> visited(H,vector<int>(W));
    using P = pair<int, int>;
    queue<P> Q;
    rep(i, 0, H) rep(j, 0, W) {
      if(G[i][j] == '@') {
        Q.push(P(i, j));
        visited[i][j] = 1;
      }
    }
    int ans = 0;
    while(!Q.empty()) {
      ans++;
      P p = Q.front(); Q.pop();
      int y = p.first, x = p.second;
      rep(i, 0, 4) {
        int ny = y + dy[i], nx = x + dx[i];
        if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
        if(visited[ny][nx]) continue;
        if(G[ny][nx] == '.') {
          visited[ny][nx] = 1;
          Q.push(P(ny, nx));
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int gcd(int x, int y){
    if (y == 0ll) {
        // y==0のときxをそのまま返す（xがyで割り切れる）
        return x;
    } else {
        // y!=0のときyとx%yのgcdを返す
        return gcd(y, x%y);
    }
}

int main() {
    int N; cin >> N;
    vector<ll> A(N); rep(i, N) cin >> A[i];

    vector<ll> L(N), R(N);
    L[0] = A[0];
    R[N-1] = A[N-1];
    // (A[0]~A[i]までのgcd)とA[i+1]のgcd
    // ※gcd は結合則が成り立つ
    for (int i=0; i<N-1; ++i) {
        L[i+1] = gcd(L[i], A[i+1]);
    }
    // (A[N-1]~A[i]までのgcd)とA[i-1]のgcd
    for (int i=N-1; i>0; i--) {
        R[i-1] = gcd(R[i], A[i-1]);
    }

    int ans = max(L[N-2], R[1]);  // A[N-1]を任意と入れ替えた場合と，A[0]を任意と入れ替えた場合で初期化
    for (int i=0; i<N-2; ++i) {
        // (A[i+1]より前のgcd)と(A[i+1]より後のgcd)のgcd
        int t = gcd(L[i], R[i+2]);
        ans = max(ans, t);
    }

    print(ans);    
}

Measured memory_bytes: 2560
INF = float('inf')
N, M = map(int, input().split())
dp = [INF for _ in range(2**N)]
dp[0] = 0
for i in range(M):
    a, _ = map(int, input().split())
    *C, = map(int, input().split())
    open_bit = 0
    for i in C: open_bit |= 1 << i-1
    for i in range(2**N):
        temp = dp[i] + a
        if dp[i|open_bit] > temp: dp[i|open_bit] = temp
if dp[-1] != INF: print(dp[-1])
else: print(-1)

Measured memory_bytes: 3188
#include<stdio.h>
#include<math.h>

double v;
int i,j;
double t,d;
int main(){
	while(scanf("%lf",&v)!=EOF){
		t=v/9.8;
		d=4.9*t*t;
		double f=ceil((d+5)/5);
		printf("%d\n",(int)f);
	}
}

Measured memory_bytes: 1060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.array(read().split(),np.int32)

answer = 0
for _ in range(32):
    A = A[A%2 == 0]
    answer += len(A)
    A >>= 1

print(answer)

Measured memory_bytes: 12668
#include <stdio.h>

int main(){

  int t[200010];
  int n,i,max=-100000000000,min,tmp;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
  }
  min=t[0];
  for(i=1;i<n;i++){
    tmp=t[i]-min;
    if(max<tmp) max=tmp;
    if(t[i]<min) min=t[i];
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a;
  int b;
  int c;
  
  cin >> a;
  cin >> b;
  cin >> c;
  
  if(b+c > a){
    cout << b+c-a << endl;
  }
   else{
    cout << "0" << endl;
}
}


Measured memory_bytes: 256
s = list( input() )
n = len(s)
kids = [0]*n

cnt = 0
for i in range(n-1):
    if s[i] == 'R':
        cnt += 1
        if s[i+1] == 'L':
            if cnt % 2 == 0:
                kids[i] = cnt//2
                kids[i+1] = cnt//2
            else:
                kids[i] = cnt//2 + 1
                kids[i+1] = cnt//2
            cnt = 0

for i in range(1,n):
    if s[-i] == 'L':
        cnt += 1
        if s[-i-1] == 'R':
            if cnt % 2 == 0:
                kids[-i] += cnt//2
                kids[-i-1] += cnt//2
            else:
                kids[-i] += cnt//2 + 1
                kids[-i-1] += cnt//2
            cnt = 0

for i in range(n):
    print(kids[i], end=' ')

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

const int kBuildingNum = 4;
const int kFloorNum = 3;
const int kRoomNum = 10;

void writeRoom(int (&floor)[kRoomNum])
{
    for (int i=0; i<kRoomNum; ++i)
    {
        cout << ' ' << floor[i];
    }
}

int main()
{    
    int infoNum=0;
    cin >> infoNum;
    
    int allInfo[kBuildingNum][kFloorNum][kRoomNum] = {0};
    int building=0, floor=0, room=0, resident=0;
    for (int i=0; i<infoNum; ++i)
    {
        cin >> building >> floor >> room >> resident;
        allInfo[building-1][floor-1][room-1] += resident;
    }
        
    for (int i=0; i<kBuildingNum; ++i)
    {
        for (int j=0; j<kFloorNum; ++j)
        {
            writeRoom(allInfo[i][j]);
//            if (!(j==kFloorNum-1 && i==kBuildingNum-1)) 
                cout << endl;
        }
        if (i!=kBuildingNum-1)  cout << "####################" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
abc = list(map(int, input().split()))


ans = 0
while True:
    if abc[0] == abc[1] == abc[2]:
        print(ans)
        exit(0)

    if abc.count(max(abc)) >= 2:
        abc[abc.index(min(abc))] += 2
    else:
        if abc[0] != max(abc):
            abc[0] += 1
        if abc[1] != max(abc):
            abc[1] += 1
        if abc[2] != max(abc):
            abc[2] += 1
    ans += 1


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
#define ll long long
ll a[212345] = { 0 };
ll bol[212345] = { 0 };
ll c[212345] = { 0 };
int main() {
	ll n, k, i, t = 0, temp = 0, ans = 0, cnt = 1, j;
	cin >> n >> k;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}
	bol[cnt] = 1;
	for (i = 0; i < k; i++) {
		if (bol[cnt] == 1)c[cnt] = i;
		if (bol[cnt] == 2) {
			ans = i;
			break;
		}
		cnt = a[cnt];
		bol[cnt]++;
	}
	ans -= c[cnt];
	i += (k - i) / ans * ans;
	for (j = i; j < k; j++) {
		cnt = a[cnt];
	}
	cout << cnt;
}

Measured memory_bytes: 8316
# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,K = (int(i) for i in input().split())
p = list(map(int, input().split()))

expected_value =[(i+1)/2 for i in p] #各さいころの期待値

#隣接する数列の和
adjacent_sum =[0]*N
adjacent_sum[0] =sum(expected_value[:K])
ans =[0]*N
ans[0] =adjacent_sum[0]
for i in range(1,N-K+1):
    adjacent_sum[i] =adjacent_sum[i-1] -expected_value[i-1] +expected_value[i+K-1]
    ans[i] =adjacent_sum[i] 
print(max(ans))

Measured memory_bytes: 32640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	int ma = 0;
	bool yes = true;
	
	for(int i = 0; i < n; ++i) {
		int h;
		cin >> h;
		ma = max(ma, h);
		
		if( ma - 1 > h ) yes = false; 
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int maxn=10010;
const int Max=10000001;
int n;
int dis[maxn];
bool vis[maxn];

struct edge
{
	int u,v,w;
	edge(int u=0,int v=0,int w=Max):u(u),v(v),w(w){}
};
vector<edge> G[maxn];

struct node
{
	int d,id;
	bool operator < (const node& rhs) const
	{
		return d>rhs.d;
	}
	node(int d=0,int id=0):d(d),id(id){}
};
priority_queue<node> Q;

void dijkstra(int s)
{
	memset(dis,0x7f,sizeof(dis));
	memset(vis,0,sizeof(vis));
	dis[s]=0;
	Q.push(node(0,s));
	while(!Q.empty())
	{
		node u=Q.top();
		Q.pop();
		if(vis[u.id]) continue;
		vis[u.id]=1;
		for(unsigned int i=0;i<G[u.id].size();++i)
		{
			edge e=G[u.id][i];
			if(dis[e.v]>dis[u.id]+e.w)
			{
				dis[e.v]=dis[u.id]+e.w;
				Q.push(node(dis[e.v],e.v));
			}
		}
	}
}

void print()
{
	for(int i=0;i<n;++i)
	  printf("%d %d\n",i,dis[i]);
	return;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		int id,k;
		scanf("%d%d",&id,&k);
		for(int j=0;j<k;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[id].push_back(edge(id,v,w));
		}
	}
	dijkstra(0);
	print();
	return 0;
} 

Measured memory_bytes: 10168
_,*s=open(0)
t='.'
b=t*101
q=range(101)
i=0
for s in s:
 a=[i];i+=1
 for x,y,z,c in zip(b,t+s,s,q):a+=min(c+(x==t>z),a[-1]+(y==t>z)),
 b,q=s,a[1:]
print(a[-2])

Measured memory_bytes: 3064
data = []
tmp = []
ans = []

def pushAns(d):
    for j in range(2):
        ans.append((d[0][0],d[0][1]))
        d.pop(0)    

for i in range(24):
    a,b = (float(x) for x in input().split())
    tmp.append((a,b))
    if (i + 1) % 8 == 0:
        tmp.sort(key=lambda x:x[1])
        pushAns(tmp)
        data.extend(tmp)
        tmp.clear()
        
data.sort(key=lambda x:x[1])
pushAns(data)

for i in range(8):
    print(int(ans[i][0]),ans[i][1])


Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    ll x,k,d; cin>>x>>k>>d;
    if(d<=abs(x)/k || k<=abs(x)/d){
        cout<<abs(abs(x)-d*k)<<endl;
    }else{
        ll cnt=abs(x)/d;
        if((k-cnt)%2==0){
            cout<<abs(abs(x)-d*cnt)<<endl;
        }else{
            cout<<abs(abs(x)-d*(cnt+1))<<endl;
        }
    }
}

Measured memory_bytes: 3620
defmodule Main do
  def main do
    IO.gets("")
    |> String.trim()
    |> String.split()
    |> Enum.map(&String.to_integer/1)
    |> Enum.sort()
    |> case do
      [5, 5, 7] ->
        "YES"
      _ ->
        "NO"
    end
    |> IO.puts()
  end
end

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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    if(n%10 == 7 || (n/10)%10 == 7 || (n/100) == 7)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        long[] fib = new long[n + 1];
        fib[0] = 1;
        if (n != 0) fib[1] = 1;
        for (int i = 2; i < fib.Length; i++) fib[i] = fib[i - 2] + fib[i - 1];
        Console.WriteLine(fib.Last());
    }
}


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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> A(N);
  
  for (int i=0; i<M; i++) {
    int a,b;
    cin >> a >> b;
    A.at(a-1)++;
    A.at(b-1)++;
  }
  
  for (int i=0; i<N; i++) {
    cout << A.at(i) << endl;
  }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,m,nn,mm;
	cin>>n>>m;
	if(n==1||m==1)cout<<"1";
	else
	{
		if(n%2==0&&m%2==0)cout<<m*n/2;
		else if(n%2==1&&m%2==1)cout<<m*(n/2+1)-(m/2);
		else
		{
			if(n%2==0)
			{
				nn=m;
				mm=n;
			}
			else
			{
				nn=n;
				mm=m;
			}
			cout<<mm*(nn/2+1)-(mm/2);
		}
		
	}
}
 

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    }
}

Measured memory_bytes: 85068
#include <iostream>
#include <iomanip>
#include <limits>
#include <stdio.h>


using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
  int n, k;
  ld ans;
  cin >> n;
  rep(i,n) {
    cin >> k;
    ans += (ld)(1.0/k);
  }
  cout << setprecision(10) << (ld)(1.0/ans) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep2(x,from,to) for(long long x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
long long M;
long long subM;
long long now;
int main()
{
    long long n;
    string s;
    cin>>n;
    cin>>s;
    rep2(sld,1,n-1)
    {
        now=0;
        for(ll i=0;i+sld<n;i++)
        {
            if(s[i]==s[i+sld])
            {
                now++;
                M=max(M,min(now,sld) );
            }
            else now=0;
        }
    }
    cout<<M<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  rep(i, N) { cin >> A[i]; }
  rep(i, N) { cin >> B[i]; }

  int64_t largerA = 0;
  int64_t largerB = 0;
  rep(i, N) {
    if (B[i] < A[i]) {
      int64_t diff = A[i] - B[i];
      largerA += diff;
    } else {
      int64_t diff = B[i] - A[i];
      largerB += diff / 2;
    }
  }
  cout << ((largerB >= largerA) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin>>n;
    ll maxi = 1e5 + 1;
    ll counter[maxi];
    for(ll i=0; i<maxi; i++)
    {
        counter[i] = 0;
    }
    ll a[n];
    ll s = 0;
    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
        counter[a[i]]++;
        s+=a[i];
    }
    ll q;
    cin>>q;
    for(ll i=0; i<q; i++)
    {
        ll b, c;
        cin>>b>>c;
        if(counter[b]>0)
        {
            ll t = counter[b];
            counter[b] = 0;
            counter[c] += t;
            s = s + (c - b)*t;
            cout<<s<<'\n';
        }
        else
        {
            cout<<s<<'\n';
        }
        
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int sz, flag;
	string s, t;
	cin>> s >> t;

	sz=s.size();

	rep(i, sz){
		flag=1;
		rep(j, sz){
			if(s[(i+j)%sz]!=t[j]){
				flag=0;
				break;
			}
		}
		if(flag){
			cout<< "Yes" <<endl;
			return 0;
		}
	}

	cout<< "No" <<endl;
 
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i,N)cin >> h[i];
    ll dp[101000];
    REP(i,101000)dp[i] = LLONG_MAX;
    dp[0] = 0;
    REP(i,N){
        REP(l,K){
            dp[i+l+1] = min(dp[i+l+1],dp[i] + abs(h[i]-h[i+l+1]));
        }
    }
    cout <<dp[N-1]<< "\n";
}

Measured memory_bytes: 1408
N, A, B = map(int, input().split())

MOD = 10 ** 9 + 7

binary_map = [(1, 2)]

while binary_map[-1][0] < N:
    binary_map.append((binary_map[-1][0]*2, binary_map[-1][1]**2 % MOD))


def modinv(a):
    b = MOD
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        c = a
        a = b
        b = c

        u -= t * v
        c = u
        u = v
        v = c
    u %= MOD
    if u < 0:
        u += MOD
    return u


def get_exp(mul_num):
    ret = 1
    index = -1
    while mul_num > 0:
        while mul_num < binary_map[index][0]:
            index -= 1
        mul_num -= binary_map[index][0]
        ret = (ret * binary_map[index][1]) % MOD
    return ret


bouquet_max = get_exp(N)

P_table = [N] * B

for i in range(B - 1):
    P_table[i + 1] = (P_table[i] * (N - i - 1)) % MOD

modinvexp_table = [1] * B

for i in range(1, B):
    modinvexp_table[i] = modinvexp_table[i - 1] * modinv(i + 1) % MOD

remove_a = P_table[A - 1] * modinvexp_table[A - 1] % MOD
remove_b = P_table[B - 1] * modinvexp_table[B - 1] % MOD

print((bouquet_max - P_table[A - 1] * modinvexp_table[A - 1] - P_table[B - 1] * modinvexp_table[B - 1] - 1) % MOD)

Measured memory_bytes: 18848
n = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

#n = int(input())
#a,b = map(int,input().split())
a_L = list(map(int,input().split()))

a_L = list(sorted(a_L))
if a_L[0] == 0:
    print(0)
    exit()

ans = 1
for i in range(n):
    ans = ans*a_L[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 21636
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
int main()
{
	fast;
	int n;cin>>n;
	int k;cin>>k;
	int c=0;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		if(x>=k)c++;
	}
	cout<<c;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    ll ans = n;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i == 0){
            ans = min(ans, (i-1)+(n/i -1));
        }
    }
    cout << ans << endl;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    bool flag = true;
    FOR(i,1,n-1){
      if(s[i-1] == s[i+1])continue;
      else flag = false;
    }

    if(flag == true ){
      cout << "Second" << endl;
      return 0;
    }
    //cout << "hi" << "\n";
    if(((n-2) % 2 == 0) ^ (s[0] == s.back() ) ){
      cout << "Second" << "\n";
    }else{
      cout << "First" << "\n";
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  reverse(all(a));
  int al=0;
  int b=0;
  rep(i,n){
    if(i%2==0)al+=a[i];
    else b+=a[i];
  }
  cout<<al-b<<endl;
  
    
    
  return 0;
}


Measured memory_bytes: 3572
I = int(input())
A = input()
B = input()
C = input()

count = 0
for i in range(I):
  if not (A[i]==B[i]==C[i]):
    count += 1 if A[i]==B[i] or B[i]== C[i] or A[i]==C[i] else 2

print(count)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 1100000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

const int MAX_N=1<<17;

//セグメント木を持つグローバル配列
ll n,dat[2*MAX_N-1];

//初期化
void init(int n_){
    //簡単のために要素数を2のべき乗に
    n=1;
    while(n<n_) n*=2;

    //全ての値をINT_MAXに
    for(int i=0;i<2*n-1;i++) dat[i]=2000000000;
}

//k番目の値(0-indexed)をaに変更
void update(int k,ll a){
    //葉の節点
    k+=n-1;
    dat[k]=a;
    //登りながら更新
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
}

//[a,b)の最小値を求める
//後ろの方の引数は、計算の簡単のための引数
//ｋは接点の番号、l,rはその接点が[l,r)に対応づいていることを表す
//したがって、外からはquery(a,b,0,0,n)として呼ぶ
ll query(int a,int b,int k,int l,int r){
    //[a,b)と[l,r)が交差しなければ,INT_MAX
    if(r<=a || b<=l) return 2000000000;

    //[a,b)が[l,r)を完全に含んでいれば、この節点の値
    if(a<=l && r<=b) return dat[k];
    else{
        //そうでなければ、２つの子の最小値
        ll vl=query(a,b,k*2+1,l,(l+r)/2);
        ll vr=query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

int main(){
    int N;
    ll a[2100],x,ans=1000000000000000,temp=0;
    cin>>N>>x;
    init(N+2);
    for(int i=0;i<N;i++){
        cin>>a[i];
        update(i,a[i]);
    } 
    for(int i=0;i<N;i++,temp=0){
        for(int j=0;j<N;j++){
            if(j+i>=N) temp+=min(query(j,N,0,0,n),query(0,j+i+1-N,0,0,n));
            else temp+=query(j,j+i+1,0,0,n);
        }
        temp+=x*i;
        ans=min(ans,temp);
    }

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

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

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

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

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

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

fn main() {
    input!{
        h: usize,
        w: usize,
        k: usize
    }
    let m = 1000000007;
    let mut ans = k * (k - 1) % m * (k + 1) % m * stair_m(h + w - 2, m) % m * inv_m(3, m) % m * h % m * w % m;
    ans = (ans + k * (k + 3) / 2 % m * stair_m(h + w, m) % m) % m;
    ans = ans * inv_m(stair_m(h + w - k, m), m) % m;
    println!("{}", ans);
}

fn stair_m(n: usize, d: usize) -> usize {
    (1..n+1).fold(1, |ac, x| ac * x % d)
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

// only when d is prime
fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}


Measured memory_bytes: 4352
def Main(X):
    for i in range(-178, 178):
        for j in range(-178, 178):
            if i**5-j**5 == X:
                return i,j

def main():
    X = int(input())
    i, j = Main(X)
    print("{0} {1}".format(i, j))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9160
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> heights(n);
    for(int &height:heights)
        cin>>height;
    vector<int> dp(n,0);
    dp[n-2]=abs(heights[n-2]-heights[n-1]);
    for(int i=n-3;i>=0;--i){
        dp[i]=min(dp[i+1]+abs(heights[i+1]-heights[i]),dp[i+2]+abs(heights[i+2]-heights[i]));
    }
//    for(int i=0;i<n;++i){
//        cout<<dp[i]<<" ";
//    }
    cout<<dp[0];
    cout<<endl;
}


Measured memory_bytes: 3972
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int main() {
	int n, m; cin >> n >> m;
	int cnt[100000] = {};
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		cnt[a]++; cnt[b]++;
	}
	bool f = true;
	rep(i, n) {
		if (cnt[i] % 2)f = false;
	}
	if (f)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 640
n,m,L=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
q=int(input())
ql=[list(map(int,input().split())) for i in range(q)]
distance=[[10**18]*n for i in range(n)]
for i in range(m):
  if l[i][2]<=L:
    distance[l[i][0]-1][l[i][1]-1]=l[i][2]
    distance[l[i][1]-1][l[i][0]-1]=l[i][2]
for i in range(n):
  for j in range(n):
    for k in range(n):
      distance[j][k]=min(distance[j][k],distance[j][i]+distance[i][k])

distance2=[[10**18]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    if distance[i][j]<=L:
      distance2[i][j]=1
      distance2[j][i]=1
for i in range(n):
  for j in range(n):
    for k in range(n):
      distance2[j][k]=min(distance2[j][k],distance2[j][i]+distance2[i][k])

for i in range(q):
  if distance2[ql[i][0]-1][ql[i][1]-1]>=10**18:
    print(-1)
  else:
    print(distance2[ql[i][0]-1][ql[i][1]-1]-1)

Measured memory_bytes: 82520
#include <stdio.h>

int main(void)
{
  int stack[10];
  int stack_size = 0;
  int car;
  while(scanf("%d", &car) != EOF){
    if(car==0){
      printf("%d\n", stack[--stack_size]);
    }else{
      stack[stack_size++] = car;
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int a,b;
bool safe(int a)
{
	if(a>0&&a<10)return true;
	return false;
}
int main()
{
	cin>>a>>b;
	if(safe(a)&&safe(b))pf(a*b);
	else pf(-1);
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        var ans = 0
        for (i in 1..N) {
            if (i.toString().length % 2 != 0) {
                ans++
            }
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 34184
#include <iostream>
#include <algorithm>
#include <cstdio>
struct athlete{int num; double time;};

bool tsort(const athlete& l, const athlete& r){
	return l.time < r.time;
}

int main(){
	athlete a[3][8], f[3];
	for(int i=0;i<3;i++){
		for(int j=0;j<8;j++){
			int num;
			double time;
			std::cin >> num >> time;
			a[i][j].num = num, a[i][j].time = time;
		}
		std::sort(a[i],a[i]+8,tsort);

		//3ÊðÅIIlÉñ·D
		f[i] = a[i][2];
	}

	//egÌ1ÊÆ2Êð\¦
	for(int i=0;i<3;i++){
		printf("%d %.2lf\n",a[i][0].num,a[i][0].time);
		printf("%d %.2lf\n",a[i][1].num,a[i][1].time);
	}

	//egÌ3ÊæèãÊ2lðÖD
	std::sort(f,f+3,tsort);
	printf("%d %.2lf\n",f[0].num,f[0].time);
	printf("%d %.2lf\n",f[1].num,f[1].time);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c!=(a+1)%13)
	{
		cout<<0<<endl;
		return;
	}
	else
	{
		if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
		{
			if(b==31&&d==1)
			{
				cout<<1<<endl;
				return;
			}
		}
		else if(a==2)
		{
			if((b==28||b==29)&&(d==1)){
				cout<<1<<endl;
				return;
			}
		}
		else
		{
			if(b==30&&d==1)
			{
				cout<<1<<endl;
				return;
			}
		}
	}
	cout<<0<<endl;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

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

def nprf(m):
    pf = {}
    for i in range(2, m + 1):
        for j in range(2, i + 1):
            while i % j == 0:
                pf[j] = pf.get(j, 0) + 1
                i //= j
    return pf

def c(P, m):
    count = 0
    for i in P:
        if P[i] >= m - 1:
            count += 1
    return count   
    
P = nprf(n)

f75 = c(P, 75)
f253 = c(P, 25) * (c(P, 3) - 1)
f155 = c(P, 15) * (c(P, 5) - 1)
f553 = int(c(P, 5) * (c(P, 5) - 1) * (c(P, 3) - 2) * 0.5)

print(f75 + f253 + f155 + f553)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL bfs(int y, int x);

int h, w;
int mp[405][405];
bool visit[405][405];

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

    cin >> h >> w;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            char c;
            cin >> c;
            if(c == '#') mp[i][j] = 1;

        }
    }

    LL res = 0;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            if(visit[i][j]) continue;
            res += bfs(i, j);
            /*
            for(int k = 1; k <= h; ++k) {
                for(int l = 1; l <= w; ++l) {
                    if(visit[k][l]) cout << 1 << " ";
                    else cout << 0 << " ";

                }
                cout << endl;

            }
            cout << endl;
            */
        }
    }
    cout << res << endl;

    return 0;
}

LL bfs(int y, int x) {
    queue<P> q;
    q.push(MP(y, x));

    LL black, white;
    black = white = 0;
    while(!q.empty()) {
        P p = q.front();
        q.pop();

        for(int i = 0; i < 4; ++i) {
            int ny, nx;
            ny = p.F + dy[i];
            nx = p.S + dx[i];
            if(ny < 1 || ny > h || nx < 1 || nx > w) continue;
            if(visit[ny][nx]) continue;
            if(mp[p.F][p.S] == mp[ny][nx]) continue;
            q.push(MP(ny, nx));
            if(mp[ny][nx] == 0) ++black;
            else ++white;
            visit[ny][nx] = true;

        }
    }

    return black * white;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  ll x,y,z;
  cin>>x>>y>>z;
  ll a1,a2,b1,b2,c1,c2;
  a1=(z/2)*(x*y);
  a2=(x*y*z)-a1;
  b1=(x/2)*(y*z);
  b2=(x*y*z)-b1;
  c1=(y/2)*(x*z);
  c2=(x*y*z)-c1;
  cout<<min({abs(a1-a2),abs(b1-b2),abs(c1-c2)})<<endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

int gcd(int a, int b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

signed main() {
	int N, X;
	cin >> N >> X;

	vector<int> x(N);
	rep(i, N) cin >> x[i];
	x.push_back(X);

	sort(all(x));

	int ret = x[1] - x[0];
	rep(i, N) {
		ret = gcd(ret, x[i + 1] - x[i]);
	}

	cout << ret << endl;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())
dp=[1]*(n+1)
for i in range(m):
  dp[int(input())]=0
for i in range(2,n+1):
  if dp[i]>0:
    dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Measured memory_bytes: 470264
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n;


int calc(int x,int y,int z)
{
  return (x*x+y*y+z*z+x*y+y*z+z*x);
}

int main(){
  ll ans=0;
  cin >> n ;
  vi a(10001);
  //REP(i,n) cin>>a[i];
  ll nn=200;

  for(ll i=1;i<nn;i++){
    for(ll j=1;j<nn;j++){
      for(ll k=1;k<nn;k++){
        if (calc(i,j,k)<=10000){
          a[calc(i,j,k)]++;
        }
      }
    }
  }


  for(ll i=1;i<=n;i++){
    cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b; cin >> a >> b;
	int sum = 0;
	for(int i=0; i<b; i++)
	{
		int t; cin >> t;
		sum += t; 
	}
	int ans = a - sum;
	if(ans >= 0) cout << ans << '\n';
	else		 cout << -1 << '\n';
	return 0;
}

Measured memory_bytes: 3588
n,m = list(map(int, input().split()))
high=10**10
low=0
for i in range(m):
    a,b = list(map(int, input().split()))
    if a>low:
        low=a
    if b<high:
        high=b
if low>high:
    print(0)
else:
    print(high-low+1)

Measured memory_bytes: 3188
import heapq

N,M = map(int,input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A)

while M != 0:
    nim = heapq.heappop(A)
    heapq.heappush(A,-(-nim//2))
    M -= 1
    
print(-sum(A))

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

int main(){
    int n;cin>>n;
    vector<int> p(n);
    int cnt = 0;
    for(int i=0; i<n; i++){
        int p;cin>>p;
        if(i+1!=p)cnt++;
    }
    if(cnt<=2)cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp.to_s

t_1 = ''
t_2 = ''
for i in 0..n - 1 do
  if i < (n / 2)
    t_1 += s[i]
  else
    t_2 += s[i]
  end
end

if t_1 == t_2
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include <cstdio>
using namespace std;
const int maxn=1e5+10;
#define LL long long
LL n,ans;
LL a[maxn],b[maxn];
int main()
{
	LL j;
    scanf("%d",&n);
	for(int i=1;i<=n;i++)
            scanf("%lld%lld",&a[i],&b[i]);
	for(int i=n;i>=1;i--)
	{
		a[i] += ans;
		for(j=a[i]/b[i];;j++)
			if(j*b[i]>=a[i])
				break;
		LL comm = j*b[i] - a[i];
		ans += comm;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1664
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[0]*n
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])


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

using namespace std;
typedef long long int64;
const int kMaxN = 1e5+10;

int a[kMaxN * 3];

void solve() {
	int n;
	cin >> n;

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

	sort (a+1, a+3*n+1);

	int64 sum = 0;
	for (int i = 3*n-1, cnt = 1; cnt <= n; ++cnt, i -= 2) {
		sum += a[i];
	}

	cout << sum << "\n";
}

void reset() {

}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		solve();
		reset();
	}
}

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

int main(){
  ll k,x;
  cin >> k >> x;
  ll s = x-k+1;
  for(ll i=0;i<k*2-1;i++){
    cout << s+i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

bool ch[100010];ll ans[100010];
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<k;i++){
		ll x;
		cin>>x;
		ch[x]=true;
	}
	ans[0]=1;
	for(ll i=0;i<=n;i++){
		ans[i+2]+=ans[i];
		ans[i+1]+=ans[i];
//		cout << ans[2]<<endl;
		if(ch[i+2]==true){
			ans[i+2]=0;
		}
		if(ch[i+1]==true){
			ans[i+1]=0;
		}
		ans[i+2]%=inf;
		ans[i+1]%=inf;
	}
	cout << ans[n];
	// your code goes here
	return 0;
}

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

using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<ll> a(N);
    //vector<ll> hus(1000000005,0);
    map<string ,int> hus;
    rep(i,N){
        int b; cin >> b;
        a[i] = b;
        hus[to_string(b)]++;
        //hus[b]++;
    }
    int res = 0;
    rep(i,N) {
        if(hus[to_string(a[i])]==0)continue; //処理済み
        if(hus[to_string(a[i])]<a[i]){
            res += hus[to_string(a[i])]; //取り除く
            hus[to_string(a[i])] = 0; //空にする
        }else{
            while(hus[to_string(a[i])]!=a[i]){
                hus[to_string(a[i])]--; 
                res++;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 11520
def sign(x):
    if x > 0:
        return 1
    if x == 0:
        return 0
    
    return -1

def solve():
    move_x = ["", "R", "L"]
    move_y = ["", "U", "D"]
    
    sx, sy, tx, ty = list(map(int, input().split()))
    
    dx = tx - sx
    dy = ty - sy

    outward = ""
    homeward = ""
    
    outward = move_x[sign(dx)] * abs(dx) + move_y[sign(dy)] * abs(dy)
    homeward = move_x[-sign(dx)] * abs(dx) + move_y[-sign(dy)] * abs(dy)
    
    fir_route = outward + homeward
    sec_route = move_y[-sign(dy)] + move_x[sign(dx)] + outward + move_y[sign(dy)] + move_x[-sign(dx)] + move_y[sign(dy)] + move_x[-sign(dx)] + homeward + move_y[-sign(dy)] + move_x[sign(dx)]

    print(fir_route, end="")
    print(sec_route)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 210;

int n;
char s[N][N];
int d[N][N];
int vis[N];

void dfs(int u) {
  for (int v = 1; v <= n; ++v)
    if (s[u][v] == '1')
      if (!vis[v]) {
        vis[v] = -vis[u];
        dfs(v);
      } else if (vis[v] == vis[u]) {
        puts("-1");
        exit(0);
      }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%s", s[i] + 1);
  vis[1] = 1;
  dfs(1);
  for (int i = 1; i <= n; ++i)
    fill(d[i] + 1, d[i] + n + 1, n);
  for (int i = 1; i <= n; ++i)
    d[i][i] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (s[i][j] == '1')
        d[i][j] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k)
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans = max(ans, *max_element(d[i] + 1, d[i] + n + 1));
  printf("%d\n", ans + 1);
  return 0;
}

Measured memory_bytes: 4040