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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S,T; cin >> S >>T ;
  if(S.size() + 1 != T.size()){
    cout << "No" << endl;
    return 0;
  }

  for(int i = 0; i < S.size(); i++){
    if(S[i] != T[i]){
      cout << "No" << endl;
      return 0;
    }

  }
  cout << "Yes" << endl;
}


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

int main() {
  vector<int> A(3) ; 
  for(int i = 0 ; i < 3; i++){
    cin >> A[i] ; 
  }
  sort(A.begin(),A.end());
  reverse(A.begin() , A.end());
  
  cout << abs(A[1] - A[0]) + abs(A[2] - A[1]) << endl ; 
  
}

Measured memory_bytes: 3620
def make_divisors(n):
    cnt = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1

    # divisors.sort()
    return cnt

n = int(input())
cnt = 0
for i in range(1,n + 1,2):
    if make_divisors(i) == 8:
        cnt += 1
print(cnt)
    

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;



int main() {
    int h, w, m;
    cin >> h >> w >> m;
    int h_max = 0; int w_max = 0;
    vector<pair<int, int>> target;

    vector<int> mh(h+10);
    vector<int> mw(w+10);
    rp(i, 0, m) {
        int x, y; cin >> x >> y;
        x--;y--;
        target.emplace_back(x, y);
        mh[x]++; mw[y]++;
        chmax(h_max, mh[x]);
        chmax(w_max, mw[y]);
    }
    ll res_x = 0ll;
    ll res_y = 0ll;
    rp(i, 0, h) {
        if(mh[i] == h_max) res_x++;
    }
    rp(i, 0, w) {
        if(mw[i] == w_max) res_y++;
    }
    ll d = 0ll;
    for(auto x: target) {
        if(mh[x.first] == h_max && mw[x.second] == w_max) d++;
    }
    
    if(res_x * res_y > d) cout << h_max + w_max << endl;
    else cout << h_max + w_max - 1 << endl;
    return 0;

}


Measured memory_bytes: 9780
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e4+9;
vector<int>adj[MAX];
int f=0;
int par[MAX];
int vis[MAX]={0};
void dfs(int u){
	vis[u]=1;
	for(int i=0;i<adj[u].size();i++){
		if(vis[adj[u][i]]==0){
			dfs(adj[u][i]);
		}
		else if(vis[adj[u][i]]==1)
			f=1;
	
	}
	vis[u]=2;
}
int main(){
	int n,m;
	cin>>n>>m;
	while(m--){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}
	for(int i=0;i<n;i++){
		if(vis[i]==0)
			dfs(i);
	}
	cout<<f<<"\n";

}


Measured memory_bytes: 3396
#include <iostream>

