akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

typedef long long int LL;
typedef unsigned long long int ULL;
typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

const int INF = 1e9;
const LL INFF = 1e17;
const double EPS = 1e-9;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 10;
int main(){
 LL n;
 vector<LL> a(N);
 bool vis[N];
 memset(vis, 0, sizeof(vis));
 scanf("%lld", &n);
 LL side1 = 0, side2 = 0;
 REP(i, n)scanf("%lld", &a[i]);
 sort(a.begin(), a.begin() + n);
 reverse(a.begin(), a.begin() + n);
 REP(i, n - 1)if(a[i] == a[i + 1]){side1 = a[i], vis[i] = 1, vis[i + 1] = 1;break;}
 REP(i, n - 1)if(a[i] == a[i + 1] && !vis[i] && !vis[i + 1]){side2 = a[i];break;}
 printf("%lld\n", side1 * side2);
 return 0;
}


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


int main(){
    int d,g,p[10],c[10];
    cin>>d>>g;
    for(int i=0;i<d;i++)cin>>p[i]>>c[i];

    int ans=1e9;
    for(int bit=0;bit<(1<<d);bit++){
        int s=0,num=0,rest_max=-1;
        for(int i=0;i<d;i++){
            if(bit>>i&1){
                s+=100*(i+1)*p[i]+c[i];
                num+=p[i];
            }
            else rest_max=i;
        }
        if(s<g){
            int s1=100*(rest_max+1);
            int need=(g-s+s1-1)/s1;
            if(need>=p[rest_max])continue;
            num+=need;
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h,a;
    scanf("%d%d",&h,&a);
    int t,k;

    t=h/a;
    k=h%a;
    if(!k)
    {
        printf("%d\n",t);
    }
    else
    {
        printf("%d\n",t+1);
    }

    return 0;
}


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

int main()
{
    int n,m,a,b[100009];
    scanf("%d %d",&n,&m);
    int ans=0,ma=-1;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b[i]);
        ma=max(a,ma);
    }
    sort(b,b+n);
    for(int i=n-1;i>=0;i--)
    {
        if(b[i]<=ma) break;
        ans++;
        m-=b[i];
        if(m<=0) break;
    }
    int t=0;
    if(m>0) {t=m/ma;
    if(m%ma!=0) t++;}
    printf("%d\n",ans+t);
    return 0;
}


Measured memory_bytes: 640
class Osa_k:
    def __init__(self, n_max):
        self.n_max = n_max
        self.min_factor = min_factor = list(range(n_max + 1))
        min_factor[2::2] = [2] * (n_max // 2)
        min_factor[3::6] = [3] * ((n_max + 3) // 6)
        for i in range(5, int(n_max ** .5) + 1, 2):
            if min_factor[i] == i:
                for j in range(i*i, n_max + 1, i):
                    if min_factor[j] == j:
                        min_factor[j] = i

    def __call__(self, n):
        min_factor = self.min_factor
        t = []
        while n > 1:
            if t and t[-1][0] == min_factor[n]:
                t[-1][1] += 1
            else:
                t.append([min_factor[n], 1])
            n //= min_factor[n]
        res = 1
        for _, i in t:
            res *= i + 1
        return res

P = Osa_k(10**7)
print(sum(i * P(i) for i in range(1, int(input()) + 1)))


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

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

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
  string S, T;
  cin >> S >> T;
  ll ans = 0;
  REP(i, S.size()) if (S[i] != T[i]) ans++;
  PRINT(ans);
  return 0;
} 


Measured memory_bytes: 3960
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int k=sc.nextInt();
	int ar[]=new int[n];
	int i;
	int sum=1;
	int last=0;
	for(i=0;i<n;i++) {
		ar[i]=sc.nextInt();
	}
	
		for(i=0;i<n-k;i++) {
			if(ar[i]<ar[i+k]) {
				System.out.println("Yes");
			}else if(ar[i]>=ar[i+k]) {
				System.out.println("No");
			}
		}
		
		
		
	
	
}
}

Measured memory_bytes: 60800
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

#include <unistd.h>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<pair<int, int> > G[SIZE];

int ok[SIZE];

int N, T, S, E;
ll w[SIZE];
int counter[SIZE];

bool dfs1(int now, int back = -1) {
  bool res =  now == E;

  for(auto p : G[now]) {
    int to = p.first;
    int idx = p.second;
    if(to == back) continue;

    counter[now]++;
    res |= dfs1(to, now);
    counter[now]++;
  }

  return ok[now] = res;
}

