akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;

int main(){
    int N,i,j, index;
    long K, in;
    scanf("%d %ld",&N, &K);

    vector<long> A(N);
    vector<long> S(N+1);
    map<int, int> num;

    S[0] = 0;
    for(i=0;i<N;i++){
        scanf(" %ld", &in);
        A[i] = in;
        S[i+1] = S[i] + A[i];
    }

    long long sum=0;

    // order O(NlogK), num[] の検索にlogK
    num[S[0]%K] = 1;

    for(j=1;j<N+1;j++){
        // del operation
        if(j-K>=0){
            index = (S[j-K] - (j-K)) % K;
            num[index]--;
        }
        // if(j==0){
        //     num[A[0] % K] ++;
        //     continue;
        // }
        index = (S[j]-j) % K;
        sum += num[index];
        // printf("j=%d sum:%lld", j,sum);
        num[index] ++;
    }

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

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

int main() {

int n, k;
cin >> n >> k;

int sum = 1;

rep(i, n) {
  
  if(sum * 2 < sum + k) {
   sum *= 2;
  }
  
  else  {
   sum += k;
  }
 }
   cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
typedef long long ll;
int a[maxn];
int n;
ll ans;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= 3 * n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + 3 * n + 1); 
	for(int i = n + 1; i <= 3 * n; i += 2) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    ll n;
    cin>>n;
    ll m = sqrt(n);
    set<ll> ans;
    set<ll> div;
    for (int i = 2; i <= m; ++i) {
        ll temp = n;
        bool done = false;
        while (temp % i == 0) {
            temp /= i;
            done = true;
        }
        if (done) div.insert(i);
        if (done && ((temp - 1) % i) == 0) ans.insert(i);
    }
    
    n--;
    map<ll, int> mp;
    for (int i = 2; i <= m && n > 1; ++i) {
        int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0 && div.count(i) == 0) mp[i] = cnt;
    }
    if (n > 1 && div.count(n) == 0) mp[n]++;
    ll com = 1;
    for (auto m : mp) com *= m.second + 1;
    cout<<ans.size() + com<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
	long long n,a[100000],sum1=0,sum2=0,x;
  	scanf("%lld",&n);
  	for(int i=1;i<=n;i++){
    	scanf("%lld",&a[i]);
    }
	for(int i=1;i<=n;i+=2){
    	sum1+=a[i];
      	sum2+=a[i+1];
    }
  	x=(sum1-sum2)/2;
  	for(int j=1;j<=n;j++){
    	printf("%lld ",2*x);
      	x=a[j]-x;
    }
  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>

#define N 100

using namespace std;

int n;
int unvisited=0,visited=1,comp_visited=2;
int M[N][N],state[N],nt[N];
int d[N],f[N],t;

int next(int u){
	for(int v=nt[u];v<n;v++){
		nt[u]=v+1;
		if(M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r){
	for(int i=0;i<n;i++){
		nt[i]=0;
	}
	stack<int> s;
	s.push(r);
	state[r]=visited;
	t++;
	d[r]=t;
	
	while(!s.empty()){
		int u=s.top();
		int v=next(u);
		if(v!=-1){
			if(state[v]==unvisited){
				state[v]=visited;
				t++;
				d[v]=t;
				s.push(v);
			}
		}
		else{
			s.pop();
			state[u]=comp_visited;
			t++;
			f[u]=t;
		}
	}
}

void dfs(){
	for(int i=0;i<n;i++){
		state[i]=unvisited;
		nt[i]=0;
	}
	t = 0;
	for(int u=0;u<n;u++){
		if(state[u]==unvisited) dfs_visit(u);
	}
	for(int i=0;i<n;i++){
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}
}

int main(){
	int u,k,v;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(int j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v]=1;
		}
	}
	dfs();
}

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

using namespace std;

using ll = long long;

using Graph = vector< vector<int> >;

bool dfs(int cur, vector<int>& memo, Graph& g, vector<int>& order) {
    memo[cur] = 1;
    for (int nex : g[cur]) {
        if (memo[nex] == 2) continue;
        if (memo[nex] == 1) return false;
        if (!dfs(nex, memo, g, order)) return false;
    }
    memo[cur] = 2;
    order.push_back(cur);
    return true;
}

