akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;

int N,W,D;

struct Cake {
	int w,d;
};

bool operator<(const Cake& l, const Cake& r) {
	return l.w * l.d < r.w * r.d;
}

int main() {
	while(true) {
		cin >> N >> W >> D;
		if (W == 0) break;
		vector<Cake> cakes;
		cakes.push_back({W, D});
		for (int i = 0; i < N; ++i) {
			int p,s;
			cin >> p >> s;
			Cake split = cakes[p-1];
			cakes.erase(cakes.begin() + p-1);
			s %= (split.w + split.d) * 2;
			int nw1,nw2,nd1,nd2;
			if (s < split.w) {
				nd1 = nd2 = split.d;
				nw1 = s;
				nw2 = split.w - nw1;
			} else if (s < split.w + split.d) {
				nw1 = nw2 = split.w;
				nd1 = s - split.w;
				nd2 = split.d - nd1;
			} else if (s < split.w * 2 + split.d) {
				nd1 = nd2 = split.d;
				nw1 = s - split.w - split.d;
				nw2 = split.w - nw1;
			} else {
				nw1 = nw2 = split.w;
				nd1 = s - split.w * 2 - split.d;
				nd2 = split.d - nd1;
			}
			Cake add1 = {nw1, nd1};
			Cake add2 = {nw2, nd2};
			if (add1.w * add1.d > add2.w * add2.d) swap(add1, add2);
			cakes.push_back(add1);
			cakes.push_back(add2);
		}
		sort(cakes.begin(), cakes.end());
		for (size_t i = 0; i < cakes.size(); ++i) {
			cout << (i == 0 ? "" : " ") << cakes[i].w * cakes[i].d;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1220
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	int n,m;
	while(1)
	{
		scanf("%d %d",&n,&m); if(!n) return 0;
		vector<int>val(0);
		vector<int>pos(0);
		int ret=0;
		for(int i=0;i<n;i++)
		{
			int f; scanf("%d",&f);
			val.pb(f);
		}
		val.pb(0);
		n++;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				pos.pb(val[i]+val[j]);
			}
		}
		sort(pos.begin(),pos.end());
		pos.erase(unique(pos.begin(),pos.end()),pos.end());
		for(int i=0;i<pos.size();i++)
		{
			int v=upper_bound(pos.begin(),pos.end(),m-pos[i])-pos.begin();
			if(!v) continue;
			ret=max(ret,pos[i]+pos[v-1]);
		}
		printf("%d\n",ret);
		
	}
}

Measured memory_bytes: 9168
#!/usr/bin/env python3
from itertools import combinations

l, r = [int(x) for x in input().split()]

if r - l >= 2019:
    l = r = 0

l %= 2019
r %= 2019
if l >= r:
    r += 2019

ans = min(i * j % 2019 for i, j in combinations(range(l, r + 1), 2))
print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            var DP = new int[N, N];
            var len = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    if (S[i] == S[j])
                    {
                        if (i == 0)
                        {
                            DP[i, j] = 1;
                            len = 1;
                        }
                        else
                        {
                            DP[i, j] = Math.Min(DP[i - 1, j - 1] + 1, j - i);
                            len = Math.Max(len, DP[i, j]);
                        }
                    }
                }
            }

            Console.WriteLine(len);
        }
    }
}


