akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int H, W, K;
  cin >> H >> W >> K;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

/*   int a = 0; */
/*   REP(i, H) REP(j, W){ */
/*     if(s[i][j] == '1') a++; */
/*   } */
/*   if(a <= K){ */
/*     cout << 0 << endl; */
/*     return 0; */
/*   } */

  vector<vector<int>> cnt(H+1, vector<int>(W+1, 0));
  REP(i, H) REP(j, W){
    if(s[i][j] == '1') cnt[i+1][j+1]++;
  }

  FOR(i, 1, H+1) REP(j, W+1){
    cnt[i][j] += cnt[i-1][j];
  }
  REP(i, H+1) FOR(j, 1, W+1){
    cnt[i][j] += cnt[i][j-1];
  }

  int ans = INF;
  REP(i, (1<<(H-1))){
    vector<int> vec = {0};
    int n = 2;
    int ret = 0;
    REP(j, H-1){
      if((i >> j)&1){
        vec.emplace_back(j+1);
        n++;
      }
    }
    vec.emplace_back(H);
    ret = n-2;
    vector<int> num(n, 0);
    bool ok = true;
    REP(j, W){
      bool flag = false;
      FOR(k, 1, num.size()){
        num[k] += cnt[vec[k]][j+1]+cnt[vec[k-1]][j]-cnt[vec[k]][j]-cnt[vec[k-1]][j+1];
        if(num[k] > K) flag = true;
      }
      if(flag){
        FOR(k, 1, num.size()){
          num[k] = cnt[vec[k]][j+1]+cnt[vec[k-1]][j]-cnt[vec[k]][j]-cnt[vec[k-1]][j+1];
          if(num[k] > K) ok = false;
        }
        ret++;
      }
    }
    if(ok) chmin(ans, ret);
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
	static void Main(string[] args)
	{

        string[] s = Console.ReadLine().Split(' ');
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);
        int[,] a = new int[n, m];
        int[] b = new int[m];
        int[] c = new int[n];

        for (int i = 0; i < n;i++)
        {
			string[] s1 = Console.ReadLine().Split(' ');
			
            for (int j = 0; j < m;j++)
            {
                a[i, j] = int.Parse(s1[j]);
            }
        }

        for (int i = 0; i < m;i++)
        {
            b[i] = int.Parse(Console.ReadLine());
        }


        for (int i = 0; i < n;i++)
        {
            for (int j = 0; j < m;j++)
            {
                c[i] += a[i, j] * b[j];
            }
        }

        for (int i = 0; i < n;i++)
        {
            Console.WriteLine(c[i]);
        }
	}
}

Measured memory_bytes: 9316
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,q,qu[100010][3],most[100010],co[100010];
vector <int> g[100010];

void bfs(int da[])
{
	if(da[1]<=most[da[0]]) return;
	most[da[0]]=da[1];
	vector <int> q;
	q.push_back(da[0]);
	rep(i,q.size())
	{
		//if(da[2]==2) cout<<q[i]<<endl;
		int t=q[i];
		if(co[t]==0) co[t]=da[2];
		if(most[t]==0) continue;
		rep(j,g[t].size())
		{
			int to=g[t][j];
			if(most[to]>=most[t]-1) continue;
			most[to]=most[t]-1;
			q.push_back(to);
		}
	}
}

int main()
{
	memset(most,-1,sizeof(most));/*要都清成-1因为输入的距离有可能为0，如果初值为0，
	距离为0时出发点就不会被涂色，因为>=，就错了*/
	cin>>n>>m;
	rep(i,m)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	cin>>q;
	rep(i,q) scanf("%d%d%d",&qu[i][0],&qu[i][1],&qu[i][2]);
	for(int i=q-1;i>=0;i--) bfs(qu[i]);
	repn(i,n) cout<<co[i]<<endl;
	rt0;
}

Measured memory_bytes: 8944
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define int ll int
#define debug(x) cout << ">>" << #x << ':' << x << endl;
#define endl "\n"
#define pb push_back
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define umap unordered_map
#define pii pair<int , int>
#define remove erase
#define all(v) v.begin() , v.end()   

const int mod = 1e9 + 7;