bool tsort(Graph& g, vector<int>& order) {
    vector<int> memo(g.size(), 0);
    for (int i = 0; i < g.size(); i++) {
        if (memo[i] != 0) continue;
        if (!dfs(i, memo, g, order)) return false;
    }
    reverse(order.begin(), order.end());
    return true;
}

const int INF = 1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector< vector<int> > a(n, vector<int>(n - 1));
    Graph g(n * n);
    vector<int> deg(n * n, 0);
    for (int i = 0; i < n; i++) {
        vector<int> tmp;
        for (int j = 0; j < n - 1; j++) {
            cin >> a[i][j];
            a[i][j]--;

            int v1 = i;
            int v2 = a[i][j];
            if (v1 > v2) swap(v1, v2);
            tmp.push_back(v1 * n + v2);
        }

        for (int j = 0; j < n - 2; j++) {
            g[tmp[j]].push_back(tmp[j + 1]);
            deg[tmp[j + 1]]++;
        }
    }

    vector<int> order;
    bool can = tsort(g, order);
    if (!can) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> dists(n * n, 0);
    for (int cur : order) {
        for (int nex : g[cur]) {
            dists[nex] = max(dists[nex], dists[cur] + 1);
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans = max(ans, dists[i * n + j]);
        }
    }
    ans++;
    cout << (ans >= INF ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 57212
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <ctime>
#include <random>
#include <queue>
  
using namespace std;
 
const int MAXN = 1e5 + 10;



int main(){
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#ifndef _DEBUG
    /*freopen("trap.in", "r", stdin);
    freopen("trap.out", "w", stdout);*/
#endif
    long long n, i;
    cin >> n;
    for (i = 1; i * 2 <= n; i *= 2){
        
    }
    cout << i;
    return 0;
}

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

using namespace std;
typedef long long ll;

int N, M;
int a[300], b[300], c[300];

int g[15][15];

ll dp[1<<15][15];
const ll INF = 1e+12;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    int sum = 0;
    for(int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        g[a[i]][b[i]] = c[i];
        g[b[i]][a[i]] = c[i];
        sum += c[i];
    }
    int fin = (1<<N)-1;
    for(int i = 1; i < (1<<N); i++){
        if(i%2 == 0) continue;
        for(int j = 0; j < N; j++){
            if(!(i&(1<<j))) continue;
            for(int k = j+1; k < N; k++){
                if(!(i&(1<<k))) continue;
                dp[i][0] += g[j][k];
            }
        }
    }
    for(int i = 1; i < (1<<N); i++){
        for(int j = 0; j < N; j++){
            if(i == 1 && j == 0) continue;
            if(dp[i][j] == 0) dp[i][j] = -INF;        
        }
    }
    for(int i = 1; i < (1<<N); i++){
        if(i%2 == 0) continue;
        if(i&(1<<(N-1))) continue;
        for(int j = (i+1)|i; j < (1<<N); j = (j+1)|i){
            int rem = j-i;
            ll sum_rem = 0;
            for(int k = 0; k < N; k++){
                for(int l = k+1; l < N; l++){
                    if((rem&(1<<k)) && (rem&(1<<l))) sum_rem += g[k][l];
                }
            }
            // cout << i << '-' << j << ' ' << rem << ' ' << sum_rem << endl;
            if(j&(1<<(N-1))){
                // N-1に行く
                for(int k = 0; k < N; k++){
                    if(!(i&(1<<k))) continue;
                    if(g[k][N-1] == 0) {}
                    else{
                        // if(i == 7) cout << i << "at"<< k << "dp" << dp[i][k] << '-' << j << endl;
                        dp[j][N-1] = max(dp[j][N-1], dp[i][k]+sum_rem+g[k][N-1]);
                    }
                }
            }else{
                // k -> l
                for(int k = 0; k < N; k++){
                    if(!(i&(1<<k))) continue;
                    for(int l = 0; l < N; l++){
                        if(!(rem&(1<<l))) continue;
                        if(g[k][l] == 0) {}
                        else{
                            dp[j][l] = max(dp[j][l], dp[i][k]+sum_rem+g[k][l]);
                        }
                    }
                }
            }
        }
    }
    ll g_max = 0;
    for(int i = 0; i < (1<<N); i++){
        g_max = max(g_max, dp[i][N-1]);
        // cout << dp[i][N-1] << endl;
    }
    cout << sum-g_max << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++) ans+=__gcd(i,__gcd(j,k));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3636
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, p;
  cin >> n >> p;
  ll a[50];
  rep(i, n) cin >> a[i];
  ll dp[51][2] = {};
  dp[0][0] = 1;
  rep(i, n)
  {
    rep(j, 2)
    {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][(j + a[i]) % 2] += dp[i][j];
    }
  }
  cout << dp[n][p] << endl;
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = []
for _ in range(H):
    a = [int(i) for i in input().split()]
    a += [sum(a)]
    s.append(a)