priority_queue<pair<ll,pair<int,int> > > pq_[SIZE];
bool visited[SIZE];

pair<bool,bool> dfs2(int now, int back = -1) {
  auto &pq = pq_[now];
  bool res = true;

  visited[now] = true;

  for(auto p : G[now]) {
    int to = p.first;
    int idx = p.second;

    w[idx] -= T;

    if(to == back) continue;

    ll cost = w[idx];
    cost -= (ll)(counter[to] - 1) * T;
    cost += LLINF * ok[to];

    pq.push({-cost, {idx, to}});

  }

  while(pq.size()) {
    auto p = pq.top();
    pq.pop();

    int to = p.second.second;
    int idx = p.second.first;

    if (w[idx] <= 0) return {false, true};
    auto tmp = dfs2(to, now);
    if (tmp.second) return tmp;
    if (w[idx] <= 0) return {false, true};
    debug(idx);
    debug(w[idx]);

    res &= tmp.first;

    for(auto q : G[now]) {
      int idx = q.second;
      w[idx] -= T;
    }
  }

  return {res, now == E};
}


int main(){
  scanf("%d%d%d%d", &N, &T, &S, &E);
  S--; E--;

  for(int i=0; i<N-1; i++) {
    int a, b;
    scanf("%d%d%lld", &a, &b, w+i);
    a--; b--;

    if (a == S || b == S) {
      w[i] += T;
    }

    G[a].push_back({b, i});
    G[b].push_back({a, i});
  }

  dfs1(S);

  auto res = dfs2(S);

  if(res.first) {
    puts("Yes");

    for(int i=0; i<N; i++) assert(visited[i]);

  } else {
    puts("No");
  }

  return 0;
}



Measured memory_bytes: 22312
#include <stdio.h>

int main()
{
    while(1){
        int n,x;
        scanf("%d %d",&n,&x);
        if(n==0 && x==0){
            break;
        }
        int combination = 0;
        int i,j,k;
        for(i=1;i<n-1;i++){
            for(j=i+1;j<n;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        combination++;
                    }
                }
            }
        }
        printf("%d\n",combination);
    }
    return 0;
}


Measured memory_bytes: 2056
#include <stdio.h>
#define N 100

