akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
struct card{
  ll val;
  char mark;
};
vector<card> ori;
vector<card> bubble;
vector<card> selec;
ll n;
void bubblesort(){
  for(int i=0;i<n;i++)
    for(int j=n-1;j>i;j--)
      if(bubble[j].val < bubble[j-1].val){
	card hog=bubble[j];
	bubble[j]=bubble[j-1];
	bubble[j-1]=hog;
      }
  return;
}
void selectionsort(){
  for(int i=0;i<n;i++){
    ll mi=i;
    for(int j=i;j<n;j++){
      if(selec[j].val < selec[mi].val){
	mi=j;
      }
    }
    card hog = selec[mi];
    selec[mi]=selec[i];
    selec[i]=hog;
  }
  return;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  ori.resize(n);
  bubble.resize(n);
  selec.resize(n);
  vector<vector<char>>oric(10);
  for(int i=0;i<n;i++){
    string s;cin>>s;
    ori[i].val=(ll)s[1]-'0';
    ori[i].mark=s[0];
    bubble[i]=selec[i]=ori[i];
    oric[s[1]-'0'].pb(s[0]);
  }
  bubblesort();
  selectionsort();
  vector<vector<char>>bub(10);
  vector<vector<char>>sel(10);
  bool bubfl=true;
  for(int i=0;i<n;i++){
    bub[bubble[i].val].pb(bubble[i].mark);
    sel[selec[i].val].pb(selec[i].mark);
  }
  for(int i=0;i<n;i++){
    cout<<bubble[i].mark<<bubble[i].val;
    if(i!=n-1)cout<<" ";
  }
  cout<<endl;
  for(int i=1;i<=9;i++){
    for(int j=0;j<oric[i].size();j++){
      if(oric[i][j]!=bub[i][j])bubfl=false;
    }
  }
  cout<<(bubfl?"Stable":"Not stable")<<endl;
  bool selfl=true;
  for(int i=0;i<n;i++){
    cout<<selec[i].mark<<selec[i].val;
    if(i!=n-1)cout<<" ";
  }
  cout<<endl;
  for(int i=1;i<=9;i++){
    for(int j=0;j<oric[i].size();j++){
      if(oric[i][j]!=sel[i][j])selfl=false;
    }
  }
  cout<<(selfl?"Stable":"Not stable")<<endl;
  return 0;
}



Measured memory_bytes: 3208
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;

char alp[11] = {'a','b','c','d','e','f','g','h','i','j','k'};

