akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define double long double
#define stp setprecision
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define vi vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define ren(i,n) for(int i=n-1;i>=0;i--)
#define iter(it,v) for(auto it:v)
#define iterp(it,v) for(auto it=v.begin(),it!=v.end();it++)
#define itern(it,v) for(auto it=v.rbegin();it!=v.rend();it++)
#define forp(i,a,b) for(int i=a;i<=b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%d",&a)
#define pf(a) printf("%d",a)
#define init(a,r) for(auto&i:a) i=r;
#define initi(a,r) memset(a,r,sizeof(a))
#define inp(a) for(auto&i:a) cin>>i;
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bi back_inserter
#define all(v) v.begin(),v.end()
#define bitc __builtin_popcount
#define fst ios::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define pq priority_queue
#define pii pair<int,int>
#define mpii map<int,int>
#define cs(a) cout<<a<<' '
#define cn(a) cout<<a<<'\n'
#define deb(a,b) cout<<a<<' '<<b<<endl;
#define yy "YES"
#define nn "NO"
#define ff first
#define ss second
#define matrix vector<vector<int>>
#define mxe *max_element
#define mne *min_element
typedef long long ll;
const int mod=1e9+7,mod1=998244353;
const int N=2e5+7;
void a_b_l(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cn(ans);
}
signed main(){
    fst;
    int t=1;
    //cin>>t;
    while(t--)
    	a_b_l();
}

Measured memory_bytes: 3636
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#define M 1000003
//#define M  1046527
long long H[M];

void getChar(char *ch){
    for(int i = 0; i < strlen(ch); i++){
        if ( ch[i] == 'A') ch[i] = '1';
        else if ( ch[i] == 'C') ch[i] = '2';
        else if ( ch[i] == 'G') ch[i] = '3';
        else if ( ch[i] == 'T') ch[i] = '4';
    }
}

long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for ( i = 0; i < strlen(str); i++ ){
        sum += p*(str[i]);
        p *= 5;
    }
    return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
int h(int key, int i) {return (h1(key) + i * h2(key)) % M;}

int find(char str[]){
    long long key,i = 0;
    key = getKey(str);
    while(i <= M)
    {
        int t = h(key, i);
        if(H[t] == key){
            return 1;
        }
        else if(H[t] == -1){
            return 0;
        }
        i++;
    }
    return 0;
}

void insert(char str[]){

    long long i = 0,key;
    key = getKey(str);
    while(1)
    {
        int t = h(key, i);
        if(H[t] == key){
            return ;
        }
        else if(H[t] == -1 )
        {
            H[t] = key;
            return ;
        }
        i++;
    }
}