s.append([sum([x[i] for x in s]) for i in range(W + 1)])

for l in s:
    print(' '.join(map(str, l)))



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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return;
  }
  cout << (h * w + 1ll) / 2ll << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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


using namespace std;

ll dp_black[100005];
ll dp_white[100005];

ll mod = 1e9 + 7;

class graph
{
  private:
    int v;
    list<int> *l;

  public:
    graph(int v)
    {
      this->v = v;
      l = new list<int>[v+1];
    }

    void add_edge(int x,int y)
    {
      l[x].push_back(y);
      l[y].push_back(x);
    }

    void print_graph()
    {
      for(int i = 1 ;i<=v ; i++)
      {
        cout<<i<<" : ";
        for(auto x : l[i])
        {
          cout<<x<<" -> ";
        }
        cout<<endl;
      }
    }

    ll nowB(int node,int parent)
    {

      if(dp_black[node] != -1)
        return dp_black[node];

      ll ans = 1;

      for(auto nbr : l[node])
      {
        if(nbr == parent)
          continue;

        else
          ans = (ans * nowW(nbr,node))%mod;

      }

      return dp_black[node] = (ans)%mod;

    }

    ll nowW(int node, int parent)
    {
      if(dp_white[node] != -1)
        return dp_white[node];

      ll ans = 1;

      for(auto nbr : l[node])
      {
        if(nbr == parent)
          continue;
        else
        {
          ans = (ans * (nowB(nbr,node) + nowW(nbr,node)))%mod;
        }
      }

      return dp_white[node] = (ans)%mod;
    }

};

int main()
{
  int n;
  cin>>n;
  graph G(n);
  int u,v;
  for(int i = 0 ; i<n-1 ; i++)
  {
    cin>>u>>v;
    G.add_edge(u,v);
  }

  //G.print_graph();

  for(int i = 0 ; i<=100004; i++)
    dp_white[i] = dp_black[i] = -1;


  cout<<(G.nowW(1,0) + G.nowB(1,0))%mod<<endl;

  /*  for(int i = 1 ; i<= n ; i++)
  {
    cout<<"for vertex "<<i<<" Black ways: "<<dp_black[i]<<" ,   white ways: "<<dp_white[i]<<endl;
  }*/

  

  
  return 0;
}

Measured memory_bytes: 13184
N = int(input())
a = list(map(int, input().split()))
bol = 0
count =0

while(1):
  for num  in a:
    if num  % 2 == 1:
      bol = 1

  if bol == 0:
        a = [ i	/2 for i in a]
        count += 1
  else:
          break

print(count)