int main(){
  int i,j,k,length,count=0,mini;
  int A[N];
  
  scanf("%d",&length);
  for(i=0;i<length;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<length;i++){
    mini=i;
    for(j=i;j<length;j++){
      if(A[j]<A[mini]){
	mini=j;
      }
    }
    if(i<mini){
      k=A[i];
      A[i]=A[mini];
      A[mini]=k;
      count++; 
    }
  }
  
  for(i=0;i<length;i++){
    printf("%d",A[i]);
    if(i!=length-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
using System;
using System.Linq;
using System.Collections.Generic;


public class HelloWorld
{
    
    
    static List<long>[] Hedge;
    static long ans = 0;
    static Queue<long> que;
    
    static long N;
    
    static public void Main ()
    {
        var AB = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
        var A = AB[0];
        var B = AB[1];
        if(A <= 9 && B<= 9){
            Console.WriteLine(A*B);
        }else{
            Console.WriteLine(-1);
        }
        
    }
    
    static void CountPath(long[] Used,long count){
        if(que.Count == 0){
            return;
        }
      // Console.WriteLine(String.Join(" ",Used));
        var top = que.Dequeue();
        Used[top] = 1;
        count++;
        if(count == N){
            ans++;
            return;
        }else if(count > N){
            return;
        }
        foreach(long item in Hedge[top]){
            if(Used[item] == 0){
                que.Enqueue(item);
            var copy = new long[N+1];
            Used.CopyTo(copy, 0);
            CountPath(copy,count);
            }
            
        }
        
    }

}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    ll n,m; cin>>n>>m;
    vector<ll> a(n), b(n), c(m), d(m);
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,m) cin>>c[i]>>d[i];
    rep(i,n){
        ll tmp=1e10;
        ll res=-1;
        rep(j,m){
            if(abs(a[i]-c[j])+abs(b[i]-d[j]) < tmp){
                tmp=abs(a[i]-c[j])+abs(b[i]-d[j]);
                res=j+1;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
#coding:utf-8
h=Hash.new(0)
gets.chomp.bytes{|c|h[c]+=1}
n=0
f=true
while f
	f=false
	[[48,57],[97,122]].each{|start,stop|
		(start..stop).each{|i|
			j=i
			j+=1 while j<=stop&&h[j]>0
			if j-i>3
				f=true
				while i<j
					h[i]-=1
					i+=1
				end
				n+=1
				break
			end
		}
	}
end
p n*3+h.values.reduce(:+)

Measured memory_bytes: 8712
#include <iostream>
using namespace std;
int main()
{
 int n,k;
 cin>>n>>k;
 if(k%2)
 {
  long long ans=n/k;
  ans=ans*ans*ans;
  cout<<ans<<endl;
 }
 else
 {
  k/=2;
  long long ans=n/k;
  ans=(ans/2)*(ans/2)*(ans/2)+(ans-ans/2)*(ans-ans/2)*(ans-ans/2);
  cout<<ans<<endl;
 }
 return 0;
}

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

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F3F3F3F3F
#define MAX 300001
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll i = min(k, x / d);
    k -= i; x -= i * d;
    if (k % 2 == 0) cout << x;
    else cout << abs(x - d);
    cout << endl;
}

Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k, p[200010];
int ans = 1;
set<int> st;
int cnt = 1;
bool bl = false;

signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> p[i];
	for (int i = 0; i < k; i++) {
		st.insert(p[i]);
		if (i) {
			if (p[i - 1] < p[i])cnt++;
			else cnt = 1;
		}
	}
	if (cnt == k)bl = true;
	for (int i = k; i < n; i++) {
		if (p[i - 1] < p[i])cnt++;
		else cnt = 1;
		if (*st.begin() != p[i - k] || *st.rbegin() > p[i]) {
			if (!bl || cnt < k)ans++;
		}
		st.erase(p[i - k]);
		st.insert(p[i]);
		if (cnt >= k)bl = true;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
n = int(input())
ukv = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]

stack = []
visited = []
time = 0
d = [0] * (n + 1)
f = [0] * (n + 1)
for i in range(1, n + 1):
    if i not in visited:
        stack.append(i)
        visited.append(i)
        time += 1
        d[i] = time

        while stack:
            s = stack[-1]
            k = ukv[s][1]
            if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time

for i in range(1, n + 1):
    print(i, d[i], f[i])


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    bool flag = false;
    rep2(i, 1, 10)
    {
        if (n % i == 0)
        {
            int b = n / i;
            if (1 <= b && b <= 9)
            {
                flag = true;
                break;
            }
        }
    }

    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int K = sc.nextInt();
      ArrayList<Integer> hateNums = new ArrayList<>();
      for(int i = 0; i < K; i++){
        int D = sc.nextInt();
        hateNums.add(D);
      }
      
      // 条件値算出
      int result = 0;
      for(int i = N; i < 100000; i++){
        if(!containHateNum(i, hateNums)){
          result = i;
          break;
        }
      }
      
      // 出力
      System.out.println(result);
    }
    
    // 引数の値に嫌いな数字が含まれているか判定する関数
    public static boolean containHateNum(int target, ArrayList<Integer> hateNums){
      int workNum = target;
      
      while(workNum > 0){
        int digit = workNum % 10;
        if(hateNums.contains(digit)){
          return true;
        }
        
        workNum = workNum / 10;
      }
      
      return false;
    }
    
}

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int t, n;

    for ( int i = 0; i < 4; ++i ) {
        scanf("%d %d", &t, &n );
        if ( t == 1 ) {
            printf("%d\n", n * 6000 );
        } else if ( t == 2 ) {
            printf("%d\n", n * 4000 );
        } else if ( t == 3 ) {
            printf("%d\n", n * 3000 );
        } else {
            printf("%d\n", n * 2000 );
        }
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

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




Measured memory_bytes: 3200
N, M, X, Y = input().split()
N = int(N)
M = int(M)
X = int(X)
Y = int(Y)

xList = [int(x) for x in input().split()]
yList = [int(y) for y in input().split()]
xList.sort()
yList.sort()

if max(xList[-1], X) < min(yList[0], Y):
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void){
  int N;
  cin >> N;
  
  if( N%10 == 7 || (N%100)/10 == 7 || N/100 == 7  ){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }



  return 0;
}

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


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

    if(op=='+') cout << a+b <<endl;
    else cout << a-b <<endl;
}

Measured memory_bytes: 3588
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (n, _, x) = toTuple(readInts())
let ai = readInts()
print(min(ai.filter { $0 > 0 && $0 < x }.count, ai.filter { $0 > x && $0 < n}.count))

Measured memory_bytes: 13508
n, k = map(int, input().split())
h = list(map(int, input().split()))

def cost(i,j):
    return abs(h[i] - h[j])

dp=[10**9]*n
dp[0]=0

for i in range(1,n):
    for j in range(i-k,i):
        if j>=0:
            cst = dp[j]+cost(j,i)
            if dp[i] > cst:
                dp[i]=cst

print(dp[n-1])

Measured memory_bytes: 52704
#include <stdio.h>
#include <string.h>
#define MAX 100
int main(void) {
    int N, i, j, ans=0;
    
    char S[MAX];
    
    scanf("%d", &N);
    scanf("%s", S);
    
    for(i=0; i<N; i++) {
        int history[2][26]={0};
        for(j=0; j<=i; j++)
            history[0][S[j]-'a']++;
        
        for(j=i+1; j<N; j++)
            history[1][S[j]-'a']++;
        
        int cnt = 0;
        for(j=0; j<26; j++) {
            if(history[0][j]>0 && history[1][j]>0)
                cnt++;
        }
        
        if(ans<cnt)
            ans = cnt;
    }
    printf("%d\n", ans);
    return 0;
}

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

signed main() {
	vector<int> a(5);
	int k;
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
	}
	cin >> k;

	for (int i = 0; i < 5; ++i) {
		for (int j = 0; j < 5;++j) {
			if (abs(a[i] - a[j]) > k) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

signed main() {
    int h, w;
    cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    int ans = 100000000;
    for (int i = 0; i < h; i++) {
        int sa = i * w;
        int s = h * w - sa;
        int sb = ((h - i) / 2) * w;
        int sc = s - sb;
        int temp = max(sa, max(sb, sc)) - min(sa, min(sb, sc));
        ans = min(ans, temp);

        sb = (h - i) * (w / 2);
        sc = s - sb;
        temp = max(sa, max(sb, sc)) - min(sa, min(sb, sc));
        ans = min(ans, temp);
    }
    for (int i = 0; i < w; i++) {
        int sa = i * h;
        int s = w * h - sa;
        int sb = ((w - i) / 2) * h;
        int sc = s - sb;
        int temp = max(sa, max(sb, sc)) - min(sa, min(sb, sc));
        ans = min(ans, temp);

        sb = (w - i) * (h / 2);
        sc = s - sb;
        temp = max(sa, max(sb, sc)) - min(sa, min(sb, sc));
        ans = min(ans, temp);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
vector<ll> counter(200001);
vector<ll> tree[200001];

void countup(ll prev, ll next)
{
    counter[next] += counter[prev];
    for(auto elem:tree[next])
    {
		if(elem==prev)continue;
		countup(next, elem);
	}
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N,Q;
    cin >> N >> Q;
    //map<ll, vector<ll>> tree;
    for(size_t i=1;i<=N-1; i++)
    {
        ll a,b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    for(size_t i=0;i<Q; i++)
    {
        long p, x;
        cin >> p >> x;
        counter[p] += x;
    }
    countup(0L, 1L);
    for(size_t i=1;i<=N; i++)
    {
        cout << counter[i] << " ";
    }
    cout << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    string s,t;
    while(cin >> n >> s >> t) {
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            if(s.substr(n-i,i) == t.substr(0,i)) {
                ans = i;
            }
        }
        cout << 2*n - ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<string> A(N);
  vector<int> B(N);
  map<string, int> m{};
  for (auto& a : A) {
    cin >> a;
    ++m[a];
  }
  for (int i = 0; i < N; ++i) {
    B[i] = m[A[i]];
  }
  auto cnt = *boost::max_element(B);
  map<string, int> res{};
  for (int i = 0; i < N; ++i) {
    if (B[i] == cnt) {
      // res.emplace(A[i]);
      res[A[i]];
    }
  }
  for (const auto& p : res) {
    cout << p.first << CRLF;
  }
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;
    REP2(m, 1, M) {
        REP2(d, 1, D) {
            int d1 = d / 10;
            int d2 = d % 10;
            if (d1 >= 2 && d2 >= 2 && d1 * d2 == m) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	vector<int> a(10.0);
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	for (int i = 0; i < 3; i++) {
		cout << a[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
int n;
string s;
  while(cin>>n){
    cin>>s;
    int cnt1=0, cnt2=0;
    for(int i=0; i<n; ++i){
        if(s[i]=='R')
            ++cnt1;
        else
            ++cnt2;
    }
    if(cnt1>cnt2){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000005
long long cnt;
int l;
int A[maxn];
int n;
vector<int> G;
void insertionSort(int A[],int n,int g)
{
    for(int i=g;i<n;i++)
    {
        int v=A[i];
        int j=i-g;
        while(j>=0&&A[j]>v)
        {
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}
void shellSort(int A[],int n)
{
    for(int h=1;;)
    {
        if(h>n) break;
        G.push_back(h);
        h=3*h+1;
    }
    for(int i=G.size()-1;i>=0;i--)
    {
        insertionSort(A,n,G[i]);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    cnt=0;
    shellSort(A,n);
    cout<<G.size()<<endl;
    for(int i=G.size()-1;i>=0;i--)
    {
        printf("%d",G[i]);
        if(i) printf(" ");
    }
    printf("\n%lld\n",cnt);
    for(int i=0;i<n;i++) printf("%d\n",A[i]);
    return 0;
}

Measured memory_bytes: 7164
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]
counter = 1000

for i in range(2**D):
    x = bin(i)[2:]
    x = '0' * (D-len(x)) + x
    total = 0
    newCounter=0
    for j in range(len(x)):
        if x[j] == '1':
            total += pc[j][0]*100*(j+1)+pc[j][1]
            newCounter += pc[j][0]

    if total >= G:
        counter = min(counter, newCounter)

    else:
        for j in range(len(x)-1, -1, -1):
            if x[j] == '0':
                for k in range(1, pc[j][0]):
                    total += 100*(j+1)
                    newCounter += 1
                    if total >= G:
                        counter = min(counter, newCounter)
                        break
                break

print(counter)


Measured memory_bytes: 3064
int main(void){
    int i=0;
    int j=0;
    
    int t[9<<14]={};
    int max=0;
    int scn=0;
    
    for(;~scanf("%d",&t[i]);i++){
        i*(t[i]>max)?max=t[i]:0;
    }
    for(;++j<t[0]+2;){
        if(abs(t[j]-max/2)<abs(scn-max/2))scn=t[j];
    }
    printf("%d %d",max,scn);
}

Measured memory_bytes: 2304
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var abc = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (a, b, c) = (abc[0], abc[1], abc[2]);
        var ans = a * b / 2;

        WriteLine(ans);
    }
}


Measured memory_bytes: 28260
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,n,c,i,x,y,z,w=0;
  cin>>a>>b>>c;
  if(a==b&&b==c&&c%2==0)
  {
     cout<<"-1"<<endl;
     return 0;
  }
  while(a%2==0 && b%2==0 && c%2==0)
  {
     x=a,y=b,z=c;
     a=(y/2)+(z/2);
     b=(z/2)+(x/2);
     c=(x/2)+(y/2);
     w++;
  }
 cout<<w<<endl;
 return 0;

}


Measured memory_bytes: 3600
N,K=map(int,input().split())
MOD=10**9+7

fac=[1]*(N+1)
ifac=[1]*(N+1)
for i in range(2,N+1): fac[i]=fac[i-1]*i%MOD
ifac[N]=pow(fac[N],MOD-2,MOD)
for i in range(N,1,-1): ifac[i-1]=ifac[i]*i%MOD

for i in range(1,K+1):
    blue=K
    red=N-K
    if red<i-1:
        print(0)
        continue
    ans=fac[red+1]*ifac[red+1-i]*ifac[i]%MOD
    ans*=fac[blue-1]*ifac[blue-1-(i-1)]*ifac[i-1]%MOD
    ans%=MOD
    print(ans)


Measured memory_bytes: 3444
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 1;i <= 7;i++) {
			if(Math.pow(2,i) > n){
				System.out.print((int) Math.pow(2,i-1));
				break;
			}
		}
	}
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
PII res[N];

int main()
{
	cin >> n >> m;
	int t = (n - 1) * (n - 2) / 2;

	if (m > t)
	{
		puts("-1");
		return 0;
	}
	
	int k = 0;
	for (int i = 2; i <= n; i ++ ) res[k ++ ] = {1, i};
	
	for (int i = 2; i <= n; i ++ )
		for (int j = i + 1; t > m && j <= n; j ++ , t -- )
			res[k ++ ] = {i, j};
	
	cout << k << endl;
	for (int i = 0; i < k; i ++ )
		cout << res[i].F << ' ' << res[i].S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 705
using namespace std;
struct Edge{
	int v,nxt;
}E[N*N];
bool flag;
int col[N],ans1,ans2,sum1,sum2,en,n,m,head[N],f[N][N],delta[N],t,sum,dp[N],ans;
void addedge(int u,int v){
	E[++en].v=v,E[en].nxt=head[u],head[u]=en;
}
void bfs(int s){
	queue <int> que;
	que.push(s);
	col[s]=0;
	while (!que.empty()){
		int u=que.front();
		que.pop();
		for (int e=head[u];e;e=E[e].nxt){
			int v=E[e].v;
			if (col[v]==col[u]){
				flag=true;return;
			}else
			if (col[v]==-1){
				que.push(v);
				col[v]=col[u]^1;
			}
		}
	}
}
int calc(int x){
	return x*(x-1)/2;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		f[u][v]=f[v][u]=1;
	}//printf("\n");
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++) if (f[i][j]==0){
			addedge(i,j);
			addedge(j,i);
			//printf("%d %d\n",i,j);
		}
	for (int i=1;i<=n;i++) col[i]=-1;
	for (int i=1,now=0;i<=n;i++)
		if (col[i]==-1){
			bfs(i);sum1=sum2=0;
			if (flag){
				printf("-1\n");
				return 0;
			}
			for (int j=1;j<=n;j++){
				if (col[j]==1) sum1++,col[j]=2;else
				if (col[j]==0) sum2++,col[j]=2;
			}
			if (sum1>sum2) swap(sum1,sum2);
			delta[++t]=sum2-sum1,sum+=delta[t];
			//printf("%d\n",delta[t]);
		}
	dp[0]=1;
	for (int i=1;i<=t;i++)
		for (int v=sum/2;v>=delta[i];v--)
			dp[v]|=dp[v-delta[i]];
	for (int v=0;v<=sum/2;v++) if (dp[v]>0) ans=v;
	ans=sum-(ans<<1);
	ans1=(n+ans)/2,ans2=(n-ans)/2;
	printf("%d\n",calc(ans1)+calc(ans2));
	return 0;
}

Measured memory_bytes: 7440
import fractions
import math
n,num=map(int,input().split())
num_set=set(map(lambda x:int(x),input().split()))
two_times_set=set()

for i in num_set:
    for j in range(1,30):
        i//=2
        if i%2!=0:
            two_times_set.add(j)
            break

    if len(two_times_set)!=1:
        print(0)
        break
else:
    num_list=list(num_set)
    lcm=num_list[0]
    for i in range(1,len(num_list)):
        
        lcm = lcm * num_list[i] // fractions.gcd(lcm, num_list[i])
        
    print((num-lcm//2)//(lcm)+1)


Measured memory_bytes: 13344
#include<iostream>
#include<string>
#include<array>
using namespace std;

int main() {
	int n,ans=0;
	cin >> n;
	array<int, 30> a,b,c;

	for (int i = 1; i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		ans += b[i];
	}
	for (int i = 1; i <= n-1; i++) {
		cin >> c[i];
	}
	for (int i = 1; i <= n-1; i++) {
		if (a[i]+1==a[i+1]) {
			ans += c[a[i]];
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix(int A[],const int N)
{
  int temp[200001];
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,N)u[A[i]>>8*k&255]++;
    rep(i,255)u[i+1]+=u[i];
    rep(i,N){temp[--u[A[N-1-i]>>8*k&255]]=A[N-1-i];}k++;
    rep(i,N)v[temp[i]>>8*k&255]++;
    rep(i,255)v[i+1]+=v[i];
    rep(i,N)A[--v[temp[N-1-i]>>8*k&255]]=temp[N-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,minus=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix(A,m+p);
  rep(i,m)A[p+i]*=-1;
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{mid*=-1l;minus=1;int low=0;rep(i,m){while(1l*A[low]*A[p+i]<mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K){if(minus)r=-mid-1l;else r=mid-1l;}else{if(minus)l=-mid+1l;else l=mid+1l;}
  }
  return OUT(l),0;
}

Measured memory_bytes: 2916
#include <cmath>
#include <climits>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  int A, B; cin >> A >> B;
  int sc[3] = {};
  for (int i = 0; i < N; ++i) {
    int P; cin >> P;
    if (P <= A)               sc[0]++;
    else if (A < P && P <= B) sc[1]++;
    else if (B < P)           sc[2]++;
  }
  cout << min({sc[0], sc[1], sc[2]}) << endl;
}


Measured memory_bytes: 3604
def resolve():
    s = input()
    t = input()
    d = {}
    for i, c in enumerate(list(s)):
        d.setdefault(c, [])
        d[c].append(i)
    
    import bisect
    nloops = 0
    prev = -1
    for c in list(t):
        if c not in d:
            print(-1)
            return
        # prevより後ろにあるcのうち、最も近いものの位置
        cidx = bisect.bisect_left(d[c], prev)
        if cidx < len(d[c]) and prev == d[c][cidx]:
            cidx += 1
        nearc = d[c][cidx] if cidx < len(d[c]) else None
        if nearc is None:
            nloops += 1
            nearc = d[c][0]
        prev = nearc
    print(nloops*len(s)+prev+1)



if '__main__' == __name__:
    resolve()

Measured memory_bytes: 85264
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long A=1;
		long B=1;
		for(int i=0; i<n; i++){
			long t=sc.nextLong();
			long a=sc.nextLong();
			long x=Math.max((A+t-1)/t,(B+a-1)/a);
			A=t*x;
			B=a*x;
		}
		System.out.println(A+B);
	}
}


Measured memory_bytes: 24660
n=int(input())
if n<=599:
  print('8')
elif n<=799:
  print('7')
elif n<=999:
  print('6')
elif n<=1199:
  print('5')
elif n<=1399:
  print('4')
elif n<=1599:
  print('3')
elif n<=1799:
  print('2')
elif n<=1999:
  print('1')

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL H,W;
int main(){
    cin>>H>>W;
    LL ans=10e12;
    //横分割
    if(H>=3){
       if(H%3==0){
          ans=0;
       }else{
          ans=min(ans,W);
       }
    }
    //縦分割
    if(W>=3){
       if(W%3==0){
          ans=0;
       }else{
          ans=min(ans,H);
       }
    }
    //よこ1
    for(int i=1;i<H;i++){
        LL a=i*W;
        LL b=(H-i)*(W/2);
        LL c=(H-i)*((W+1)/2);
        LL d=0;
        d=max(d,abs(a-b));
        d=max(d,abs(a-c));
        d=max(d,abs(c-b));
        //cout<<a<<" "<<b<<"c"<<c<<endl;
        //cout<<"d"<<d<<endl;
        ans=min(ans,d);
    }
    //たて1
    for(int i=1;i<W;i++){
        LL a=i*H;
        LL b=(W-i)*(H/2);
        LL c=(W-i)*((H+1)/2);
        LL d=0;
        d=max(d,abs(a-b));
        d=max(d,abs(a-c));
        d=max(d,abs(c-b));
        //cout<<"dd"<<d<<endl;
        ans=min(ans,d);
    }
    
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 256
class Integer
def gcd(other)
  min = self.abs
  max = other.abs
  while min > 0
    tmp = min
    min = max % min
    max = tmp
  end
  max
end
def lcm(other)
  g = self.gcd(other)
  self * other / g
end
end

while STDIN.gets do
  a, b = $_.split(" ").map(&:to_i)
  puts "#{a.gcd(b)} #{a.lcm(b)}"
end

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

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            sum += a[i];
        }
        Arrays.sort(a);
        System.out.println(a[0] + " " + a[n - 1] + " " + sum);
    }
}


Measured memory_bytes: 41268
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, sum, ans;
	
	while(cin >> n, n)
	{
		sum = 0; ans = 0;
		queue<int> q;

		for(int i = 1; i <= n/2 + 1; i++)
		{
			q.push(i);
			sum += i;

			while(sum > n)
			{
				sum -= q.front();
				q.pop();
			}

			if(sum == n && q.size() >= 2)
			{
				ans++;
				/*
				queue<int> debug = q;

				while(!debug.empty())
				{
					printf("%d ",debug.front());
					debug.pop();
				}
				puts("");
				*/
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1200
import sys
input = sys.stdin.readline
import numpy as np
 
N=int(input())
A = np.array([int(x) for x in input().split()])
if N==2:
  print(abs(A[0]-A[1]))
else:
  B = np.concatenate([[0],A.cumsum()])
  H = np.searchsorted(B,sum(A)//2)
  result=float('inf')
  for i in range(min(5,len(A)//2)):
    result=min(result,abs(sum(A[:H+i])-sum(A[H+i:])),abs(sum(A[:H-i])-sum(A[H-i:])))

  print(result) 

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



int main() {
    ll n;
    cin >> n;
    
    ll y = 1;
    for(ll i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            y = i;
        }
    }
    //cout << y << endl;
    cout << n/y + y - 2 << endl;
    
    
    
    return 0;
}




Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
#define ii pair<int, int>
#define x first
#define y second
int k;
bool visited[1000001];

int main(){
    cin >> k;
    deque<ii> q;
    q.push_back(ii(1, 1));
    while(!q.empty()){
        ii u = q.front(); q.pop_front();
        if (visited[u.x]) continue;
        visited[u.x] = true;
        if (u.x == 0){
            cout << u.y;
            break;
        }
        else{
            q.push_front(ii(u.x*10%k, u.y));
            q.push_back(ii((u.x + 1)%k, u.y + 1));
        }
    }
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

int main(){

    ll N;
    cin >> N;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    sort(all(v));

    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            ll cMin = v[j] - v[i];
            ll cMax = v[j] + v[i];
            auto minIt = upper_bound(all(v), cMin);
            auto maxIt = lower_bound(all(v), cMax);
            //ll i1 = minIt - v.begin();
            ll i1 = j + 1;
            ll j1 = maxIt - v.begin() - 1;
            ll tmp = j1 - i1 + 1;

            if(DEBUG){
                cout << "i and j " << i << " " << j << endl;
                cout << i1 << " " << j1 << endl;
            }


            ans += max(tmp, 0ll);

        }
    }
    cout << ans << endl;

}

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

int main(){
    string s;
    cin >> s;
    vector<char> b;
    rep(i,s.size()){
        b.pb(s[i]);
    }
    rep(i,s.size()){
        rep(j,s.size()){
            if(b[i] == s[j] && i != j){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
} 

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

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

  std::vector<int64_t> n(s.size());

  for (size_t i = 0; i < s.size(); i++) {
    n[i] = s[i] - '0';
  }

  int64_t ans = 0;

  std::reverse(n.begin(), n.end());

  for (size_t i = 0; i < n.size(); i++) {
    if (10 <= n[i]) {
      if (i + 1 < n.size()) {
        n[i + 1] += n[i] / 10;
      } else {
        n.push_back(n[i] / 10);
      }
      n[i] %= 10;
    }

    if (6 <= n[i]) {
      ans += 10 - n[i];
      if (i + 1 < n.size()) {
        n[i + 1] += 1;
      } else {
        n.push_back(1);
      }
    } else if (i + 1 < n.size() && 5 == n[i] && 5 <= n[i + 1]) {
      ans += 10 - n[i];
      n[i + 1] += 1;
    } else {
      ans += n[i];
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 18820
#include <iostream>

using namespace std;

int main() {

    int A, B;
    cin >> A >> B;

    if(A > B) swap(A, B);
    if(A == 1 && B == 2) cout << 3 << endl;
    else if(A == 1 && B == 3) cout << 2 << endl;
    else if(A == 2 && B == 3) cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        for (int datasetidx = 0; datasetidx < datasetNum; datasetidx++) {
            String A = sc.nextLine();
            String B = sc.nextLine();
            int NA = A.length();
            int NB = B.length();

            int[][] dp = new int[NA+1][NB+1];

            for (int i = 0; i < NA; i++) {
                for (int j = 0; j < NB; j++) {
                    if (A.charAt(i) == B.charAt(j)) {
                        dp[i+1][j+1] = dp[i][j] + 1;
                    } else {
                        dp[i+1][j+1] = Math.max(dp[i+1][j], dp[i][j+1]);
                    }
                }
            }

            System.out.println(dp[NA][NB]);
        }
    }
}


Measured memory_bytes: 63924
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
H = H + [0] * max(0, K - N)

costs = [0] * max((N + 1), (K + 1))

for i in range(2, N+1):
    min_tmp = costs[i-1] + abs(H[i] - H[i-1])
    for j in range(2, min(i, K+1)):
        costs_tmp = costs[i-j] + abs(H[i] - H[i-j])
        min_tmp = min(min_tmp, costs_tmp)
    costs[i] = min_tmp

print(costs[N])

Measured memory_bytes: 53344
#include <bits/stdc++.h>
using namespace std;
int main(){

  int A,B,C;
  cin >> A >> B >> C;
  int X;
  cin >> X;



  int ans = 0;
  for(int i = 0;i <= A;i++){
    for(int j = 0;j <= B;j++){
      for(int k = 0;k <= C;k++){
        if((i * 500 + j * 100 + k * 50) == X)ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    from math import ceil

    t_cur, a_cur = list(map(int, readline().split()))

    for _ in range(n - 1):
        t, a = list(map(int, readline().split()))
        i_t = (t_cur + t - 1) // t
        i_a = (a_cur + a - 1) // a
        x = max(i_t, i_a)
        t_cur, a_cur = t * x, a * x

    print(t_cur + a_cur)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152