signed main()
{
	IOS
	int n , x , t;
	cin>>n>>x>>t;
	int ans = (n/x);
	if(n%x !=0)ans++;
	cout<<ans*t<<endl;
}



Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{

    int N;
    cin >> N;

    int a;
    deque<int> b;
    for (int i=0;i<N;++i) {
        cin >> a;
        if (i&1) {
            b.push_front(a);
        } else {
            b.push_back(a);
        }
    }

    if (N&1) {
        reverse(b.begin(), b.end());
    }
    for (auto c:b) {
        cout << c << " ";
    }

    return 0;
}

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

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int h,w,g[50][50], c[4];
    int dist[50][50][4];
    while(cin >> w >> h && w){
        rep(i,h)rep(j,w) cin >> g[i][j];
        rep(i,4) cin >> c[i];
        // d, y, x, dir
        typedef tuple<int,int,int,int> State;
        rep(i,50)rep(j,50)rep(k,4) dist[i][j][k] = 1e9;
        dist[0][0][1] = 0;
        priority_queue<State> q;
        int dx[] = {1,0,-1,0};
        int dy[] = {0,1,0,-1};
        q.emplace(0,0,0,0);
        int ans = -1;
        while(q.size()){
            int d,y,x,dir;
            tie(d,y,x,dir) = q.top();
            q.pop();
            d = -d;
            //printf(" %d %d %d %d\n", d,y,x,dir);
            if(dist[y][x][dir] < d) continue;
            if(y==h-1 && x==w-1){
                ans = d;
                break;
            }
            rep(op,4){
                int nx, ny, nd, ndir;
                int cost = op == g[y][x] ? 0 : c[op];
                nd = d + cost;
                ndir = (dir+op)%4;
                nx = x+dx[ndir], ny = y+dy[ndir];
                if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
                if(dist[ny][nx][ndir] <= nd) continue;
                dist[ny][nx][ndir] = nd;
                q.emplace(-nd,ny,nx,ndir);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1360
import math

S = int(input())

root_s = math.sqrt(S)
root_si = math.ceil(root_s)

M = root_si
a = 0
if M == root_s:
    b = 0
    c = 0
else:
    flag = False
    while(not flag):
        for bi in range(1, M+1):
            cf = (M*M - S - M*a + a*bi) / bi
            if (cf.is_integer() is True) and (cf <= M):
                flag = True
                b = bi
                c = int(cf)
                break
        if flag is False:
            a = a+1

xylist = [a, 0, M, b, c, M]

output = ''
for i in xylist:
    output = output + str(i) + ' '
print(output)


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

int main(){
	int a,b,c,t;
	cin>>a>>b>>c;
	if (a > b) {
		t = a;
		a = b;
		b = t;
	}

	if (b > c) {
		t = b;
		b = c;
		c = t;
	}

	if (a > b) swap(a,b);
	
	cout<<a<<" "<<b<<" "<<c<<endl;
	
	return 0;
}


Measured memory_bytes: 3116
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(readline())

ans = -1
x = 7 % K
for n in range(1, K + 10):
    if x == 0:
        ans = n
        break
    x = (10 * x + 7) % K
print(ans)

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}



int main(){
    int x,a;
    cin >> x >> a;
    if(x < a)   cout << "0\n";
    else
    {
        cout << "10\n";
    }
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();

    if (n>1&&m>1) {
      System.out.println(n*(n-1)/2+m*(m-1)/2);
    }
    if (n>1&&m<2) {
      System.out.println(n*(n-1)/2);
    }
    if (n<2&&m>1) {
      System.out.println(m*(m-1)/2);
    }
    if (n<2&&m<2) {
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 22612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  int data;
  struct node *prev,*next;
};

struct node *head;

struct node *find(int key){
  struct node *p;
  p=head->next;
  while(p != head && p->data != key){
    p=p->next;
  }
  return p;
}

void insert(int data){
  struct node *newnode;
  newnode = (struct node *)malloc(sizeof(struct node));
  newnode->data=data;
  newnode->next=head->next;
  head->next->prev=newnode;
  head->next=newnode;
  newnode->prev=head;
}

void delete(struct node *p){
  if(p==head)return;
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
}

void deleteFirst(){
  delete(head->next);
}

void deleteLast(){
  delete(head->prev);
}

int main(){
  int data,n,i;
  char command[12];
  struct node *out;
  scanf("%d",&n);
  if(n>2000000) exit(2);
  head = (struct node *)malloc(sizeof(struct node));
  head->next=head;
  head->prev=head;
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(strcmp(command,"insert") == 0){  // insert
      scanf("%d",&data);
      insert(data);
    }
    else if(strcmp(command,"delete")==0){ // delete and so on
      scanf("%d",&data);
      delete(find(data));
    }
    else if(strcmp(command,"deleteFirst")==0){
      deleteFirst();
    }
    else if(strcmp(command,"deleteLast")==0){
      deleteLast();
    }
  }
  out=head->next;
  i=0;
  while(1){
    if(out == head) break;
    if(i>0) printf(" ");
    printf("%d",out->data);
    out=out->next;
    i++;
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 32996
#include "bits/stdc++.h"
using namespace std;
int n,m,q,a[55],b[55],c[55],d[55];
vector<int> next(vector<int> v)
{
	for(int i=v.size()-1;i>=0;i--)
	{
		if(v[i]+1<=m)
		{
			int tmp=v[i]+1;
			for(int j=i;j<v.size();j++)
			{
				v[j]=tmp;
			}
			return v;
		}
	}
	vector<int> t;
	return t;
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;
		b[i]--;
	}
	vector<int> v; 
	for(int i=0;i<n;i++)
	{
		v.push_back(1);
	}
	int ans=0;
	while(1)
	{
//		for(int i=0;i<v.size();i++)
//		{
//			cout<<v[i]<<" ";
//		}
//		cout<<endl;
		int sum=0;
		for(int i=0;i<q;i++)
		{
			if(v[b[i]]-v[a[i]]==c[i])
			{
				sum+=d[i];
			}
		}
		ans=max(ans,sum);
		v=next(v);
		if(v.empty())
		{
			break;
		}
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 3624
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
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 (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}

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

  int ans = 1;
  rep(i, n-1){
    if(s[i]==s[i+1]) continue;
    else ans++;
  }
  cout << ans << endl;
}


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

int main(void){
    int x;
    cin >> x;
    
    if (x>=65 && x<=90) cout << 1 << endl;
    else if (x>=97 && x<=122) cout << 2 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3116
import math
n=int(input())
l=0
summ=0
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      ans=math.gcd(i,j,)
      ans=math.gcd(ans,k)
      summ+=ans
print(summ)

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

int main() {
  int a=0,b=0,c=0,d=0,e=0;
  cin >> a >> b >> c;
  for(int i=a;i<=b;i++){
    if( c%i==0 ){
    d++;
    }
  }
  cout << d <<endl;
  return 0;
}



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

signed main()
{	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int test=1;
    //cin>>test;
    while(test--){
        string s;
        cin>>s;
        for(int i=0;i<s.length();i++) cout<<"x";
    }
    return 0;
}       

Measured memory_bytes: 384
/*
    Sk arman Hossain
    University of Barisal

    Problem name :
    Algorithm :
 */

#include<bits/stdc++.h>
#define nl printf("\n");
#define N 200001
#define PR pair<int,int>
#define sf(n) scanf("%d", &n)
#define sff(n, m) scanf("%d %d",&n,&m)
#define sfl(n) scanf("%lld", &n)
#define sfu(n) scanf("%llu", &n)
#define sffl(n, m) scanf("%lld %lld",&n,&m)
#define pfn(n) printf("%d\n",n)
#define pf(n) printf("%d ",n)
#define pfl(n) printf("%lld ",n)
#define pfln(n) printf("%lld\n",n)
#define pfu(n) printf("%llu\n",n)
#define pfs(s) printf("%s",s)
#define YES printf("YES\n")
#define NO printf("NO\n")
#define PB push_back
#define PI 3.1415926536
#define VST(v) sort(v.begin(),v.end())
#define fori(i,n) for(;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define MP make_pair
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
vector<ll>V,V2,V3;
vector<ll> :: iterator it1,it2;
void CLEAR(){
    V.clear();
    V2.clear();
    V3.clear();
}
int main()
{
    ///freopen("1input.txt","r",stdin);
    int tcase=1;
    //sf(tcase);
    for(int test=1;test<=tcase;test++)
    {

       ll n,ans;
       sfl(n);
       ans=(n*(n+1))/2;
       ans-=n;
       printf("%lld\n",ans);
    }
///*****************************  ALHAMDULILLAH  *****************************/
}



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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 55555, M = N * N;

int n;

bool is_prime(int x)
{
    if (x < 2) return false;
    for (int i = 2; i <= x / i; i ++ )
        if (x % i == 0)
            return false;
    return true;
}

int main()
{
	cin >> n;
	for (int i = 2; i <= N; i ++ )
		if (is_prime(i) && i % 5 == 1)
		{
			cout << i << ' ';
			if ( -- n == 0) break;
		}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N,A,B,C,D=map(int,input().split())
mod=10**9+7
table=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t%=mod
    table[i]=t
rtable=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=pow(i,mod-2,mod)
    t%=mod
    rtable[i]=t
dd=defaultdict(int)
dd[N]=1
for i in range(A,B+1):
    nd=defaultdict(int)
    for gro,num in dd.items():
        nd[gro]+=num
        t=gro//i
        for k in range(C,min(t,D)+1):
            #print(i, gro, t)
            u=(table[gro] * rtable[gro - k * i] * pow(rtable[i],k,mod) * rtable[k] )%mod
            nd[gro - k*i] += num* u
            nd[gro - k * i]%=mod
    dd=nd
    #print(dd)
print(dd[0]%mod)


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

int main(){
    int a,b,c,tmp;
    scanf("%d %d %d",&a,&b,&c);
    if (a>b){
        tmp=b;
        b=a;
        a=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=b;
        b=a;
        a=tmp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    long long res = 0;
    for (int bit = 0; bit < (1<<(N-1)); ++bit) {
        long long tmp = 0;
        for (int i = 0; i < N-1; ++i) {
            tmp *= 10;
            tmp += S[i] - '0';
            if (bit & (1<<i)) res += tmp, tmp = 0;
        }
        tmp *= 10;
        tmp += S.back() - '0';
        res += tmp;
    }
    cout << res << endl;
}

Measured memory_bytes: 3568
n,k=map(int,input().split())
tmp=[int(input()) for i in range(n)]

left=max(tmp)-1
right=sum(tmp)
while left+1 < right:
	mid=(left+right)//2
	count=1
	now=0
	for i in tmp:
		if mid<now+i:
			now=i
			count+=1
		else:
			now+=i

	if count<=k:
		right=mid
	else:
		left=mid

print(right)



Measured memory_bytes: 9560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vvi dp;
string gx, gy;
int dfs(int ix, int iy) {
    if (ix == gx.length() or iy == gy.length()) {
        return 0;
    }
    if (dp[ix][iy] != -1) return dp[ix][iy];

    if (gx[ix] != gy[iy]) {
        int c1 = dfs(ix+1, iy);
        int c2 = dfs(ix, iy+1);
        dp[ix][iy] = max(c1, c2);
    } else {
        int c1 = dfs(ix+1, iy+1)+1;
        int c2 = dfs(ix, iy+1);
        dp[ix][iy] = max(c1, c2);
    }

    return dp[ix][iy];
}

void solve(string x, string y) {
    gx = x, gy = y;
    dp = vvi(1005, vi(1000, -1));
    cout << dfs(0, 0) << endl;
}

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

    int n;
    cin >> n;
    REP(i, n) {
        string x, y;
        cin >> x >> y;
        solve(x, y);
    }

    return 0;
}



Measured memory_bytes: 11028
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int p = scan.nextInt();
			int f = scan.nextInt();
			for(int i = 1;i < n;i++){
				int a = scan.nextInt();
				int b = scan.nextInt();
				if(f < b){
					p = a;
					f = b;
				}else if(f == b){
					p = (p < a)?p:a;
				}
			}
			System.out.println(p + " " + f);
		}
	}
}

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

#define ll long long
using namespace std;
long long power(ll  x, ll n){
    if(n==0)return 1;
    ll temp=power(x,n/2);
    if(n%2==0)return temp*temp;
    else return x*temp*temp;

}
ll max(ll a,ll b){
    return a>b?a:b;

}

ll max(ll a,ll b,ll c){
    return max(max(a,b),c);
}
ll min(ll x,ll  y){
    return x+y-max(x,y);
}
ll min(ll x,ll y,ll z){
    return min(min(x,y),z);

}



void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

bool f(ll x,ll y){
    return x>y;

}


int main(){
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll z=1;z<=n;z++){
                sum+=__gcd(i,__gcd(j,z));

            }


        }



    }
    cout<<sum;

    return 0;
}






































Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________



	pp x;
	cin >> x;
	pp a, b;

	for (pp i = -300; i <= 300; i++)
	{
		for (pp j = -300; j <= 300; j++)
		{
			if (pow(j, 5) - pow(i, 5) == x)
			{
				a = j;
				b = i;
				break;
			}
		}
	}

	cout << a << " " << b << en;
	return 0;
}