Measured memory_bytes: 3060
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String input = scanner.nextLine();
    Integer ft = Integer.parseInt(input.substring(0,2));
    Integer rest = Integer.parseInt(input.substring(2,4));
    
    String result = "NA";
    
    boolean isFtAvaMon = ft >= 1 && ft <= 12;
    boolean isRestAvaMon =  rest >= 1 && rest <= 12;
    
    if(isFtAvaMon && isRestAvaMon) {
        result = "AMBIGUOUS";
    } else if(!isFtAvaMon && isRestAvaMon) {
        result = "YYMM";
    } else if(isFtAvaMon && !isRestAvaMon) {
        result = "MMYY";
    }
    
    System.out.println(result);
  }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    string a,b;
    cin>>a>>b;
    if(a.length()<b.length()){
        cout<<"LESS"<<endl;
    }
    else if(a.length()>b.length()){
        cout<<"GREATER"<<endl;
    }
    else{
        int n=a.length();
        bool eq = true;
        rep(i,n){
            if(a[i]!=b[i]){
                eq = false;
                if(a[i]<b[i])cout<<"LESS"<<endl;
                else cout<<"GREATER"<<endl;
                break;
            }
        }
        if(eq){
            cout<<"EQUAL"<<endl;
        }
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    if (n<=111) {
        cout<<111<<endl;
    } else if (n<=222) {
        cout<<222<<endl;
    } else if (n<=333) {
        cout<<333<<endl;
    } else if (n<=444) {
        cout<<444<<endl;
    } else if (n<=555) {
        cout<<555<<endl;
    } else if (n<=666) {
        cout<<666<<endl;
    } else if (n<=777) {
        cout<<777<<endl;
    } else if (n<=888) {
        cout<<888<<endl;
    } else {
        cout<<999<<endl;
    }
}


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

using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    long long  temp = 1;
    
    int waru = 1000000007;
    for(int i=1;i<=n;i++){
        temp = (temp%waru * i%waru )%waru;
    }
    cout << temp % waru;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define res register int
using namespace std;
#define MAXN 100010
int n,ans;
struct papa
{
  int x,id;
  inline bool operator <(const papa& b) const
  {
    return x<b.x;
  }
} a[MAXN];
int main()
{
  scanf("%d",&n);
  for(res i=1; i<=n; i++)
  {
    scanf("%d",&a[i].x);
    a[i].id=i;
  }
  sort(a+1,a+1+n);
  for(res i=1; i<=n; i++)
    ans+=((a[i].id&1)!=(i&1));
  printf("%d\n",ans/2);
}

Measured memory_bytes: 1024
#include <iostream>

