akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++)
#define INF 1010001000

typedef pair<int, int> i_i;
typedef struct data{int pos, tick, cost;}data;

int dp(vector<vector<i_i > > &g);

int c, n, m, s, d;

int main(void)
{
    while (cin >> c >> n >> m >> s >> d, c) {
        n++;
        vector<vector<i_i > > g(n);
        loop(i, m) {
            int a, b, f;
            cin >> a >> b >> f;
            g[a].push_back(i_i(f, b));
            g[b].push_back(i_i(f, a));
        }
        cout << dp(g) << endl;
    }
    return 0;
}

int dp(vector<vector<i_i > > &g)
{
    vector<vector<int> > table(c+1, vector<int>(n, INF));
    queue<data> a;
    data dt = {s, c, 0};
    a.push(dt);
    while (!a.empty()) {
        data tmp = a.front(); a.pop();
        for (i_i i : g[tmp.pos]) {
            if (table[tmp.tick][i.second] > tmp.cost + i.first) {
                table[tmp.tick][i.second] = tmp.cost + i.first;
                dt.pos = i.second; dt.tick = tmp.tick; 
                dt.cost = tmp.cost + i.first;
                a.push(dt);
            }
            if (tmp.tick && 
                    table[tmp.tick-1][i.second] > tmp.cost + i.first / 2) {
                table[tmp.tick-1][i.second] = tmp.cost + i.first / 2;
                dt.pos = i.second; dt.tick = tmp.tick-1; 
                dt.cost = tmp.cost + i.first / 2;
                a.push(dt);
            }
        }
    }
    int ret = INF;
    for (int i = 0; i < c+1; i++) {
        ret = min(ret, table[i][d]);
    }
    return ret;
}
    

Measured memory_bytes: 3140
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int l; cin>>l;
    double ans = (double)l * (double)l * (double)l / 27;
    printf("%.10lf\n",ans);
    return 0;
}































Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;

#define endl '\n'
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef pair<int, int> ii;
typedef long long LL;
typedef long double LD;