int main(int argc, char* argv[]){
  int a;
  std::cin >> a;
  if (a < 1200){
    std::cout << "ABC" << std::endl;
  } else if(a < 2800) {
    std::cout << "ARC" << std::endl;
  } else {
    std::cout << "AGC" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;

void ABC070D()
{
	int N;
	cin >> N;
	vector<int> ai(N-1), bi(N-1), ci(N - 1);
	for (int i = 0; i < N - 1; ++i)
	{
		cin >> ai[i] >> bi[i] >> ci[i];
	}

	int Q, K;

	cin >> Q >> K;

	struct Edge {
		int to;
		int dist;
	};
	vector<map<int, int> > graph(N + 1);

	for (int i = 0; i < N - 1; ++i)
	{
		graph[ai[i]][bi[i]] = ci[i];
		graph[bi[i]][ai[i]] = ci[i];
	}

	struct Tree {
		int parent;
		ll distance;
	};
	vector<Tree> tree(N + 1);
	tree[K].distance = 0;
	queue<int> qu;
	qu.push(K);
	while (!qu.empty())
	{
		int i = qu.front();
		qu.pop();
		ll theDist = tree[i].distance;
		for (auto& x : graph[i])
		{
			tree[x.first].parent = i;
			tree[x.first].distance = theDist + x.second;
			graph[x.first].erase(i);
			qu.push(x.first);
		}
	}

	for (int i = 0; i < Q; ++i)
	{
		int x, y;
		cin >> x >> y;
		cout << tree[x].distance + tree[y].distance << endl;
	}
}
int main()
{
	ABC070D();
	return 0;
}


Measured memory_bytes: 18560
using System;
namespace test
{
   class program
    {
        static void Main()
        {
            for (int i = 1; ; i++)
            {
                int x = int.Parse(Console.ReadLine());
                if (x == 0) break;                
                Console.WriteLine("Case {0}: {1}", i, x);
                
            }
        }
    }
}

Measured memory_bytes: 9404
def main():
    s = input()
    i = j = len(s) // 2
    if len(s) % 2 == 0:
        j -= 1
    ss = s[j]
    while len(s) > i and j >= 0 and ss == s[i] and ss == s[j]:
        i += 1
        j -= 1
    print(i)


main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
vector<ll> a;
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=1;i<=n;i++) {
		int x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	ll t=0;
	while(k!=0 && t<k && !a.empty()) {
		t++;
		vector<ll>::iterator it;
		it=a.end();
		it--;
		a.erase(it);
	}
	ll ans=0;
	for(int i=0;i<a.size();i++) {
		ans+=a[i];
		// cout<<a[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True

s = input()
n = len(s)
a = is_kaibun(s)
b = is_kaibun(s[:int((n-1)/2)])
c = is_kaibun(s[int((n+1)/2):])
if(a and b and c):print("Yes")
else:print("No")


Measured memory_bytes: 38384
from math import gcd

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
A,B=map(int,input().split())
GCD = gcd(A,B)
GCDs = make_divisors(GCD)
ans = [1 for i in range(len(GCDs)//2+1)]
for i in range(1,len(GCDs)//2):
  for j in range(i+1,len(GCDs)//2+1):
    if GCDs[j]%GCDs[i]==0:ans[j]=0
print(sum(ans))

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

using namespace std;

int main(){
    int n;
    while(cin >> n){
        vector<int > v;
        for(int i=0; i < n; i++){
            int m;
            cin >> m;
            v.push_back(m);
        }
        sort(v.begin(), v.end());

        int ans = 0;
        for(int i=0; i < v.size(); i++){
            if(i != 0) v[i] += v[i-1];
            ans += v[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline

def djkstra(a,in_connect_list,v,money_kind):

    out_shortest_list = [10**15 for i in range(v)]
    out_shortest_list[a] = 0
    searching_list = [a]
    
    while searching_list != []:
    
        new_search_list = []
        for i in searching_list:
            for j in in_connect_list[i]:
                c = j[0]
                p = j[money_kind] 
                if out_shortest_list[c] > p + out_shortest_list[i]:
                    out_shortest_list[c] = p + out_shortest_list[i]
                    new_search_list.append(j[0])
        searching_list = new_search_list

    return out_shortest_list

n, m, s, t = [ int(v) for v in input().split() ]
connect_list = [ [] for i in range(n) ]

for i in range(m):
    u, v, a, b = [ int(v) for v in input().split() ]
    connect_list[u-1].append((v-1,a,b))
    connect_list[v-1].append((u-1,a,b))


yen_list = djkstra(s-1,connect_list,n,1)
snuke_list = djkstra(t-1,connect_list,n,2)

remain_snule_list = [ 10**15 - yen_list[i] - snuke_list[i] for i in range(n) ][::-1]


for i in range(n-1):
    if remain_snule_list[i+1] < remain_snule_list[i]:
        remain_snule_list[i+1] = remain_snule_list[i]

remain_snule_list = remain_snule_list[::-1]

for i in remain_snule_list:
    print(i)

Measured memory_bytes: 83636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int main() {
    int n, x;

    std::cin >> n >> x;

    std::vector<int> v(2 * n - 1), ans;

    int center = n, val = 1;
    v[n - 1] = x;
    for (int i = center - 2; i >= 0; i--) {
        if (val == x) val++;
        v[i] = val;
        val++;
    }
    for (int i = 2 * n - 2; i >= center; i--) {
        if (val == x) val++;
        v[i] = val;
        val++;
    }
    ans = v;
    if(x != 1 && x != 2 * n - 1){
        std::cout << "Yes" << std::endl;
        for (int i = 0; i < v.size(); i++) {
            std::cout << ans[i] << std::endl;
        }
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#!python3

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

# input
N = int(input())
A = LI()

MOD = 10 ** 9 + 7
MAX = 10 ** 5 + 5
fac, finv, inv = [None] * MAX, [None] * MAX, [None] * MAX


def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = -inv[MOD%i] * int(MOD / i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def main():
    comb_init()
    d = {i: [] for i in range(1, N + 1)}
    x, y = [None] * 2
    for i in range(N + 1):
        d[A[i]].append(i)
        if len(d[A[i]]) == 2:
            x, y = d[A[i]]
            break
    
    for i in range(1, N + 2):
        ans = comb(N + 1, i)
        ans -= comb(N + x - y, i - 1)
        ans %= MOD
        print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, h[103];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> h[i+1];
	h[0] = 0; h[n+1] = 0; h[n+2] = 1;
	bool f = false;
	ll res = 0, v = 0;
	REP(i, n+2) {
		if (f && h[i] < h[i+1]) {
			f = false;
			res += v - h[i];
			v = h[i+1];
		}
		if (h[i] > h[i+1]) f = true;
		v = max(v, h[i+1]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class Main
{
  public static void main(String[] args) throws NumberFormatException, IOException
  {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    final String[] HEADER_STR = input.readLine().split(" ");

    final int MEMBER_COUNT = Integer.valueOf(HEADER_STR[0]);

    final int EVENT_COUNT = Integer.valueOf(HEADER_STR[1]);

    int[][] array = new int[MEMBER_COUNT][2];
    for (int i = 0; i < array.length; i++)
    {
      array[i][0] = i + 1;
    }

    int index = -1;
    int value = -1;

    int currentMaxIndex = MEMBER_COUNT + 1;
    int currentMax = -1;

    for (int i = 0; i < EVENT_COUNT; i++)
    {
      String[] INPUT_STR = input.readLine().split(" ");
      index = Integer.valueOf(INPUT_STR[0]);
      value = Integer.valueOf(INPUT_STR[1]);

      array[index - 1][0] = index;
      array[index - 1][1] += value;

      if (0 <= value)
      {
        if (currentMaxIndex == index)
        {
          currentMax = array[index - 1][1];
          systemOutput(array[index - 1][0], array[index - 1][1]);
          continue;
        }
        else if (currentMax > array[index - 1][1])
        {
          systemOutput(currentMaxIndex, currentMax);
          continue;
        }
        else if (currentMax < array[index - 1][1])
        {
          currentMaxIndex = index;
          currentMax = array[index - 1][1];
          systemOutput(currentMaxIndex, currentMax);
          continue;
        }
      }
      else
      {
        if (currentMaxIndex != index)
        {
          if (currentMax == array[index - 1][1] && currentMaxIndex > index)
          {
            currentMaxIndex = index;
            systemOutput(currentMaxIndex, currentMax);
            continue;
          }
          systemOutput(currentMaxIndex, currentMax);
          continue;
        }
      }

      Arrays.sort(array, new Comparator<int[]>() {
        public int compare(int[] o1, int[] o2)
        {
          if (o1[1] == o2[1])
          {
            return o1[0] - o2[0];
          }
          else
          {
            return o2[1] - o1[1];
          }
        }
      });
      currentMaxIndex = array[0][0];
      currentMax = array[0][1];
      Arrays.sort(array, new Comparator<int[]>() {
        public int compare(int[] o1, int[] o2)
        {
          return o1[0] - o2[0];
        }
      });
      systemOutput(currentMaxIndex, currentMax);
    }
  }

  private static void systemOutput(int menberNumber, int fishCount)
  {
    System.out.println(menberNumber + " " + fishCount);
  }
}



Measured memory_bytes: 98836
#include <iostream>

const unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913};
// generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)

inline unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

inline void shell_sort(unsigned a[], unsigned n){
  unsigned gap_num = 0;
  while(gaps[++gap_num] < n);
  gap_num--;

  unsigned count = 0;
  for(int i = gap_num; i >= 0; i--) count += insertion_sort(a,n,gaps[i]);

  std::cout << (gap_num+1) << '\n';

  for(int i = gap_num; i; i--) std::cout << gaps[i] << ' ';
  std::cout << gaps[0] << '\n';

  std::cout << count << '\n';
}

int main(){
  std::ios::sync_with_stdio(false);
  unsigned n;
  unsigned a[1000000];
  std::cin >> n;
  for(unsigned i = 0; i < n; i++) std::cin >> a[i];
  shell_sort(a,n);
  for(unsigned i = 0; i < n; i++) std::cout << a[i] << '\n';
}

Measured memory_bytes: 5100
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      for(int i = 0; i < s.length()-1; i++) {
        if(s.charAt(i) == s.charAt(i+1)) {
          System.out.println("Bad");
          return;
        }
      }
      System.out.println("Good");
  }
}


Measured memory_bytes: 23892
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def bfs(path, start, visited_set):
    que = deque([start])
    while 1:
        if len(que) == 0:
            break;
        nd = que.popleft()
        for adj in path[nd]:
            if adj not in visited_set:
                visited_set.add(adj)
                que.append(adj)



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    path = {}
    ofset = 1000000
    for i in range(N):
        path[i + ofset] = []

    for i in range(N):
        input_raw = read_func().strip().split()
        K = int(input_raw[0])
        for j in range(1, K + 1):
            path[i + ofset].append(int(input_raw[j]))
            if int(input_raw[j]) not in path:
                path[int(input_raw[j])] = [i + ofset]
            else:
                path[int(input_raw[j])].append(i + ofset)
    visited_set = set([])
    bfs(path, ofset, visited_set)
    for i in range(N):
        if i + ofset not in visited_set:
            print "NO"
            return
    print "YES"

if __name__ == '__main__':
    main()


Measured memory_bytes: 66924
/*input
1 7 10
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	ll n,a,b;
	cin>>n>>a>>b;
	if(a>b) return cout<<"0\n",0;
	if(n==1){
		if(a==b) cout<<"1\n";
		else cout<<"0\n";
		return 0;
	}
	n-=2;
	cout<<n*(b-a)+1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e9;
const long long MOD = 1e9+7;
signed main(){
    string s; cin >> s;
    if(s[s.size()-1]=='3') cout<<"bon"<<endl;
    else if(s[s.size()-1]=='0'||s[s.size()-1]=='1'||s[s.size()-1]=='6'||s[s.size()-1]=='8') cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}

Measured memory_bytes: 3624
((stdin) => {
  var lines = stdin.trim().split('\n');
  var n = Number(lines.shift());
  var ratings = lines.map(function(val, index) {
    var vals = val.split(' ');
    return [index, vals[0], Number(vals[1])];
  });
  ratings.sort(function(a, b) {
    if (a[1] === b[1]) {
      return b[2] - a[2];
    } else if (a[1] > b[1]) {
      return 1;
    } else {
      return -1;
    }
  });
  console.log(ratings.map(function(val) { return val[0] + 1; }).join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
def readln():
    return list(map(int, input().split()))


N, M, C = readln()
B = readln()

A = [readln() for _ in range(N)]

ans = 0
for a in A:
    tmp = sum([aa * b for aa, b in zip(a, B)]) + C
    if tmp > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	ll i, n, m, A = 0, B = 0;
	cin >> n >> m;
	vector<ll> a(n);
	vector<ll> b(m);
	vector<ll> as(n);
	vector<ll> bs(m);
	cin >> a[0];
	as[0] = a[0];
	for (i = 1; i < n; i++) {
		cin >> a[i];
		as[i] = a[i] + as[i - 1];
	}
	cin >> b[0];
	bs[0] = b[0];
	for (i = 1; i < m; i++) {
		cin >> b[i];
		bs[i] = b[i] + bs[i - 1];
	}
	for (i = 0; i < n; i++) {
		A += (i + 1) * a[i] - as[i];
		A %= PRIME;
	}
	for (i = 0; i < m; i++) {
		B += (i + 1) * b[i] - bs[i];
		B %= PRIME;
	}
	cout << (A * B) % PRIME << endl;
	return 0;
}

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

int c[40],a;
int main(){
  for(int i=0;i<41;i++){c[i]=0;}
  while(~scanf("%d",&a)){
    c[a]=1;
  }
  for(int i=1;i<=30;i++){
    if(c[i]==0){
      printf("%d\n",i);
    }
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll dp[110][200100];
ll dp2[110][200100];

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    dp[0][0] = 1;
    rep(i,100001){
        dp2[0][i+1] = 1;
    }
    rep(i,n){
        rep(j,100001){
            dp[i+1][j] = (mod+dp2[i][j+1]-dp2[i][max(0,j-a[i])])%mod;
        }
        rep(j,100001){
            dp2[i+1][j+1] = (dp2[i+1][j] + dp[i+1][j])%mod;
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C; cin >> A >> B >> C;
  int K; cin >> K;
  while(A >= B){
    B *= 2;
    K--;
  }
  while(B >= C){
    C *= 2;
    K--;
  }

  if(A < B && B < C && K >= 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int l,a,b;
	cin>>l>>a>>b;
	a += b;
	int ans = 0, j = l;
	for(int i = a; i<=l ; i+=a)
	{
		ans++;
		j -= a;
	}
	if(j<b)
		ans--;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
const int maxn = 1e5+5;

int cmp(long long int a,long long int b)
{
    return a>b;
}

struct node
{
    long long int num;
    long long int cnt;
}ans[maxn];

int main()
{
    long long int n;
    cin>>n;
    long long int a[maxn];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    long long int cnt = 0;
    long long int now = 0;
    ans[0].num = a[0];
    ans[0].cnt = 1;

    for(int i=1;i<n;i++)
    {
        if(a[i]==ans[now].num)
        {
            ans[now].cnt++;
        }
        else
        {
            now++;
            ans[now].num = a[i];
            ans[now].cnt = 1;
        }
    }
    long long int max1=0,max2=0;
    //cout<<now<<endl;
    for(int i=0;i<=now;i++)
    {
        if(ans[i].cnt>=4)
        {
            max1 = max(max1,ans[i].num);
            max2 = max(max2,ans[i].num);
        }
        if(ans[i].cnt>1&&ans[i].cnt<4)
        {
            if(ans[i].num>max1)
            {
                max2 = max1;
                max1 = ans[i].num;
            }
            else if(ans[i].num<max1&&ans[i].num>max2)
                max2 = ans[i].num;
        }
    }

    long long int ans0 = max1*max2;
    cout<<ans0;

}


Measured memory_bytes: 2560
# A - Serval vs Monster
# https://atcoder.jp/contests/abc153/tasks/abc153_a?lang=en
# s[0],[1]
# a = input().split()strs
def main():
  s = list(map(int,input().split()))
  hp = s[0]
  ad = s[1]
  ans = int(hp / ad)
  if(ans * ad < hp):ans = ans + 1
  print(ans)
if __name__ == '__main__':
  main()



Measured memory_bytes: 2940
n=input()
n=list(n)
if n[0]=="1":
	n[0]="9"
elif n[0]=="9":
	n[0]="1"
if n[1]=="1":
	n[1]="9"
elif n[1]=="9":
	n[1]="1"
if n[2]=="1":
	n[2]="9"
elif n[2]=="9":
	n[2]="1"
ans=int("".join(n))
print(ans)	

Measured memory_bytes: 3064
from collections import Counter


class UnionFind:
  def __init__(self, n):
    self.par = [x for x in range(n)]
    
  def find(self, x):
    if x == self.par[x]:
      return x
    self.par[x] = self.find(self.par[x])
    return self.par[x]
  
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x != y:
      self.par[y] = x

      
N, K, L = map(int, input().split())  

rails = UnionFind(N + 1)
roads = UnionFind(N + 1)

for _ in range(K):
  p, q = map(int, input().split())
  rails.unite(p, q)

for _ in range(L):
  p, q = map(int, input().split())
  roads.unite(p, q)

counter = Counter([
  (rails.find(p), roads.find(p))
  for p in range(1, N + 1)
])

print(' '.join(
  str(counter[(rails.find(i), roads.find(i))])
  for i in range(1, N + 1)
))   

Measured memory_bytes: 131544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep(j,n) for(int j = 0; j < n; j++)
using namespace std;

int main() {
	int N,M,C;
	double x;
	cin >> N >> M >> C;
	vector<int> B(M);
	int A;
	rep(i, M){
		cin >> B[i];
	}

	int sum = 0, ans = 0;
	rep(i, N){
		rep(j, M){
			cin >> A;
			sum += B[j] * A;
		}
		if(sum + C > 0){
			ans++;
		}
		sum = 0;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int main()
{
   int n,m;
   long long sum=0;
   cin>>n>>m;
   for(int i=1;i<=m;i++)
   {
   	cin>>a[i];sum+=a[i];
   }
   if(sum>n)cout<<-1<<endl;
   else
   cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3676
#include<cstdio>

int main(void){
	char c[101][101], r[101][101];
	int h, w, i, j;
	scanf("%d%d", &h, &w);
	for(i=0; i<101; ++i){ for(j=0; j<101; ++j){ r[i][j]=-1; } }
	for(i=0; i<h; ++i){ scanf("%s", c[i]); }
	for(i=0; i<h; ++i){
		r[i][0]=(c[i][0]=='c')?0:-1;
		for(j=1; j<w; ++j){
			r[i][j]=(c[i][j]=='c')?0:((r[i][j-1]!=-1)?r[i][j-1]+1:-1);
		}
	}
	for(i=0; i<h; ++i){ for(j=0; j<w; ++j){ if(j>0){ printf(" "); } printf("%d", r[i][j]); } puts(""); }
	return(0);
}


Measured memory_bytes: 2700
package main 

import ( 
        "fmt"
        "sort"
)

func main () {
        var n, a int
        ko := []int{}
        fmt.Scan(&n)
        for i := 0 ; i < n ; i++ {
                fmt.Scan(&a)
                ko = append (ko, a)
        }
        sort.Sort(sort.IntSlice(ko))
        x := ko[0]
        k := n -1
        y :=ko[k]
        fmt.Println(y-x)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

vector<int> g[100010];
map<pair<int, int>, pair<int, int> > memo;
pair<int, int> candidate[100010][2];
int notEnd[100010];
int n, B;

void CandidatePlus(int from, pair<int, int> nret) {
  if (nret.first > candidate[from][0].first) {
    candidate[from][1] = candidate[from][0];
    candidate[from][0] = nret;
  } else if (nret.first == candidate[from][0].first) {
    candidate[from][0].second += nret.second;
  } else if (nret.first > candidate[from][1].first) {
    candidate[from][1] = nret;
  } else if (nret.first == candidate[from][1].first) {
    candidate[from][1].second += nret.second;
  }
}

pair<int, int> dfs(int from, int parent) {
  int depth = -1;
  int size = -1;
  if (candidate[from][0].first == -1) {
    candidate[from][0] = make_pair(0, 0);
    FORIT(it, g[from]) {
      if (*it == parent) { continue; }
      pair<int, int> nret = dfs(*it, from);
      memo[make_pair(from, *it)] = nret;
      CandidatePlus(from, nret);
    }
  }
  if (notEnd[from] == parent) {
    depth = candidate[from][0].first;
    size = candidate[from][0].second + 1;
  } else if (notEnd[from] != -1) {
    pair<int, int> nret = dfs(notEnd[from], from);
    memo[make_pair(from, notEnd[from])] = nret;
    CandidatePlus(from, nret);
    notEnd[from] = -1;
    return dfs(from, parent);
  } else {
    pair<int, int> used = memo[make_pair(from, parent)];
    if (candidate[from][0].first == used.first &&
        candidate[from][0].second == used.second) {
      depth = candidate[from][1].first;
      size = candidate[from][1].second + 1;
    } else if (candidate[from][0].first == used.first) {
      depth = candidate[from][0].first;
      size = candidate[from][0].second - used.second + 1;
    } else {
      depth = candidate[from][0].first;
      size = candidate[from][0].second + 1;
    }
  }
  depth = max(depth, 1);
  if (size > B) {
    depth = max(1, depth + 1);
    size = 1;
  }
  return make_pair(depth, size);
}

int main() {
  int test_case = 0;
  while (scanf("%d %d", &n, &B), n|B) {
    test_case++;
    MEMSET(candidate, -1);
    REP(i, n) { g[i].clear(); }
    memo.clear();
    notEnd[0] = -1;
    REP(i, n - 1) {
      int t;
      scanf("%d", &t);
      t--;
      g[i + 1].push_back(t);
      g[t].push_back(i + 1);
      notEnd[i + 1] = t;
    }
    for (int i = n - 1; i > 0; i--) { dfs(i, notEnd[i]); }
    printf("Case %d:\n", test_case);
    REP(i, n) {
      printf("%d\n", dfs(i, i).first);
    }
  }
}

Measured memory_bytes: 19000
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int A, B;
    int btm, top;
    /* 入力 */
    scanf("%d%d", &A, &B);
    
    if(A <= B){
        btm = A;top = B;
    }else{
        btm = B;top = A;
    }
    /* 判定 */
    for(int i = btm; i <= top; i++){
        if( abs(A-i) == abs(B-i) && A != B ){
            printf("%d", i);
            return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 128
# AOJ 0590: Available Areas
# Python3 2018.6.30 bal4u

def check(s):
	u, v, x = 3, 4, 1
	while v <= s:
		if (s-x)%u == 0: return False
		u += 2
		x += 1
		v += x<<2
	return True

ans = 0
for i in range(int(input())):
	if check(int(input())): ans += 1
print(ans)


Measured memory_bytes: 5616
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();


		HashMap<Character, Integer> sMap = new HashMap<>();
		HashMap<Character, Integer> tMap = new HashMap<>();

		for (int i = 0; i < S.length; i++) {
			if (sMap.containsKey(S[i])) {
				sMap.put(S[i], sMap.get(S[i]) + 1);
			} else {
				sMap.put(S[i], 0);
			}
			if (tMap.containsKey(T[i])) {
				tMap.put(T[i], tMap.get(T[i]) + 1);
			} else {
				tMap.put(T[i], 0);
			}
		}

		int[] sCnt = new int[S.length];
		int[] tCnt = new int[T.length];
		for (int i = 0; i < S.length; i++) {
			if (sMap.containsKey(S[i])) {
				sCnt[i] = sMap.get(S[i]);
			}
			if (tMap.containsKey(T[i])) {
				tCnt[i] = tMap.get(T[i]);
			}
		}

		for (int i = 0; i < tCnt.length; i++) {
			if (sCnt[i] != tCnt[i]) {
				System.out.println("No");
				return;
			}
		}

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


Measured memory_bytes: 39572
from bisect import bisect

A, B, Q = map(int, input().split())
INF = 10 ** 18
S = [-INF]
T = [-INF]
for i in range(A):
    S.append(int(input()))
for i in range(B):
    T.append(int(input()))
S.append(INF)
T.append(INF)
for i in range(Q):
    x = int(input())
    sr = bisect(S, x)
    sl = sr - 1
    tr = bisect(T, x)
    tl = tr - 1
    def d(y): return abs(x - y)
    ans = min(d(max(S[sr], T[tr])), d(min(S[sl], T[tl])))
    ans = min(ans, 2 * d(S[sr]) + d(T[tl]))
    ans = min(ans, d(S[sr]) + 2 * d(T[tl]))
    ans = min(ans, 2 * d(S[sl]) + d(T[tr]))
    ans = min(ans, d(S[sl]) + 2 * d(T[tr]))
    print(ans)


Measured memory_bytes: 16964
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>

using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;

template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353

#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define init(v,size) v.resize(size); for(auto &a__: v) cin>>a__
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<endl

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;
}

template<class T> inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

ll nPr(ll n, ll r) {
	if(n<r) return 0;

	ll result=1LL;
	for(ll i=0; i<r; i++) result*=n-i;
	return result;
}

ll nPrP(ll n, ll r, ll p) { // mod pにおけるnPr
	if(n<r) return 0;

	ll result=1LL;
	for(int i=0; i<r; i++) {
		result*=n-i;
		result%=p;
	}
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}


string S;

void input() {
	cin>>S;
}

void solve() {
	cout<<(int)count(all(S),'g')-(int)(S.length()+1)/2<<endl;
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
  int n,i,array[105],ans;
  char str[101];
  scanf("%d",&n);
  scanf("%s",str);
  array[0]=0;
  for(i=1;i<n+1;i++){
    if(str[i-1]=='I'){
      array[i]=array[i-1]+1;
    }else{
      array[i]=array[i-1]-1;
    }
  }
  ans = 0;
  for(i=0;i<n;i++){
    if(array[i+1]>ans){
      ans=array[i+1];
    }
  }
  printf("%d\n",ans);

  return 0;
}


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

bool isRightTri(int a,int b,int c);
void swap(int& a,int &b);

int main(void){
  int n,a,b,c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b>>c;
    if(isRightTri(a,b,c)) cout<<"YES"<<endl; 
    else cout<<"NO"<<endl;
  }
  return 0;
}

bool isRightTri(int a,int b,int c){
  if(a>b) swap(a,b);
  if(b>c) swap(b,c);
  if(a*a+b*b-c*c==0) return true;
  return false;
}

void swap(int& a,int &b){
  int tmp;
  tmp=b;
  b=a;
  a=tmp;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int main(){
    long long N, P; cin >> N >> P;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    long long len = s.size();

    vector<long long> d(len+1);

    long long keta = 1;
    d[0] = 0;

    vector<long long> count(P+1, 0);
    count[0]++;

        for(long long i=0; i<len; ++i){
            long long digit = (s[i] - '0');
            long long a = (digit * keta) %P;
            d[i+1] = (d[i] + a) % P;
            keta *= 10;
            keta %= P;
            count[d[i+1]]++;
        }

    long long ans =0;

    if( P == 2 || P == 5){
        for(long long i=0; i<len; ++i){
            long long digit = (s[i] - '0');
            if(digit % P == 0){
                ans += len - i;
            }
        }
        
        
    }else{
        for(long long i=0; i<P; ++i){
            if(count[i] > 1){
                    ans += (count[i] * (count[i]-1) )/2;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5228
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = input[0];
            var b = input[1];

            Console.WriteLine(a > b ? new String(char.Parse(b.ToString()), a) : new String(char.Parse(a.ToString()), b));
        }
    }
}


Measured memory_bytes: 13396
K, N = map(int, input().split())
A = list(map(int, input().split()))

memo = []

for i in range(len(A)-1):
    distance = A[i+1] - A[i]
    memo.append(distance)

memo.append(K - A[-1] + A[0])
ans = sum(memo)
ans -= max(memo)
print(ans)


Measured memory_bytes: 26100
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;

int main() {
	int l, r;
	cin >> l >> r;
	if (r - l > 2020) {
		cout << 0 << endl;
		return 0;
	}
	int ans = inf;
	ff(i, l, r) {
		ff(j, i + 1, r + 1) {
			ans = min(ans, ((i % 2019) * (j % 2019))%2019);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7

int main() {
    ll N;
    cin >> N;
    vector<pair<ll, ll>> X(N+1);
    for(ll i = 1; i < N+1; i ++){
        cin >> X.at(i).first >> X.at(i).second;
    }
    sort(X.begin() + 1, X.end());
    
    
    vector<pair<ll,ll>> dp(N+1); //i個目まででの最大数と一番右にあるやつの右端
    dp.at(0) = make_pair(zero, zero);
    ll one = 1;
    dp.at(1) = make_pair(one, X.at(one).first + X.at(one).second );
    
    for(int i = 2; i < N+1; i++){
        if( X.at(i).first - X.at(i).second >= dp.at(i-1).second ){
            dp.at(i) = make_pair(dp.at(i-1).first + 1, X.at(i).first + X.at(i).second);
        }
        else{
            dp.at(i) = make_pair(dp.at(i-1).first, min(dp.at(i-1).second,  X.at(i).first + X.at(i).second));
        }
    }
    
    printf("%lld\n", dp.at(N).first);
    
    
}


Measured memory_bytes: 3328
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    maxA = A[-1]
    v = maxA / 2
    min_d = float('inf')
    min_i = None
    for i in range(n-1):
        d = abs(A[i]-v)
        if min_d > d:
            min_d = d
            min_i = i
    return  maxA, A[min_i]


if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))

Measured memory_bytes: 14060
#include<stdio.h>

int main(){
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    int x3, y3, x4, y4;
    x3 = x2 - (y2-y1);
    y3 = y2 + (x2-x1);
    x4 = x3 - (x2-x1);
    y4 = y3 - (y2-y1);
    printf("%d %d %d %d", x3, y3, x4, y4);

    return 0;
}

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

int main()
{
  double a, b;
  cin >> a >> b;
  
  vector<int> a_n, b_n;
  
  for (int i = 13; i <= 1262; i ++)
  {
    int a_fixed = (int)((double)i * 0.08);
    if (a_fixed >= a && a_fixed < (a + 1)) a_n.push_back(i);
  }
  for (int j = 10; j <= 1010; j ++)
  {
    int b_fixed = (int)((double)j * 0.1);
    if (b_fixed >= b && b_fixed < (b + 1)) b_n.push_back(j);
  }
  
  int a_size = a_n.size();
  int b_size = b_n.size();
  
  if (a_n.at(a_size - 1) < b_n.at(0))
    cout << "-1" << endl;
  else if (b_n.at(b_size - 1) < a_n.at(0))
    cout << "-1" << endl;
  else if (a_n.at(a_size - 1) >= b_n.at(0) && b_n.at(b_size - 1) >= a_n.at(a_size - 1))
    cout << b_n.at(0) << endl;
  else if (b_n.at(b_size - 1) >= a_n.at(0) && a_n.at(a_size - 1) >= b_n.at(b_size - 1))
    cout << a_n.at(0) << endl;
  else if (a_n.at(0) >= b_n.at(0) && b_n.at(b_size - 1) >= a_n.at(a_size - 1))
    cout << a_n.at(0) << endl;
  else if (b_n.at(0) >= a_n.at(0) && a_n.at(b_size - 1) >= b_n.at(b_size - 1))
    cout << b_n.at(0) << endl;

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int ans = (n+1)/2;
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string S,S_copy,T;
char temp;
bool not_exist =true;
int main(){
    cin >>S>>T;
    for(int time=0;time<S.size();++time){
        S_copy = S;
        for(int i=0;i<S.size();++i){
        S[(i+1)%S.size()] = S_copy[i];
        }
        if(S==T){
            not_exist = false;
            cout << "Yes"<< endl;
            break;
            }
            }
    if(not_exist){
        cout << "No" << endl;
    }        
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 110

int g[SIZE][SIZE], a[SIZE * SIZE];
int main() {
   int h, w, n, num = 1;
   scanf("%d %d %d", &h, &w, &n);
   for (int i = 1 ; i <= n ; ++i) scanf("%d", a + i); 
   for (int i = 0 ; i < h ; ++i) {
      int u = 1, st = 0, en = w;
      if (i & 1) {
         st = w - 1;
         en = -1;
         u = -1;
      }
      for (int j = st ; j != en ; j += u) {
         g[i][j] = ((a[num] != 0) ? num : ++num);
         --a[num];
      } 
   }
   for (int i = 0 ; i < h ; ++i) {
      for (int j = 0 ; j < w ; ++j) {
         printf("%d ", g[i][j]);
      }
      printf("\n");
   }
   return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
	int cnt[26]={0},i,ch;
	while(scanf("%c",&ch)!=EOF){
		if(97<=ch && ch<=122){
			cnt[ch-97]++;
		}
		else if(65<=ch && ch<=90){
			cnt[ch-65]++;
		}
	}
	for(i=0;i<26;i++){
		ch=97+i;
		printf("%c : %d\n",ch,cnt[i]);
	}
	return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  string s,t;cin>>s>>t;
  int n = s.size();
  fol(i,n){
    s = s[n-1]+s.substr(0,n-1);
    if(s==t){
      cout << "Yes"<<endl;
      return 0;
    }
  }
  cout << "No" <<endl;
  return 0;
}


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

using namespace std;

int x[90001], y[90001], D[90001];
int main()
{
    int h, w, d, a;
    cin >> h >> w >> d;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            cin >> a;
            x[a] = j, y[a] = i;
        }
    }
    for (int i = d + 1; i <= h * w; ++i)
        D[i] = D[i - d] + abs(x[i] - x[i - d]) + abs(y[i] - y[i - d]);

    int q;
    cin >> q;
    while(q--)
    {
        int i, j;
        cin >> i >> j;
        cout << D[j] - D[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int Takoyaki_Kazu = int.Parse(Console.ReadLine())-1;
            int[] Takoyaki = new int[Takoyaki_Kazu];
            string[] Takoyaki_oisisa = Console.ReadLine().Split(' ');
            int sum = 0;

            for(int i=0; i<=Takoyaki_Kazu; i++)
            {
                for(int k = i+1; k<=Takoyaki_Kazu; k++)
                {
                    sum = sum + int.Parse(Takoyaki_oisisa[i]) * int.Parse(Takoyaki_oisisa[k]);
                }
            }
           
           Console.WriteLine(sum);
        }
    }


Measured memory_bytes: 13140
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String args[]){
		Counter<Character> c=new Counter<>(26);
		for(char i='a'; i<='z'; i++)
			c.add(i,0);
		while(s.hasNextLine())
			for(char i:s.nextLine().toLowerCase().replaceAll("[^a-z]","").toCharArray())
				c.add(i);
		c.map.forEach((k, v)->System.out.printf("%c : %d\n",k,v));
	}
}

class Counter<T>{
	
	public HashMap<T, Integer> map;
	
	public Counter(int initSize){
		map=new HashMap<>(initSize);
	}
	
	public Counter(){
		this(10);
	}
	
	public void add(T key, int v){
		Integer i;
		if((i=map.get(key))==null){
			map.put(key,v);
		}else{
			map.put(key,i+v);
		}
	}
	
	public void add(T key){
		add(key,1);
	}
}

Measured memory_bytes: 32244