int main(void) {

    int a, b;
    int max, min;

    std::cin >> a;
    std::cin >> b;

    max = a;
    min = b;

    if(max < b) {
        max = b;
        min = a;
    }

    for (int i = 0; i < max; i++)
        std::cout << min;

    return 0;
        
        
    
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        mut l: [usize; n],
    }

    l.sort();
    let mut ans = 0;

    for i in 0..n {
        for j in i + 1..n {
            let mut ng = n;
            let mut ok = j;
            while (ok as i64 - ng as i64).abs() > 1 {
                let m = (ok + ng) / 2;
                if l[m] < l[i] + l[j] {
                    ok = m;
                } else {
                    ng = m;
                }
            }
            if ok != n {
                ans += ok - j;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#define INFINITY 100000001
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX], p[MAX], color[MAX];
  int i, v, sum;
  
  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFINITY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    
    if(u == -1) break;
    color[u] = BLACK;

    for(v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFINITY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  sum = 0;
  for(i = 0; i < n; i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}

int main(){
  int i, j, e;
  
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d",&e);
      M[i][j] = (e == -1) ? INFINITY : e;
    }
  }

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



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

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int v[n],c[n];
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    rep(i,n){
        if(v[i]>c[i]) ans += (v[i]-c[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int A, B, K;
	scanf("%d %d %d", &A, &B, &K);
	
	int i;
	for (i = A; i < A + K && i <= B; i++) printf("%d\n", i);
	if (A + K * 2 - 1 > B) for (; i <= B; i++) printf("%d\n", i);
	else for (i = B - K + 1; i <= B; i++) printf("%d\n", i);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        ArrayList<Integer> Array = new ArrayList<Integer>();
        ArrayList<String> S_Array = new ArrayList<String>();
        ArrayList<Integer> Number = new ArrayList<Integer>();
        
        for(int i = 0; i<num1;i++){
            String str = scan.next();
            int num3 = scan.nextInt();

            if(Array.size() == 0){
                Array.add(num3);
                S_Array.add(str);
                Number.add(i+1);
            }
            else{
                int j = 0;
                while(j+1 <= Array.size()){
                    if(S_Array.get(j).compareTo(str) >= 0){
                        if(S_Array.get(j).compareTo(str) == 0){
                            if(Array.get(j) > num3){
                                if(j+1 >= Array.size()){
                                    Array.add(j+1,num3);
                                    S_Array.add(j+1,str);
                                    Number.add(j+1,i+1);
                                    break;
                                }
                                while(S_Array.get(j+1).compareTo(str) == 0){
                                    if(Array.get(j+1) > num3){
                                        j++;
                                    }
                                    else    break;
                                    if(j+1 == Array.size()) break;
                                }
                                Array.add(j+1,num3);
                                S_Array.add(j+1,str);
                                Number.add(j+1,i+1);
                                break;
                            }
                            else{
                                Array.add(j,num3);
                                S_Array.add(j,str);
                                Number.add(j,i+1);
                                break;
                            }
                        }
                        else{
                            Array.add(j,num3);
                            S_Array.add(j,str);
                            Number.add(j,i+1);
                            break;
                        }
                    }
                    else{
                        j++;
                    }
                }
                if(j == Array.size()){
                    Array.add(num3);
                    S_Array.add(str);
                    Number.add(i+1);
                }
            }
        }
        for(int i: Number)
        System.out.println(i);

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
using namespace std;

int X, Y, n;
int id[20], k[20], sx[20], sy[20];
int bd[10][10], ans[10][10];
vector<pair<int,int> > area[101];

int dfs(int u) {
	if (u == n) {
		memcpy(ans, bd, sizeof ans);
		return 1;
	}
	int h, w, tx, ty, lx, rx, uy, dy;
	tx = sx[id[u]];
	ty = sy[id[u]];
	bd[ty][tx] = 0;
	int ret = 0;
	for (int i=0; i<(int)area[k[u]].size(); ++i) {
		h = area[k[u]][i].first;
		w = area[k[u]][i].second;
		lx = max(tx-w+1, 0);
		rx = min(tx+w-1, X-1);
		uy = max(ty-h+1, 0);
		dy = min(ty+h-1, Y-1);
		if (rx-lx+1 < w || dy-uy+1 < h) continue;
		for (int y=uy; y+h-1<=dy; ++y) {
			for (int x=lx; x+w-1<=rx; ++x) {
				bool ok = true;
				for (int y2=y; y2<y+h && ok; ++y2) {
					for (int x2=x; x2<x+w; ++x2) {
						if (bd[y2][x2] != 0) {
							ok = false;
							break;
						}
					}
				}
				if ( ! ok) continue;
				for (int y2=y; y2<y+h; ++y2) {
					for (int x2=x; x2<x+w; ++x2) {
						bd[y2][x2] = id[u];
					}
				}
				ret += dfs(u+1);
				for (int y2=y; y2<y+h; ++y2) {
					for (int x2=x; x2<x+w; ++x2) {
						bd[y2][x2] = 0;
					}
				}
				if (2 <= ret) return 2;
			}
		}
	}
	bd[ty][tx] = id[u];
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int i=1; i<=10; ++i) {
		for (int j=1; j<=10; ++j) {
			area[i*j].push_back(make_pair(i, j));
		}
	}
	while (cin >> X >> Y >> n, X) {
		int sum = 0;
		for (int i=0; i<n; ++i) {
			cin >> id[i] >> k[i];
			sum += k[i];
		}
		for (int i=0; i<Y; ++i) {
			for (int j=0; j<X; ++j) {
				cin >> bd[i][j];
				if (bd[i][j] != 0) {
					sx[bd[i][j]] = j;
					sy[bd[i][j]] = i;
				}
			}
		}
		int res = dfs(0);
		if (X * Y != sum || res == 0 || 2 <= res) {
			cout << "NA\n";
			continue;
		}
		for (int i=0; i<Y; ++i) {
			for (int j=0; j<X; ++j) {
				cout << (j == 0 ? "" : " ") << ans[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int d,t,s;
    cin >> d >> t >> s;
    string ans = t * s >= d ? "Yes" : "No";
    cout << ans << endl;
}

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, w, V = 1; cin >> n >> w;
	ll v[n], c[n];
	rep(i, 0, n) cin >> c[i] >> v[i], V += v[i];
	ll dp[V] = {0};  rep(x, 1, V) dp[x] = inf;
	rep(i, 0, n) per(x, v[i], V) ckmin(dp[x], dp[x - v[i]] + c[i]);
	per(x, 0, V) if (dp[x] <= w) return cout << x, 0;
}

Measured memory_bytes: 1024
import sys

INF = 2**31 - 1


class RMQ:

    def __init__(self, n):
        tmp = 1
        while tmp < n:
            tmp *= 2
        self.n = tmp * 2 - 1
        self.A = [INF] * (2 * self.n - 1)

    def update(self, i, x):
        i = self.n // 2 + i
        self.A[i] = x
        while i:
            i = (i - 1) // 2
            self.A[i] = min(self.A[i * 2 + 1], self.A[i * 2 + 2])

    def find(self, a, b, k, l, r):
        if r < a or b < l:
            return INF
        if a <= l and r <= b:
            return self.A[k]
        vl = self.find(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = self.find(a, b, k * 2 + 2, (l + r) // 2 + 1, r)
        return min(vl, vr)


line = sys.stdin.readline()
n, q = map(int, line.split())
t = RMQ(n)
for i in range(q):
    line = sys.stdin.readline()
    com, x, y = map(int, line.split())
    if com == 0:
        t.update(x, y)
    else:
        print(t.find(x, y, 0, 0, t.n // 2))



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max();
constexpr auto llinf = numeric_limits<ll>().max();

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << *it << " ";
	}
	cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << (*it).first << ":" << (*it).second << " ";
	}
	cout << endl;
}

template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

int n, m;
vvi adj;
constexpr int mxN = 100010;
bitset<mxN> visited;
vi parent;

void bfs(int st) {
	queue<int> q;
	q.push(st);
	while (!q.empty()) {
		auto u = q.front();
		// debug({u}); 
		q.pop();
		if (visited.test(u)) continue;
		for (auto v : adj[u]) {
			if (!visited.test(v)) {
				if (parent[v] == -1) {
					parent[v] = u;
				}
				q.push(v);
			}
		}
		visited.set(u);
	}
}

void solve() {
	cin >> n >> m;
	adj.resize(n + 1);
	int a, b;
	rep(i, m) {
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	// repa(i, 1, n) {
	// 	cout << i << ": ";
	// 	dump(all(adj[i]));
	// }
	visited.reset();
	parent.resize(n + 1);
	fill(all(parent), -1);
	bfs(1);
	if (find(parent.begin() + 2, parent.end(), -1) == parent.end()) {
		cout << "Yes\n";
		repa(i, 2, n) {
			cout << parent[i] << "\n";
		}
	} else {
		cout << "No\n";
	}
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 10284
solve list = g . f $ filter (\n -> even n) list
  where
    g b = if b then "APPROVED" else "DENIED"
    f list = foldr (\x y -> if (x `mod` 3 == 0) || (x `mod` 5 == 0)
                        then (True &&) y
                        else (False &&) y) True $ list

main = do
  _ <- readLn :: IO Int
  ls <- map read . words <$> getLine :: IO [Int]
  putStrLn $ solve ls

Measured memory_bytes: 1020
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
int main() {
	int a;
	cin >> a;
	cout << a * a << endl;
	return 0;
}



Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) (a)<=(i) && (i)<(b)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;

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

  int n;
  cin >> n;

  vector<int> h(n);
  REP(i,n) cin >> h[i];
  
  int ans = 0;
  bool f = true, ff = true;
  while(f){
    f = false; ff = true;
    REP(i,n){
      if(h[i] != 0){
        h[i]--;
        f = true;
        if(ff){
          ans++;
          ff = false;
        }
      }
      else{
        ff = true;
      }
    }
    //debug(ans);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1000005
    const ll MOD = 1000000000 + 7;
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
           string a , b;
           cin >> a >> b;
           
          
           int len = a.length();  
           int sum = 0;          
           for(int i = 0 ; i < len ; i++)
           {
               if(a[i] != b[i])sum++;
           }
        
           cout << sum << endl;
        }
    }



Measured memory_bytes: 3792
n,m = gets.chomp.split(' ').map{|n| n.to_i}
disn = 100000
a = Array.new
b = Array.new
c = Array.new
dist = Array.new(100)
dist.length.times {|i| dist[i] = Array.new(100)}
for i in 0...m do
  a[i],b[i],c[i] = gets.chomp.split(' ').map{|n| n.to_i}
  a[i] =a[i]-1
  b[i] =b[i]-1
end
for i in 0...n do
  for j in 0...n do
    if i == j
      dist[i][j] = 0
    else
      dist[i][j] = disn
    end
  end
end
for i in 0...m do
  dist[a[i]][b[i]] = [dist[a[i]][b[i]],c[i]].min
  dist[b[i]][a[i]] = [dist[b[i]][a[i]],c[i]].min
end
for k in 0...n do
  for i in 0...n do
    for j in 0...n do
      dist[i][j] = [dist[i][j],dist[i][k] + dist[k][j]].min
    end
  end
end
ans = m
for i in 0...m do
  f = false
  for j in 0...n do
    f = true if (dist[j][a[i]] + c[i]) == dist[j][b[i]]
  end
  ans = ans - 1 if f
end
puts ans

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

const double INF = 1e9;
const double EPS = 1e-11;

// ????¬????
struct P3{
  double x,y,z;
  double vx,vy,vz;
  double r,vr;
  P3(double x=0, double y=0, double z=0):x(x),y(y),z(z){}
  P3 operator + (const P3 &a) const{ return P3(x+a.x, y+a.y, z+a.z); }
  P3 operator - (const P3 &a) const{ return P3(x-a.x, y-a.y, z-a.z); }
  P3 operator * (const double &c) const{ return P3(x*c, y*c, z*c); }
  void input(){scanf("%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf",&x,&y,&z,&vx,&vy,&vz,&r,&vr);};
  P3 v ()const{return P3(vx,vy,vz);}
};
P3 operator * (double c, const P3 &a){ return P3(c * a.x, c * a.y, c * a.z); }


double norm(const P3 &a){ return a.x*a.x + a.y*a.y + a.z*a.z; }
double abs(const P3 &a){ return sqrt(norm(a)); }

typedef pair<int,int> P;
typedef pair<double,P> PP;

double calc(const P3 &A,const P3 &B,double t){
  if((A.r-t*A.vr)<0|| (B.r-t*B.vr)<0) return -1;
  return abs((A+t*A.v())-(B+t*B.v())) - ((A.r-t*A.vr) + (B.r-t*B.vr));
}

double calc(const P3 &A,const P3 &B){
  double L=0,R=INF,cnt = 65;
  while(cnt--){
    double M = (L+R)/2;
    double y1 = calc(A,B,M);
    double y2 = calc(A,B,M+EPS);
    if(y1<0||y1-y2<0) R = M;
    else L = M+EPS;
  }
  return L-EPS;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<P3>A(n);
    for(int i=0;i<n;i++) A[i].input();

    priority_queue<PP,vector<PP>,greater<PP> >Q;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++){
	double t = calc(A[i],A[j]);
	if(abs(calc(A[i],A[j],t))<2e-8)Q.push(PP(t,P(i,j)));
      }

    vector<double> ans(n,-1);
    while(!Q.empty()){
      PP t = Q.top();Q.pop();
      double c = t.first;
      int a = t.second.first;
      int b = t.second.second;
      if(ans[a]>=0||ans[b]>=0)continue;
      ans[a] = ans[b] = c;
    }

    for(int i=0;i<n;i++){
      if(ans[i]<0) ans[i] = A[i].r / A[i].vr;
      ans[i] = min(ans[i],A[i].r / A[i].vr);
      printf("%.10Lf\n",ans[i]);
    }    
    
  }
  return 0;    
}

Measured memory_bytes: 3316
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

ll check(ll x,vector<ll>&a){
  rep(i,a.size()){
    x-=x%a[i];
  }
  return x;
}

bool solve(){  
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll right=INF,left=0;
  for(;right-left>1;){
    ll mid=(right+left)/2;
    if(check(mid,a)>=2)right=mid;
    else left=mid;
  }
  //rightが最小
  if(check(right,a)!=2){
    cout<<-1<<endl;
    return false;
  }
  cout<<right<<endl;

  right=INF,left=0;
  for(;right-left>1;){
    ll mid=(right+left)/2;
    if(check(mid,a)<=2)left=mid;
    else right=mid;
  }
  cout<<left<<endl;

  return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
    char S[27];     scanf("%s", S);
    int i, j;
    int check = 0;

    for(i = 0; S[i]; i++){
        for(j = 0; S[j]; j++){
            if(i != j){
                if(S[i] == S[j]){
                    check = 1;
                }
            }
        }
    }

    if(check == 0){
        printf("yes\n");
    }
    else{
        printf("no\n");
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] S = new String[H];

        for(int i = 0; i < H; i++){
            S[i] = sc.next();
        }
        
        char[][] s = new char[H][W];
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                s[i][j] = S[i].charAt(j);
            }
        }
        //地雷のない箇所を0で置換
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(s[i][j] != '#') s[i][j] = '0';
            }
        }
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                //s[i][j]に地雷があったとき、地雷のない周囲8マスをカウントアップ()する。
                if(s[i][j] == '#'){
                    for(int k = -1; k <= 1; k++){
                        for(int l = -1; l <= 1; l++){
                            if(((0 <= i + k && i + k < H) && (0 <= j + l && j + l < W)) && (!(k == 0 && l == 0))){
                                if(s[i + k][j + l] != '#'){
                                    s[i + k][j + l]++;
                                }
                            }
                        } 
                    }
                }
            }
        }

        for(int i = 0; i< H; i++){
            for(int j = 0; j < W; j++){
                System.out.print(s[i][j]);
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 22484
#include <stdio.h>
using namespace std;

int main(){
    int n,tmp,max=-1000000,min=1000000;
    long long int sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&tmp);
        if(tmp>max)max=tmp;
        if(min>tmp)min=tmp;
        sum+=tmp;
    }
    printf("%d %d %lld\n",min,max,sum);
}



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

int main(){
  int n,ans=0;cin>>n;
  map<int, int> mp;
  REP(i,n){
    int tmp;cin>>tmp;
    mp[tmp]++;
  }
  for(auto p:mp) if((p.second)%2) ans++;
  
  cout<<ans;
}

Measured memory_bytes: 4864
// Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,x;
    cin>>n>>m;
    if(n==m||n%m==0)cout<<"0\n";
    else if(n<m)
    {
        if(m-n<n)cout<<m-n<<endl;
       else cout<<n<<endl;
    }
    else
    {
      while(true)
      {
          if(n<m)
          {
              cout<<m-n<<endl;
              break;
          }
          else if(n==m)
          {
              cout<<m<<endl;
              break;
          }

          n=n%m;
      }

    }

}