Measured memory_bytes: 108512
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;++i)
#define per(i,r,l) for (int i=r;i>=l;--i)
#define rep0(i,r) for (int i=0;i<r;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
using namespace std;
const int N=1e6+6;
int main(){
    int a,v,b,w,t; cin>>a>>v>>b>>w>>t;
    if ((ll)t*(v-w)>=max(a,b)-min(a,b)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main(){
	int numData, Rate;
	int vmin;
	int dmax = -1e9;
	cin >>  numData;
	cin >> vmin;

	for ( int i = 1; i < numData; i++ ){
		cin >> Rate;
		dmax = max(dmax, Rate - vmin);
		vmin = min(vmin, Rate);
	}

	cout << dmax << endl;

	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n,d;
  cin>>n>>d;
  int ans=0;
  rep(i,n){
    ll x,y;
    cin>>x>>y;
    ll diff=x*x+y*y;
    double dist=sqrt(diff);
    if(dist<=(double)d)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2018,MaxK = 10003;
typedef pair<int,int> PII;
#define mp make_pair
int n,k;
string str[MaxN];
bitset<MaxK> can[MaxN];  //can[i][j] => string with length j can be made up by str[i~n]
int cur,cnt0,cnt1;
PII pos[2][1000000];  //candidate solution list
char ans[MaxK];
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n >> k;
    for (int i=1;i<=n;++i) cin >> str[i];
    can[n+1][0]=1;
    for (int i=n;i>=1;--i) can[i]=can[i+1]|(can[i+1]<<(str[i].length()));
    for (int i=1;i<=n;++i) if (can[i+1][k-str[i].length()]) pos[cur][++cnt0]=mp(i,0);
    for (int I=1;I<=k;++I) {
        char ch='z';
        cnt0=min(cnt0,MaxK);
        for (int i=1;i<=cnt0;++i) {
            PII& t=pos[cur][i];
            ch=min(ch,str[t.first][t.second]);
        }
        ans[I]=ch;
        cnt1=0;
        int mn=0x7fffffff;  //minimum new string
        for (int i=1;i<=cnt0;++i) {
            PII& t=pos[cur][i];
            if (str[t.first][t.second]!=ch) continue;
            if (t.second==str[t.first].length()-1)
                mn=min(mn,t.first+1);
            else
                pos[cur^1][++cnt1]=mp(t.first,t.second+1);
        }
        for (int i=mn;i<=n;++i)
            if (I+str[i].length()<=k && can[i+1][k-I-str[i].length()])
                pos[cur^1][++cnt1]=mp(i,0);
        cur^=1;cnt0=cnt1;
    }
    cout << ans+1 << endl;
    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define ull unsigned long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pul pair<ull,LL> 
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int mod=998244353;
template<typename T> void chkmin(T &x,T y) {if(y<x) x=y;}
template<typename T> void chkmax(T &x,T y) {if(y>x) x=y;}
template<typename T> void upd(T &x,T y) {if((x+=y)>=mod) x-=mod;}
int n,m,sl,fh,f[110][110];
char s[110][110];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();m=rd();memset(f,127,sizeof(f));
	for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
	f[1][1]=s[1][1]=='#';
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(!(i==1&&j==1))
			{
				if(j>1) chkmin(f[i][j],f[i][j-1]+(s[i][j]=='#'&&s[i][j-1]=='.'));
				if(i>1) chkmin(f[i][j],f[i-1][j]+(s[i][j]=='#'&&s[i-1][j]=='.'));
			}
	printf("%d\n",f[n][m]);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  cout << (M1 == M2 ? 0 : 1) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	double beg = clock();
	//freopen("out.txt", "w", stdout);
#endif

	int n;
	scanf("%d",&n);
	int cnt = 0;
	FOR(i,0,n) {
		int v;
		scanf("%d",&v);
		if (v&1) {
			cnt++;
		}
	}
	if(cnt&1) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}


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

int main() {
    //input
    string s;
    cin >> s;
    int a = 0;
    for(auto c : s){
        if(c == '+'){
            a++;
        }else if(c == '-'){
            a--;
        }
    }
    cout << a;

    return 0;
}

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

int main()
{
    std::string str;
    std::cin >> str;

    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        std::string order;
        std::cin >> order;

        if(order == "replace"){
            int a,b;
            std::cin >> a >> b;

            std::string replase;
            std::cin >> replase;

            for (int k = a; k < b+1; ++k) {
                str[k] = replase[k-a];
            }

        }else if(order == "reverse"){
            int a,b;
            std::cin >> a >> b;
            std::string rev = str.substr(a,b-a+1);
            std::reverse(rev.begin(),rev.end());

            for (int k = a; k < b+1; ++k) {
                str[k] = rev[k-a];
            }

        }else{
            //print
            int a,b;
            std::cin >> a >> b;
            std::cout << str.substr(a,b-a+1) << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3176
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

int main() {
	int nm;
	cin >> nm;
	vector<int> a(nm), c;
	for (int& i : a) cin >> i;
	cin >> nm;
	vector<int> b(nm);
	for (int& i : b) cin >> i;
	set_symmetric_difference(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.end()));
	for (int& i : c) cout << i << endl;
}


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

#define TR 100000

int l[TR], k;
using namespace std;
vector<int> h;


int solve(int p) {
	if(p == 0)
		return 0;
	if(p < 0)
		return 10000000;
	if(l[p] != -1)
		return l[p];
	int m_min = 1e9, tmp;
	for(int i = 1 ; i <= k ; i++) {
		if(p - i < 0)
			continue;
		tmp = abs(h[p] - h[p - i]) + solve(p - i);
		if(m_min > tmp)
			m_min = tmp;
	}
	l[p] = m_min;
	return l[p];

}

int main() {
	int n;
	cin >> n >> k;
	memset(l, -1, TR * sizeof(int));
	for(int i = 0, tmp ; i < n ; i++) {
		cin >> tmp;
		h.push_back(tmp);
	}
	solve(n - 1);
	cout << l[n - 1] << endl;
}

Measured memory_bytes: 8952
#include<stdio.h>
int main()
{
  int n,k,i;
  scanf("%d", &n);
  
  if (n % 1000 != 0 )
  {
    printf("%d",(n/1000+1)*1000-n);
  } else {
  printf("%d\n",n % 1000);
  }
    return 0;
}

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

fact_ct = [0 for _ in range(N+1)]
pr = []

def primes():
  ans = set()
  visited = set()
  for p in range(2,N+1):
    if p in visited:
      continue
    ans.add(p)
    q = p
    while q <= N:
      visited.add(q)
      q += p    
  return ans

pr = primes() 

def add_fact_ct(n):
  visited = set()
  for p in range(2,N+1):
    if p not in pr:
      continue
    while n % p == 0:
      fact_ct[p] += 1
      n //= p  

for n in range(2, N+1):
  add_fact_ct(n)
  
ct_75 = 0
ct_25 = 0
ct_15 = 0
ct_5 = 0
ct_3 = 0
ct_1 = 0
  
for ct in fact_ct:
  if ct >= 74:
    ct_75 += 1
  if ct >= 24:
    ct_25 += 1
  if ct >= 14:
    ct_15 += 1
  if ct >= 4:
    ct_5 += 1 
  if ct >= 2:
    ct_3 += 1

ans = 0

ans += ct_75

ans += ct_25 * (ct_3-1)
ans += ct_15 * (ct_5-1)

ans += ct_5*(ct_5-1)*(ct_3-2) // 2

print(ans)
#print(fact_ct) 


Measured memory_bytes: 64360
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;

int main() {
    int n; scanf("%d", &n);
    int arr[n];
    for (int i=0; i<n; i++) scanf("%d", &arr[i]);
    map<int, pair<long long int, long long int> > m;
    for (int i=0; i<n; i++) {
        if (m.find(-arr[i])==m.end()) {
            m.insert(mp(-arr[i],mp(i,1)));
        }
        else {
            m[-arr[i]].second++;
        }
    }
    long long int ans[n];
    memset(ans,0,sizeof(ans));
    long long int num=0, id = n;
    for (auto it=m.begin(); it!=m.end(); it++) {
        auto it2 = it;
        it2++;
        num += (it->second).second;
        long long nxt, curr=-(it->first);
        if (it2 == m.end()) nxt=0;
        else nxt = -(it2->first);
        id = min(id,(it->second).first);
        ans[id] += (curr-nxt)*num;
    }
    for (int i=0; i<n; i++) {
        printf("%lld\n", ans[i]);
    }
}


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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    ll ans = 0;
    rep(i,n){
        cin >>  s[i];
        ans += s[i];
    }
    sort(s.begin(),s.end());
    if(ans%10 != 0){
        cout << ans << endl;
        return 0;
    }
    rep(i,n){
        if(s[i]%10 != 0){
            cout << ans - s[i] << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int A = Integer.parseInt(stdR.readLine());
        int B = Integer.parseInt(stdR.readLine());
        int C = Integer.parseInt(stdR.readLine());
        int X = Integer.parseInt(stdR.readLine());
        int count = 0;
        for(int i = 0 ; i <= A ; i++) {
            for(int j = 0 ; j <= B ; j++) {
                for(int k = 0 ; k <= C ; k++) {
                    if((500 * i + 100 * j + 50 * k) == X)count++;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22484
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	A := [2]int{
		nextInt(),
		nextInt(),
	}
	B := [3]int{1, 2, 3}

loop:
	for j := 0; j < len(B); j++ {
		for i := 0; i < len(A); i++ {
			if A[i] == B[j] {
				continue loop
			}
		}

		fmt.Println(B[j])
		return
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
#define debug(var) cout << "[" << #var << "] " << var << endl

const int INF = 1<<29;
const double EPS=1e-9;
const int MOD=998244353;

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

    vector<int> ans(4, 0);
    rep(i, N) {
        string S;
        cin >> S;
        if (S == "AC") ans[0]++;
        else if (S == "WA") ans[1]++;
        else if (S == "TLE") ans[2]++;
        else if (S == "RE") ans[3]++;
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;
}

Measured memory_bytes: 3624
import sys


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

    def roots(self):
        return [i for i, x in enumerate(self.table) if x < 0]

    def group_count(self):
        return len(self.roots())


def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    U = UnionFind(n)
    for i in sys.stdin.buffer.readlines():
        a, b = map(lambda x: int(x) - 1, i.split())
        U.union(a, b)
    print(U.group_count() - 1)


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(string S) { cout << 700+100*count(ALL(S), 'o') << endl; }

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


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

typedef long long ll;

int main(){
    int A, B;
    cin >> A >> B;
    int ans;
    if (A>B){
        ans = A + (A - 1);
    } else if (A < B){
        ans = B + (B - 1);
    } else {
        ans = A + B;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    def dfs(edge,s):
        use={s}
        q=[s]
        while q:
            v=q.pop()
            for w in edge[v]:
                if w in use:continue
                use.add(w)
                q.append(w)
        return use
    n,m,p,*t=map(int,open(0).read().split())
    edge=[[]for _ in range(n)]
    edge_rev=[[]for _ in range(n)]
    e=[]
    for a,b,c in zip(t[::3],t[1::3],t[2::3]):
        edge[a-1].append(b-1)
        edge_rev[b-1].append(a-1)
        e.append((a-1,b-1,p-c))
    use=dfs(edge,0)&dfs(edge_rev,n-1)
    e=[(a,b,c)for a,b,c in e if a in use and b in use]
    INF=10**18
    d=[0]+[INF]*(n-1)
    for _ in range(n):
        f=False
        for a,b,c in e:
            cost=d[a]+c
            if cost<d[b]:
                d[b]=cost
                f=True
        if not f:break
    else:
        print(-1)
        exit()
    print(max(-d[-1],0))
main()

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

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int i, s, sum;
	sum = 0;
	for(i = 0; i < 4; i++) {
		cin >> s;
		sum += s;
	}
	cout << sum / 60 << "\n" << sum % 60 << endl;

	return 0;

}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll,ll>
#define endl "\n"
#define MAXN 100005
using namespace std;

ll n,x,sum,q,b,c;
map<ll,ll> m;

void solve()
{
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>x;
		m[x]++;
		sum+=x;
	}
	cin>>q;
	while(q--)
	{
		cin>>b>>c;
		sum+=(m[b]*(c-b));
		m[c]+=m[b];
		m[b]=0;
		cout<<sum<<endl;
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
}

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

int main(){
	// おまじない
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int N;
	// 出入力
	cin>>N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    
    int ans = 0;
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            //二分探索で探す
            // cout<<L[i]+L[j]<<"\n";
            auto ind = lower_bound(L.begin()+j+1,L.end(),L[i]+L[j]);
            // cout<<ind-(L.begin()+j+1)<<"\n";
            ans+=ind-(L.begin()+j+1);
            
        }
    }
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
ans = ''

ans += 'U'*(ty - sy)
ans += 'R'*(tx - sx)
ans += 'D'*(ty - sy)
ans += 'L'*(tx - sx)

ans += 'L'
ans += 'U'*(ty - sy + 1)
ans += 'R'*(tx - sx + 1)
ans += 'D'
ans += 'R'
ans += 'D'*(ty - sy + 1)
ans += 'L'*(tx - sx + 1)
ans += 'U'

print(ans)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, m; cin >> n >> m;

    map<int, int, greater<int>> ma;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        ma[a]++;
    }

    for (int i = 0; i < m; ++i) {
        int b, c; cin >> b >> c;

        ma[c] += b;
    }

    ll ans = 0;
    int cnt = 0;

    for (auto t : ma) {
        if (cnt + t.second > n) {
            ans += (ll)(n - cnt) * (ll)t.first;
            break;
        } else {
            ans += (ll)t.first * (ll)t.second;
            cnt += t.second;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    REP(i,s.length()){
        if (s[i] == '1') s[i] = '9';
        else if (s[i] == '9') s[i] = '1';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, m, k;
  scanf("%lld%lld", &m, &k);
  if(k >= (1 << m) || (m == 1 && k == 1)) printf("-1"); 
  else if(k) {
    for(i = 0; i < (1 << m); ++i) if(i != k) printf("%lld ", i);
    printf("%lld ", k);
    for(i = (1 << m) - 1; i >= 0; --i) if(i != k) printf("%lld ", i);
    printf("%lld", k);
  } else for(i = 0; i < (1 << m); ++i) printf("%lld %lld ", i, i);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

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

int main()
{
  int n;
  cin >> n;
  if (n < 10) cout << n << endl;
  else if (n < 100) cout << 9 << endl;
  else if (n < 1000) cout << n - 90 << endl;
  else if (n < 10000) cout << 909 << endl;
  else if (n < 100000) cout << n - 9090 << endl;
  else cout << 90909 << endl;
  return 0;
}


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

long long n, res = 0;
string s, s1, s2;
map<pair<string, string>, long long> a;
int main() {
	cin >> n >> s;
	s1 = s.substr(0, n), s2 = s.substr(n);
	reverse(s2.begin(), s2.end());
	for (int bit = 0; bit < 1<<n; bit++)
	{
		string x, y;
		for (int i = 0; i < n; i++)
		{
			(bit>>i & 1 ? x : y).push_back(s1[i]);
		}
		a[{x, y}]++;
	}
	for (int bit = 0; bit < 1<<n; bit++)
	{
		string x, y;
		for (int i = 0; i < n; i++)
		{
			(bit>>i & 1 ? x : y).push_back(s2[i]);
		}
		res += a[{x, y}];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 60948
import java.io.*;

public class Main {
	public static void main( String[] args ) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] AB = br.readLine().split( " " );
		Integer A = Integer.valueOf( AB[0] );
		Integer B = Integer.valueOf( AB[1] );

		Integer Ans = A * B;
		if( (Ans % 2) == 0 ) {
			System.out.println( "Even" );
		} else {
			System.out.println( "Odd" );
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 1e6;

int n, a, b;

int32_t main(){_
      
   cin >> a >> b;
   
   for (int p = 1; p <= 1e6; ++p)
   {
      int A = (8*p) / 100;
      int B = (10*p) / 100;
      if(A == a and B == b){
         cout<<p;
         exit(0);
      }
   }

   cout<<-1;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N;
	int R;
	int minus;
	scanf ("%d %d",&N,&R);
	minus = 100 * (10-N);
	if (N < 10){
		printf ("%d",R+minus);
	}
	else {
		printf ("%d",R);
	}
	return 0;
}

Measured memory_bytes: 2116
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	char s[127];
	while(~scanf("%s",s)){
		int l=strlen(s),t=0,k=0;
		long long a[3]={0},x[3]={0};
		rep(i,l){
			if(s[i]>='0' && s[i]<='9'){
				a[t]*=10;
				x[t]*=10;
				a[t]+=s[i]-'0';
			}
			else if(s[i]=='X'){
				a[t]*=10;
				x[t]*=10;
				x[t]++;
			}else t++;
		}
		t=1;
		rep(i,3)if(a[i]<x[i] && x[i]>9)k=1;
		reps(i,k,9){
			long long c=0;
			rep(j,2)c+=a[j]+x[j]*i;
			if(c==a[2]+x[2]*i){
				printf("%d\n",i);
				t=0;
				break;
			}
		}
		if(t)puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;

int n,a,b,c;
int l[8];
int dfs(int m,int aa,int bb,int cc){
	if(m==8){
		if(min(aa,min(bb,cc))==0)
			return 99999999;
		return abs(a-aa)+abs(b-bb)+abs(c-cc)-30;
	}
	int ret0,ret1,ret2,ret3;
	ret0=dfs(m+1,aa,bb,cc);
	ret1=dfs(m+1,aa+l[m],bb,cc)+10;
	ret2=dfs(m+1,aa,bb+l[m],cc)+10;
	ret3=dfs(m+1,aa,bb,cc+l[m])+10;
	return min(min(min(ret0,ret1),ret2),ret3);
}


int main(){
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++)
	{
		cin>>l[i];
	}
	cout<<dfs(0,0,0,0)<<endl;
	return 0;
}


	

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++){
			A[i] = sc.nextInt();
		}
		int q = partition(A, 0, n - 1);
		for (int i = 0; i < n; i++){
			if (i == q) {
				System.out.print("[" + A[i] + "]");
			}
			else {
				System.out.print(A[i]);
			}
			if (i != A.length - 1) {
				System.out.print(" ");
			}
			else {
				System.out.println();
			}
		}
	}

	public static int partition(int[] A, int p, int r){
		int x = A[r];
		int i = p - 1;
		for (int j = p; j < r; j++){
			if (A[j] <= x){
				i++;
				int m = A[i];
				A[i] = A[j];
				A[j] = m;
			}
		}
		int m = A[i + 1];
		A[i + 1] = A[r];
		A[r] = m;
		return i + 1;
	}

}



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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int main() {
  cout << setprecision(18);
  u32 N, K;
  string S;
  cin >> N >> K >> S;

  vector<pair<u32, u32>> Zeros;
  u32 L = 0, R = 0;

  bool flag = false;
  for (u32 i = 0; i < N; ++i) {
    if (S[i] == '0') {
      if (!flag) L = i;
      flag = true;
    } else {
      if (flag) {
        R = i - 1;
        Zeros.push_back(make_pair(L, R));
        flag = false;
      }
    }
  }
  if (flag) Zeros.push_back(make_pair(L, N - 1));

  if (K >= Zeros.size())
    cout << N << endl;
  else {
    if (Zeros[0].first != 0) L = 0;
    u32 res = 0;
    for (u32 i = 0; i + K <= Zeros.size(); ++i) {
      u32 tmp;
      L = (i != 0) ? Zeros[i - 1].second + 1 : 0;
      R = (i + K != Zeros.size()) ? Zeros[i + K].first - 1 : N - 1;

      tmp = R - L + 1;
      if (res < tmp) res = tmp;
    }
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 1020
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
 class Main {
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int n=scan.nextInt();
        int m=scan.nextInt();
        long sum=0;
        for(int i=0;i<m;i++){
            sum+=scan.nextInt();
        }
        if(sum>n){
            System.out.println(-1);
        }else{
            System.out.println(n-sum);
        }
    }
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


Measured memory_bytes: 33808
#include <iostream>
#include<cmath>

int main()
{
	using namespace std;
	int S;
	cin >>S;
	int h,m,s;
	h = S /(60*60);
	m = (S % (60*60)) / 60;
	s = (S % (60*60)) % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3108
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
MOD=10**9+7
plus=[]
minus=[]
zero=[]
for i in range(n):
  if a[i]>0:
    plus.append(a[i])
  if a[i]<0:
    minus.append(a[i])
  if a[i]==0:
    zero.append(a[i])
if k==n:
  ans=1
  for i in range(k):
    ans=(ans*a[i])%MOD
  print(ans)
  sys.exit()
if len(plus)==0:
  if k%2!=0:
    a.reverse()
  ans=1
  for i in range(k):
    ans=(ans*a[i])%MOD
  print(ans)
  sys.exit()
if len(plus)+len(minus)<k:
  print(0)
  sys.exit()
m=len(minus)
minus.sort()
plus.reverse()
plpointer=k
if k>len(plus):
  plpointer=2*(len(plus)//2)
  if k%2==1:
    if plpointer+1<=len(plus):
      plpointer+=1
    else:
      plpointer-=1
mnpointer=k-plpointer
while mnpointer<m-1 and plpointer>=2 and minus[mnpointer]*minus[mnpointer+1]>plus[plpointer-1]*plus[plpointer-2]:
  mnpointer+=2
  plpointer-=2
ans=1
for i in range(mnpointer):
  ans=(ans*minus[i])%MOD
for i in range(plpointer):
  ans=(ans*plus[i])%MOD
print(ans)


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  int n; cin >> n;
  int x = n % 10;

  vi hon = { 2, 4, 5, 7, 9 };
  vi pon = { 0, 1, 6, 8 };

  rep(i, 5) {
    if (x == hon[i]) {
      cout << "hon" << endl;
      return 0;
    }
  } 

  rep(i, 4) {
    if (x == pon[i]) {
      cout << "pon" << endl;
      return 0;
    }
  }

  cout << "bon" << endl;
}

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

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

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
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(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

ll factorial(int x){
    ll cur=1;
    for(int i=1;i<=x;i++){
        cur=cur*i%MOD;
    }
    return cur;
}

signed main(){
    CIN(N,M);
    ll ans;
    if(N==M)ans=(factorial(N)*factorial(M)*2)%MOD;
    else if(abs(N-M)==1)ans=(factorial(N)*factorial(M))%MOD;
    else ans=0;
    COUT(ans);

    return 0;
}

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

int main(){
    int N,D;
    
    cin >> N >> D;
    int X[N][D];

    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X[i][j];
        }
    }
    int count = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int sum = 0;
            for(int k=0;k<D;k++){
                sum += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            double v = sqrt(double(sum));
            if(ceil(v) == floor(v)){
                //cout << i << ' ' << j << ' ' << v << endl;
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        int maxi=-INF,mini=INF;
        rep(i,n){
            int hoge=0;
            rep(j,5){int t; cin>>t; hoge+=t;}
            cmin(mini,hoge);
            cmax(maxi, hoge);
        }
        cout<<maxi<<" "<<mini<<endl;
    }
}

Measured memory_bytes: 3008
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <assert.h>
#include <immintrin.h>
#include <emmintrin.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
int rint();char rch();long long rlong();
const int mn=302;
char a[mn][mn];
int n;
int norm(int x) {
  return (x>=n)?x-n:x;
}
int main()
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  n=rint();
  for (int x=0;x<n;x++) {
    for (int y=0;y<n;y++) {
      a[x][y]=rch();
    }
  }
  int ans=0;
  for (int d=0;d<n;d++) {
    bool ok=1;
    for (int x=0;ok&&(x<n);x++) {
      for (int y=0;y<x;y++) {
        if (a[norm(d+x)][y]!=a[norm(d+y)][x]) {
          ok=0; break;
        }
      }
    }
    ans+=ok;
  }
  ans*=n;
  printf("%d\n",ans);
}


inline int _read_char() {
  static char buf[1 << 16], *ptr = buf, *end_ptr = buf;
  if (ptr == end_ptr) {
    int len = fread(buf, 1, sizeof(buf), stdin);
    if (len <= 0) return EOF;
    ptr = buf;
    end_ptr = buf + len;
  }
  return *ptr++;
}

inline char rch() {
  char ch=_read_char();
  while(ch=='\0'||ch=='\n') ch=_read_char();
  return ch;
}

inline int rint() {
  int ch; bool sg = 0;
  do {
    ch = _read_char();
    if (ch == '-') sg = 1;
  } while (ch < '0' || ch > '9');
  int x = ch - '0';
  while (true) {
    ch = _read_char();
    if (ch < '0' || ch > '9') break;
    x = x * 10 + ch - '0';
  }
  return (sg?-x:x);
}

inline long long rlong() {
  int ch; bool sg = 0;
  do {
    ch = _read_char();
    if (ch == '-') sg = 1;
  } while (ch < '0' || ch > '9');
  long long x = ch - '0';
  while (true) {
    ch = _read_char();
    if (ch < '0' || ch > '9') break;
    x = x * 10 + ch - '0';
  }
  return (sg?-x:x);
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
      
         Scanner entrada=new Scanner(System.in);
         int count=0;
         String S=entrada.next();
        int [] x =new int[4];
        
        
       
        for (int i = 0; i <4; i++) {
            x[i]=S.charAt(i);
            
        }
        
        Arrays.sort(x);
        for (int i = 0; i < 3; i++) {
            if(x[i]==x[i+1]){
                count++;
            }
            
        }
       
        if(x[0]==x[1]&&x[2]==x[3]&& count!=3){
            System.out.println("Yes");
        }else if(count==3 || (x[0]!=x[1]&&x[2]!=x[3])||(x[0]==x[1]&&x[2]!=x[3]) ||x[0]!=x[1]&&x[2]==x[3]  ){
            System.out.println("No");
        }
        
    }
    
}


Measured memory_bytes: 23508
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ll count[100002] = {};
    rep(i, n) { count[a[i]]++; }
    ll count_new[100001];
    repd(i, 1, 100001) {
        count_new[i] = count[i - 1] + count[i] + count[i + 1];
    }
    ll ans = 0;
    repd(i, 1, 100001) { ans = max(ans, count_new[i]); }
    cout << ans << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 2560
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = input()
lst = int(N[-1])
if lst in [2,4,5,7,9]:
    print("hon")
elif lst in [0,1,6,8]:
    print("pon")
else:
    print("bon")

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
  ll N,M,Q;
  cin>>N>>M>>Q;
  vector<vector<ll>> v = vector<vector<ll>> (N+1,vector<ll>(N+1,0));
  ll a,b;
  FOR(i,0,M){
    cin>>a>>b;
    v[a][b]++;
  }

  FOR(i,0,N){
    FOR(j,0,N+1){
      v[i+1][j] += v[i][j];
    }
  }
  FOR(i,0,N+1){
    FOR(j,0,N){
      v[i][j+1] += v[i][j];
    }
  }


  FOR(i,0,Q){
    cin>>a>>b;
    cout<<v[b][b]-v[a-1][b]-v[b][a-1]+v[a-1][a-1]<<endl;
  }


}


Measured memory_bytes: 2944
#include <stdio.h>
#include <limits.h>

int n;
int mins[270000];

void update(int ul, int ur, int val, int k, int nl, int nr) {
  if (ur < nl || ul > nr)
    return;
  else if (ul <= nl && ur >= nr)
    mins[k] = val;
  else {
    if (mins[k] >= 0) {
      update(nl, nr, mins[k], 2 * k + 1, nl, (nl + nr) / 2);
      update(nl, nr, mins[k], 2 * k + 2, (nl + nr) / 2 + 1, nr);
      mins[k] = -1;
    }
    update(ul, ur, val, 2 * k + 1, nl, (nl + nr) / 2);
    update(ul, ur, val, 2 * k + 2, (nl + nr) / 2 + 1, nr);
  }
}

int min(int n1, int n2) {
  return n1 < n2 ? n1 : n2;
}

int find(int sl, int sr, int nodeID, int nl, int nr) {
  if (sr < nl || sl > nr)
    return INT_MAX;
  else {
    if (mins[nodeID] != -1)
      return mins[nodeID];
    else {
      int left = find(sl, sr, 2 * nodeID + 1, nl, (nl + nr) / 2);
      int right = find(sl, sr, 2 * nodeID + 2, (nl + nr) / 2 + 1, nr);
      return min(left, right);
    }
  }
}

int main() {
  int q, i, j, query, counter, cur, leaves, k, val;

  scanf("%d %d", &n, &q);

  for (leaves = 1; leaves < n; leaves *= 2);

  for (counter = 0; counter < leaves * 2; counter++)
    mins[counter] = INT_MAX;

  for (counter = 0; counter < q; counter++) {
    scanf("%d", &query);

    if (query) {
      scanf("%d %d", &i, &j);
      printf("%d\n", find(i, j, 0, 0, leaves - 1));
    } else {
      scanf("%d %d %d", &i, &j, &val);
      update(i, j, val, 0, 0, leaves - 1);
    }
  }
}



Measured memory_bytes: 2872
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int W = in.nextInt();
        int H = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();
        int r = in.nextInt();

        if(x>0 && x<W)
        	if(y>0 && y<H)
        		if(x+r<=W && x-r>=0)
        			if(y+r<=H && y-r>=0){
        				System.out.println("Yes");
        				return;
        			}

        System.out.println("No");
    }
}

Measured memory_bytes: 26260