void dfs(string s){
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    set<char> se;
    int key = 0;
    rep(i,s.size()){
        se.insert(s[i]);
        chmax(key, s[i] - 'a');
    }
    for(auto p : se){
        dfs(s + p);
    }
    ++key;
    char next = 'a' + key;
    dfs(s + next);
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dfs("a");
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
int sv[1000000]={0};
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
void sve() {sv[0]=1;sv[1]=1;for(int i=2;i*i<=maxx;i++){if(!sv[i]){for(int j=2*i;j<=maxx;j+=i)sv[j]=1;}}}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
*/
using namespace std;
bool visited[200005];
int dp[200005];
int func(vector<int> graph[],int v)
{
    visited[v]=1;
    if(graph[v].size()==0)
    {
        return 0;
    }
    if(dp[v])
        return dp[v];
    int ans=0;
    for(int i=0;i<graph[v].size();i++){
        ans=max(func(graph, graph[v][i]),ans);
    }
    dp[v]=ans+1;
    return ans+1;
}

signed main(){
  //fast;
  //usefile;
  //test
  {
   // cout<<"hello"<<endl;
    int n,m;
    cin>>n>>m;
    vector<int> graph[200005];
    for (int i = 0; i < m; i++)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        graph[x].push_back(y);
    }
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        if(!visited[i])
        {
            ans=max(func(graph,i),ans);
        }
    }
    cout<<ans;        
  }
  //time("");
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int c1[26] = {0};
    string a[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    /**/
    for(int i = 0;i < n;i++){
        int c2[26] = {0};
        for(int j = 0;j < a[i].size();j++){
            int c = a[i].at(j) - 'a';
            c2[c]++;
        }
        if(i == 0){
            for(int i = 0;i < 26;i++){
                c1[i] = c2[i];
            }
        }
        else{
            for(int i = 0;i < 26;i++){
                c1[i] = min(c2[i],c1[i]);
            }
        }
    }
    /**/

    string ans;

    for(int i = 0;i < 26;i++){
        //cout << c1[i] << " ";
        if(c1[i] != 0){
            for(int j = 0;j < c1[i];j++){
                ans += i + 'a';
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n;cin>>n;
    ll m=0,r=0,c=0,a=0,h=0;
    rep(i,n){
        string s;cin>>s;
        if(s[0]=='M')m++;
        if(s[0]=='A')a++;
        if(s[0]=='R')r++;
        if(s[0]=='C')c++;
        if(s[0]=='H')h++;
    }
    ll ans = m*a*r;
    ans+=m*a*c;
    ans+=m*a*h;
    ans+=m*r*c;
    ans+=m*r*h;
    ans+=m*c*h;
    ans+=a*r*c;
    ans+=a*r*h;
    ans+=a*c*h;
    ans+=r*c*h;
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 100000;
const int MOD = 1000000007;

ll N;
ll A[MAX];

ll dp[MAX];

int solve() {
    ll a = 1, b = 0, c = 0;
    dp[0] = 3;
    if (A[0] != 0) return 0;
    FOR (i, 1, N) {
        ll count = (a == A[i]) +  (b == A[i]) +  (c == A[i]);
        dp[i] = dp[i-1] * count % MOD;
        if (a == A[i]) a++;
        else if (b == A[i]) b++;
        else c++;
    }
    return dp[N-1];
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 1792
h,w,a,b = map(int,input().split())

line = []
inv_line = []

for i in range(w):
    if i <= a-1:
        line.append(0)
        inv_line.append(1)
    else:
        line.append(1)
        inv_line.append(0)


for i in range(h):
    if i >= b:
        for j in range(w):
            print(line[j],end="")
        print('')
    else:
        for j in range(w):
            print(inv_line[j],end="")
        print('')


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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n+2);
    v.at(0) = 0, v.at(n+1) = 0;
    for(int i=1; i<=n; i++){
        cin >> v.at(i);
    }

    vector<int> sub(n+1);
    int sum = 0;
    for(int i=0; i<=n; i++){
        sub.at(i) = v.at(i+1) - v.at(i);
        sum += abs(sub.at(i));
    }

    for(int i=0; i<n; i++){       
        int ans = sum - abs(sub.at(i)) - abs(sub.at(i+1)) + abs(sub.at(i)+sub.at(i+1));
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2048
#import numpy as np
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

# each bildings'color is different.

ans = 1000000000 * 15 * 15
for x in range(2 ** N):
    bi = bin(x)[2::][::-1]
    bi = bi + ( "0" * (N - len(bi)) )
    higest = A[0]
    bilging = 1
    cost = 0
    for index , a in enumerate(A[1::]) :
        if bi[index+1] == "1" and a <= higest:
            diff = higest - a 
            cost += diff + 1
            higest = a + diff + 1
            bilging += 1
        
        if higest < a :
            bilging += 1
            higest = a
    if bilging >= K:
        ans = min(ans , cost)
print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a * b % 2 == 0) {
    cout << "Even" << endl;
  }
  // ここにプログラムを追記
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int x[10],y[10],n,use[10],a[10];
double ans;
void cal(){
	for (int i=1;i<n;i++){
		int t1=a[i],t2=a[i+1];
		ans=ans+sqrt((x[t1]-x[t2])*(x[t1]-x[t2])+(y[t1]-y[t2])*(y[t1]-y[t2]));
	}
}
void dfs(int x){
	if (x>n){
		cal();
		return;
	}
	for (int i=1;i<=n;i++){
		if(use[i]) continue;
		a[x]=i;
		use[i]=1;
		dfs(x+1);
		use[i]=0;
	}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	dfs(1);
	for (int i=1;i<=n;i++) ans=ans/i;
	printf("%.10lf",ans);
}

Measured memory_bytes: 256
n,m=map(int,input().split())
#l=[int(i) for i in input().split()]
d=[[] for i in range(n)]
ans=[]
for i in range(m):
    p,y=map(int,input().split())
    d[p-1].append((y,i))
for a,i in enumerate(d):
    i.sort()
    for b,j in enumerate(i):
        c=str(a+1)
        d=str(b+1)
        c="0"*(6-len(c))+c
        d="0"*(6-len(d))+d
        ans.append((j[1],c+d))
ans.sort()
for i in ans:
    print(i[1])


Measured memory_bytes: 40936
#include<iostream>

using namespace std;

int main()
{
	int n,i,j,ans,array[1000];
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		ans=0;
		for(i=0;i<n;i++)
			cin >> array[i];
		
		for(;n>1;)
		{
			for(i=0;i<n-1;i++)
			{
				if(array[i]>array[i+1])
				{
					int a;
					a=array[i];
					array[i]=array[i+1];
					array[i+1]=a;
					ans++;
				}
			}
			n--;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class ANovember30 {
    vector<int> DAYS = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public:
    void solve(std::istream &in, std::ostream &out) {
        int m1, d1, m2, d2;
        in >> m1 >> d1 >> m2 >> d2;
        --m1;
        bool res = d1 == DAYS[m1];
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    ANovember30 solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long int


int main()
{
    ll L, R;
    scanf("%lld %lld",&L,&R);
    ll min=(L*(L+1))%2019;
    for (ll i = L; i<=R; i++)
    {
        for (ll j = L; j<i; j++)
        {
          ll res = (i*j)%2019;

          if (res <= min) min = res;

          if (min==0)
          {
             printf("0");
             return 0;
          }

        }
    }

    printf("%lld",min);

    return 0;
}


Measured memory_bytes: 128
from itertools import groupby


def solve(s, k):
    rle = [len(list(g)) for c, g in groupby(s)]
    if len(rle) == 1:
        return len(s) * k // 2
    ans = sum(l // 2 for l in rle) * k
    if s[0] == s[-1] and rle[0] % 2 == 1 and rle[-1] % 2 == 1:
        ans += k - 1
    return ans


s = input()
k = int(input())
print(solve(s, k))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   list<char> s;
   string x;
   cin>>x;

   for(auto ele : x)
   	s.push_back(ele);

   long int t;
   cin>>t;

   long int check = 0;
   while(t--){

   	 long int type;
   	 cin>>type;


   	 if(type == 1)
   	 	check = 1 - check;
   	 else{
   	 	long int f;
   	 	char c;
   	 	cin>>f>>c;

   	 	if(check)
   	 		f = 3 - f;

   	 	if(f == 2)
   	 		s.push_back(c);
   	 	else
   	 		s.push_front(c);
   	 }
	}

   if(check == 1)
   	reverse(s.begin(),s.end());

   for(auto ele : s)
   	cout<<ele;

   return 0;
}

Measured memory_bytes: 10064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m,k;
   cin>>n;
   vector<ll> V(n,0);
   for(int i=0;i<n;i++){
   	cin>>V[i];
   }
   sort(all(V));
   ll res=0;
   res+=V[n-1];
   int right=n-2;
   int left=n-2;
   while(right>0){
   	   res+=V[left];
   	   right--;
   	   if(right>0){
   	   	res+=V[left];
		}
		right--;
		left-=1;
   }

   cout<<res<<endl;
}


Measured memory_bytes: 4780
program main
	implicit none
    integer::n,m,i
    integer(8),allocatable::t(:),p(:),x(:),ans(:)
    integer(8)::a,b,sum1
    read(*,*) n
    allocate(t(n))
    read(*,*) t
    read(*,*) m
    allocate(p(m), x(m), ans(m))
    do i=1,m
    	read(*,*) a,b
        p(i)=a
        x(i)=b
    end do
    ans=sum(t)
    
    do i=1,m
    	ans(i)=ans(i)-(t(p(i))-x(i))
    end do
    
    do i=1,m
    	write(*,*) ans(i)
    end do
    deallocate(t,p,x,ans)
    stop
end program main
    
        



Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	deque<int> dq;
	rep(i,n){
		if(i%2==0) dq.push_back(a[i]);
		else dq.push_front(a[i]);
	}
	if(n%2==1) reverse(dq.begin(),dq.end());
	rep(i,n-1) cout << dq[i] << " ";
	cout << dq[n-1] << endl;

	return 0;
}

Measured memory_bytes: 3840
#参考URL:http://lethe2211.hatenablog.com/entry/2014/12/30/011030
import heapq
n,m,s,t=map(int,input().split())
s-=1
t-=1
Gyen=[dict() for i in range(n)]
Gsnu=[dict() for i in range(n)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    u-=1
    v-=1
    Gyen[u][v]=a
    Gyen[v][u]=a
    Gsnu[u][v]=b
    Gsnu[v][u]=b
def dijkstra(adj, start):
    num = n          # グラフのノード数
    dist = [10**15 for i in range(num)] # 始点から各頂点までの最短距離を格納する
   
    dist[start] = 0
    q = []                  # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
    heapq.heappush(q, (0, start)) # 始点をpush
    while (len(q) != 0):
        prov_cost, src = heapq.heappop(q) # pop
        # プライオリティキューに格納されている最短距離が，現在計算できている最短距離より大きければ，distの更新をする必要はない
        if dist[src] < prov_cost:
            continue
        # 他の頂点の探索
        for dest in adj[src]:
            cost = adj[src][dest]
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost # distの更新
                heapq.heappush(q, (dist[dest], dest)) # キューに新たな仮の距離の情報をpush                  
    return dist
CostYen=dijkstra(Gyen,s)
CostSnu=dijkstra(Gsnu,t)
Cost=[0 for i in range(n)]
for i in range(n):
    Cost[i]=CostYen[i]+CostSnu[i]
ans=[0 for i in range(n)]
ans[-1]=Cost[-1]
for i in list(range(n-1))[::-1]:
    ans[i]=min(ans[i+1],Cost[i])
for i in range(n):
    print(10**15-ans[i])


Measured memory_bytes: 128412
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

A = {}
for _ in range(N):
    a = input()
    A[a] = A.get(a, 0) + 1

M = int(input())
B = {}
for _ in range(M):
    b = input()
    B[b] = B.get(b, 0) + 1

ans = 0
for k, v in A.items():
    ans = max(ans, v - B.get(k, 0))

print(ans)

Measured memory_bytes: 9628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

    // auto mod int
    // https://youtu.be/L8grWxBlIZ4?t=9858
    // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
    // https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint dp[61][2][2][2];

int main() {
  ll l, r;
  cin >> l >> r;
  dp[60][0][0][0] = 1;
  for (int i = 59; i >= 0; i--) {
    int lb = l>>i&1;
    int rb = r>>i&1;
    rep(j,2)rep(k,2)rep(s,2) { // mae no joutai
      mint pre = dp[i+1][j][k][s];
      rep(x,2)rep(y,2) { // senni
        if (x && !y) continue; // x = 1, y = 0
        int nj = j, nk = k, ns = s; // next no joutai
        // tsugi dou naru?
        if (!s && x != y) continue;
        if (x && y) ns = 1;
        // j: L <= X
        if (!j && !x && lb) continue;
        if (x && !lb) nj = 1;
        // k: Y <= R
        if (!k && y && !rb) continue;
        if (!y && rb) nk = 1;
        //
        dp[i][nj][nk][ns] += pre;
      }
    }
  }
  mint ans;
  rep(j,2)rep(k,2)rep(s,2) ans += dp[0][j][k][s];
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX_N 200000
int par[MAX_N];
int rank[MAX_N];
int original_par[MAX_N];
int query_list[MAX_N][2];


void init(int n){
  int i;
  for(i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else {
    return par[x] = find(par[x]);
  }
}
void unite(int x,int y){
  x =find(x);
  y =find(y);
  if(x==y){
    return ;
  }
  par[y] = x;
  /*
  if(rank[x] < rank[y]){
    par[x] = y;
  }else {
    par[y] = x;
    if(rank[x] == rank[y])rank[x]++;
  }
  */
}
int same(int x,int y){
  return find(x)==find(y);
}
int main(){
  int N,Q;
  long long int ans;
  int i,j,k;
  int marked_list[MAX_N];
//??¨??¨????????§?????????????????§1?????¬???
  while(1){
    scanf("%d %d",&N,&Q);
    if(N==0&&Q==0)break;
    memset(marked_list,0,sizeof(int)*N);
    //for(i=0;i<N;i++){ marked_list[i]=0; }
    marked_list[0]=1;
    original_par[0]=0;
    ans=0;

    for(i=1;i<N;i++){
      scanf("%d\n",&original_par[i]);
      original_par[i]--;
    }
    for(i=0;i<Q;i++){
      char bc;
      scanf("%c %d\n",&bc,&query_list[i][1]);
      query_list[i][0] = bc;
      query_list[i][1]--;
    }

    init(N);
    for(i=0;i<Q;i++){
      if(query_list[i][0]=='M'){
        if(marked_list[query_list[i][1]]==1){
          query_list[i][0]='N';
        }
        marked_list[query_list[i][1]]=1;
      }
    }
    for(i=0;i<N;i++){
      if(0==marked_list[i]){
        unite(original_par[i],i);
      }
    }
    for(i=Q-1;i>=0;i--){
      if(query_list[i][0]=='Q'){
        int q_a = find(query_list[i][1])+1;
        ans += q_a;
      //  printf(":%d\n",ans);
      }else if(query_list[i][0]=='M'){
        int m = query_list[i][1];
        unite(original_par[m],m);
      }
    }
    printf("%lld\n",ans);
  }
  return 0;

}

Measured memory_bytes: 4924
def ru(n):
  if n % 10 ==0:
    return n
  else:
    return ((n//10)+1)*10
li1=[int(input()) for i in range(5)]
li2=[ru(li1[i]) for i in range(5)]
sub= [x - y for (x, y) in zip(li2, li1)]
print(sum(li2)-max(sub))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll n;
    cin >> n;
    vector<ll> sticks(n,0);
    for(ll i = 0;i < n;++i){
        cin >> sticks[i];
    }

    ll result = 0;
    for(ll i = 0;i < n;++i){
        for(ll j = i + 1;j < n;++j){
            for(ll k = j + 1;k < n;++k){
                if((sticks[i] == sticks[j]) || (sticks[i] == sticks[k]) || (sticks[j] == sticks[k]))continue;
                if((sticks[i] + sticks[j] > sticks[k]) && (sticks[i] + sticks[k] > sticks[j]) && (sticks[j] + sticks[k] > sticks[i])){
                    ++result;
                   // cout << sticks[i] << ":" << sticks[j] << ":" << sticks[k] << endl;
                }
            }
        }
    }

    cout << result << endl;
}




Measured memory_bytes: 3196
N=gets.to_i
h=gets.split(" ").map(&:to_i)
cnt=0
for i in 1..100
	if h[0]>=i
		cnt+=1
	end
	for j in 1..N-1
		if h[j-1]<i&&h[j]>=i
			cnt+=1
		end
	end
end
puts cnt

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i = 0; i < (n); ++i)
ll x[100010], v[100010];
ll cw_ccwf[100010];
ll cw_cwf[100010];
ll ccw_cwf[100010];
ll ccw_ccwf[100010];
int main() {
    ll n, c;
    cin >> n >> c;
    rep(i, n) cin >> x[i] >> v[i];
    ll vtl=0;
    ll vtr=0;
    ll ans=-1e18;
    rep(i, n) {
        vtl += v[i];
        vtr += v[n-i-1];
        cw_ccwf[i+1]    = max(cw_ccwf[i], vtl-x[i]);
        cw_cwf[i+1]     = max(cw_cwf[i], vtl-x[i]*2);
        ccw_cwf[n-i-1]  = max(ccw_cwf[n-i], vtr-(c-x[n-i-1]));
        ccw_ccwf[n-i-1] = max(ccw_ccwf[n-i], vtr-(c-x[n-i-1])*2);
    }
    rep(i, n+1) ans = max(ans, max(cw_ccwf[i]+ccw_ccwf[i], cw_cwf[i]+ccw_cwf[i]));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iostream>
using namespace  std;
const int N=1E5+5;

int main() {
int n;
cin>>n;
long long  finall=0;
int res=n/500;
finall=1000*res;
int res2=n%500;
finall+=(res2/5)*5;
cout<<finall;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

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

	map<ll, int> mp;

	mp.insert(make_pair(0, 1));

	ll sum = 0;

	for (int i = 0; i < N; i++) {
		sum += A[i];
		auto itr = mp.find(sum);
		if (itr == mp.end()) {
			mp.insert(make_pair(sum, 1));
		}
		else {
			itr->second++;
		}
	}

	ll count = 0;
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		ll n = itr->second;

		count += (n * (n - 1)) / 2;
	}

	cout << count << endl;

	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

void compress(vl &i2x, map<ll,ll> &x2i) {
	sort(all(i2x));
	i2x.erase(unique(all(i2x)), end(i2x));
	FOR(i,0,sz(i2x)) x2i[i2x[i]] = i;
}

const ll N = 3010;
bool wallns[N][N], wallew[N][N], reach[N][N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll m, n;
	cin >> m >> n;

	vl i2x = {-oo,oo}, j2y = {-oo,oo};

	vector<tuple<ll,ll,ll>> ns, ew;
	while (m--) {
		ll a, b, c;
		cin >> a >> b >> c;
		i2x.pb(a), i2x.pb(b), j2y.pb(c);
		ns.pb(make_tuple(a,b,c));
	}
	while (n--) {
		ll d, e, f;
		cin >> d >> e >> f;
		i2x.pb(d), j2y.pb(e), j2y.pb(f);
		ew.pb(make_tuple(d,e,f));
	}

	map<ll,ll> x2i, y2j;
	compress(i2x,x2i), compress(j2y,y2j);

	for (auto tpl: ns) {
		ll a, b, c;
		tie(a,b,c) = tpl;
		a = x2i[a], b = x2i[b], c = y2j[c];
		FOR(i,a,b) wallns[i][c-1] = 1; //, cerr << "NS " << i << " " << c-1 << endl;
	}
	for (auto tpl: ew) {
		ll d, e, f;
		tie(d,e,f) = tpl;
		d = x2i[d], e = y2j[e], f = y2j[f];
		FOR(j,e,f) wallew[d-1][j] = 1; //, cerr << "EW " << d-1 << " " << j << endl;
	}
	
	queue<pll> q;

	FOR(i,0,sz(i2x)-1) if (i2x[i] <= 0 && i2x[i+1] >= 0) {
		FOR(j,0,sz(j2y)-1) if (j2y[j] <= 0 && j2y[j+1] >= 0) {
			q.emplace(i,j), reach[i][j] = 1;
		}
	}
	
	while (sz(q)) {
		ll i, j;
		tie(i,j) = q.front();
		q.pop();
//		cerr << i << " " << j << endl;

		if (i > 0 && !wallew[i-1][j] && !reach[i-1][j]) {
			q.emplace(i-1,j), reach[i-1][j] = 1;
		}
		if (j > 0 && !wallns[i][j-1] && !reach[i][j-1]) {
			q.emplace(i,j-1), reach[i][j-1] = 1;
		}
		if (i+2 < sz(i2x) && !wallew[i][j] && !reach[i+1][j]) {
			q.emplace(i+1,j), reach[i+1][j] = 1;
		}
		if (j+2 < sz(j2y) && !wallns[i][j] && !reach[i][j+1]) {
			q.emplace(i,j+1), reach[i][j+1] = 1;
		}
	}
	
	ll res = 0;
	FOR(i,0,sz(i2x)-1) FOR(j,0,sz(j2y)-1) if (reach[i][j]) {
		if (i == 0 || j == 0 || i == sz(i2x)-2 || j == sz(j2y)-2) {
			cout << "INF" << endl;
			return 0;
		}
		res += (i2x[i+1]-i2x[i]) * (j2y[j+1]-j2y[j]);
	}
	cout << res << endl;
}



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

int main()
{
 string s;
 cin >> s;
  int c=0,n;
  n=s.length();
  for(int i=0;i<n/2;i++)
    if(s[i]!=s[n-1-i])
      	c++;
  cout << c;
	return 0;
}

Measured memory_bytes: 256
ABCD = list(input())

for bit in range(1 << 3):
    SUM = int(ABCD[0])
    for i in range(3):
        if (bit >> i) & 1:
            SUM += int(ABCD[i + 1])
        else:
            SUM -= int(ABCD[i + 1])
    if SUM != 7: continue
    ans = ABCD[0]
    for i in range(3):
        ans += "+" if (bit >> i) & 1 else "-"
        ans += ABCD[i + 1]
    print(ans + "=7")
    exit()

Measured memory_bytes: 3064
import queue
h, w = map(int, input().split())
m = []
for i in range(h):
  m.append(input())
#print(h, w)
#print(m)
q = queue.Queue()
a = []
def init():
  global a
  a = []
  for i in range(h):
    a.append([-1] * w)

def bfs(cx, cy):
  nxs = [1, 0, -1, 0]
  nys = [0, -1, 0, 1]
  for i in range(4):
    nx = cx + nxs[i]
    ny = cy + nys[i]
    if 0 <= nx and nx < w and 0 <= ny and ny < h and m[ny][nx] == '.' and a[ny][nx] == -1:
      a[ny][nx] = a[cy][cx] + 1
      q.put([nx, ny])
  
def check(start_x, start_y):
  if m[start_y][start_x] == '#':
    return 0
  
  global a, q
  init()
  q.put([start_x, start_y])
  a[start_y][start_x] = 0
  end_x = -1
  end_y = -1
  while not q.empty():
    cx, cy = q.get()
    bfs(cx, cy)
    end_x = cx
    end_y = cy
  return a[end_y][end_x]

ans = 0
for i in range(h * w - 1):
    start_x = i % w
    start_y = i // w
    ans = max(ans, check(start_x, start_y))
    
print(ans)

Measured memory_bytes: 79284
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
   priority_queue<pair<long long ,long long>>q;
   long long n,m,i,j,b,c,x;
   long long ans=0;
   cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>x;
       q.push({x,1});
   }
   for(i=0;i<m;i++)
   {
       cin>>b>>c;
       q.push({c,b});
   }
   while(n>0)
   {
       auto p=q.top();
        q.pop();
        ans+=p.first*min(n,p.second);
        n-=p.second;
   }
   cout<<ans<<"\n";
   
    return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
int n, m, low[N], dep[N], cur = 0, id[N], indeg[N], par[N];
vector<int> g[N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	fw (i, 0, n - 1 + m) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		indeg[v]++;
	}
	int root = -1;
	memset(par, -1, sizeof par);
	fw (i, 0, n) if (!indeg[i]) root = i;
	queue<int> q;
	q.push(root);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		fa (v, g[u]) {
			if (indeg[v] == 1) {
				par[v] = u;
				q.push(v);
			} else indeg[v]--;
		}
	}
	fw (i, 0, n) cout << par[i] + 1 << "\n";
	return 0;
}


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

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

    int n;
    cin >> n;
    vector<pair<int, int>> as;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        as.emplace_back(a, b);
    }
    sort(as.begin(), as.end(), [](auto &a, auto &b) {
        return a.second < b.second;
    });
    long long acc = 0;
    for (int i = 0; i < n; i++) {
        acc += as[i].first;
        if (acc > as[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3444
#include <iostream>
#include <map>
using namespace std;
map<string,bool> m;
int main(){
	int n;
	string tmp,s;
	cin>>n;
	cin>>s;
	tmp=s;
	m[s]=1;
	bool flag=true;
	for (int i=1;i<n;i++){
		cin>>s;
		if (m[s] || s[0]!=tmp[tmp.size()-1]){
			cout<<"No";
			flag=false;
			break;
		}
		m[s]=1;
		tmp=s;
	}
	if (flag)	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define ll long long int
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve(int t)
{
    int a,k,i,j,n,mx=0,ct=0,sum=0;
    cin >> n;
    int L[n+5];
    for(i=0; i<n; i++)
        cin >> L[i];
    sort(L,L+n);
    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n; j++)
        {
            if(L[i]==L[j]) continue;
            for(k=j+1; k<n; k++)
            {
                if(L[j]==L[k]) continue;
                if((L[i]+L[j])>L[k])
                    ct++;
            }
        }
    }
    cout <<ct<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
  //  cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}



Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  ll x, a, b;
  cin >>  x >> a >> b;
  if(abs(x-a) < abs(x-b)) cout << 'A' << endl;
  else cout << 'B' << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int limit = 100010;
using edge = struct {int to; ll cost;};

vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
  depth[v] = d;
  for (auto &e : tree[v]) {
    if (e.to == p) {
      continue;
    }
    dfs(e.to, v, d + e.cost);
  }
}

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

  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    tree[a].push_back({b, c});
    tree[b].push_back({a, c});
  }

  int q, k;
  cin >> q >> k;
  k--;

  dfs(k, -1, 0);

  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << depth[x] + depth[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 14336
n,a,b,c,d=input().split()
n=int(n)
a=int(a)
b=int(b)
c=int(c)
d=int(d)
pricea=((n+a-1)//a)*b
pricec=((n+c-1)//c)*d
if pricea>pricec:
    print(pricec)
else:
    print(pricea)


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    int N; cin >> N;
    vi T(N); REP(i, N) cin >> T[i];
    int M; cin >> M;
    vi P(M), X(M);
    REP(i, M) cin >> P[i] >> X[i], P[i]--;

    int sum = accumulate(ALL(T), 0);
    REP(i, M)
    {
        cout << sum - T[P[i]] + X[i] << endl;
    }
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, k; cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
    
    int ans = -1;
    while(true) {
        string N = to_string(n);
        bool flag = true;
        rep(i, k) {
            if(count(N.begin(), N.end(), d[i]+'0')) {
                n++;
                flag = false;
                break;
            }
        }
        if(flag) break;
    }
    cout << n << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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 h, w;
    cin >> h >> w;
    string s[h];
    int dx[4] = { 0, 0, 1, -1 }, dy[4] = { 1, -1, 0, 0 };
    for (int i = 0; i < h; i++) cin >> s[i];
    bool flag = true;
    for (int cx = 0; cx < h; cx++) {
        for (int cy = 0; cy < w; cy++) {
            if (s[cx][cy] != '#') continue;
            bool small_flag = false;
            for (int i = 0; i < 4; i++) {
                int nx = cx + dx[i], ny = cy + dy[i];
                if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '#') small_flag = true;
            }
            if (!small_flag) {
                flag = false;
                break;
            }
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))
H, W = inpl()
s = ['.'*(W+2)]
for i in range(H):
    s.append('.'+input()+'.')
s.append('.'*(W+2))

end = 0
dxy = [[1,0],[0,1],[-1,0],[0,-1]]
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == '#':
            for k in dxy:
                if s[i+k[0]][j+k[1]]=='#':
                    break
            else:
                end = 1
                break
    if end == 1:
        break
if end == 1:
    print('No')
else:
    print('Yes')

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N, M;
  std::priority_queue<ll> q;

  std::cin >> N >> M;
  rep(i, N) {
    ll A;
    std::cin >> A;
    q.push(A);
  }

  while(M > 0) {
    ll a = q.top(); q.pop();
    a /= 2;
    q.push(a);
    --M;
  }

  ll ans = 0;
  while(! q.empty()) {
    ans += q.top(); q.pop();
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

string in[100];

int main() {
  int m;
  while(cin >> m) {
    map<string, pii> mp;
    REP(i,m) {
      string name;
      cin >> name;
      int a, b;
      cin >> a >> b;
      mp[name] = pii(a,b);
    }
    int n;
    cin >> n;
    REP(i,n)cin >> in[i];
    stack<set<int> > stk;
    int mod = 256;
    REP(i,n) {
      string s = in[i];
      if (mp.count(s)) {
        pii p = mp[s];
        set<int> se;
        for (int j=p.first; j<=p.second; ++j) {
          se.insert(j);
        }
        stk.push(se);
      } else if (s.size() == 1 && !isdigit(s[0])) {
        assert(stk.size());
        set<int> b = stk.top();
        stk.pop();
        assert(stk.size());
        set<int> a = stk.top();
        stk.pop();
        set<int> se;
        FOR(it, a) {
          FOR(jt, b) {
            if (s=="+") se.insert((*it + *jt)%mod);
            else if (s=="-") se.insert((*it - *jt + mod)%mod);
            else if (s=="*") se.insert((*it * *jt) %mod);
            else {
              if (*jt == 0) goto error;
              se.insert(*it / *jt % mod);
            }
          }
        }
        stk.push(se);
      } else {
        set<int> se;
        se.insert((atoi(s.c_str()) % mod + mod) % mod);
        stk.push(se);
      }
      //FOR(it, stk.top()) cout << *it << " ";cout << endl;
    }
    puts("correct");
    continue;
  error:
    puts("error");
  }
}

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

int main() {
  string N;
  cin >> N;
  if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) {
  	cout << "Yes" << endl;
  } else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)) {
  	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}


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

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

    vector<long> l(87);
    l.at(0) = 2;
    l.at(1) = 1;
    for (int i = 2; i <= n; i++) {
        l.at(i) = l.at(i - 1) + l.at(i - 2);
    }

    cout << l.at(n) << endl; 
}

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

int ary[12];
int tmp[12];

int sumup(int k,int n) {
  int res = 0;
  int tar = ary[k];
  for(int i=0; i<n; ++i)
    if(ary[i] == tar) res++;
  return res;
}
int main() {
  int n,t;
  while(cin>>n, n) {
    for(int i=0; i<n; ++i) {
      cin>>t;
      ary[i] = t;
    }

    int count = 0;
    while(1) {
      for(int i=0; i<n; ++i)
	tmp[i] = sumup(i,n);

      count++;
      for(int i=0; i<n; ++i) {
	if(ary[i] != tmp[i]) goto NEXT;
      }

      cout<<count-1<<endl;
      for(int i=0; i<n-1; ++i)
	cout<<ary[i]<<" ";
      cout<<ary[n-1]<<endl;
      break;
    NEXT:
      for(int i=0; i<n; ++i)
	ary[i] = tmp[i];
    }
  }
}

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

int main() {
    long N, M;
    cin >> N >> M;
    long ans;
    vector<long> a(M);
    rep(i,M){
        cin >> a.at(i);
    }
    long sum = accumulate(a.begin(), a.end() , 0L);
    ans = N - sum;
    if(ans >= 0) cout << ans << endl;
    else cout << "-1" << endl;
}


Measured memory_bytes: 3676
n = int(input())
a = list(map(int, input().split()))
q = int(input())
total = sum(a)
dct = {}
for i in range(n):
    if a[i] in dct:
        dct[a[i]] += 1
    else:
        dct[a[i]] = 1

for i in range(q):
    b, c = map(int, input().split())
    if b not in dct: dct[b] = 0
    if c not in dct: dct[c] = 0
    total += dct[b] * (c - b)
    print(total)
    
    dct[c] += dct[b]
    dct[b] = 0

Measured memory_bytes: 23688
#include<iostream>

using namespace std;

int main() {

	int A, B, C;
	cin >> A >> B >> C;
	int a=0, b=0, c=0;
	if (A == B)c++;
	if (A == C)b++;
	if (B == C)a++;
	if (a) {
		cout << A << endl;
	}else if (b) {
		cout << B << endl;
	}
	else {
		cout << C << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final Map<String, Integer> counter = new HashMap<>();
        for (int i = 0; i < n; i++) {
            final String word = in.next();
            counter.compute(word, (key, count) -> {
                if (count == null) {
                    count = 0;
                }
                count += 1;
                return count;
            });
        }

        final Comparator<Map.Entry<String, Integer>> comparing = Comparator.comparing(Map.Entry::getValue);
        List<Map.Entry<String, Integer>> result = counter.entrySet().stream()
                .sorted(Comparator.comparingInt((ToIntFunction<Map.Entry<String, Integer>>) Map.Entry::getValue)
                        .reversed()
                        .thenComparing(Map.Entry::getKey)).collect(Collectors.toList());
        final Integer count = result.get(0).getValue();
        for (int i = 0; i < result.size(); i++) {
            final Map.Entry<String, Integer> entry = result.get(i);
            if (entry.getValue().equals(count)) {
                System.out.println(entry.getKey());
            } else {
                break;
            }
        }
    }
}


Measured memory_bytes: 92336
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>

typedef long long int64;

int main(void) {
  int h, a;
  std::cin >> h >> a;
  int ans = h / a;
  if (h % a) ans++;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pa pair<int,int>
const int N=1e6+10; 
const int mod=998244353;
using namespace std;


vector<int> v[N];
int d[N],s,ans;
void dfs(int x,int fa)
{
    d[x]=d[fa]+1;
    if(d[x]>ans) ans=d[x],s=x;
    for(auto e:v[x]) if(e!=fa) dfs(e,x);
}
int main()
{
    int n; cin>>n;
    for(int i=1,x,y;i<n;++i) cin>>x>>y,v[x].pb(y),v[y].pb(x);
    dfs(1,0);
    dfs(s,0);
    puts(ans%3==2?"Second":"First");
return 0;
}
/*
*/

Measured memory_bytes: 41984
#include<bits/stdc++.h>
#define register rg
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
typedef long long ll;
int a[101][101];
int main() {
	//file("a");
	int n,m,l,ans=0,N;
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		cin>>N;
		while(N--)
			cin>>l,a[i][l]=1;
	}
	for(int i=1; i<=m; i++) {
		int flag=0;
		for(int j=1; j<=n; j++)
			if(!a[j][i])
				flag=1;
		if(!flag)
			ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256