Measured memory_bytes: 256
input = open(0).read
S, T = input().split()


def main():
    C1 = [None] * (ord('z') - ord('a') + 1)
    C2 = [None] * (ord('z') - ord('a') + 1)

    flg = True

    for i in range(len(S)):
        c1 = ord(S[i]) - ord('a')
        c2 = ord(T[i]) - ord('a')

        if C1[c1] or C2[c2]:
            if c1 != C2[c2] or c2 != C1[c1]:
                flg = False
                break

        C1[c1] = c2
        C2[c2] = c1

    print("Yes" if flg else "No")
    return


main()


Measured memory_bytes: 3828
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type pair struct {
	a int
	b int
}

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}

func nextLong() int64 {
	i, _ := strconv.ParseInt(nextLine(), 10, 64)
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	graph := make([][]int, N+1)
	for i := 1; i < N+1; i++ {
		graph[i] = make([]int, 0, N-1)
		for j := 0; j < N-1; j++ {
			graph[i] = append(graph[i], nextInt())
		}
	}
	queue := make([]pair, 0)
	for i := 1; i < N; i++ {
		if graph[graph[i][0]][0] == i && i < graph[i][0] {
			queue = append(queue, pair{i, graph[i][0]})
		}
	}
	ans := 0
	for cnt := 0; cnt < N*(N-1)/2; ans++ {
		if len(queue) == 0 {
			fmt.Println("-1")
			return
		}
		for b := len(queue); b > 0; b-- {
			n := queue[0].a
			graph[n] = graph[n][1:]
			if len(graph[n]) != 0 && graph[graph[n][0]][0] == n {
				queue = append(queue, pair{n, graph[n][0]})
			}
			n = queue[0].b
			graph[n] = graph[n][1:]
			if len(graph[n]) != 0 && graph[graph[n][0]][0] == n {
				queue = append(queue, pair{n, graph[n][0]})
			}
			queue = queue[1:]
			cnt++
		}
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 20480