int main(){
    int i, n;
    char str[14], com[9];
    for ( i = 0; i < M; i++ ) H[i] = -1;
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf(" %s %s", com, str);

        if ( com[0] == 'i' ){
            getChar(str);
            insert(str);
        } else {
            getChar(str);
            if (find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 9492
S=input()
# Python3 program to Split string into characters 
def split(word): 
    return [char for char in word]  
word = S
splits=split(S)
Q=int(input())
flipcounter=0
prestring=[]
poststring=[]
for i in range(0,Q):
  inputforround=input()
  if inputforround=='1':
    flipcounter=flipcounter+1
  else:
    T,F,C=map(str,inputforround.split())
    if (int(F)+flipcounter)%2==1:
      prestring.append(C)
    else:
      poststring.append(C)
prestring.reverse()
for j in splits:
  prestring.append(j)
for k in poststring:
  prestring.append(k)
if flipcounter%2==1:
  prestring.reverse()
ans=''.join(prestring)
print(ans)


Measured memory_bytes: 110312
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int h = ReadInt();
        int w = ReadInt();
        int ch = ReadInt() - 1;
        int cw = ReadInt() - 1;
        int dh = ReadInt() - 1;
        int dw = ReadInt() - 1;
        string[] s = Read(h).ToArray();

        var que = new Queue<(int, int)>[1000000];
        for (int i = 0; i < 1000000; i++) que[i] = new Queue<(int, int)>();
        que[0].Enqueue((ch, cw));
        int[,] magic = new int[h, w];
        for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) magic[i, j] = 1000000;
        magic[ch, cw] = 0;
        for (int nc = 0; nc < 1000000; nc++)
        {
            while (que[nc].Any())
            {
                var (nh, nw) = que[nc].Dequeue();
                if (nh == dh && nw == dw)
                {
                    Console.WriteLine(nc);
                    return;
                }
                for (int dlh = -2; dlh <= 2; dlh++)
                {
                    for (int dlw = -2; dlw <= 2; dlw++)
                    {
                        if (nh + dlh < 0 || nh + dlh >= h) continue;
                        if (nw + dlw < 0 || nw + dlw >= w) continue;
                        if (s[nh + dlh][nw + dlw] == '#') continue;
                        if (magic[nh + dlh, nw + dlw] <= nc) continue;
                        int dlc = dlh * dlh + dlw * dlw == 1 ? 0 : 1;
                        que[nc + dlc].Enqueue((nh + dlh, nw + dlw));
                        magic[nh + dlh, nw + dlw] = nc + dlc;
                    }
                }
            }
        }
        Console.WriteLine("-1");
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

Measured memory_bytes: 127016
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int i,j,w,h,n,sx,sy,x,y,g=0;
cin>>w>>h>>n;
cin>>sx>>sy;
for(i=1;i<n;i++){
	cin>>x>>y;
	while(1){
		if(sx<x&&sy<y){
			j=min(abs(x-sx),abs(y-sy));
			sx=sx+j;
			sy=sy+j;
			g=g+j;//printf("nanameue\n");
		}
		else if(sx>x&&sy>y){
			j=min(abs(x-sx),abs(y-sy));
			sx=sx-j;
			sy=sy-j;
			g=g+j;//printf("nanameshita\n");
		}
		else if(sx>=x&&sy<y){
			j=abs(y-sy);
			sy=sy+j;
			g=g+j;//printf("ue\n");
		}
		else if(sx<x&&y<=sy){
			j=abs(x-sx);
			sx=sx+j;
			g=g+j;//printf("migi\n");
		}
		else if(sy>y&&sx<=x){
			j=abs(y-sy);
			sy=sy-j;
			g=g+j;//printf("shita\n");
		}
		else if(sx>x&&sy<=y){
			j=abs(x-sx);
			sx=sx-j;
			g=g+j;//printf("hidari\n");
		}
		//cout<<g<<endl;
		if(sx==x&&sy==y)break;
	}
	//cout<<x<<' '<<y<<endl<<sx<<' '<<sy<<endl<<g<<endl;
}
cout<<g<<endl;
return 0;
}









	

Measured memory_bytes: 3080
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;


int main()
{
  ll a, b, k;
  
  scanf("%lld %lld %lld", &a, &b, &k);
  
  if (a >= k)
    printf("%lld %lld\n", a-k, b);
  else if (b >= (k-a))
    printf("0 %lld\n", b-(k-a));
  else
    printf("0 0\n");
  
  return 0;
}


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

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <cassert>

using namespace std;

constexpr int mod = 1e9 + 7;
class atcoderC {
public:
    void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        
        vector<int> primes{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
        
        int64_t res = 1;
        for (size_t i = 0; i < primes.size(); ++i) {
            int cur = n / primes[i];
            int64_t cnt = cur;
            while (cur) {
                cur /= primes[i];
                cnt += cur;
            }
            //out << cnt << " ";
            res = res * (cnt + 1) % mod;
            //out << res << endl;
        }
        out << res << endl;
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	atcoderC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
from collections import defaultdict


def main():
    N, A, B = map(int, input().split())
    X_list = list(map(int, input().split()))

    ans = 0
    for i in range(len(X_list) - 1):
        d = abs(X_list[i] - X_list[i + 1])
        ans += min(A * d, B)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14636
#include<iostream>
using namespace std;
int main(void)
{
	int a[100000],n,k,i,cnt=0;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(k<=a[i]) cnt+=1;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n,k;
    cin>>n>>k;
    int v[n];
    int ans=0;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int l=0;l<=k;l++){
        for(int r=0;r<=k-l;r++){
            if(l+r>n) continue;
            int d=k-l-r;
            int now=0;
            vector<int> s;
            for(int i=0;i<=l-1;i++){
                now+=v[i];
                s.push_back(v[i]);
            }
            for(int i=n-r;i<=n-1;i++){
                now+=v[i];
                s.push_back(v[i]);
            }
            sort(s.begin(),s.end());
            for(int i=0;i<=d-1;i++){
                if(i>=s.size()) break;
                if(s[i]>0) break;
                now-=s[i];
            }
            ans=max(ans,now);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int n, *a;
	char *w, tmp, tmp2;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int *)calloc(130, sizeof(int));
		w = (char *)calloc(n+1, sizeof(char));
		for(int i = 1; i <= n; i++){
			cin >> tmp >> tmp2;
			a[(int)(tmp)] = i;
			w[i] = tmp2;
		}
		cin >> n;
		
		for(int i = 0; i < n; i++){
			cin >> tmp;
			if(a[(int)(tmp)] != 0){
				cout << w[a[(int)(tmp)]];
			} else {
				cout << tmp;
			}
		}
		cout << endl;
		
		free(a);
		free(w);
	}
	
	
	return 0;
}

Measured memory_bytes: 892
import sys
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
dc = {}
for i in range(n):
    s, p= input().split()
    if s not in dc:
        dc[s] = []
        dc[s].append((i+1, int(p)))
    else:
        dc[s].append((i+1,int(p)))
dc = sorted(dc.items())
for k, v in dc:
    v.sort(key=itemgetter(1), reverse=True)
    for i in range(len(v)):
        print(v[0][0])
        v.pop(0)


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;


int main() {
#ifdef LOCAL
    // freopen("input", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(12);
    int r, cols;
    cin >> r >> cols;
    int n;
    cin >> n;
    vector<vector<int>> ans(r, vector<int>(cols));
    int i = 0;
    int j = 0;
    int dj = 1;
    for (int c = 1; c <= n; ++c) {
        int k;
        cin >> k;
        for (int foo = 0; foo < k; ++foo) {
            ans[i][j] = c;
            if (j + dj >= cols || j + dj < 0) {
                i++;
                dj = -dj;
            } else {
                j += dj;
            }
        }
    }
    for (const auto& row : ans) {
        for (int c : row)
            cout << c << " ";
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define bl bool
#define INF 1e+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll fsqt(ll x,ll n)   // n:±íÊ¾´ÎÊý	  x:±íÊ¾µ×Êý
{
	return n==0 ? 1:x*fsqt(x,n-1);
}
int main(){
	ll p;
	read(p);
	cout<<fsqt(p,3)<<endl;
	return 0;
}

Measured memory_bytes: 256
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	int n,c; scanf("%d%d",&n,&c);
	vector<int> s(n),t(n),r(n),tsum(200020),sum(200020);
	rep(i,0,n) scanf("%d%d%d",&s[i],&t[i],&r[i]);
	rep(i,1,c+1){
		rep(j,0,200020) tsum[j]=0;
		rep(j,0,n) if(r[j]==i){
			tsum[s[j]*2-1]++;
			tsum[t[j]*2]--;
		}
		rep(j,0,200010) tsum[j+1]+=tsum[j];
		rep(j,0,200020) if(tsum[j]>0) sum[j]++;
	}
	int ans=0;
	rep(i,0,200020) ans=max(ans,sum[i]);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2944
h, w = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

ans = 0
for i in range(h):
    for j in range(w):
        if A[i][j] != -1:
            ans += C[A[i][j]][1]

print(ans)
        

Measured memory_bytes: 40284
#require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi

a.each do |i|
  h[i]+=1
end

ar=h.to_a.map{|i|i[1]}.select{|i|i>=2}
sum=sum(ar)-ar.size

puts n-(ceil sum,2)*2

Measured memory_bytes: 21028
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		System.out.println( factional( sc.nextInt() ) );
	}

	private static long factional(int nextInt) {
		int n = nextInt;

		long ans = (n == 0) ? 1: n * factional(n - 1);

		return ans;
	}

}


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


int main(){
 vector<int> str(3);
 for (int i = 0; i < 3; i++){
   cin >> str.at(i);
 } 
 sort(str.begin(), str.end());
 int cost = str.at(2) - str.at(0);
 cout << cost << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> P(N);
  rep(i,N){
    cin>>P.at(i);
  }
  int count=0,now=200100;
  rep(i,N){
    if(P.at(i)<now){
      count++;
      now=P.at(i);
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

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

    string s;
    for(int i = 0; i < 3; i++){
        cin >> s;
        char t =  toupper(s.at(0));
        cout << t;
    }




    return 0;
}


Measured memory_bytes: 256
int N,t,i,j,a[50][20];
int main(){
    char c[2]="",s[4]="SHCD";
    for(scanf("%d",&N);N--;){
        scanf("%s%d",c,&t);
        switch(c[0]){
            case'S':a[0][t-1]=1;break;
            case'H':a[1][t-1]=1;break;
            case'C':a[2][t-1]=1;break;
            case'D':a[3][t-1]=1;break;
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(a[i][j]==0)
            printf("%c %d\n",s[i],j+1);
        }
    }
}

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

int main(){
   long long int N, A, B;
   std::cin >> N >> A >> B;
   if ((B-A)%2 == 0){
      std::cout << (B-A)/2 << std::endl;
   } else{
      std::cout << std::min(A, N-B+1)+(B-A-1)/2 << std::endl;
   }
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 k;
    cin >> k;
    queue<int64> que;
    FOR(i,1,10)que.push(i);
    REP(i,k-1){
        int64 x = que.front();
        que.pop();
        if(x % 10 != 0){
            que.push(x * 10 + x % 10 - 1);
        }
        que.push(x * 10 + x % 10);
        if(x % 10 != 9){
            que.push(x * 10 + x % 10 + 1);
        }
    }
    ANS(que.front());
    return 0;
}

Measured memory_bytes: 1792
/* author : akshatjai258 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define int ll
#define mod int(1e9 + 7)
#define inf int(1e9)
#define endl "\n"
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define fi first
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define se second
#define mp make_pair
#define pb push_back
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define ps(x, y) fixed << setprecision(y) << x
void prep()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
}
int32_t main()
{
	prep();
	int n,m,x,ans=mod;
	cin>>n>>m>>x;
	vvi inp(n,vi(m+1));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			cin>>inp[i][j];
		}
	}
	for(int b=0;b<(1<<n);b++)
	{
		int cost=0;
		vi vec(m+1,0);
		for(int i=0;i<32;i++)
		{
			if(b&(1<<i))
			{
				cost+=(inp[i][0]);
				for(int k=1;k<=m;k++)
				{
					vec[k]+=inp[i][k];
				}
			}
		
			
		}
		int op=0;
		for(int i=1;i<=m;i++)
		{
			if(vec[i]>=x)
				op++;
		}
		if(op==m)
			ans=min(ans,cost);
	
	}
	if(ans==mod)
		cout<<-1;
	else
		cout<<ans;
		
	return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll a,b,c,d; cin >> a >> b >> c >> d;
  cout << max(max(a*c,a*d),max(b*c,b*d));
}


Measured memory_bytes: 3644
#include<iostream> 
#include<cstdio> 
using namespace std; 
int main()
{
    long long i,n,a,sum=0,min=10000000,max=-10000000;
    cin>>n;
    for(i=0;i<n;++i){
        cin>>a;
        if(max<=a)max=a;
        if(min>=a)min=a;
        sum=sum+a;
    }
    cout<<min<<" "<<max<< " "<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3108
def func(N, A_i, B_i):
    ans = 0
    for i in range(N):
        ans += min(A_i[i], B_i[i]) + min(A_i[i+1], max(0, B_i[i] - A_i[i]))
        A_i[i+1] = max(0, A_i[i+1] - max(0, B_i[i] - A_i[i]))
    return ans

N = int(input())
A_i = list(map(int, input().split(" ")))
B_i = list(map(int, input().split(" ")))
print(func(N, A_i, B_i))

Measured memory_bytes: 19156
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")

#include "bits/stdc++.h"
using namespace std;
#define PI 3.14159265358979323846264338327950L

long double findAngle(int h, int m)
{
    long double hourMove = (long double) (h+m/60.0)*5;
    long double minMove = (long double) m;
    long double diff = hourMove-minMove;
    //theta in radians. 360deg = 2*pi rad.
    long double theta = (long double)(2*PI)* (long double)(diff/60); // 360*(diff/60) in degrees
    return theta;
}

int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double theta = findAngle(h,m);
    // we've 2 sides and angle between them, hence cosine theorm.
    // a2 = b2 + c2 − 2bc cosA
    long double thirdSideSquared = (long double) (a*a+b*b) - (long double) (2*a*b*cos(theta));
    printf("%20.20Lf\n", sqrt(thirdSideSquared));
}


Measured memory_bytes: 3756
import java.util.*;
import java.util.stream.Collectors;
public class Main {
	public static void main(String[] args){
	   Scanner sc = new Scanner(System.in);
	  int N = sc.nextInt();
      int K = sc.nextInt();
      //System.out.println(N);
      //System.out.print( K);
      
      Integer[] P = new Integer[N];
      for(int i=0;i<N;i++){
      	P[i]= sc.nextInt();
       // System.out.print(P[i]+" ");
      }    
     	
      List<Integer> PList = Arrays.asList(P);
      
     PList = PList.stream()
       .sorted((p1, p2) -> p1.compareTo(p2))
       .collect(Collectors.toList());
      
       Integer sum = 0;
  for(int j=0;j<K;j++){
   sum += PList.get(j);
  }
  
  System.out.println(sum);
   }
}

Measured memory_bytes: 39992
module Main where

import Control.Applicative
import Text.Printf

main :: IO ()
main = loop 1

loop :: Int -> IO ()
loop i = do
  { [x] <- getInts
  ; if x == 0 then return ()
    else do
      { putStr $ printf "Case %d: %d\n" i x
      ; loop (i+1)
      }
  }
    

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show



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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    bool judge = false;
    vector<int> counter(n);rep(i, n)counter[i]==0;
    rep(i, n) counter[a[i]]++;
    ll ans = 1;
    if(n%2==0)
    {
        for(int i = 1; i < n; i+=2)
        {
            if(counter[i]!=2)
            {
               ans = 0;
               break;
            }
            ans *= 2;
            ans %= MOD;
        }
    }else
    {
        for (int i = 0; i < n; i += 2)
        {
            if(i==0)
            {
                if(counter[i]!=1)
                {
                    ans = 0;
                    break;
                }
                continue;
            }
            if (counter[i] != 2)
            {
                ans = 0;
                break;
            }
            ans *= 2;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;




int main(){
  int N,M,Q;
  cin >> N >> M >> Q;
  vector<int> l(Q+1);
  vector<int> m(Q+1);
  vector<int> n(Q+1);
  vector<int> o(Q+1);
  vector<int> A(11);
  rep(i,Q){
    cin >> l.at(i+1) >> m.at(i+1) >> n.at(i+1) >> o.at(i+1);
  }
  int sum=0;
  int max=0;

  for(int a=1;a<=M;a++){
    A.at(1) = a;
    for(int b=a;b<=M;b++){
      A.at(2) = b;
      for(int c=b;c<=M;c++){
        A.at(3) = c;
        for(int d=c;d<=M;d++){
          A.at(4) = d;
          for(int e=d;e<=M;e++){
            A.at(5) = e;
            for(int f=e;f<=M;f++){
              A.at(6) = f;
              for(int g=f;g<=M;g++){
                A.at(7) = g;
                for(int h=g;h<=M;h++){
                  A.at(8) = h;
                  for(int i=h;i<=M;i++){
                    A.at(9) = i;
                    for(int j=i;j<=M;j++){
                      A.at(10) = j;
                      for(int k=1;k<=Q;k++){
                        if(A.at(m.at(k))-A.at(l.at(k)) == n.at(k)){
                          sum += o.at(k);
                          if(sum > max){
                            max=sum;
                          }
                        }
                        if(k==Q)sum=0;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << max;

  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=20003,INF=1<<30;
const double eps=1e-12;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int R,N;cin>>R>>N;
        if(R==0&&N==0) break;
        
        vector<int> maxi(60,0.0);
        
        for(int i=0;i<N;i++){
            int l,r,h;cin>>l>>r>>h;
            for(int i=l;i+1<=min(r,0);i++){
                maxi[30+i+1]=max(h,maxi[30+i+1]);
            }
            for(int i=max(0,l);i<r;i++){
                maxi[31+i]=max(h,maxi[31+i]);
            }
        }
        
        double left=0.0,right=100.0;
        
        for(int q=0;q<100;q++){
            double mid=(left+right)/2.0;
            
            bool ok=true;
            
            for(int i=-R;i+1<=0;i++){
                double h=mid-double(R);
                h+=sqrt(double(R*R-(i+1)*(i+1)));
                if(h>maxi[30+i+1]+eps) ok=false;
            }
            
            for(int i=0;i<R;i++){
                double h=mid-double(R);
                h+=sqrt(double(R*R-i*i));
                if(h>maxi[31+i]+eps) ok=false;
            }
            
            if(ok) left=mid;
            else right=mid;
        }
        
        cout<<fixed<<setprecision(25)<<left<<endl;
        
        /*for(int i=25;i<=35;i++) cout<<maxi[i]<<" ";
        cout<<endl;*/
    }
}







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

const int maxn=1e6+10;
const int mod=1000000000+7;
const double eps=1e-6;


int main() {
   // freopen("test.txt","r",stdin);
    double n;
    cin>>n;
    printf("%.12f\n",(n/3)*(n/3)*(n/3));
    return 0;
}
/*

*/


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

n,m = map(int, readline().split())
data = list(map(int, read().split()))

point = [{0,10**9,-1*10**9} for _ in range(2)]
dic_en = [{} for _ in range(2)]
dic_de = [{} for _ in range(2)]

it = iter(data[:3*n])
for a,b,c in zip(it,it,it):
    point[0].add(a)
    point[0].add(b)
    point[1].add(c)

it = iter(data[3*n:])
for d,e,f in zip(it,it,it):
    point[0].add(d)
    point[1].add(e)
    point[1].add(f)

for i,p in enumerate(point):
    p = sorted(list(p))
    for after,before in enumerate(p):
        dic_en[i][before] = after
        dic_de[i][after] = before

len_x = len(point[0])
len_y = len(point[1])

wall_x = [[0] * (len_y-1) for _ in range(len_x)]
wall_y = [[0] * (len_y) for _ in range(len_x-1)]

it = iter(data[:3*n])
for a,b,c in zip(it,it,it):
    a,b,c = dic_en[0][a],dic_en[0][b],dic_en[1][c]
    wall_y[a][c] += 1
    if(b != len_x-1):
        wall_y[b][c] -= 1

it = iter(data[3*n:])
for d,e,f in zip(it,it,it):
    d,e,f = dic_en[0][d],dic_en[1][e],dic_en[1][f]
    wall_x[d][e] += 1
    if(f != len_y-1):
        wall_x[d][f] -= 1

for i in range(len_x):
    for j in range(1,len_y-1):
        wall_x[i][j] += wall_x[i][j-1]

for i in range(1,len_x-1):
    for j in range(len_y):
        wall_y[i][j] += wall_y[i-1][j]

start = (dic_en[0][0], dic_en[1][0])
area = [[0] * (len_y-1) for _ in range(len_x-1)]

ans = 0
stack = [start]
i,j = start
area[i][j] = 1
while(stack):
    i,j = stack.pop()
    ans += (dic_de[0][i+1] - dic_de[0][i])*(dic_de[1][j+1] - dic_de[1][j])
    #x+
    if(wall_x[i+1][j]==0):
        if(i==len_x-2):
            print('INF')
            exit()
        if(area[i+1][j] == 0):
            stack.append((i+1,j))
            area[i+1][j] = 1
    #x-
    if(wall_x[i][j]==0):
        if(i==0):
            print('INF')
            exit()
        if(area[i-1][j] == 0):
            stack.append((i-1,j))
            area[i-1][j] = 1
    #y+
    if(wall_y[i][j+1]==0):
        if(j==len_y-2):
            print('INF')
            exit()
        if(area[i][j+1] == 0):
            stack.append((i,j+1))
            area[i][j+1] = 1

    #y-
    if(wall_y[i][j]==0):
        if(j==0):
            print('INF')
            exit()
        if(area[i][j-1] == 0):
            stack.append((i,j-1))
            area[i][j-1] = 1

print(ans)

Measured memory_bytes: 581928
import java.io.*;

public class Main
{
    public static void main (String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);

        String str1 = br.readLine();
        String[] str2 = str1.split(" ", 0);
        double i[] = new double[3];

        for(int j=0; j<3; j++) {
        	i[j] = Integer.parseInt(str2[j]);
        	//System.out.println(i[j]);
        }

		double r = (i[0] - i[2]) / (i[1] + i[2]);

       	System.out.println((int)r);
       
    }
}

Measured memory_bytes: 21332
import Data.List
import Data.Maybe
import qualified Data.Map as M

digitNum :: Integral a => a -> a
digitNum = go 0
  where
    go i 0 = i
    go i x = go (i+1) (x `div` 10)

solve n = foldl f 0 $ map pair ns
  where
    ns = [1..n]
    m = M.fromListWith (+) $ map (\i -> (pair i,1)) ns
    pair i = (i `quot` 10^(digitNum i - 1), i `rem` 10)
    f a p = let p' = (snd p, fst p)
             in a + fromMaybe 0 (M.lookup p' m)

main :: IO ()
main = do
    n <- readLn :: IO Int
    print $ solve n

Measured memory_bytes: 35196
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>

#define INFL (1LL << 62)

using namespace std;

typedef long long ll;

bool between(ll a, ll b, ll c) {
    if ((a <= b && b <= c) || (a >= b && b >= c)) return true;
    return false;
}

int main() {
    int n, k;
    ll ans = INFL;
    scanf("%d%d", &n, &k);
    vector<ll> x(n + 1), y(n + 1);
    x.at(0) = -INFL, y.at(0) = -INFL;
    vector< pair<ll, ll> > d(n + 1);
    for (int i = 1; i <= n; ++i) scanf("%lld%lld", &x.at(i), &y.at(i)), d.at(i) = {x.at(i), y.at(i)};
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    sort(y.begin(), y.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    vector< vector<int> > s(x.size(), vector<int>(y.size()));
    for (int i = 1; i <= n; ++i) ++s.at(lower_bound(x.begin(), x.end(), d.at(i).first) - x.begin()).at(lower_bound(y.begin(), y.end(), d.at(i).second) - y.begin());
    for (int i = 1; i < int(x.size()); ++i) for (int j = 1; j < int(y.size()); ++j) s.at(i).at(j) += s.at(i - 1).at(j);
    for (int j = 1; j < int(y.size()); ++j) for (int i = 1; i < int(x.size()); ++i) s.at(i).at(j) += s.at(i).at(j - 1);
    for (int i = 1; i < int(x.size()); ++i) for (int j = 1; j < int(y.size()); ++j) for (int di = i; di < int(x.size()); ++di) for (int dj = j; dj < int(y.size()); ++dj) if (s.at(i - 1).at(j - 1) + s.at(di).at(dj) - s.at(i - 1).at(dj) - s.at(di).at(j - 1) >= k) ans = min(ans, (x.at(di) - x.at(i)) * (y.at(dj) - y.at(j)));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    cout << (N-2)*180 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAXN 100
#define MAXW 100000

typedef struct ABC {
  int v,w;
} ITEM;

ITEM A[MAXN+1];
long   S[MAXN+1][MAXW+1];

long   napsack ( int n, int w )
{
	int i,j;
	long long tmp1, tmp2;

	for ( i = 0; i <= w; i++ ) S[0][i] = 0;
	for ( i = 0; i <= n; i++ ) S[i][0] = 0;

	for ( i = 1; i <= n; i++ ) {
		for ( j = 1; j <= w; j++ ) {
			if ( A[i].w > j ) S[i][j] = S[i-1][j];
			else {
				tmp1 = S[i-1][j];
				tmp2 = S[i-1][j-A[i].w]+A[i].v;
				S[i][j] = tmp1 > tmp2 ? tmp1:tmp2;
			}
		}
	}

	return S[n][w];
}


int main(void)
{
	int n,i,w;

	scanf("%d", &n); scanf("%d", &w);
	for ( i = 1; i <= n; i++ ) scanf("%d%d", &A[i].w, &A[i].v);


	printf("%ld\n", napsack(n,w));

	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n;
	cin>>n;
	ll h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	ll chk = 0;
	ll cnt = 0;
	for(int i=0;i<n-1;i++){
		//cout<<h[i]<<' '<<h[i+1]<<' ';
		if(h[i]>=h[i+1]){
			cnt++;
			if(cnt>chk)chk=cnt;
		}
		
		else cnt=0;

		//cout<<chk<<" c "<<cnt<<endl;
		
				
	}

	cout<<chk<<endl;

}

Measured memory_bytes: 1024
S = gets.chomp.split(//)

count = 0
(2**(S.size-1)).times do |i|
    op = []
    S.size.times do |j|
        if i[j] == 0
            op << ""
        else
            op << "+"
        end
    end
    count += eval(S.zip(op).flatten!.join)
end
puts count

Measured memory_bytes: 2044
from pprint import pprint
import sys

N, W = map(int, sys.stdin.readline().strip().split(" "))

w = []
for _ in range(N):
    w_i, v_i = map(int, sys.stdin.readline().strip().split(" "))
    w.append((w_i, v_i))

dp = []
for _ in range(N+1):
    dp.append([0] * (W+1))


for i in range(N):
    for j in range(W+1):
        if j - w[i][0] >= 0:
            # dp[i+1][j] = max(dp[i][j - w[i][0]] + w[i][1], dp[i+1][j])
            dp[i+1][j] = dp[i][j - w[i][0]] + w[i][1]
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
# pprint(dp)
print(dp[N][W]) 

Measured memory_bytes: 120556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		int ans = 0, ans1 = 0;
		n = sc.nextInt();
		for(int i= 1; i <= n; ++i) {
			ans1 += 1;
			ans += ans1;
		}
		
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
vector<P> v[100001];
int n,m;
ll ans=1;
ll C[100005]={-1};
string s;
multiset<ll> lset,rset;
P a[100005];
P b[100005];
P c[100005];

ll x;
int main() {
	cin>>n;
	rep(i,0,n){
		cin>>x;
		a[i]=P(x,i);

	}
	rep(i,0,n){
		cin>>x;
		b[i]=P(x,i);
	}
	sort(a,a+n);
	sort(b,b+n);
	rep(i,0,n){
		if(a[i].first>b[i].first){
			cout<<"No"<<endl;
			return 0;
		}
		c[a[i].second].first=i;
		c[b[i].second].second=i;
	}
	int j=0,k=0;
	while(1){
//		cout<<k<<endl;
		if(c[0].second==c[k].first)break;
		k=b[c[k].first].second;
		j++;
	}

	if(j<n-1){
		cout<<"Yes"<<endl;
		return 0;
	}
	rep(i,0,n-1){
		if(b[i].first>=a[i+1].first){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    map<string, int> m;
    REP(i, N) {
        string S;
        cin >> S;
        if (m.find(S) != m.end()) {
            m[S]++;
        }
        else {
            m.insert(make_pair(S, 1));
        }
    }
    cout << m.size() << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;


int main()
{
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int ans = 0;
	
	for (int i = 0; i * r <= n; i++) {

		for (int j = 0; j * g <= n - i * r; j++) {

			if ((n - j * g - i * r) %b == 0) {
				
				ans++;
			}
		}
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n ,a[100005], m1,m2, i,t;
    scanf("%d",&n);
    m1=0;
    for(i=0;i<n;i++)
        {
            scanf("%d",a+i);
            if(a[i]>m1) m1=a[i];
        }
    m2=1e9+5;
    for(i=0;i<n;i++) {if(abs((m1+1)/2-a[i])<m2){m2=abs((m1+1)/2-a[i]);t=i;}}
    if(m1==a[t]) t++;
    printf("%d %d\n", m1, a[t]);
}


Measured memory_bytes: 512
/*
verified on 2020/3/1
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4222399
*/

#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

/* snippet starts */

#include <limits>

// 全対全の距離を求める N^3
template<typename dist_t>
class WarshallFloyd {

    int n; // 頂点数

    vector<vector<dist_t>> d;

public:

    static const dist_t INF;
    static const string INF_STR;

    WarshallFloyd(int _n) 
        : n(_n)
        , d((size_t)n, vector<dist_t>((size_t)n, INF)) {
        for (size_t i=0; i<(size_t)n; i++) d[i][i] = 0;
    }

    WarshallFloyd(int _n, vector<vector<dist_t>> &_d)
        : n(_n)
        , d(_d) {}

    inline void add_edge(int from, int to, dist_t dist) {
        d[(size_t)from][(size_t)to] = dist;
    }

    friend istream &operator>>(istream &is, WarshallFloyd &in) {
        dist_t d = 1;
        for (int i=0, u, v; i<in.input_edge_num; i++) {
            is >> u >> v;
            if (in.edge_length_input) is >> d;
            if (!in.zero_indexed_input) { u--; v--; }
            in.add_edge(u, v, d);
        }
        return is;
    }

    friend ostream &operator<<(ostream &os, const WarshallFloyd &in) {
        for (int i=0; i<in.n; i++)
            for (int j=0; j<in.n; j++)
                os << (in[i][(size_t)j] < INF ? to_string(in[i][(size_t)j]) : INF_STR) 
                   << (j < in.n-1 ? ' ' : '\n');
        return os;
    }

    // 負のループがある時trueを返す
    inline bool operator()() {
        for (size_t k=0; k<(size_t)n; k++)
            for (size_t i=0; i<(size_t)n; i++)
                for (size_t j=0; j<(size_t)n; j++)
                    if (d[i][k] < INF && d[k][j] < INF)
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        bool negloop = false;
        for (size_t k=0; k<(size_t)n; k++)
            for (size_t i=0; i<(size_t)n; i++)
                for (size_t j=0; j<(size_t)n; j++)
                    if (d[i][k] < INF && d[k][j] < INF && d[i][j] > d[i][k] + d[k][j]) {
                        negloop = true;
                        d[i][j] = -INF;
                    }
        return negloop;
    }

    auto &operator[](int i) { return d[(size_t)i]; }
    auto operator[](int i) const { return d[(size_t)i]; } 
    auto begin() { return d.begin(); }
    auto end()   { return d.end(); }
};


template<typename dist_t>
const dist_t WarshallFloyd<dist_t>::INF = numeric_limits<dist_t>::max();

template<typename dist_t>
const string WarshallFloyd<dist_t>::INF_STR = "INF";

/* Constructers
 *
 * WarshallFloyd(int _n, int _m, bool _directed=false, bool _edge_length_input=false, bool _zero_indexed_input=false) 
 * WarshallFloyd(int _n, vector<vector<dist_t>> _d, bool _directed=false)
 */

/* snippet ends */

int main() {
    int n, m;
    cin >> n >> m;
    WarshallFloyd<ll> wf(n);
    for (int i=0, u, v, d; i<m; i++) {
        cin >> u >> v >> d;
        wf.add_edge(u, v, d);
    }
    if (wf())
        cout << "NEGATIVE CYCLE" << '\n';
    else
        cout << wf;
    return 0;
}


Measured memory_bytes: 3364
h1, h2 = map(int, input().split())
k1, k2 = map(int, input().split())
a, b, c, d = map(int, input().split())
hiroshi = (a * h1) + (b * h2) + (divmod(h1, 10)[0] * c) + (divmod(h2, 20)[0] * d)
kenjiro = (a * k1) + (b * k2) + (divmod(k1, 10)[0] * c) + (divmod(k2, 20)[0] * d)
print("even" if hiroshi == kenjiro else ["hiroshi", "kenjiro"][hiroshi < kenjiro])

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int n,k;
    cin>>n>>k;
    if(k==1)cout<<0<<endl;
    else{
        cout<<n-k<<endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>

using namespace std;

queue<string> Q;
unordered_map<string, int> mp; 
const int dif[] = {1, 4, -1, -4};

void bfs()
{
	mp["01234567"] = 0;
	Q.push("01234567");
	string s, ns; int p, np;
	while(Q.size()){
		s = Q.front();
		Q.pop();
		for(int i = 0; i < 8; i++){
			if(s[i] == '0'){
				p = i;
				break;
			}
		}
		for(int i = 0; i < 4; i++){
			np = p + dif[i];
			if(np < 0 || np >= 8) continue;
			if( p == 3 && np == 4 || p == 4 && np == 3) continue;
			ns = s;
			char c = ns[p]; ns[p] = ns[np], ns[np] = c;
			if(mp.count(ns)) continue;
			mp[ns] = mp[s] + 1;
			Q.push(ns);
		}
	}
}

int main(void)
{
	bfs();
	
	int a[8]; string s;
	while(cin >> a[0]){
		for(int i = 1; i < 8; i++) cin >> a[i];
		s = "";
		for(int i = 0; i < 8; i++) s += a[i] + '0';
		cout << mp[s] << endl;
	}
	return 0;
}


Measured memory_bytes: 4868
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;++i){
		scanf("%d",a+i);
	}
	sort(a,a+n);
	map<int,int> mp,mp2;
	for(int i=0;i<n;++i){
		mp[a[i]]++;
	}
	int res=0;
	for(int i=n-1;i>=0;--i){
		if(mp2[a[i]]>0)continue;
		if(mp[a[i]] > a[i]){
			res += mp[a[i]]-a[i];
			mp2[a[i]]++;
		}
		else if(mp[a[i]]<a[i]){
			res += mp[a[i]];
			mp2[a[i]]++;
		}
	}
	printf("%d\n", res);
}

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

int main() {
  int N, now, count;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  B.at(0) = 1;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    now = A.at(now) - 1;
    if (B.at(now) == 0 && now != 1) {
      B.at(now)++;
      count++;
    }
    
    else if (now == 1) {
      cout << count + 1 << endl;
      break;
    }
    
    else {
      cout << -1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue> 

using namespace std;

int main(){
    int t,sum,s,e,n;
 
    while(true){
        scanf("%d",&t);
        if(t == 0)break;
 
        scanf("%d",&n);
 
        sum = 0;
 
        for(int i = 0; i < n; i++){
            scanf("%d %d",&s,&e);
            sum += e-s;
        }
 
        if(sum >= t){
            printf("OK\n");
        }else{
            printf("%d\n",t-sum);
        }
 
    }
 
 
    return 0;
    
  
}


Measured memory_bytes: 2692
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=200100;
typedef long long LL;
int n,a[maxn];
LL ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int now=n-1,t=0;ans+=a[n];
	for(int i=n-2;i;--i)
	{	
		if(t==2)
		{
			now--;
			t=0;
		}
		ans+=a[now];
		t++;
		//cout<<ans<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4572
n,k = gets.split.map(&:to_i)

if k > n
  puts 1
  exit
end

ans = 1
(k..n).each do |i|
  min = (1..(i-1)).sum
  max = ((n-i+1)..n).sum
  ans += max-min+1
end

puts ans % (10**9 + 7)

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

using namespace std;

#define pb push_back
#define X first
#define Y second
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define all(v) v.begin() , v.end()
#define int long long

typedef long long ll;

const ll INF = 1e18 ;
int n ; 

int32_t main()
{
 	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >>n ;
	int ans=0; 
	bool ok = 1 ; 
	while(n)
	{
		if(n<10)
			ans+=n-1 + ok ; 
		else
			ans+=9 ;
		if(n%10 != 9)
			ok = 0 ; 
		n/=10 ; 
	}
	cout << ans << endl ;
}



Measured memory_bytes: 256