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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<pll> v(N);
    REP(i, N) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end(), [](pll a, pll b) { return a.first < b.first; });

    REP(i, N) {
        K -= v[i].second;
        if (K <= 0) {
            cout << v[i].first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
long long mod = 1e9 + 7;
const int N = 3e5 + 500;

long long n, m, u, v, k, t, q, a, h;

string str;

long double prob[N];

int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   
   cin >> n >> k;
   
   for (int i = 1; i <= n; ++i) {
      prob[i] = (1.0 / (long double)n);
   }
   
   for (int i = 1; i <= k - 1; ++i) {
      prob[0] += 0.5 * prob[i];
      prob[2 * i] += 0.5 * prob[i];
      prob[i] = 0;
   }
   
   long double sol = 0.0;
   
   for (int i = k; i <= max(2 * k, n); ++i) {
      sol += prob[i];
   }
   
   cout << fixed << setprecision(10) << sol << endl;
   
   //cout << fixed << setprecision(9) << prob[0] << endl;
}






Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)INT_MAX)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}

struct segTree{
	vi val;
	int N;
	segTree(int n){
		N=1;
		while(N<n)N*=2;
		val.resize(N*2);
		fill(all(val),0);
	}
	
	void add(int k, int a){
		k+=N;
		val[k]+=a;
		while(k){
			k/=2;
			val[k]=val[k*2]+val[k*2+1];
		}
	}
	int sum(int a, int b){return sum(a,b,1,0,N);}
	int sum(int a, int b, int k, int l, int r){
		if(r<=a or l>=b) return 0;
		if(a<=l and r<=b) return val[k];
		int m=(l+r)/2;
		return sum(a,b,k*2,l,m)+sum(a,b,k*2+1,m,r);
	}	
};


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,q;
	while(cin>>n>>q){
		segTree st(100000);
		rep(_,q){
			int c,x,y;
			cin>>c>>x>>y;
			if(c==0) st.add(x,y);
			else cout<<st.sum(x,y+1)<<endl;
		}
	}
	return 0;
}
 



Measured memory_bytes: 3892
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n,m,k=MI()
a=[0]+LI()
b=[0]+LI()
for i in range(1,n+1):
  a[i]+=a[i-1]
for i in range(1,m+1):
  b[i]+=b[i-1]
ans=0
j=m
for i in range(n+1):
  if a[i]>k:
    continue
  while a[i]+b[j]>k:
    j-=1
  ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 119700
#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;