Measured memory_bytes: 4080
res1  = []
r, c = [int(temp) for temp in input().split()]

for temp in range(c + 1) : res1.append(0)

for tem in range(r) :
    tem1 = [temp for temp in input().split()]
    tem2 = list(map(int, tem1))
    print(' '.join(tem1) + ' ' + str(sum(tem2)))
    for mak in range(c) :
        res1[mak] = res1[mak] + tem2[mak]
    res1[c] += sum(tem2)

res2 = list(map(str, res1))
print(' '.join(res2))

Measured memory_bytes: 7748
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='1') ans++;
    }
    else{
      if(s[i]=='0') ans++;
    }
  }
  int res=0;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='0') res++;
    }
    else{
      if(s[i]=='1') res++;
    }
  }
  cout<<min(ans,res)<<endl;
  return 0;
}


Measured memory_bytes: 512
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split("\n")
        .skip(1)
        .map(|x| {
            x.split_whitespace()
                .map(|x| x.parse::<i64>().unwrap())
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let mut a = list[0].clone();
    let mut b = list[1].clone();

    let mut a_sum = a.iter().sum::<i64>();
    let mut b_sum = b.iter().sum::<i64>();

    loop {
        if a == b {
            return "Yes".to_string();
        }
        if a_sum >= b_sum {
            return "No".to_string();
        }

        let mut a_c = 0;
        let mut b_c = 0;
        for i in 0..a.len() {
            if a[i] < b[i] {
                let d = b[i] - a[i];
                let d = if d % 2 != 0 { d + 1 } else { d };

                a[i] += d;
                a_sum += d;
                a_c += d / 2;
            }

            if b[i] < a[i] {
                let d = a[i] - b[i];

                b[i] += d;
                b_sum += d;
                b_c += d;
            }
        }

        if a_c > b_c {
            let d = a_c - b_c;
            b[0] += d;
            b_sum += d;
        }

        if a_c < b_c {
            let d = (b_c - a_c) * 2;
            a[0] += d;
            a_sum += d;
        }
    }
}

#[test]
fn test() {
    let tests = vec![
        (
            "3
1 2 3
5 2 2",
            "Yes",
        ),
        (
            "5
3 1 4 1 5
2 7 1 8 2",
            "No",
        ),
        (
            "5
2 7 1 8 2
3 1 4 1 5",
            "No",
        ),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = 0;
        for (int i = A; i <= B; i++) {
            if (i / (int) Math.pow(10, 4) == i % 10 && i / 10 % 10 == i % (int) Math.pow(10, 4) / 1000) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define MODNum 1000000007
#define WHITE  0
#define GRAY   1
#define BLACK  2
#define INFTY  2147483647
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N;
    scanf("%d", &N);
    int u,v,k;
    int c[N][N];  /* 辺の重みを記録した隣接行列 */
    int color[N]; /* 頂点の訪問状態 */
    int d[N];     /* 最短コストの記録 */
    int p[N];     /* 最短経路木における頂点vの親 */
    int weight;
    /* Initialization */
    for ( int i = 0; i < N; i++ ){
        d[i]     = INFTY;
        color[i] = WHITE;
        p[i]     = -1;
        for ( int j = 0; j < N; j++ ) c[i][j] = INFTY;
    }
    /* グラフを読み込み */
    for ( int i = 0; i < N; i++ ){
        scanf("%d %d", &u, &k);
        for ( int j = 0; j < k; j++ ){
            scanf("%d %d", &v, &weight);
            c[u][v] = weight;
        }
    }
    /* 始点 */
    d[0]     = 0;
    color[0] = GRAY;
    int minv;

    while ( 1 ){
        minv = INFTY;
        u = -1;
        /* 確定していない値の中で最小のものを探す　*/
        for ( int i = 0; i < N; i++ ){
            if ( minv > d[i] && color[i] != BLACK ){
                u    = i;
                minv = d[i];
            }
        }
        if ( u == -1 ) break;
        color[u] = BLACK; /* 値を確定 */
        for ( v = 0; v < N; v++ ){
            if ( color[v] != BLACK && c[u][v] != INFTY ){
                /* まだ確定していない頂点との経路が存在するなら */
                if ( d[v] > d[u] + c[u][v] ){
                    /* 最短経路を探索、他にあるなら更新 */
                    d[v] = d[u] + c[u][v];
                    color[v] = GRAY;
                }
            }
        }

    }

    /* 各頂点までの最短距離 */
    for ( int i = 0; i < N; i++ ){
        printf("%d %d\n", i, d[i]);
    }

    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 110;
int x[maxn],y[maxn],h[maxn],n,pos;
inline int ABS(int x){if (x<0) x = -x; return x;}
bool check(int xx,int yy){
    int H = h[pos] + ABS(xx-x[pos]) + ABS(yy-y[pos]);
    for (int i=1,tmp;i<=n;i++) {
        tmp = max(0, H - ABS(xx - x[i]) - ABS(yy - y[i]) );
        if (tmp != h[i]) return false;
    }
    cout<<xx<<" "<<yy<<" "<<H<<endl;
    return true;
}
void work(){
    pos = 1;
    for (int i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>h[i];
        if (h[i] > 0) pos = i;
    }

    for (int xx=0;xx<=100;xx++)
        for (int yy=0;yy<=100;yy++) if (check(xx,yy)) return;


}
int main(){
    while (cin>>n) work();
    return 0;
}


Measured memory_bytes: 256
class MakeGraph:
    
    # 隣接行列もしくは隣接リストの初期化
    # node_num：ノード数
    # isMat：隣接行列(True) / 隣接リスト(False)
    def __init__(self, node_num:int, isMat:bool) -> None:
        self.n = node_num
        self.isMat = isMat

        # 隣接行列の初期化
        if self.isMat:
            INF = float("inf")
            self.graph = [[INF for _ in range(self.n)] for _ in range(self.n)]
    
        # 隣接リストの初期化
        else:
            self.graph = [[] for _ in range(self.n)]

    # エッジの追加
    # frm, to：起点ノード, 終点ノード
    # dist：frm→toへのコスト
    def add_undr_edge_mat(self, frm:int, to:int, dist:int) -> None:
        self.graph[frm][to] = dist
        self.graph[to][frm] = dist
        
    def add_drct_edge_mat(self, frm:int, to:int, dist:int) -> None:
        self.graph[frm][to] = dist
        
    def add_undr_edge_lst(self, frm:int, to:int, dist:int) -> None:
        self.graph[frm].append((dist, to))
        self.graph[to].append((dist, frm))
        
    def add_drct_edge_lst(self, frm:int, to:int, dist:int) -> None:
        self.graph[frm].append((dist, to))

                
    # 完成したグラフを取り出す
    def get_graph(self) -> list:
        return self.graph
    
N,M = map(int, input().split())
ABC = []
for i in range(M):
    ABC.append(tuple(map(int, input().split())))
    
graphMaker = MakeGraph(N,True)
distMaker = MakeGraph(N,True)
add_edge = graphMaker.add_undr_edge_mat
add_edge2 = distMaker.add_undr_edge_mat
for a,b,c in ABC:
    add_edge(a-1, b-1, c)
    add_edge2(a-1, b-1, c)

graph = graphMaker.get_graph()
dist = distMaker.get_graph()

# WF
for i in range(N):
    dist[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
            
ans = 0
for i in range(N):
    for j in range(N):
        if graph[i][j] != float("inf") and graph[i][j] != dist[i][j]:
            ans += 1

  
print(ans//2)   


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long> v(100);
	v[0] = 2;
	v[1] = 1;
	REP(i, 86) {
		v[i + 2] = v[i + 1] + v[i];
	}
	cout << v[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read();
	ll ans=1e15,sum=0;
	bool flag=0;
	REP(i,1,n){
		ll x=read(),y=read();
		if(x!=y) flag=1;sum+=x;
		if(x>y) ans=min(ans,y);
	}
	if(!flag) printf("0\n");
	else printf("%lld\n",sum-ans);
	return 0;
}


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

using namespace std;

int main() {
       char temp[10];
	cin >> temp;
	int a = 0;
	int b = 0;
	while (temp[b] != '\0') {
		if (temp[b] == 'B') {
			if (a > 0) {
				a--;
			}
		}
		else {
			temp[a++] = temp[b];
		}
		b++;
	}
	temp[a] = '\0';
	cout << temp << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	ll n,k;
	cin>>n>>k;
	ll dp[n+1];
	rep(i,1,n+1)cin>>dp[i];
	ll len;
	unordered_set<int>s;
	vector<int>v;
	s.insert(1);
	v.push_back(1);
	ll pos=dp[1];
	while(s.find(pos)==s.end())
	{
		s.insert(pos);
		v.push_back(pos);
		pos=dp[pos];
	}
	int ind;
	for(int i=0;i<v.size();i++)
	{
		if(pos==v[i])
		{
			ind=i;
			break;
		}
	}
	if(k<v.size())cout<<v[k];
	else
	{
		k-=ind;
		k=k%(v.size()-ind);
		cout<<v[k+ind];
	}
}



Measured memory_bytes: 13620
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int X;
  int A;
  cin >> X>>A;
  if (X<A) {
cout << 0<< endl;
  }
  else {
cout << 10 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <sstream>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

int n,m,s,g1,g2;
int d[111][111];

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n>>m>>s>>g1>>g2;
		if(n==0)break;
		s--; g1--; g2--;
		rep(i,111)rep(j,111)d[i][j]=INF;
		rep(i,111)d[i][i]=0;
		rep(i,m){
			int v,u,c;
			cin>>v>>u>>c;
			v--; u--;
			d[v][u]=c;
		}
		rep(k,n)rep(i,n)rep(j,n)minch(d[i][j],d[i][k]+d[k][j]);
		int res=INF;
		rep(i,n)minch(res,d[s][i]+d[i][g1]+d[i][g2]);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type* arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define all(v) (v.begin(), v.end())
#define tests(x) \
    int x;       \
    cin >> x;    \
    while (x--)
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int INF = 1e18;
const int N = 1e6 + 2;
void run() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("intput.txt", "r", stdin);
    freopen("o2.txt", "w", stdout);
#endif
}
int r, c, k, ri, ci, va, a[3003][3003], dp[3003][3003][4];
int mx(int i, int j) {
    int ans = 0;
    for (int k = 1; k <= 3; k++) {
        ans = max(ans, dp[i][j][k]);
    }
    return ans;
}
int solve() {
    cin >> r >> c >> k;
    forn(i, k) {
        cin >> ri >> ci >> va;
        a[ri][ci] = va;
    }
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            dp[i][j][1] = max(mx(i - 1, j) + a[i][j], dp[i][j - 1][1]);
            dp[i][j][2] = max(dp[i][j - 1][1] + a[i][j], dp[i][j - 1][2]);
            dp[i][j][3] = max(dp[i][j - 1][2] + a[i][j], dp[i][j - 1][3]);
        }
    }
    return mx(r, c);
}
int32_t main() {
    run();
    // tests(t) {
    cout << solve() << "\n";
    //}
    return 0;
}

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



Measured memory_bytes: 3084
import heapq
n=int(input())
a=list(map(int,input().split()))
heapq.heapify(a)

while len(a)!=1:
  b=heapq.heappop(a)
  c=heapq.heappop(a)
  heapq.heappush(a,(b+c)/2)
print(sum(a))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int Setnum(int i,int j){
    int num = 1;
    if(i==1)
        num *= 10;
    if(i==2)
        num *= 100;
    return num;
}
int main()
{
    vector<vector<int>> A(3, vector<int>(3));
    int N;
    for (int i = 0; i < 3;i++){
        for (int j = 0; j < 3;j++){
            cin >> A.at(i).at(j);
        }
    }
    cin >> N;
    vector<int> b(N);
    for (int i = 0; i < N;i++){
        cin >>b.at(i);
    }
    vector<vector<int>> Ans(3, vector<int>(3,0));
    for (int i = 0; i < 3;i++){
        for (int j = 0; j < 3;j++){
            int num = Setnum(i,j);
            bool Match = false;
            for (int k = 0; k < N;k++){
                 if( A.at(i).at(j)==b.at(k))
                     Ans.at(i).at(j) = num;      
            }
        }
    }
   
    bool check = false;
    for (int i = 0; i < 3;i++){
        int num = Ans.at(i).at(0) + Ans.at(i).at(1) + Ans.at(i).at(2);
        if(num==0)
            continue;
        if(num%3==0)
            check = true;
    }
    for (int i = 0; i < 3;i++){
        int num= Ans.at(0).at(i) + Ans.at(1).at(i) + Ans.at(2).at(i);
        if(num==0)
            continue;
        if(num%111==0)
            check = true;
    }
    int num= Ans.at(0).at(0) + Ans.at(1).at(1) + Ans.at(2).at(2);
        if((num==111)&&num!=0)
            check = true;
    num= Ans.at(0).at(1) + Ans.at(1).at(1) + Ans.at(2).at(1);
        if(num==111&&num!=0)
            check = true;
    num= Ans.at(0).at(2) + Ans.at(1).at(1) + Ans.at(2).at(0);
        if(num==111&&num!=0)
            check = true;
    if(check)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define float double
#define double long double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	int mini[n], maxi[n];
	for(int i=0;i<n;i++){
		cin>>mini[i]>>maxi[i];
	}
	sort(mini,mini+n);
	sort(maxi,maxi+n);
	double l,h;
	int ans;
	if(n%2==0){
		l = (double)(mini[n/2] + mini[n/2-1])/2;
		h = (double)(maxi[n/2] + maxi[n/2-1])/2;
		ans = (double)((h-l)*2 +1);
	}else{
		l = mini[n/2];
		h = maxi[n/2];
		ans = (h-l)+1;
	}
	cout<<ans<<endl;
	return 0;
}



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

const int MX = 100005;

int main() {
    int n, q;
    cin >> n;
    vector<int> bunpu(MX);
    ll tot = 0;
    rep(i, n) {
        int a;
        cin >> a;
        bunpu[a]++;
        tot += a; 
    }
    cin >> q;
    vector<int> b(q+5), c(q+5);
    rep(i, q) cin >> b[i] >> c[i];
    rep(i, q) {
        tot += (c[i] - b[i])*bunpu[b[i]];
        bunpu[c[i]] += bunpu[b[i]];
        bunpu[b[i]] = 0;
        cout << tot << endl;
    }

    return 0;
}

Measured memory_bytes: 4528
#include<stdio.h>
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int c;

void merge(int e[], int n, int left, int mid, int right){
  int i, j, k;

  int x = mid - left;
  int y = right - mid;
  for ( i = 0; i < x; i++ ) L[i] = e[left + i];
  for ( i = 0; i < y; i++ ) R[i] = e[mid + i];
  L[x] = R[y] = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ){
    c++;
    if ( L[i] <= R[j] ){
      e[k] = L[i++];
    } else {
      e[k] = R[j++];
    }
  }
}

void mergeSort(int e[], int n, int left, int right ){
  int mid;
  if ( left+1 < right ){
    mid = (left + right)/2;
    mergeSort(e, n, left, mid);
    
    mergeSort(e, n, mid, right);
    merge(e, n, left, mid, right);
  }
}

main(){
  int e[MAX], n, i;
  scanf("%d", &n);
  c = 0;
  for ( i = 0; i < n; i++ ) {
    scanf("%d", &e[i]);
    if (e[i] >= SENTINEL ){
      return 1;
    }
  }
  mergeSort(e, n, 0, n);

  for ( i = 0; i < n; i++ ) {
    if ( i!=0 ) printf(" ");
    printf("%d", e[i]);
    }
  printf("\n");

  printf("%d\n", c);

  return 0;
}


Measured memory_bytes: 5704
#include <bits/stdc++.h>
#define rp1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define rp0(i,n) for ((i)=0;(i)<(n);(i)++)
using namespace std;
const int maxn=(1<<18),mod=998244353;
inline void inc(int &x,int y){x+=y;if (x>=mod) x-=mod;}
inline void dec(int &x,int y){x-=y;if (x<0) x+=mod;}
inline int ppw(int x,int y){int z=1;while(y){if(y&1)z=1ll*z*x%mod;y>>=1;x=1ll*x*x%mod;}return z;}
int n,i;
int cc[100005],h[100005];
vector<int> v[100005];
int fac[maxn+5],inv[maxn+5],fi[maxn+5],lg[maxn+5],pw[maxn+5],w[maxn+5],iw[maxn+5];
int rev[maxn+5],a[maxn+5],b[maxn+5];
inline int c(int x,int y){
	return 1ll*fac[x]*fi[y]%mod*fi[x-y]%mod;
}
inline void init(){
    int i;for(i=2;i<=maxn;i++) lg[i]=lg[i>>1]+1;pw[0]=1;rp1(i,lg[maxn]) pw[i]=pw[i-1]*2; 
    fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;for(i=2;i<=maxn;i++){
        fac[i]=1ll*fac[i-1]*i%mod;inv[i]=(mod-mod/i)*1ll*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;
    }
    w[0]=1;w[1]=ppw(3,(mod-1)/maxn);for(i=2;i<=maxn;i++) w[i]=1ll*w[i-1]*w[1]%mod;
    iw[maxn]=ppw(w[maxn],mod-2);for(i=maxn-1;i>=0;i--) iw[i]=1ll*iw[i+1]*w[1]%mod;
}
inline int getrev(int x){
    int i,s=1;while (s<x) s*=2;rev[0]=0;rp1(i,s-1) rev[i]=((rev[i>>1]>>1)|((i&1)<<(lg[s]-1)));return s;
}
inline void ntt(int *a,int n,int *w){
    int i,j,k;
    rp0(i,n) if (rev[i]<i) swap(a[i],a[rev[i]]);
    for (i=1;i<n;i<<=1){int ys=maxn/i/2;
        for (j=0;j<n;j+=i+i){
            int *t=w;
            rp0(k,i){
                int x=a[j+k],y=1ll*a[j+k+i]*(*t)%mod;
                a[j+k]=x+y;if (a[j+k]>=mod) a[j+k]-=mod;
                a[j+k+i]=x-y;if (a[j+k+i]<0) a[j+k+i]+=mod;
                t+=ys;
            }
        }
    }
}
inline vector<int> mul(const vector<int> &aa,const vector<int> &bb){
    vector<int> ans;long long br=1ll*aa.size()*bb.size(),ft=1ll*(aa.size()+bb.size())*lg[aa.size()+bb.size()]*10+100;
    if (br<ft){
        while (ans.size()+1<aa.size()+bb.size()) ans.push_back(0);
        int i,j;rp0(i,aa.size()) rp0(j,bb.size()) inc(ans[i+j],1ll*aa[i]*bb[j]%mod);
    }
    else{
        int len=getrev(aa.size()+bb.size()),i;
        rp0(i,len) a[i]=b[i]=0;
        rp0(i,aa.size()) a[i]=aa[i];
        rp0(i,bb.size()) b[i]=bb[i];
        ntt(a,len,w);ntt(b,len,w);
        rp0(i,len) a[i]=1ll*a[i]*b[i]%mod;
        ntt(a,len,iw);int inv=ppw(len,mod-2);
        rp0(i,len) ans.push_back(1ll*a[i]*inv%mod);
    }
    while (!ans.empty()&&!ans.back()) ans.pop_back();
    return ans;
}
vector<int> solve(int l,int r){
	if(l==r) return v[l];
	int mid=(l+r)/2;
	vector<int> v0=solve(l,mid),v1=solve(mid+1,r);
	return mul(v0,v1);
}
int main(){
	init();
	scanf("%d",&n);
	rp1(i,n+n){
		scanf("%d",&h[i]);
		cc[h[i]]++;
	}
	rp1(i,100000){
		v[i].resize(cc[i]+1);
		int j;rp0(j,cc[i]/2+1){
			v[i][cc[i]-j-j]=((!(j&1))?1ll:(mod-1ll))*fac[j]%mod*c(cc[i],j+j)%mod*c(j+j,j)%mod*ppw(inv[2],max(0,j))%mod;
		}
	}
	vector<int> ans=solve(1,100000);
	int res=0;
	rp0(i,ans.size())if(!(i&1)){
		res=(res+1ll*ans[i]*c(i,i/2)%mod*ppw(inv[2],max(0,i/2))%mod*fac[i/2])%mod;
	}
	cout<<res<<endl;
	return 0;
}

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

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

    ll p[n];
    ll sum = 0, ma = 0;
    rep(i, n){
        cin >> p[i];
        ma = max(ma, p[i]);
        sum += p[i];
    }


    cout << sum - ma / 2 << endl;
}


Measured memory_bytes: 256
# E - Simple String Queries
from operator import or_


class SegmentTree:
    __slots__ = ["_default_value", "_seg_func", "_modifying_func", "_size", "_tree"]

    def __init__(self, initial_values: "Sequence", default_value: "Union[int, str]", seg_func: "Callable",
                 modifying_func: "Optional[Callable]" = None) -> None:
        self._default_value = default_value
        self._seg_func = seg_func
        self._modifying_func = modifying_func
        self._size = 1 << (len(initial_values) - 1).bit_length()
        self._tree = self._build(initial_values)

    def _build(self, initial_values: "Sequence") -> "List":
        """Build a segment tree with initial values."""
        tree = [self._default_value] * (2 * self._size)

        if self._modifying_func:
            initial_values = map(self._modifying_func, initial_values)

        for idx, val in enumerate(initial_values):  # set a tree
            tree[idx + self._size - 1] = val

        for idx in range(self._size - 2, -1, -1):  # build
            tree[idx] = self._seg_func(tree[2 * idx + 1], tree[2 * idx + 2])

        return tree

    def update(self, index: int, value: int) -> None:
        """Update index to value."""
        index += self._size - 1
        if self._modifying_func:
            value = self._modifying_func(value)
        self._tree[index] = value
        while index:
            index = (index - 1) // 2
            self._tree[index] = self._seg_func(self._tree[2 * index + 1], self._tree[2 * index + 2])

    def query(self, left: int, right: int) -> "Union[int, str]":
        """Respond to query in [left, right]."""
        left += self._size
        right += self._size
        result = self._default_value
        while left < right:
            if left & 1:
                result = self._seg_func(result, self._tree[left - 1])
                left += 1
            if right & 1:
                right -= 1
                result = self._seg_func(result, self._tree[right - 1])
            left >>= 1
            right >>= 1
        return result


def main():
    _, S, _, *queries = open(0).read().split()
    tree = SegmentTree(list(S), 0, or_, lambda c: 1 << (ord(c) - 97))
    ans = []
    popcount = lambda x: bin(x).count("1")
    for com, a, b in zip(*[iter(queries)] * 3):
        if com == "1":
            tree.update(int(a) - 1, b)
        else:
            ans.append(popcount(tree.query(int(a) - 1, int(b))))
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 49972