int main(int argc, char *argv[]){
    string s;
    while(cin>>s){
        int k;
        cin>>k;
        for(int i=0;i<s.length();i++){
            if(i== s.length() -1 ){
                s[i] = ( s[i] - 'a' + k%26) % 26 + 'a';
                break;
            }
            int dist = 'z' - s[i] + 1;
            if(s[i] > 'a' &&  dist <= k){
                k -= dist;
                s[i] = 'a';
            }

        }
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
using namespace std;

int main()
{
  long long n;
  cin>>n;
  vector<long long>a(n);
  for(int i=0;i<n;i++) cin>>a[i];

  cout<<accumulate(a.begin(),a.end(),0ll)-n<<endl;
}


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<int> alpha[26];

int main(void) {
    string s,t;
    cin>>s>>t;
   
    for(int i = 0;i < s.size();i++) {
        alpha[s[i]-'a'].push_back(i);
    }
    for(int i = 0;i < s.size();i++) {
        alpha[s[i]-'a'].push_back(s.size()+i);
    }

    Int ans = 0;
    int p = 0;
    for(int i = 0;i < t.size();i++) {
        int index = t[i]-'a';
        if(alpha[index].size() == 0) {
            cout<<-1<<endl;

            return 0;
        }
        p = *lower_bound(alpha[index].begin(),alpha[index].end(), p) + 1;
        if(p >= s.size()) {
            p -= s.size();
            ans += s.size();
        }
    }

    ans += p;
    
    cout<<ans<<endl;

    return 0;
}


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

int main(){
  int N;cin>>N;
  pair<pair<string,int>,int> M[N];
  for(int i=0;i<N;i++){
    string S;int P;cin>>S>>P;
    M[i]=make_pair(make_pair(S,-P),i+1);
  }
  //auto m=M.begin();
  sort(M,M+N);
  for(int i=0;i<N;i++) cout<<M[i].second<<endl;
    
}
  

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int h[100];
  int cnt = 0;
  cin >> n;
  for(int i=0;i<n;i++) cin >> h[i];
  for(int i=0;i<n;i++){
    while(h[i] > 0){
      cnt++;
      for(int j=i;j<n;j++){
        if(h[j] == 0) break;
        h[j]--;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()

e=[0 for i in range(n)]
w=[0 for i in range(n)]

if s[0]=='E':
    e[0]+=1
else:
    w[0]+=1

#累積和
for i in range(1,n):
    if s[i]=='E':
        e[i]=e[i-1]+1
        w[i]=w[i-1]
    else:
        w[i]=w[i-1]+1
        e[i]=e[i-1]

mn = 10**10
for i in range(n):
    dire = s[i]
    if dire == "E":
        if i != 0 and i != n-1:
            ans = w[i-1] + (e[n-1] - e[i])
        elif i == 0:
            ans = e[n-1] - 1
        else:
            ans = w[n-1]
    else:
        if i != 0 and i != n-1:
            ans = w[i-1] + (e[n-1] - e[i])
        elif i == 0:
            ans = e[n-1]
        else:
            ans = w[i-1]
    if ans < mn:
        mn = ans

print(mn)


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



int main()
{
    ll n,x=0,y=0;
    cin>>n;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        if(l1[i]%4==0)x++;
        else if(l1[i]%2==0)y++;
    }
    //if(x==1)x+=1;
    if(2*x+1+y-1>=n&&y>=2&&x!=0)cout<<"Yes";
    else if(2*x+1>=n&&x!=0)cout<<"Yes";
    else if(x==0&&y>=2&&y-1>=n-1)cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 1024
s=input()
k=int(input())

import re
def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """

    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
        
if len(s)==1:
    print(k//2)
elif len(s)==2:
    if len(set(s))==1:
        print(k)
    else:
        print(0)
elif len(s)==3:
    if len(set(s))==1:
        print(3*k//2)
    elif len(set(s))==2:
        if s[-1]==s[-(i+1)]:
            print(k)
        else:
            print(k-1)
elif len(set(s))==1 :
	print(len(s)*k//2)
else:
    if s[0]!=s[-1]:
        a=list(nchars(s, 2))
        b=0
        for i in a:
            b+=len(i)//2
        print(b*k)
    else:
        if s[0]!=s[1] and s[-1]!=s[-2]:
            a=list(nchars(s, 2))
            b=0
            for i in a:
                b+=len(i)//2
            print(b*k+k-1)
        else:
            chain_hajime=0
            chian_owa=0
            for i in range(len(s)):
                if s[0]==s[i]:
                    chain_hajime+=1
                else: break
            for i in range(len(s)):
                if s[-1]==s[-(i+1)]:
                    chian_owa+=1
                else: break
            a=list(nchars(s, 2))
            b=0
            for i in a:
                b+=len(i)//2
            if chian_owa%2==1 and chain_hajime%2==1:
                print(b*k+k-1)
            else:
                print(b*k)

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

const long long INF=pow(10,15);

long long minll(long long n, long long m){
  if(n>m){
    return m;
  }
  else {
    return n;
  }
}

int main() {
  long long N,W;
  cin >> N >> W;
  
  vector<long long> w(N),v(N);
  
  for(int i=0;i<N;i++){
    cin >> w[i] >> v[i];
  }
  
  vector<vector<long long>> dp(N+1,vector<long long>(100001,INF));
  
    dp[0][0]=0;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<100001;j++){
      if(j<v[i])
        dp[i+1][j]=dp[i][j];
      else
        dp[i+1][j]=minll(dp[i][j],dp[i][j-v[i]]+w[i]);
    }
  }
  int ans=100000;
  while(dp[N][ans]>W){
    ans--;
  }
  cout << ans << endl;

}


Measured memory_bytes: 80256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(x,b) ((0)<=(x)&&(x)<(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef queue<int> qi;
typedef long long ll;

vii card(5, vi(4));
int N, dy[4] = {-1,0,1,1}, dx[4] = {1,1,1,0};

vii narrow(vii c){
  int t;
  rep(i, 5) rep(j, 4){
    if(j){
      if(c[i][j-1] != -1) continue;
      t = c[i][j-1]; 
      c[i][j-1] = c[i][j];
      c[i][j] = t;
    }else{
      if(i == 0) continue;
      if(c[i-1][3] != -1) continue;
      t = c[i-1][3];
      c[i-1][3] = c[i][j];
      c[i][j] = t;
    }
  }
  rep(i, 5) rep(j, 4){
    if(j){
      if(c[i][j-1] != -1) continue;
      t = c[i][j-1];
      c[i][j-1] = c[i][j];
      c[i][j] = t;
    }else{
      if(i == 0) continue;
      if(c[i-1][3] != -1) continue;
      t = c[i-1][3];
      c[i-1][3] = c[i][j];
      c[i][j] = t;
    }
  }
  return c;
}

int csize(vii origin){
  int ret = 0;
  rep(i, 5) rep(j, 4) if(origin[i][j] != -1) ret++;
  return ret;
}

int main(){
  scanf("%d", &N);
  while(N--){
    rep(i, 5) rep(j, 4) scanf("%d", &card[i][j]);

    map<vii, bool> m; // memo map 
    queue<vii>q;
    int res = 20;
    q.push(card);
    m[card] = true;
    while(!q.empty()){
      int qsize = (int)q.size();
      //      fprintf(stderr, "%d\n", qsize);
      //      if(qsize  > 1) break;
      rep(i, qsize){
	vii c = q.front(); q.pop();

	rep(j, 5) rep(k, 4) rep(d, 4){
	  vii n = c;
	  //	  if(n[j][k] == -1){ j = 5; k = 4; break;}
	  //	  fprintf(stderr, "%d %d %d\n", j, k, d);
	  int ny = j + dy[d], nx = k + dx[d];
	  //	  fprintf(stderr, "%d %d\n", ny, nx);
	  //	  if(!BW(ny, 5) || !BW(nx, 4) || n[ny][nx] == -1 || n[j][k] == -1 || n[ny][nx] != n[j][k]) continue;
	  if(!BW(ny, 5) || !BW(nx, 4) || n[ny][nx] != n[j][k]) continue;
	  n[ny][nx] = n[j][k] = -1;
	  //	  fprintf(stderr,"%d %d\n", ny, nx);
	  n = narrow(n);
	  res = min(res, csize(n));
	  if(m.count(n) == 0){
	    m[n] = true;
	    q.push(n);
	  }

	  /*	  rep(i, 5){
	    rep(j, 4) printf("%d ", n[i][j]);
	    puts("");
	    }puts("");*/

	}
      }
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1540
#include <iostream>
#include <algorithm>
#define MAX_N 100
#define MAX_V 100
#define INF 2000000000
using namespace std;

int n, W;
int v[MAX_N + 1], w[MAX_N + 1];
long long dp[MAX_N + 1][MAX_N * MAX_V + 1];

void solve() {
  for (int i = 0; i < MAX_N + 1; i++) {
    for (int j = 0; j < MAX_N * MAX_V + 1; j++) {
      dp[i][j] = INF;
    }
  }

  for (int i = 0; i <= n; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < MAX_N * MAX_V + 1; j++) {
      if (j - v[i] < 0) dp[i][j] = dp[i - 1][j];
      else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
    }
  }

  int max = 0;
  for (int i = 1; i < MAX_N * MAX_V + 1; i++) {
    if (dp[n][i] <= W) max = i;
  }
  cout << max << endl;
}

int main() {
  cin >> n >> W;
  for (int i = 1; i <= n; i++) {
    cin >> v[i] >> w[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 10992
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.math;

void main() {
	auto n = readln.chomp.to!long;
	auto a = readln.chomp.split(' ').map!(to!int).array;
	int[4] numbers;
	foreach (e;a) {
		++numbers[e];
	}

	auto dp = new double[][][](n + 1, n + 1, n + 1);

	double solve(int s1, int s2, int s3) {
		if (s1 == 0 && s2 == 0 && s3 == 0) {
			return 0.0;
		}
		if (!dp[s1][s2][s3].isNaN) {
			return dp[s1][s2][s3];
		}

		double result = 0.0;
		if (s1 >= 1) result += solve(s1 - 1, s2, s3) * s1;
		if (s2 >= 1) result += solve(s1 + 1, s2 - 1, s3) * s2;
		if (s3 >= 1) result += solve(s1, s2 + 1, s3 - 1) * s3;
		result += n;
		result /= (s1 + s2 + s3);

		dp[s1][s2][s3] = result;

		return result;
	}

	writefln("%.10f", solve(numbers[1], numbers[2], numbers[3]));
}


Measured memory_bytes: 368420
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    int cnt=1; 
    string s[h];
    int ans[h][w];
    bool aru[h];
    fill(aru, aru+h, false);
    for (int i=0; i<h; i++) {
        cin >> s[i];
        for (auto &c:s[i]) {
            if (c == '#') {
                aru[i] = true;
                break;
            }
        }
    }
    for (int i=0; i<h; i++) {
        int init = cnt;
        for (int j=0; j<w; j++) {
            if (s[i][j] == '#')
                cnt++;
            if (aru[i])
                ans[i][j] = (cnt == init ? cnt + 1 : cnt);
            else if (i > 0)
                ans[i][j] = ans[i-1][j];
        }
    }
    if (!aru[0]) {
        int I=0;
        while (!aru[I]) I++;
        for (int i=I; i>0; i--)
            for (int j=0; j<w; j++) ans[i-1][j] = ans[i][j];
    }
    int off = ans[0][0] - 1;
    for (auto &ai:ans) {
        for (auto &aij:ai) {
            cout << aij - off << ' ';
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
while true do
        a = gets.split(" ").map{|x| x.to_i}
        if a[0] == 0 and a[1] == 0
                break;
        end

        if a[0] < a[1] then
                print("#{a[0]} #{a[1]}\n")
        else
                print("#{a[1]} #{a[0]}\n")
        end
end

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

typedef long long ll;
const int len = 1e5+5;
int arr[len];

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]);

    ll ans = 0, cnt = 0;
    for (int i = 1; i <= n+1; i++){
        if (arr[i] == 0){
            ans += cnt/2;
            cnt = 0;
        }
        else cnt += arr[i];
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 640
N = int(input())
a = []
a.append([0, 0, 0])
for i in range(N):
    a.append(list(map(int, input().split())))
travel = True
for i in range(N):
    c = abs(a[i+1][1]-a[i][1]) + abs(a[i+1][2]-a[i][2])
    if c <= a[i+1][0]-a[i][0] and (a[i+1][0] - a[i][0] - c) % 2 == 0:
        pass
    else:
        travel = False
        break
if travel == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27300
function Main(input) {
  var inputs = input.split("\n");
  var t_a = inputs[1].split(" ").map(e => parseInt(e, 10));
  var h = inputs[2].split(" ").map(e => Math.abs(t_a[1] - (t_a[0] - parseInt(e, 10) * 0.006)));
  var ans = h.indexOf(Math.min(...h)) + 1;
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
#define forn(i,n) for (int i=0; i<int(n); ++i)

int main() {
    cxxio();
    int n, m;
    cin>>n>>m;
    vvi P(n, vi(m+1));
    forn(i, n) forn(j, m)
        cin>>P[i][m-j];
    int ans=n;
    vi out(m+1);
    forn(_, m) {
        vi cnt(m+1);
        forn(i, n) cnt[P[i].back()]++;
        int x=0;
        forn(i, m+1) if (cnt[i]>cnt[x]) x=i;
        ans=min(ans, cnt[x]);
        out[x]=1;
        forn(i, n)
            while (out[P[i].back()]) P[i].pop_back();
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;

int main(int argc, char *argv[])
{
    int N, A, B;
    std::cin >> N;
    
    if (N == 1) {
        std::cout << "Hello World" << std::endl;
    } else {
        std::cin >> A >> B;
        std::cout << A+B << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, C;
    cin >> n >> C;

    vvl d(C, vl(C));  // d[x][y] : マスを色xから色yに塗り替えるときのコスト
    rep(i, C) {
        rep(j, C) {
            cin >> d[i][j];
        }
    }

    vvl c(n, vl(n));  // c[i][j] : マス(i,j)の色
    vvl t(C, vl(3));  // t[x][y] : 色xのマスのうち (i+j)%3 = y となるものの個数
    rep(i, n) {
        rep(j, n) {
            cin >> c[i][j];
            c[i][j]--;
            t[c[i][j]][(i+j)%3]++;
        }
    }
    
    ll ans = INF;
    rep(i, C) {
        rep(j, C) {
            rep(k, C) {
                if(i == j || j == k || k == i) {
                    continue;
                }
                ll now = 0;
                rep(x, C) {
                    now += d[x][i]*t[x][0];
                    now += d[x][j]*t[x][1];
                    now += d[x][k]*t[x][2];
                }
                chmin(ans, now);
            }
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<cmath>

int main(){
	double a[4][2];
	double d[4];
	bool f = 0;
	int count;
	while(1 + scanf("%lf,%lf,", &a[0][0], &a[0][1])){
		count = 0;
		for(int i = 1; i < 4; i++){
			scanf("%lf,%lf,", &a[i][0], &a[i][1]);
		}
		for(int i = 0; i < 4; i++){
			d[i] = atan2(a[i][0] - a[(i+1)%4][0],a[i][1] - a[(i+1)%4][1]);
		}
		for(int i = 0; i < 4; i++){
			if(0 < sin(d[i] - d[(i+1)%4])){
				count++;
			}else{
				count--;
			}
		}
		if(count / 3){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1108
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a

num = input().split(" ")
a = int(num[0])-1
b = int(num[1])
c = int(num[2])
d = int(num[3])
e = int(c * d / int(gcd(c, d)))
bb = b - (b//c) -(b//d) +(b//e) 
aa = a - (a//c) -(a//d) + (a//e)
print(int(bb-aa))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        String[] s=new String[n];
        for(int i=0;i<n;i++) s[i]=sc.next();
        int[][] alpha=new int[n][26];
        int[] minAlpha=new int[26];
        for(int i=0;i<n;i++){
            for(int j=0;j<s[i].length();j++){
                int t=s[i].charAt(j)-'a';
                alpha[i][t]++;
            }
            if(i==0) for(int k=0;k<26;k++){
                minAlpha[k]=alpha[0][k];
            }
            else{
                for(int k=0;k<26;k++){
                    minAlpha[k]=Math.min(alpha[i][k],minAlpha[k]);
                }
            }
        }
        for(int i=0;i<26;i++){
            while(minAlpha[i]>0){
                System.out.print((char)(i+'a'));
                minAlpha[i]--;
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 21844
A, B = map(int, input().split())
list_ab = [A, B]
ans = 0
if A > B :
    ans += A
    A -= 1
else:
    ans += B
    B -= 1

if A > B :
    ans += A
    A -= 1
else:
    ans += B
    B -= 1

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s, t;
    cin >> s >> t;
    map<char, int> cnts, cntt;
    map<char, set<int>> chpost, chposs;
    string ss = s + s;
    for (int i = 0; i < s.size(); ++i) {
        cnts[s[i]]++;
    }
    for (int i = 0; i < ss.size(); ++i) {
        chposs[ss[i]].insert(i);
    }
    for (int i = 0; i < t.size(); ++i) {
        cntt[t[i]]++;
        chpost[t[i]].insert(i);
    }
    for (auto &p : cntt) {
        if (cnts[p.first] == 0) {
            cout << -1 << "\n";
            return 0;
        }
    }
    ll ret = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == t[0]) {
            ret = i + 1;
            break;
        }
    }
    int sidx = ret - 1;
    for (int i = 0; i < t.size() - 1; ++i) {
        auto it = chposs[t[i + 1]].upper_bound(sidx);
        ret += (*it - sidx);
        sidx = *it % s.size();
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 14848
#include "bits/stdc++.h"
using namespace std;

int n,mx;
string a;
map <string,int> m;
set <string> s;

int main()
{
	cin>>n;
	while(n--)
	{
		cin>>a;
		m[a]++;
	}

	for(auto i:m)
		mx=max(mx,i.second);
	for(auto i:m)
		if(i.second==mx) s.insert(i.first);

	for(auto i:s) cout<<i<<"\n";
}

Measured memory_bytes: 34560
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		boolean canin = true;
		int inputn = sc.nextInt();

		for(int i = 0; i < inputn; i++) {
			int num = sc.nextInt();
			if((num % 2) == 0) {
				if((num % 3 == 0) || num % 5 == 0 ) {

				}else {
					canin = false;
				}
			}
		}

		if(canin) {
			System.out.println("APPROVED");
		}else {
			System.out.println("DENIED");
		}

	}
}

Measured memory_bytes: 21332
N=int(input())
import math

XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]

ans=0
for i in range(N):
  for j in range(N):
    if i<j:
      ans+=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)


print(2*ans/N)


Measured memory_bytes: 3060
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			float[] x = new float[4];
			float[] y = new float[4];
			
			for(int i=0; i<4; i++)
			{
				x[i] = scanner.nextFloat();
				y[i] = scanner.nextFloat();
			}
				
			String output = "NO";
			if(x[0]<=x[3] && x[2]<=x[1] && y[0]<=y[3] && y[2]<=y[1])
			{
				output = "YES";
			}
		
			System.out.println(output);
		}
	}
}

Measured memory_bytes: 28984
INDEX_LEFT = 0
INDEX_RIGHT = 1


# INPUT
n = int(input())

list_child = [[] for _ in range(n)]
list_parent = [-1 for _ in range(n)]

for _ in range(n):

    id, *C = map(int, input().split())

    list_child[int(id)].extend(C)

    for c in C:
        if c == -1:
            continue

        list_parent[int(c)] = int(id)


# PROCESS
def treewalk_preorder(u):
    if u == -1:
        return

    print(f" {u}", end="")
    treewalk_preorder(list_child[u][INDEX_LEFT])
    treewalk_preorder(list_child[u][INDEX_RIGHT])


def treewalk_inorder(u):
    if u == -1:
        return

    treewalk_inorder(list_child[u][INDEX_LEFT])
    print(f" {u}", end="")
    treewalk_inorder(list_child[u][INDEX_RIGHT])


def postorder_treewalk(u):
    if u == -1:
        return

    postorder_treewalk(list_child[u][INDEX_LEFT])
    postorder_treewalk(list_child[u][INDEX_RIGHT])
    print(f" {u}", end="")


root = list_parent.index(-1)

# OUTPUT
print("Preorder")
treewalk_preorder(root)
print()

print("Inorder")
treewalk_inorder(root)
print()

print("Postorder")
postorder_treewalk(root)
print()


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int s1, s2, s3;
  s1 = N / 100;
  s2 = (N - s1*100) / 10;
  s3 = (N - s1*100 - s2*10);
 
  vector<int> vec;
  vec = {s1, s2, s3};
  int result = 0;
  for (int i=0; i<3; i++){
    if (vec.at(i) == 7){
      result = 1;
    }
  }
  if (result == 1){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  int a,b,k,i;
  scanf("%d%d%d",&a,&b,&k);
  for(i=a;i<=fmin(b,a+k-1);i++){
    printf("%d\n",i);
  }
  for(i=fmax(b-k+1,a+k);i<=b;i++){
    printf("%d\n",i);
  }
  return 0;
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
string S;

int main()
{
	cin >> S;
	N = S.size();

	int ans = 1e9;
	for(char c = 'a';c <= 'z';c++){
		int mx = 0;
		FOR(i,0,N){
			int j = i;
			while(j < N && S [j] != c) j++;
			if(j == N){
				chmax(mx,N - i);
			}
			else{
				chmax(mx,j - i);
			}
		}
		chmin(ans,mx);
	}

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

	return 0;
}


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

int main(int argc, char *argv[]) {
	int N = 0;
	std::cin >> N;

	int SN = 0;
	std::string n_str(std::to_string(N));
	for (int i = 0; i < n_str.size(); i++) {
		SN += (n_str[i] - '0');
	}

	std::cout << ((N % SN == 0) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 2000000000
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long a, b, c;
	cin >> a >> b;
	c=a*b;
	cout << a*b << '\n';
}

Measured memory_bytes: 3648
N=int(input())
x=[]
u=[]
for i in range(N):
	a,b=input().split()
	a=float(a)
	x.append(a)
	u.append(b)

ans=0
for i in range(N):
	if u[i]=="JPY": ans+=x[i]
	else: ans+=x[i]*380000

print(ans)

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

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fr freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 5e5 + 2;
const int mod = 1e9 + 7;

int main ()
{
	speed;
	int h,a;
	cin>>h>>a;
	if (h<=a){
		cout<<1;
	}
	else {
		cout<<ceil((double)h/a);
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2005
#define INF 1000000005
#define INFLL 4000000000000000003
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    string s;
    cin>>s;
    REP(i,SZ(s)){
        if(s[i]=='?')s[i]='D';
    }
    OUT(s);
    return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n;
    int a[n],b[m];
    map<int,int>q;
    rep(i,0,n){
        cin>>a[i];
    }
    cin>>m;
    rep(i,0,m){
        cin>>b[i];
    }
    rep(i,0,n){
        q[a[i]]++;
    }
    rep(i,0,m){
        q[b[i]]--;
    }
    rep(i,0,m){
        if(q[b[i]]<0){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES"<<endl;return 0;
}

Measured memory_bytes: 18432
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string s;
int n;
int main()
{
	int j;
	string index = "1";
	cin >> n;
	n++;
	s = to_string(n);
	reverse(s.begin(), s.end());
	long long ans = 0;
	while (index != s) 
	{
		int len = index.length();
		if (!len % 2) 
		{
			index.insert(0, "0");
			continue;
		}
		if (index.length() % 2) ans++;
		index[0]++;
		for (j = 0; j < len; j++) 
		{
			if (index[j] > '9') 
			{
				index[j] = '0';
				if (j == len - 1) index.push_back('1');
				else index[j + 1]++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    AB.sort(key=lambda x: x[1])
    ans = 0
    p = -1
    for a, b in AB:
        if a <= p:
            continue
        p = b - 1
        ans += 1
    return ans


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 31452
#define DEBUG 0

/**
 * File    : C2.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-26 23:54:38
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
vector<int> V;
int ans = 0;
int res = 0;

int main()
{
  cin >> N >> M;
  V = vector<int>(N);
  for (auto i = 0; i < M; i++)
  {
    int k;
    cin >> k;
    for (auto j = 0; j < k; j++)
    {
      int s;
      cin >> s;
      s--;
      V[s] |= 1 << i;
    }
  }
  for (auto i = 0; i < M; i++)
  {
    int p;
    cin >> p;
    res |= p << i;
  }
  for (auto i = 0; i < (1 << N); i++)
  {
    int sw = 0;
    for (auto j = 0; j < N; j++)
    {
      if (i >> j & 1)
      {
        sw ^= V[j];
      }
    }
    if (res == sw)
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input) {
	let inputs = input.split(' ').map((n) => (parseInt(n, 10)));
	let a = inputs[0];
	let b = inputs[1];
	let c = inputs[2];
	console.log(Math.min(Math.floor(b / a), c));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

//create arrays outside of main()
int a[50] = {};

stack<char> s;


int main() {

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

    sort(a, a+n, greater<int>());

    cout << a[0] - a[n-1];

    return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

mt19937 mt_engine(chrono::steady_clock::now().time_since_epoch().count());
template <class T> enable_if_t<is_integral_v<T>, T> rng(T l, T r) {
  return uniform_int_distribution<T>(l, r - 1)(mt_engine);
}
template <class T> enable_if_t<is_floating_point_v<T>, T> rng(T l, T r) {
  return uniform_real_distribution<T>(l, r)(mt_engine);
}

struct stopwatch {
  clock_t t = clock();
  void restart() { t = clock(); }
  int elapsed() const { return (clock() - t) * 1000 / CLOCKS_PER_SEC; }
  void operator()(string s = "Time") const {
    cerr << s + ": " << elapsed() << " ms\n";
  }
};

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmax = [](auto&& a, auto b) { return a < b ? a = b, 1 : 0; };

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  vector<int> last(m, -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

void solve() {
  vector<int> last(m, -1);
  for (int i = 0; i < n; ++i) {
    int mx = -inf<int>, mj = -1;
    for (int j = 0; j < m; ++j) {
      if (chmax(mx, s[i][j] + c[j] * (i - last[j]))) {
        mj = j;
      }
    }
    type[i] = mj;
    last[mj] = i;
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int _n;
  cin >> _n;
  assert(_n == n);
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  solve();
  for (int i = 0; i < n; ++i) {
    cout << type[i] + 1 << '\n';
  }
  DEBUG(score());
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll h, w;
  cin >> h >> w;

  vector<vector<char>> hw(h, vector<char>(w));
  for (ll i = 0; i < h; ++i) {
      for (ll j = 0; j < w; ++j) {
        cin >> hw[i][j];
      }
  }

  vector<vector<char>> ans;
  for (ll i = 0; i < h; ++i) {
    ans.push_back(hw[i]);
    ans.push_back(hw[i]);
  }

  for (ll i = 0; i < h*2; ++i) {
    for (ll j = 0; j < w; ++j) {
      cout << ans[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import Data.List

isBeautifulString :: String -> String
isBeautifulString s
  | s == "" = "Yes"
  | mod (length s) 2 /= 0 = "No"
  | s!!0 /= s!!1 = "No"
  | otherwise = isBeautifulString $ drop 2 s

main = do
  s <- getLine
  putStrLn $ isBeautifulString $ sort s


Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main()
{
  int N;
  long K;
  cin >> N >> K;
  vector<P> p(N);
  for (int i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  long ans = 0;
  long len = 0;
  for (int i = 0; i < N; i++)
  {
    len += p[i].second;
    if (K <= len)
    {
      ans = p[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e5+10;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],monster[MAX],hero[MAX],n,m;
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);

    int n;
    cin>>n;
    m=n+1;
    for(int i=0; i<m; i++)
    {
        cin>>monster[i];
    }
    for(int i=0; i<n; i++)
    {
        cin>>hero[i];
    }
    ll ans=0;
    for(int i=0; i<n; i++)
    {
        if(monster[i]>hero[i])
            ans+=hero[i],hero[i]=0;
        else
        {
            ans+=monster[i];
            hero[i]-=monster[i];

        }
        if(i+1<=n)
        {
            if(monster[i+1]>hero[i])
                ans+=hero[i],monster[i+1]-=hero[i];
            else
            {
                ans+=monster[i+1];
                monster[i+1]=0;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;



int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    vector<ll> b(n+1);
    b[0] = 0;
    for(int i =1; i < n + 1; i++)
    {
        b[i] = a[i-1]+b[i-1];
    }
    ll ans = 0;
    map<ll, ll> mp;
    for(int i = 1; i < n + 1; i++)
    {
        mp[b[i]]++;
    }

    for(auto i : mp)
    {
        ans += i.second*(i.second - 1)/2;
        if(i.first == 0) ans += i.second;
    }
    cout << ans << endl;
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll ma=-1;
  rep(i,n-1){
    if(min(a[i],a[n-1]-a[i])>ma) ma=a[i];
  }
  
  cout<<a[n-1]<<" "<<ma<<endl;
  
  
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())

    if H % 3 == 0 or W % 3 == 0:
        print(0)
        exit()

    res = f_inf
    for h in range(H):
        A = h * W

        B = W * ((H - h) // 2)
        C = W * ((H - h) - (H - h) // 2)
        ma = max(A, B, C)
        mi = min(A, B, C)
        res = min(res, ma - mi)

        B = (H - h) * (W // 2)
        C = (H - h) * (W - W // 2)
        ma = max(A, B, C)
        mi = min(A, B, C)
        res = min(res, ma - mi)

    for w in range(W):
        A = w * H

        B = H * ((W - w) // 2)
        C = H * ((W - w) - (W - w) // 2)
        ma = max(A, B, C)
        mi = min(A, B, C)
        res = min(res, ma - mi)

        B = (W - w) * (H // 2)
        C = (W - w) * (H - H // 2)
        ma = max(A, B, C)
        mi = min(A, B, C)
        res = min(res, ma - mi)

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
// atcoder/abc046/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << set<int>({a, b, c}).size() << endl;
  }

  return 0;
}


Measured memory_bytes: 256
x,k,d=gets.split.map(&:to_i)
if x.abs>=k*d
  puts x.abs-k*d
elsif x==0
  if k%2==0
    puts 0
  else
    puts d
  end
else
  x=x.abs
  k-=x/d
  x-=d*(x/d)
  if k%2==0
    puts x
  else
    puts (x-d).abs
  end
end


Measured memory_bytes: 14272
N=int(input())
answer=0

xylist=[]
for _ in range(N):
  x,y=map(int,input().split())
  xylist.append((x,y))

ppxylist=[]
for i in range(N):
  x,y=xylist[i]
  ppxylist.append((x+y,x,y))
ppxylist.sort()
#print(ppxylist)
answer=max(answer,ppxylist[-1][0]-ppxylist[0][0])

pmxylist=[]
for i in range(N):
  x,y=xylist[i]
  pmxylist.append((x-y,x,y))
pmxylist.sort()
#print(ppxylist)
answer=max(answer,pmxylist[-1][0]-pmxylist[0][0])

mpxylist=[]
for i in range(N):
  x,y=xylist[i]
  mpxylist.append((-x+y,x,y))
mpxylist.sort()
#print(ppxylist)
answer=max(answer,mpxylist[-1][0]-mpxylist[0][0])

mmxylist=[]
for i in range(N):
  x,y=xylist[i]
  mmxylist.append((-x-y,x,y))
mmxylist.sort()
#print(ppxylist)
answer=max(answer,mmxylist[-1][0]-mmxylist[0][0])
  
print(answer)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vector<int> count(n, 0);
    for(int i = 0; i < n; i++){
        while(a[i] % 2 == 0){
            count[i]++;
            a[i] /= 2;
        }
    }

    int ans = 1001001001;
    for(int i = 0; i < n; i++){
        if(ans > count[i]) ans = count[i];
    }

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int maxn = 128;

int ask(char buf[]) {
	printf("? %s\n", buf);
	fflush(stdout);
	int ret;
	scanf("%d", &ret);
	return ret;
}
void close(char buf[]) {
	printf("! %s\n", buf);
	fflush(stdout);
	exit(0);
}

int tot, sum, pL[maxn + 1], pR[maxn + 1];
char buf[maxn + 1], out[maxn + 1];
void solve(int L, int R) { // merge -> [pL[L], pR[L]]
	if(L == R)
		return;
	int M = (L + R) >> 1;
	solve(L, M);
	solve(M + 1, R);
	int lft = pR[L] - pL[L] + 1;
	int rht = pR[M + 1] - pL[M + 1] + 1;
	int pos = 0, i, j;
	static char tmp[maxn + 1];
	for(i = 0, j = 0; i < rht; ++i) {
		for( ; j < lft; ++j) {
			int len = 0;
			for(int k = 0; k < pos; ++k)
				buf[len++] = tmp[k];
			buf[len++] = out[pL[M + 1] + i];
			for(int k = j; k < lft; ++k)
				buf[len++] = out[pL[L] + k];
			buf[len] = '\0';
			int ret = ask(buf);
			if(ret == sum - len)
				break;
			tmp[pos++] = out[pL[L] + j];
		}
		tmp[pos++] = out[pL[M + 1] + i];
	}
	for( ; j < lft; ++j)
		tmp[pos++] = out[pL[L] + j];
	pR[L] = pR[M + 1];
	for(int i = 0; i < pos; ++i)
		out[pL[L] + i] = tmp[i];
}

int main() {
	sum = 0;
	for(char ch = 'a'; sum < maxn && ch <= 'z'; ++ch) {
		for(int i = 0; i < maxn; ++i)
			buf[i] = ch;
		buf[maxn] = '\0';
		int cnt = maxn - ask(buf);
		if(!cnt)
			continue;
		pL[tot] = tot ? pR[tot - 1] + 1 : 0;
		pR[tot] = pL[tot] + cnt - 1;
		for(int i = pL[tot]; i <= pR[tot]; ++i)
			out[i] = ch;
		++tot;
		sum += cnt;
	}
	for(char ch = 'A'; sum < maxn && ch <= 'Z'; ++ch) {
		for(int i = 0; i < maxn; ++i)
			buf[i] = ch;
		buf[maxn] = '\0';
		int cnt = maxn - ask(buf);
		if(!cnt)
			continue;
		pL[tot] = tot ? pR[tot - 1] + 1 : 0;
		pR[tot] = pL[tot] + cnt - 1;
		for(int i = pL[tot]; i <= pR[tot]; ++i)
			out[i] = ch;
		++tot;
		sum += cnt;
	}
	for(char ch = '0'; sum < maxn && ch <= '9'; ++ch) {
		for(int i = 0; i < maxn; ++i)
			buf[i] = ch;
		buf[maxn] = '\0';
		int cnt = maxn - ask(buf);
		if(!cnt)
			continue;
		pL[tot] = tot ? pR[tot - 1] + 1 : 0;
		pR[tot] = pL[tot] + cnt - 1;
		for(int i = pL[tot]; i <= pR[tot]; ++i)
			out[i] = ch;
		++tot;
		sum += cnt;
	}
	solve(0, tot - 1);
	out[sum] = '\0';
	close(out);
	return 0;
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N, K;   cin >> N >> K;
    V v(N);  VECCIN(v);
    SORT(v);

    int ans = 0;
    for(int i = 0 ; i < K ; i++)  ans += v[i];

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

Measured memory_bytes: 3612
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_C
r,c = gets.split.map(&:to_i)

table = []
r.times.each do
    table.push gets.split.map(&:to_i)
end

sumrow=[]
(c+1).times do
    sumrow.push 0
end


table.each do |row|
    row.push row.inject(0){|sum,i|sum+i}
    
    for i in 0..c
        sumrow[i]= sumrow[i]+row[i]
    end
end

table.push sumrow

table.each do |row|
    puts row.join(" ")
end

Measured memory_bytes: 6172