signed main(){
#ifdef LOCAL
	freopen("B_input.txt", "r", stdin);
	//freopen("B_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, v, p;
	cin >> n >> m >> v >> p;
	vector <int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector <int> sum(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		sum[i] = sum[i - 1] + a[i - 1];
	}
	int res = 0;
	for (int l = 0, r; l < n; l = r + 1) {
		r = l + 1;
		while (r < n && a[r] == a[l]) {
			r++;
		}
		r--;
		int pos = upper_bound(a.begin(), a.end(), a[l] + m) - a.begin();
		if (n - pos > p - 1) {
			continue;
		}
		int lt = r + 1, rt = n - p;
		if (lt > rt) {
			res += r - l + 1;
			//cout << l << " " << r << " " << a[l] << " case1\n";
			continue;
		}
		int max_add = (a[l] + m) * (rt - lt + 1) - (sum[rt + 1] - sum[lt]);
		int bad_judges = v - lt - (p - 1);
		//cout << a[l] << " " << lt << " " << rt << " " << max_add << " " << sum[rt + 1] - sum[lt] << "\n";
		if (max_add >= bad_judges * m) {
			res += r - l + 1;
			//cout << lt << " " << rt << " " << bad_judges << " case2\n";
			continue;
		}
	}
	cout << res << "\n";
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = float('INF')

# solve


def solve():
    a = II()
    b = II()
    l = [3, 1, 2]
    l.remove(a)
    l.remove(b)
    print(l[0])
    return


# main
if __name__ == '__main__':
    solve()


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	vll p(m),y(m);
	vvll v(n);
	rep(i,m){
		cin >> p[i] >> y[i];
		v[p[i]-1].pb(y[i]);
	}
	rep(i,n){
		sort(all(v[i]));
	}
	rep(i,m){
		printf("%06lld%06lld",p[i],lower_bound(all(v[p[i]-1]),y[i])-v[p[i]-1].begin()+1);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
 
int a[105];
int main ()
{
    int n; cin>>n; for(int i = 1; i<=n; i++)cin>>a[i];
    int ans = 1e9;
    int sum1 = 0;
    for(int T = 1; T<=n; T++)
    {
        sum1+=a[T];
        int sum2 = 0;
        for(int i = T+1; i<=n; i++)
        {
            sum2+=a[i];
        }
        ans = min(ans, abs(sum1 - sum2));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    string S;
    const char *s = NULL;
    cin >> S;
    s = S.c_str();
    vector<char> A;
    A.assign(s, s + S.length());
    if(A[2] == A[3] && A[4] == A[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 504
local N = io.read("n")
local W = {}

for i=1, N do
    local w = io.read("n")
    W[i] = w
end

local ans = 100 * 100
for T=1,N do
    local sum_left = 0
    local sum_right = 0
    for i=1,T do
        sum_left = sum_left + W[i]
    end
    for i=T+1,N do
        sum_right = sum_right + W[i]
    end
    ans = math.min(ans, math.abs(sum_left - sum_right))
end
print(ans)


Measured memory_bytes: 256
N = int(input())
judge_list = []
judge = ['AC', 'WA', 'TLE', 'RE']
judge_dict = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    judge_list.append(str(input()))
for k in judge:
    judge_dict[k] = judge_list.count(k)
print(f"AC x {judge_dict['AC']}")
print(f"WA x {judge_dict['WA']}")
print(f"TLE x {judge_dict['TLE']}")
print(f"RE x {judge_dict['RE']}")

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

int main(){
	int a,b;cin>>a>>b;
	if (a==b) {
		for(int i=0;i<a;i++)cout<<b;cout<<endl;
	} else if (a<b) {
		for(int i=0;i<b;i++)cout<<a;cout<<endl; 
	} else if (a>b) {
		for(int i=0;i<a;i++)cout<<b;cout<<endl;
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(' ')))
ABS_LIST = list(map(abs,A))
ABS_SUM = sum(ABS_LIST)
if len([x for x in A if x < 0])%2 != 0:
    print(ABS_SUM-min(ABS_LIST)*2)
else:
    print(ABS_SUM)

Measured memory_bytes: 14208
N= int(input())
A = input().split(" ")
A = [int(i) for i in A]

B = input().split(' ')
B = [int(j) for j in B]

string=""

for i in range (1,N+1):
    string+=str(i)

def permutation(lst): 
    if len(lst) == 0: 
        return [] 
    if len(lst) == 1: 
        return [lst] 
    l = []
    for i in range(len(lst)): 
       m = lst[i] 
       remLst = lst[:i] + lst[i+1:] 
       for p in permutation(remLst): 
           l.append([m] + p) 
    return l 

data = list(string)
permut_int=[]

for p in permutation(data): 
    permut_int.append([int(i) for i in p])

A_index = permut_int.index(A)+1
B_index = permut_int.index(B)+1

print(abs(A_index-B_index))



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

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

    vector<int> b(N);
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    vector<int> output;
    for (int i = N - 1; i >= 0; i--) {
        bool found = false;
        for (int j = i; j >= 0; j--) {
            if (b[j] == j + 1) {
                output.push_back(j + 1);
                found = true;
                b.erase(b.begin() + j);
                break;
            }
        }
        if (!found) {
            cout << -1 << endl;
            return 0;
        }
    }

    for (int i = 0; i < N; i++) {
        cout << output[N - i - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
N, M = map(int, input().split())
min_ID = 0
max_ID = N
for _ in range(M):
    L, R = map(int, input().split())
    if min_ID < L:
        min_ID = L
    if max_ID > R:
        max_ID = R

if max_ID < min_ID:
    print(0)
else:
    print(max_ID - min_ID + 1)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int A,P;cin >> A >> P;
  cout << (A*3+P)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
#define sz(x) int(x.size())
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

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

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

// 高橋が料理i選んだらスコアはAi + Bi増え
// 青木が料理i選んだらスコアは-(Ai + Bi)増える

#define NDEBUG

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<int> ab(n);
    repeat(i, n) {
        cin >> a[i] >> b[i];
        ab[i] = a[i] + b[i];
    }

    sort(ab.rbegin(), ab.rend());
    long long ans = 0;
    repeat(i, n) ans -= b[i];
    repeat(i, n) {
        if (i % 2 == 0) ans += ab[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4560
n = int(input())
s = input()
xyz = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#print(xyz[2])
for ch in s:
    #print("ch",ch)
    #print(xyz.find(ch))
    #print(xyz.find(ch)+n+1)
    if xyz.find(ch)+n+1 > len(xyz):
        print(xyz[xyz.find(ch)+n-len(xyz)],end = "")
    else:
        print(xyz[xyz.find(ch)+n],end = "")

print("")


Measured memory_bytes: 4468
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 2e3+1;
ll tc[maxn][maxn];
ll dis[maxn][maxn];
vector<ll> nodes[maxn];
void bfs(ll x)
{
     tc[x][x]=1;
     queue<ll> q;
     q.push(x);

     while(!q.empty())
     {
          ll cur = q.front();
          q.pop();

          for(auto ch : nodes[cur]){
               if(tc[x][ch]==0){
                    tc[x][ch]=1;
                    dis[x][ch]=dis[x][cur]+1;
                    q.push(ch);
               }
          }
     }
}
void solve()
{    

     ll n,x,y;
     cin >> n >> x >> y;

     f(i,1,n)
          nodes[i].pb(i+1), nodes[i+1].pb(i);

     nodes[x].pb(y);
     nodes[y].pb(x);

     for(ll i=1; i<=n; i++)
          bfs(i);
     map<ll,ll> cnt;
     f(i,1,n+1)
          f(j,1,n+1)
               cnt[dis[i][j]]++;   

     f(i,1,n)
          cout << cnt[i]/2 << endl;

     
}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
          
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 66432
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define iter ::iterator
#define upb upper_bound
#define lwb lower_bound

#define sz(v) v.size()
#define aloc(i, a, n) i *a = new i[n]

#define for0(i,a) for(ll i = 0; i < a; i++)
#define fori(i,a,b) for(ll i = a; i < b; ++i)
#define rfor0(i,a) for(ll i = a; i >= 0; --i)
#define rfor(i,a,b) for(ll i = a; i >= b; --i)


//##############################################################################

int main(){
 
	int N;
	cin >> N;
	
	aloc(int, arr, N - 1);
	for0(i, N - 1) cin >> arr[i];

	aloc(int, arr2, N);
	for0(i, N) arr2[i] = 0;
	
	arr2[0] = arr[0];
	
	for0(i, N - 1){

		if(arr2[i] > arr[i]) arr2[i] = arr[i];
		arr2[i+1] = arr[i];	

	}

	ll sum = 0;
	for0(i, N) sum += arr2[i];

	cout << sum << endl;

//	for0(i, N) cout << arr2[i] << endl;

 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Edge
{
	int from;
	int to;
	ll cost;
};

bool calcShortest(vector<Edge>& list, int s, int maxV, vector<ll>& d, vector<bool>& negativeLoop)
{
	for (auto i = 0; i < maxV; ++i)
	{
		d.push_back(LLONG_MAX);
		negativeLoop.push_back(false);
	}
	d[s] = 0;

	auto isLoop = false;
	for (auto i = 0; i <= 2 * maxV; ++i)
	{
		auto isUpdate = false;
		for (auto& e : list)
		{
			if (d[e.from] < LLONG_MAX && d[e.to] > d[e.from] + e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
				isUpdate = true;
				if (i >= maxV)
				{
					negativeLoop[e.to] = true;
				}
			}
		}
		if (!isUpdate)
		{
			break;
		}
		if (i >= maxV)
		{
			isLoop = true;
		}
	}

	return isLoop;
}

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

	vector<Edge> list;
	for (auto i = 0; i < M; ++i)
	{
		int a, b;
		ll c;
		cin >> a >> b >> c;
		--a;
		--b;
		list.push_back({ a, b, -c });
	}

	vector<ll> d;
	vector<bool> negativeLoop;
	calcShortest(list, 0, N, d, negativeLoop);
	if(negativeLoop[N - 1])
	{
		cout << "inf" << endl;
	}
	else
	{
		cout << -d[N - 1] << endl;
	}

	return 0;
}

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

long long int ans=0;
int main(){
 map<long long int, long long int>a;
 int n;cin>>n;
 for(int i=0;i<n;i++){
	 long long int h;
	 cin>>h;
	 ans+=h;
	 if(a.count(h)){
		 //exist
		 a[h]=a[h]+1;
	 }
	 else{
		 //no exist
		 a[h]=1LL;
	 }
 }
 int q;cin>>q;
 for(int i=0;i<q;i++){
	 long long int b,c;
	 cin>>b>>c;
	 if(a.count(b)){
		 long long int piyo=a[b];
		 ans+=((c-b)*piyo);
		 cout<<ans<<endl;
		 a.erase(b);
		 if(a.count(c)){
			 //exist
			 a[c]=a[c]+piyo;
		 }
		 else{
			 //no exist
			 a[c]=piyo;
		 }
	 }
	 else{
		 cout<<ans<<endl;
	 }
 }
}


Measured memory_bytes: 7492
#include<cstdio>
using namespace std;
int main()
{
	int n,m,k;
	scanf("%d%d",&n,&m);
	k=m/n;
	for(int i=k;i>=1;i--)
	if(m%i==0)
	{
		printf("%d",i);
		return 0;
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<numeric>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i <= (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	int N;
	cin >> N;

	map<int, int> m;
	rep(i, N)
	{
		int a;
		cin >> a;
		m[a]++;
	}

	for(auto p : m){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n,i,k;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		if (i % 3 == 0)
		{
			printf(" %d", i);
		}
		else
		{
			k = i;
			while (k != 0)
			{
				if (k % 10 == 3)
				{
					printf(" %d", i);
					break;
				}
				k = k / 10;
			} 
		}
	}
	printf("\n");
	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

int main() {
  int A, B;
  cin >> A >> B;
  cout << A + (B/2) << endl;
};


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

ll lcm(ll x, ll y) {
    ll a = x;
    ll b = y;
    ll temp;
    while (y != 0) {
        temp = y;
        y = x % y;
        x = temp;
    }
    return a * b / x;
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}


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

int main(void) {
  int A, B;
  cin >> A >> B;

  int value[14] = {0, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

  if(value[A] >  value[B]) cout << "Alice" << endl;
  if(value[A] == value[B]) cout << "Draw"  << endl;
  if(value[A] <  value[B]) cout << "Bob"   << endl;

  return 0;
}


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

#define int long long

// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1

// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())

// debug
#define check(x) std::cout << #x << " = " << x << '\n'

// print
#define cout(x) std::cout << x << '\n'

// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

int SumOfDigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

void PrintMap(std::map<int, int>& m) {
  for (auto iter: m) {
    std::cout << iter.first << " => " << iter.second << "\n";
  }
}

int Digits(int x) {
  int d = 0;
  while (x > 0) {
    x /= 10;
    d++;
  }
  return d;
}

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> vec(h);
  REP(i, h) {
    std::cin >> vec.at(i);
  }

  for (int i = 0; i < vec.at(0).size(); i++) {
    bool flag = true;
    for (int j = 0; j < h; j++) {
      if (vec.at(j).at(i) != '.') {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int j = 0; j < h; j++) {
        std::string s = vec.at(j);
        if (i == w-1) {
          vec.at(j) = s.substr(0, i);
        } else {
          vec.at(j) = s.substr(0, i) + s.substr(i+1);
        }
      }
      i--;
    }
  }

  std::string empty = "";
  REP(i, vec.at(0).size()) {
    empty += ".";
  }

  
  REP(i, h) {
    if (vec.at(i) != empty) {
      std::cout << vec.at(i) << '\n';
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i,n) for(int i=0; i<n; i++)
int main(void){
  int sum=0;
  int h,n;
  scanf("%d%d",&h,&n);
  rep(i,n){
    int a=0;
    scanf("%d",&a);
    sum+=a;
  }
  sum>=h?printf("Yes"):printf("No");
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, P: "List[int]", Q: "List[int]"):
    a = 0
    b = 0
    for i, v in enumerate(itertools.permutations(range(1, N+1))):
        flagp = True
        flagq = True
        for j in range(N):
            if v[j] != P[j]:
                flagp = False
            if v[j] != Q[j]:
                flagq = False
        if flagp:
            a = i+1
        if flagq:
            b = i+1
    print(abs(b-a))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, Q)

if __name__ == '__main__':
    main()


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

int main() {
  int N,K;
  int sum = 0;
  cin >> N >> K;
  for (int i; i < N; i++){
    int x;
    cin >> x;
    if (x*2 < K){
      sum += x;
    }
    else
      sum += K-x;
  }
  cout << sum*2 <<endl;
 }
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int A, B;
  cin >> A >> B;
  if (A * B % 2 == 1) {
    print("Odd");
  } else {
    print("Even");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<int> G[200010];
int pr[200010];

void dfs(int now, int pre){
    pr[now] = pre;
    rep(i, 0, G[now].size()){
        int nxt = G[now][i];
        if(nxt == pre) continue;
        dfs(nxt, now);
    }
}
int cnt = 0;

void dfs2(int now, int pre){
    cnt++;
    rep(i, 0, G[now].size()){
        int nxt = G[now][i];
        if(nxt == pre) continue;
        dfs2(nxt, now);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    vector<int> path;
    int now = n - 1;
    path.push_back(now);
    while(now != 0){
        now = pr[now];
        path.push_back(now);
    }
    reverse(all(path));
    dfs2(path[(path.size() + 1) / 2 - 1], path[(path.size() + 1) / 2]);
    if(cnt > n - cnt) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

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

const int INF = (1LL << 31) - 1;
vector<int> v;

struct DelaySegmentTree {
  int n;
  vector<int> node,delay;
  vector<bool> delayflag;

  // 元配列 v をセグメント木で表現する
  void init(){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,INF);
    delay.resize(2*n-1,INF);
    delayflag.resize(2*n-1,false);

    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
  }

  void eval(int k,int l,int r){
    if(delayflag[k]){
      node[k] = delay[k];
      if(r-l > 1){
        delay[2*k+1] = delay[k];
        delayflag[2*k+1] = true;
        delay[2*k+2] = delay[k];
        delayflag[2*k+2] = true;
      }
      delayflag[k] = false;
    }
  }

  void update(int a,int b,int x){ update(a,b,x,0,0,n); }
  void update(int a,int b,int x,int k,int l,int r){
    eval(k,l,r);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b){
      delay[k] = x;
      delayflag[k] = true;
      eval(k,l,r);
    }
    else {
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      node[k] = min(node[2*k+1],node[2*k+2]);
    }
  }

  int getmin(int a,int b){ return getmin(a,b,0,0,n); }
  int getmin(int a,int b,int k,int l,int r){
    //区間 [a, b) 中の要素の最小値を返す
    eval(k,l,r);
    if(b <= l || r <= a) return INF;
    if(a <= l && r <= b) return node[k];
    int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
    int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }
}seg;

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

  int n,q; cin >> n >> q;
  v.resize(n,INF);
  seg.init();
  for(int i = 0; i < q; i++){
    int com,s,t,x; cin >> com;
    if(com){
      cin >> s >> t;
      cout << seg.getmin(s,t+1) << endl;
    }
    else {
      cin >> s >> t >> x;
      seg.update(s,t+1,x);
    }
  }

  return 0;
}



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

int main() {
  int n; cin >>n;
  vector<vector<int>> a(2, vector<int>(n));
  for (int i=0; i<n; i++) cin >>a.at(0).at(i);
  for (int i=0; i<n; i++) cin >>a.at(1).at(i);
  int ans = 0;
  for (int i=0; i<n; i++){
    // i列目で下へ行く
    int buf = 0;
    for (int j=0; j<n; j++){
      if (j<i) buf += a.at(0).at(j);
      if (j==i) buf += a.at(0).at(j) + a.at(1).at(j);
      if (j>i) buf += a.at(1).at(j);
    }
    if (buf > ans) ans = buf;
  }

  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
a, b= map(int, input().split())
if a == 1:
    print('1')
elif b == 1:
    print('1')
else:
    if (a*b)%2 == 0:
        print(round((a*b)/2))
    else:
        print(round(((a//2)+(a%2))*b)-(b//2))

Measured memory_bytes: 3060
#include <stdio.h>
int main(){

    int count0 = 0;
    int count1 = 0;
    int ans = 0;
    char s[100001] = {'a'};
    scanf("%s",s);


    for (int i = 0; i < sizeof(s); i++) {
        if (s[i] == '0') {
            count0++;
        } else if (s[i] == '1'){
            count1++;
        } else {
            
        }
    }

    if ( count0 >= count1 ) {
        ans = count1*2;
    } else {
       ans = count0*2; 
    }

    printf("%d\n",ans);
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

ll exor(ll a)
{
    if (a == 0)
        return 0;
    ll b = (a + 1) / 2;
    ll c = b % 2 == 0 ? 0 : 1;
    if ((a + 1) % 2 == 1)
        c ^= a;
    return c;
}

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

    ll a, b;
    cin >> a >> b;
    ll x, y;
    x = exor(a - 1);
    y = exor(b);
    ll ans = x ^ y;
    cout << ans << endl;

    return 0;
}

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

using namespace std;


vector<vector<int>> line;
vector<int> even_odd;

bool right_on(int right_idx, vector<int> state, int even_odd) {
    vector<int> v = line[right_idx];
    int on_count = 0;
    for(int i = 0; i < v.size(); i++) {
        //cout << v[i] << ":" << state[v[i] - 1] << endl;
        if(state[v[i] - 1] == 1) on_count++;
    }
    //cout << "on_count" << on_count << "even_odd" << even_odd << endl;
    if(on_count % 2 == even_odd) return true;
    else return false;
}

int main() {
    int N, M;
    int count = 0;
    cin >> N >> M;

    for(int i = 0; i < M; i++) {
        int k;
        cin >> k;
        vector<int> sv;
        for(int j = 0; j < k; j++) {
            int s;
            cin >> s;
            sv.push_back(s);
        } 
        line.push_back(sv);
    }

    for(int i = 0; i < M; i++) {
        int p;
        cin >> p;
        even_odd.push_back(p);
    }

    for(int i = 0; i < pow(2, N); i++) {
        vector<int> state;
        for(int j = 0; j < N; j++) {
            state.push_back((i >> j) % 2);
            //cout << ((i >> j) % 2);
        }
        //cout << endl;
        for(int k = 0; k < M; k++) {
            if (!right_on(k, state, even_odd[k])) break;
            else if (k == M - 1) count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m, q;
  while(cin >> n >> m >> q, n){
    vector<string> S(q+1), B(q+1);
    S[0] = string(n,'0');
    B[0] = string(m,'0');
    for(int i = 0; i < q; ++i) cin >> S[i+1] >> B[i+1];
    vector< vector<bool> > A(m,vector<bool>(n,true));
    for(int i = 1; i <= q; ++i){
      for(int j = 0; j < n; ++j){
        if(S[i][j] == '1'){
          for(int k = 0; k < m; ++k){
            if(B[i][k] == B[i-1][k] && A[k][j]) A[k][j] = false;
          }
        }else{
          for(int k = 0; k < m; ++k){
            if(B[i][k] != B[i-1][k] && A[k][j]) A[k][j] = false;
          }
        }
      }
    }
    for(int i = 0; i < m; ++i){
      int c = 0;
      char ans;
      for(int j = 0; j < n; ++j){
        if(A[i][j]){
          if(c == 0){
            if(j < 10) ans = '0' + j;
            else ans = 'A' + j - 10;
            ++c;
          }else{
            ans = '?';
            break;
          }
        }
      }
      cout << ans;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll>l4 ;
const int maxn=2e5+5;
int n,a[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
	    int x;
		scanf("%d",&x);
		a[x]=a[x-1]+1; 		
	}
	printf("%d\n",n-*max_element(a+1,a+1+n));
	return 0;
}

Measured memory_bytes: 1024
function main()
	n = parse(readline())
	a = parse.(split(readline()))
	b = sort(a, rev=true)
	d = 0
	if n%2 == 0
		for i in 1:convert(Int64, n/2)
			d += b[2*i-1] - b[2*i]
		end
	else
		for i in 1:convert(Int64, (n-1)/2)
			d += b[2*i-1] - b[2*i]
		end
		d += b[n]
	end
	print(d)
end


main()

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

const int MAX = 105;
int m[MAX][MAX];

int main() {
  int n, u, k;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;
      m[u][v] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j != 1) cout << " ";
      cout << m[i][j];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, k = LI()
h = LI()
h.sort()
ans = len([hi for hi in h if hi >= k])
print(ans)


Measured memory_bytes: 51440
#include <bits/stdc++.h>
#define long long long
using namespace std;
const long M = 1e5+1, LINF = 1e18 + 1;

int n, W, w[101], v[101];
long dp[M], ans;
int main() {
  cin >> n >> W;
  for(int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  fill(dp+1, dp+M, -LINF);
  dp[0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = W; j >= w[i]; j--) {
      dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
      ans = max(dp[j], ans);
    }
  }
  cout << ans;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		if(M <= N * 2) {
			System.out.println(M / 2);
		} else {
			M -= N * 2;
			System.out.println(N + (M / 4));
		}
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
ll a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n + 1) {
    cin >> a[i];
  }

  ll sum = 0;
  ll next = 0;
  REP(i, n) {
    ll b;
    cin >> b;

    ll t = a[i] - min(a[i], next);
    ll tt = t - min(t, b);
    sum += (a[i] - tt);
    next = b - min(t, b);
  }
  sum += min(next, a[n]);

  cout << sum << endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	int ni[] ={-1,0,1,0};
	int nj[] ={0,-1,0,1};
	int h ;
	int w ;
	int c ;
	
	void label2(int i , int j , int prev, int post, int [][] map){
		for(int z=  0; z < 4; z++){
			int nni = i + ni[z];
			int nnj = j + nj[z];
			
			if(nni < 0){
				continue;
			}
			if(nni  >= h ){
				continue;
			}
			if(nnj < 0){
				continue;
			}
			if(nnj  >= w ){
				continue;
			}
			
			if(map[nni][nnj] != prev){
				continue;
			}
			map[nni][nnj] = post;
			label2(nni,nnj,prev,post,map);
		}
	}
	
	void fill(int prev,int post, int map[][]){
		for(int i = 0; i < h ; i ++){
			for(int j= 0; j < w ; j++){
				if(map[i][j] == prev){
					map[i][j] = post;
				}
			}
		}
	}
	
	void label(int [][] map, int color){
		int prev1 = map[0][0];
		map[0][0] = -1;
		this.label2(0, 0, prev1, -1, map);
		fill(-1,color,map);
	}
	int count( int map[][]){
		int ret = 0;
		for(int i = 0; i < h ; i ++){
			for(int j= 0; j < w ; j++){
				if(map[i][j] ==-1){
					ret++;
				}
			}
		}
		return ret;
	}
	
	int labelz(int [][] map, int color){
		
		int prev1 = map[0][0];
		map[0][0] = -1;
		this.label2(0, 0, prev1, -1, map);
		this.fill(-1, color, map);
		map[0][0] = -1;
		this.label2(0, 0,color, -1, map);
		return count(map);
	}

	int[][] clone(int map[][]){
		int[][] ret = new int[map.length][];
		for(int i = 0; i < map.length; i++){
			ret[i] = map[i].clone();
		}
		return ret;
	}
	
	void run(){
		for(;;){
			h =sc.nextInt();
			w = sc.nextInt();
			c = sc.nextInt();
			if((h|w|c) == 0){
				break;
			}
			int map [][] = new int[h][w];
			c--;
			for(int i = 0; i < h ; i ++){
				for(int j = 0 ; j < w ; j++){
					map[i][j] = sc.nextInt() -1;
				}
			}
			
			int res = 0;
			
			for(int g = 0; g < 6; g++){
				int mapg[][] = clone(map);
				label(map,g);
				for(int f = 0 ; f < 6 ; f++){
					int mapf[][] = clone(map);
					label(map,f);
					for(int e = 0; e < 6; e++){
						int mape[][] = clone(map);
						label(map,e);
						for(int d = 0 ; d < 6 ; d++){
							int mapd[][] = clone(map);
							label(map,d);
								
							res = Math.max(labelz(map,c),res);
							
							map = mapd;
						}
						map = mape;
					}
					map = mapf;
				}
				map = mapg;
			}
			System.out.println(res);
			
		}		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

const long long mod = 1e9 + 7;

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

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

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

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

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

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

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    vector<pair<char, int>> rl;
    rl.emplace_back('R', 0);
    rep(i, n) {
        if (s[i] != rl.back().first) rl.emplace_back(s[i], 0);
        rl.back().second++;
    }
    vi ans(n);
    int pos = 0;
    for (int i=0; i<sz(rl); i+=2) {
        int cnt = rl[i].second + rl[i+1].second;
        pos += rl[i].second;
        if (rl[i].second%2==0) {
            ans[pos-1] += cnt/2;
            ans[pos] += (cnt+1)/2;
        }
        else {
            ans[pos-1] += (cnt+1)/2;
            ans[pos] += cnt/2;
        }
        pos += rl[i+1].second;
    }
    rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 4596
console.log((args=>{
  const [[N,T],t] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  t.sort((a,b)=>a-b);
  let s = T;
  for ( let i = 1; i < N; i++ ) {
    if ( t[i-1] + T > t[i] ) s += t[i] - t[i-1];
    else s += T;
  }
  return `${s}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 51404
class UF_weighed:
    def __init__(self, n):
        self.n = n
        self.par = list(range(n+1))
        self.rank = [0]*(n+1)
        self.size = [1]*(n+1)
        self.diff_w = [0]*(n+1)

    def find(self, x):
        if self.par[x] == x: return x
        p = self.find(self.par[x])
        self.diff_w[x] += self.diff_w[self.par[x]]
        self.par[x] = p
        return self.par[x]

    def weight(self, x):
        self.find(x)
        return self.diff_w[x]

    def diff(self, x, y):
        if not self.same(x, y): return None
        return self.weight(y) - self.weight(x)

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def merge(self, x, y, w):
        w += self.weight(x) - self.weight(y)
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.rank[x] < self.rank[y]:
            x, y, w = y, x, -w
        self.par[y] = x
        self.size[x] += self.size[y]
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.diff_w[y] = w
        return True
      
def main():
  n,m = map(int, input().split())
  uf = UF_weighed(n+1)
  q = [tuple(map(int, input().split())) for _ in range(m)]
  for a, b, c in q:
    if uf.same(a, b) and uf.diff(a, b) != c:
      return 'No'
    uf.merge(a, b, c)
  return 'Yes'

if __name__ == '__main__':
  print(main())

Measured memory_bytes: 42736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,w,m;
typedef pair<int,int> P;
//行与列
unordered_map<int,int> m1;
unordered_map<int,int> m2;
map<P,int> c;
int main() {
    vector<int> col,row;
    int ans = 0;
    int max1 = -1,max2 = -1;
    int index1,index2;
    cin >> h >> w >> m;
    
    int x,y = 0;
    for(int i = 0;i<m;i++){
        scanf("%d%d",&x,&y);
        if(!m1.count(x)){
            m1[x]= 1;
        }else{
            m1[x] += 1;
        }
        if(!m2.count(y)){
            m2[y] = 1;
        }else{
            m2[y] += 1;
        }
        max1 = max(max1,m1[x]);
        max2 = max(max2,m2[y]);
        c[make_pair(x,y)] = 1;
    }
    unordered_map <int,int>::iterator iter;
    for(iter = m1.begin(); iter != m1.end();iter++){
        if(iter->second == max1) row.push_back(iter->first);
    }
    for(iter = m2.begin(); iter != m2.end();iter++){
        if(iter->second == max2) col.push_back(iter->first);
    }
    // for(int i = 0;i<row.size();i++){
    //     cout << row[i] << " ";
    // }
    // cout << endl;
    for(int i = 0;i<row.size();i++){
        for(int j = 0;j<col.size();j++){
            int num;
            if(c[make_pair(row[i],col[j])] == 1) num = max1 + max2 -1;
            else num = max1 + max2;
            ans = max(ans,num);
            if(ans == max1 + max2) break;
        }
    }
    cout << ans << endl;

    
    return 0;
} 


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

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

    int ans = (a + b < a - b ? a - b : a + b);

    ans = (ans < a * b ? a * b : ans);

    cout << ans << endl;

    return 0;
}


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

A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(len(A)-1):
    if B[i] >= A[i]:
        ans += A[i]
        if A[i+1] > B[i]-A[i]:
            A[i+1] -= B[i]-A[i]

            ans += B[i] - A[i]
        else:
            ans += A[i+1]
            A[i+1] = 0        
    else:
        ans += B[i]
print(ans)

Measured memory_bytes: 18624
/*
CODED BY               
**************
DARSHAN JAIN
darshanjain31
**************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define MOD 1000000007

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

	if(a>=k)
		cout<<k<<endl;
	else if(a+b>=k)
		cout<<a<<endl;
	else if(a+b+c>=k)
	{
		cout<<a-(k-a-b)<<endl;
	}
	else
		cout<<a-c<<endl;
	
}

Measured memory_bytes: 3664
#include <cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",&a);
#define m(a,b) a<b?a:b
int w,n,m,c[k],d[k],p[k];
int main(){s(n)s(m)r(n)s(d[i])r(m)s(c[i])r(n+1)p[i]=1e9;p[0]=0;r(m*n)w=n-i%n,p[w]=m(p[w],p[w-1]+c[i/n]*d[w-1]);printf("%d\n",p[n]);}

Measured memory_bytes: 1036