akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define max(a,b) (((a)>(b)) ? (a):(b))
#define min(a,b) (((a)<(b)) ? (a):(b))
#define rep(i,s,n) for(int i=(int)s;i<(int)(n);i++)
#define MAX 10000000
#define MIN -10000000

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

int cp_min(const int *a,const int *b) {
    return *a-*b;
}

int cp_max(const int *a,const int *b) {
    return *b-*a;
}

int main(void){
    int n,m,cnt=0;
    int l[100000],r[100000];
    int maxl=MIN,minr=MAX;
    scanf("%d %d",&n,&m);
    rep(i,0,m){
        scanf("%d %d",&l[i],&r[i]);
        maxl=max(maxl,l[i]);
        minr=min(minr,r[i]);
    }
    printf("%d\n",max(0,minr-maxl+1));
    return 0;
}

Measured memory_bytes: 896
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  ll b;cin>>b;
  ll a=100;
  ll count=0;
  while(true){
    ll d=a/100;
    a+=d;
    count++;
    if(a>=b)break;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t x;
    std::cin >> x;
    
    int64_t quotient = x / 11;
    int64_t ans = quotient * 2;
    x %= 11;
    if (0 < x && x <= 6) ans += 1;
    if (6 < x && x <= 11) ans += 2;

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

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> G[1000000];
vector<pair<int, int> > bridge;
vector<int> articulation;
int ord[1000000], low[1000000];
bool vis[1000000];

void dfs(int v, int p, int &k)
{
	vis[v] = true;
	
	ord[v] = k++;
	low[v] = ord[v];
	
	bool isArticulation = false;
	int ct = 0;
	
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	
	int k = 0;
	for (int i = 0; i < n; i++){
		if (!vis[i]) dfs(i, -1, k);
	}
	
	sort(bridge.begin(), bridge.end());
	sort(articulation.begin(), articulation.end());
	
	//printf("%d\n", articulation.size());
	
	for (int i = 0; i < articulation.size(); i++)
		printf("%d\n", articulation[i]);
	
	//printf("%d\n", bridge.size());
	
	/*for (int i = 0; i < bridge.size(); i++)
		printf("%d %d\n", bridge[i].first + 1, bridge[i].second + 1);
	*/
	
	return (0);
}

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

int main() {
  string s;
  int kotae=700;
  cin>>s;
  if(s[0]=='o')kotae+=100;
  if(s[1]=='o')kotae+=100;
  if(s[2]=='o')kotae+=100;
  cout <<kotae<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi                first
#define se                 second
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.se >b.se);
    }
    else
        return (a.fi<b.fi);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
ll sumofdigit(ll n)
{
    ll c=0,d=0,sum=0,i;
    while(n>0)
    {
        c=n%10;
        sum+=c;
        n/=10;
    }
    return sum;
}
ll fact(ll n)
{
    ll c=1;
    for(ll i=1;i<=n;i++)
    {
        c*=i;
    }
    return c;
}
ll ks(vector<ll> &a,ll k,ll n)
{
     ll dp[n+1][k+1];
    for(ll i=0;i<n+1;i++)
    {
        for(ll j=0;j<k+1;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else
            {
                if(a[i-1]>j)
                {
                    dp[i][j]=dp[i-1][j];
                }
                else
                {
                    if(dp[i][j-a[i-1]]!=0||j==a[i-1])
                    dp[i][j]=max(dp[i-1][j],(1+dp[i][j-a[i-1]]));
                    else
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
    }
    return dp[n][k];
}
int main()
{
 fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
        ll k=0,n,i=0,j=0,c=0,d=0,e=0,f=0,sum=0,g=0,h=0,maxi=0;
         cin>>n;
         map<ll,ll> m;
         for(i=1;i<=105;i++)
         {
             for(j=1;j<=105;j++)
             {
                 for(k=1;k<=105;k++)
                 {
                     c=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
                     m[c]+=1;
                 }
             }
         }
         for(i=1;i<=n;i++)
         {
             cout<<m[i]<<endl;
         }

     }
}



Measured memory_bytes: 6212
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

// solution 
use std::collections::BinaryHeap;
use std::collections::HashSet;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        X: usize,
        Y: usize,
        Z: usize,
        K: usize,
        A: [usize; X],
        B: [usize; Y],
        C: [usize; Z],
    }

    A.sort();
    B.sort();
    C.sort();
    let mut candidates: BinaryHeap<Point> = BinaryHeap::with_capacity(6000);
    let mut selected: HashSet<Point> = HashSet::with_capacity(6000);
    let mut pick = Point(A[X-1]+B[Y-1]+C[Z-1], X-1, Y-1, Z-1);
    println!("{}", pick.0);
    K = K - 1;
    while K > 0 {
        if pick.1 > 0 {
            let p = Point(A[pick.1-1]+B[pick.2]+C[pick.3], pick.1-1, pick.2, pick.3);
            if selected.insert(p) {
                candidates.push(p);
            }
        }
        if pick.2 > 0 {
            let p = Point(A[pick.1]+B[pick.2-1]+C[pick.3], pick.1, pick.2-1, pick.3);
            if selected.insert(p) {
                candidates.push(p);
            }
        }
        if pick.3 > 0 {
            let p = Point(A[pick.1]+B[pick.2]+C[pick.3-1], pick.1, pick.2, pick.3-1);
            if selected.insert(p) {
                candidates.push(p);
            }
        }
        pick = candidates.pop().unwrap();
        println!("{}", pick.0);
        K -= 1;
    }
}

#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
struct Point(usize, usize, usize, usize);


Measured memory_bytes: 4352
while True:
    H,W = map(int,input().split())
    if H == 0 == W:
        break
    else :
        for i in range(H):
            if i == 0 or i == H-1: 
                print("#" * W )
            else :
                print("#" + "." *(W-2) + "#")
        print()


Measured memory_bytes: 5608
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(caseCount: Int = 1): Unit = {
    val n = readInt()
    if (n == 0) return
    val state = Array.fill(n){Array.fill(n){0}}
    var count = 1
    for (d ← 0 until 2 * n) {
      val pos = math.max(0, d - n + 1) to math.min(d, n - 1)
      for (x ← if (d % 2 == 0) pos else pos.reverse) {
        state(d - x)(x) = count
        count += 1
      }
    }
    println(s"Case $caseCount:")
    println(state.map(_.map(it ⇒ f"$it%3d").mkString(sep = "")).mkString(sep = "\n"))
    loop(caseCount + 1)
  }
}


Measured memory_bytes: 44556
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


at = 0
over = 0
for i in range(n):
    diff = max(0, a[i] - over) - b[i]
    over = max(0, -diff)
    at += max(0, diff)
print(sum(a) - (at + max(0, a[-1] - over)))


Measured memory_bytes: 19116
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn=1010;
int n,a[maxn];
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n,cmp);
	int suma=0,sumb=0;
	for(i=0;i<n;i++){
		if(i<n){
			suma+=a[i];
			i++;
		}
		if(i<n){
			sumb+=a[i];
		}	
	}
	printf("%d\n",abs(suma-sumb));
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct UnionFind {
  vector< ll > data;

 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(ll x, ll y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y, char c) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};
int h,w;
int main() {
  
  cin >> h >> w;
  vector<string> G(h);
  UnionFind tree(h*w);
  rep(i,h)cin >> G[i];
  auto P = [](int i,int j){
    return(i*w+j);
  };
  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      //cout<<P(i,j)<<endl;
      if(i+1<h)if(G[i+1][j] != G[i][j]) tree.unite(P(i,j),P(i+1,j),G[i+1][j]);
      if(i-1>=0)if(G[i-1][j] != G[i][j]) tree.unite(P(i,j),P(i-1,j),G[i-1][j]);
      if(j-1>=0)if(G[i][j-1] != G[i][j]) tree.unite(P(i,j),P(i,j+-1),G[i][j-1]);
      if(j+1<w)if(G[i][j+1] != G[i][j]) tree.unite(P(i,j),P(i,j+1),G[i][j+1]);
    }
  }
  ll ans = 0;
  vector< ll > color(h*w);
  rep(i,h){
    rep(j,w)
    if(G[i][j]=='#')color[tree.root(P(i,j))]++;
  }
  rep(i,h*w){
    // show(tree.data[i]);
    // show(color[i]);
    if(tree.data[i]<0){
      ll b = color[i];
      ll w = -tree.data[i]-b;
      ans+=b*w;;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)n; ++i)

int x[100001];
vector<int> tr[100001];

int go(int v = 1){
	vector<int> z;
	f(i, 0, tr[v].size())z.push_back(go(tr[v][i]));
	sort(z.begin(), z.end());
	int mx = 0;
	for (int i = z.size() - 1; i >= 0; --i)mx = max(mx, z[i] + (int)z.size() - i);
	return mx;
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 2, n + 1)scanf("%d", x + i), tr[x[i]].push_back(i);
	printf("%d\n", go());
}


Measured memory_bytes: 15488
#include <cmath>
#include <queue>
#include <iostream>
using namespace std;

int G[110][110] = {0};
int n;
int D[110] = {0};
void bfs(int src){
 queue<int> Q;
 Q.push(src);
 D[src] = 0;
 while(! Q.empty()){
  int cur = Q.front();
  Q.pop();
  for(int i=1; i<=n; i++){
   if(G[cur][i]==1 && D[i]==0 && i!=1){
    D[i] = D[cur]+1;
    Q.push(i);
   }
  }
 }

 for(int i=1; i<=n; i++){
  if(i!=1 && D[i]==0){
   D[i]=-1;
  }
  cout << i << " " << D[i] << endl;
 }
}

int main(){
 cin >> n;
 int u, k;
 int v[100000];
 for(int i=0; i<n; i++){
  cin >> u >> k;
  for(int j=0; j<k; j++){
   cin >> v[j];
   G[i+1][v[j]] = 1;
  }
 }
 bfs(1);
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define int long long
const int maxn=1e5+1;

int n,k;
int a[maxn],f[100101];

main()
{
    cin>>n>>k;
    forinc(i,1,n) cin>>a[i];
    memset(f,127,sizeof f);
   // f[2]=abs(a[2]-a[1]);
   f[1]=0;
    forinc(i,1,n)
    {
        forinc(j,1,k)
        {
            if(f[i+j]>f[i]+abs(a[i]-a[j+i]))
            {
                f[i+j]=f[i]+abs(a[i]-a[j+i]);
            }
        }
    }
    cout<<f[n];
}




Measured memory_bytes: 1792
fn main() {
    let n = rv::<usize>()[0];
    let mut a = rv::<i32>();
    let mut c = Vec::with_capacity(n*2);
    let mut k=0;
    for i in 1..n {
        if a[k].abs()<a[i].abs() {
            k=i;
        }
    }
    if a[k]<0 {
        for i in (0..n-1).rev() {
            if a[i+1]<a[k] {k=i+1;}
            if a[i+1]>=a[i] {continue;}
            a[i]+=a[k]; c.push((k,i));
            if a[i+1]>=a[i] {continue;}
            for j in (i+1..n).rev() {
                if a[i+1]>=a[i]+a[j] {
                    a[i]+=a[j]; c.push((j,i));
                    break;
                }
            }
        }
    }
    else if a[k]>0 {
        for i in 1..n {
            if a[i-1]>a[k] {k=i-1;}
            if a[i-1]<=a[i] {continue;}
            a[i]+=a[k]; c.push((k,i));
            if a[i-1]<=a[i] {continue;}
            for j in 0..i {
                if a[i-1]<=a[i]+a[j] {
                    a[i]+=a[j]; c.push((j,i));
                    break;
                }
            }
        }
    }
    println!("{}",c.len());
    for (i,j) in c {
        println!("{} {}",i+1,j+1);
    }
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T>
  where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>
#include <functional>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;

int n;

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

		vector<vector<int>> dp(n + 1,vector<int>(n + 1,-1));

		//[l,r)
		function<int(int,int)> rec = [&](int l,int r){
			if(dp[l][r] != -1) return dp[l][r];

			if(abs(l - r) <= 1) return 0;

			int res = 0;
			//l [able] r ?
			if(abs(w[l] - w[r - 1]) <= 1 && rec(l + 1,r - 1) == r - l - 2)
			{
				res = r - l;
			}

			//[l any] [any r]
			for(int mid = l + 1;mid <= r - 1;mid++)
			{
				res = max(res , rec(l,mid) + rec(mid,r));
			}
			return dp[l][r] = res;
		};

		cout << rec(0,n) << endl;
	}
}
				


			




Measured memory_bytes: 3356
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
 
int k;
cin>>k;
vector<long long> all(k);
long long res=0;
for(int i=0;i<k;i++)
cin>>all[i];
 
sort(all.begin(),all.end());
 
long long a=0,b=0,tmp=-1;
for(int i=k-1;i>=0;i--)
{
if(tmp==all[i])
{
if(a==0)
{
a=tmp;
tmp=0;
}
else
{
b=tmp;
break;
}
}
else
tmp=all[i];
}
if(a*b>res)
res=a*b;
cout<<res<<endl;
 
return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
 
struct data{
  int p,t;
  data(int p=0, int t=0):p(p),t(t){}
  bool operator < (const data &d) const {
    return t < d.t;
  }
};
 
const int INF = 1 << 29;
int n;
data v[40];
 
void solve(){
  int dp[41][4], ans = INF;
  fill(dp[0],dp[n],INF);
 
  if(v[0].p > v[0].t){
    cout << "NG 1" << endl;
    return;
  } else if(n == 1){
    cout << "OK " << v[0].p*2 << endl;
    return;
  }
 
  dp[0][1] = v[0].p;
  for(int i=0;i<n-1;i++){
    bool f = false;
    for(int j=1;j<=3;j++){
      if(j < 3){
        if(abs(v[i+1].p-v[i].p)*(j+1) <= v[i+1].t-v[i].t && dp[i+1][j+1] > dp[i][j]+abs(v[i+1].p-v[i].p)){
          dp[i+1][j+1] = dp[i][j] + abs(v[i+1].p-v[i].p);
          f = true;
        }
      }
      if(v[i].p*(j+1) + v[i+1].p <= v[i+1].t-v[i].t && dp[i+1][1] > dp[i][j] + v[i+1].p+v[i].p){
        dp[i+1][1] = dp[i][j] + v[i+1].p+v[i].p;
        f = true;
      }
    }
    if(!f){
      cout << "NG " << i+2 << endl;
      return;
    }
  }
 
  for(int i=1;i<4;i++) ans = min(ans,dp[n-1][i]+v[n-1].p);
  cout << "OK " << ans << endl;
  assert(ans < INF);
}
 
int main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++) cin >> v[i].p >> v[i].t;
    sort(v,v+n);
    solve();
  }
}

Measured memory_bytes: 1164
from numpy import *
N = int(input())
A = list(map(int,input().split()))
print(2*N-1)

if abs(max(A))<abs(min(A)):
  x = argmin(A)
  for n in range(N):
    print(x+1,n+1)
  for n in range(N-1):
    print(N-n,N-n-1)
else:
  x = argmax(A)
  for n in range(N):
    print(x+1,n+1)
  for n in range(N-1):
    print(n+1,n+2)

Measured memory_bytes: 27244
#include <iostream>
#include <vector>
#include <utility>

int main() {
		
	// recieve |V| and |E|
	int V, E; std::cin >> V >> E;
	std::vector<std::vector<std::pair<int, int>>> G(V);
	
	for(int i = 0; i < E; i++) {
		// recieve edges
		int u, v, d; std::cin >> u >> v >> d;
		u--; v--;
		G[u].push_back({v, d});
		G[v].push_back({u, d});
	}

	// calc cost
	std::vector<std::vector<int>> D(V,std::vector<int>(V));
	for(int i = 0; i < V; i++){
		for(int j = 0; j < V; j++){
			D[i][j] = 999999999;
		}
		std::vector<bool> flag(V);
		D[i][i] = 0;
		for(int j = 0; j < V; j++){
			int minnode = -1;
			int mincost = 999999999;
			for(int k = 0; k < V; k++){
				if(flag[k]==false && D[i][k] < mincost){
					minnode = k;
					mincost = D[i][k];
				}
			}
			flag[minnode] = true;
			for(int k = 0; k < G[minnode].size(); k++){
				if(D[i][minnode]+G[minnode][k].second < D[i][G[minnode][k].first]){
					D[i][G[minnode][k].first] = D[i][minnode]+G[minnode][k].second;
				}
			}
		}
	}
	
	int Tmax; std::cin >> Tmax;
	long long score = 0;
	std::vector<int> orderFlag;
	std::vector<std::pair<int, int>> ORDER;

	int nowNode = 0;
	int targetNode = 0;
	int remainDist = 0;

	// recieve info
	for(int i = 0; i < Tmax; i++) {
		int Nnew; std::cin >> Nnew;
		for(int j = 0; j < Nnew; j++) {
			int new_id, dst; std::cin >> new_id >> dst;
			dst--;
			orderFlag.push_back(0);
			ORDER.push_back({i, dst});
		}
		// insert your code here to get more meaningful output
		int ans = -1;
		if(remainDist == 0){
			nowNode = targetNode;
			int mintarget = -1;
			int mincost = 999999999;
			for(int j = 0; j < ORDER.size(); j++){
				if(orderFlag[j] == 1 && nowNode == ORDER[j].second){
					score += Tmax * Tmax - (i - ORDER[j].first) * (i - ORDER[j].first);
					orderFlag[j] = 2;
				}
				if(nowNode == 0 && orderFlag[j] == 0){
					orderFlag[j] = 1;
				}
				if(orderFlag[j] == 0){
					if(D[nowNode][0]+D[0][ORDER[j].second] <= mincost){
						mintarget = 0;
						mincost = D[nowNode][ORDER[j].second];
					}
				}
				if(orderFlag[j] == 1){
					if(D[nowNode][ORDER[j].second] < mincost){
						mintarget = ORDER[j].second;
						mincost = D[nowNode][ORDER[j].second];
					}
				}
			}
			if(mintarget == -1 && nowNode > 0){
				mintarget = 0;
			}
			int minNextCost = 999999999;
			if(mintarget >= 0){
				for(int j = 0; j < G[nowNode].size(); j++){
					if(D[G[nowNode][j].first][mintarget] < minNextCost){
						ans = G[nowNode][j].first + 1;
						targetNode = ans - 1;
						remainDist = G[nowNode][j].second - 1;
						minNextCost = D[G[nowNode][j].first][mintarget];
					}
				}
			}
		} else {
			ans = targetNode + 1;
			remainDist--;
        }
		std::cout << ans << std::endl;
		//std::cerr << nowNode << " " << targetNode << " " << remainDist << std::endl;
	}
	std::cerr << score << std::endl;
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#define REP(i, n) for (int i = 0; i < (n); i++)
 
using namespace std;
 
int main() {
  int N, T = 1;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int m = 1000000,sum = 0;
  for (int i = 0; i < N; i++) {
    sum = 0;
    for (int j = 0; j <= i; j++)
      sum += A[j];
    for (int j = N - 1; j > i; j--)
      sum -= A[j];
    sum = abs(sum);
    m = min(m, sum);
  }
  cout << m << endl;
}  

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

public class Main {
	int cnt;
	int n;
	int m;
	int array[];
	ArrayList<Integer> g;
	public static void main(String args[]) {
		Main m = new Main();
		m.shellSort();
		m.printAnswer();
	}
	public Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		g = new ArrayList<Integer>();
	}
	public void printAnswer() {
		System.out.println(g.size());
		for(int i = 0; i < g.size(); i++) {
			System.out.print((i == 0?"":" ") + g.get(i));
		}
		System.out.println();
		System.out.println(cnt);

		for(int i = 0; i < n; i++) {
			System.out.print((i == 0?"":"\n") + array[i]);
		}
	}
	public void insertionSort(int g) {
		for (int i  = g; i < n; i++) {
			int v = array[i];
			int j = i;
			while (j >= g && array[j - g] > v){
				array[j] = array[j - g];
				j -= g;
				cnt++;
			}
			array[j] = v;
		}
	}
	public void shellSort() {
		cnt = 0;
		m = 0;
		while(true){
			int tm = m * 3 + 1;
			if (m > n / 9) break;
			m = tm;
		}
		while (m > 0) {
			insertionSort(m);
			g.add(m);
			m /= 3;
		}
	}
}



Measured memory_bytes: 306356
#! /usr/bin/env python3

import re

gkey = input()

yaml = {}
opening_key = ['']
opening_ind = [-1]
space_prog = re.compile(r' *')
key_prog = re.compile(r'[a-z\d]+')
while True:
    try:
        line = input()
    except EOFError:
        break

    indent = len(space_prog.match(line).group())
    while opening_ind[-1] >= indent:
        opening_ind.pop()
        opening_key.pop()

    key = key_prog.search(line).group()
    if not line.endswith(':'):
        yaml['.'.join(opening_key+[key])] = (
            'string "{}"'.format(line[line.index(':')+2:])
        )
        continue

    opening_key.append(key)
    opening_ind.append(indent)

    yaml['.'.join(opening_key)] = 'object'

print(yaml.get(gkey, 'no such property'))



Measured memory_bytes: 6712
#include<bits/stdc++.h> 
using namespace std; 
int main(){ int a,b,c,t7=0; scanf("%d%d%d",&a,&b,&c); if(a==7) t7++; if(b==7) t7++; if(c==7) t7++; if(t7==1) printf("YES"); else printf("NO"); }

Measured memory_bytes: 256
import heapq as hp

INF = 1000000

def diikstraMethd(G, s):
    # ?????????
    n = len(G)
    d = [INF for _ in range(n)]
    d[s] = 0
    PQ = [(d[s], s)]

    while PQ:
        u = hp.heappop(PQ)[1]
        for v, c in G[u]:
            alt = d[u] + c
            if d[v] > alt:
                d[v] = alt
                hp.heappush(PQ, (alt, v))

    return d


if __name__ == '__main__':
    n = int(input())
    G = [ [] for _ in range(n)]
    for _ in range(n):
        tmp = list(map(int, input().split()))
        u = tmp.pop(0)
        k = tmp.pop(0)
        for i in range(k):
            v = tmp.pop(0)
            c = tmp.pop(0)
            G[u].append((v, c))

    d = diikstraMethd(G, 0)

    for i in range(n):
        print('{0} {1}'.format(i, d[i]))

Measured memory_bytes: 70632
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		ll H,W;
		string a;

		cin >> H >> W;

		for(int i=0;i<H;i++){
				cin >> a;
				cout << a << endl;
				cout << a << endl;

		}

		return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=200005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n,m;
    cin >> n >> m;
    ll a[n+1]={0};
    rep(i,1,n+1) cin >> a[i];
    vll adj[n+1];
    rep(i,0,m) {
    	ll x,y;
    	cin >> x >> y;
    	adj[x].pb(y);
    	adj[y].pb(x);
    }

    ll ans=0;
    rep(i,1,n+1) {
    	ll v=a[i];
    	ll mx=0;
    	for(auto it:adj[i]) {
    		mx=max(mx,a[it]);
    	}
    	if(v>mx) ans++;
    }
    ret(ans);

}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        if(A[i] == B[i] && B[i] == C[i]){
            cnt += 0;
        } else if(A[i] != B[i] && B[i] != C[i] && A[i] != C[i]){
            cnt += 2;
        } else {
            cnt += 1;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  cin>>n;
  vector<double> x(n);
  vector<string> u(n);
  rep(i,n) {
    cin>>x[i]>>u[i];
  }
  double ans=0;
  double rate=380000.0;
  rep(i,n) {
    if(u[i]=="JPY") {
      ans+=x[i];
    } else {
      ans+=x[i]*rate;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define show(x) cerr << #x << " = " << x << "\n";
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define pb(x) emplace_back(x)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = INF;
class mint {
public:
	ll x;
	mint(ll x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const { 
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}
	friend ostream& operator<<(ostream& os, const mint& m){
		os << m.x;
		return os;
	}
};

ll modpow(ll x, ll n, ll p = INF) {
	if (n == 0) return 1 % p;
	if (n % 2 == 0) return modpow(x * x % p, n / 2, p);
	else return x * modpow(x, n - 1, p) % p;
}

void Main(){

	ll a, b, x, ans;
	cin >> a >> b >> x;
	if(!a) ans = b / x + 1;
	else ans = b / x - (a - 1) / x;
	print(ans);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin >> t;
	rep(i, t) Main();
	return 0;
	
}





Measured memory_bytes: 3548
//2019.8.18 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define unl __int128
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG unl x){
//    if(x>10)write(x/10);
//    putchar(int(x%10)+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=1e5+10;
namespace MAIN{
    char s[N],t[N];
    int ns,nt;
    int st[N],nxt[N][26],las[N];
    inline void MAIN(){
        scanf("%s",s+1),scanf("%s",t+1);
        ns=int(strlen(s+1)),nt=int(strlen(t+1));
        for(res i=1;i<=ns;i++){
            res x=s[i]-'a';
            if(!st[x])nxt[ns+1][x]=i,st[x]=1;
        }
        for(res i=ns;i;i--){
            res x=s[i]-'a';
            for(res j=0;j<26;j++){
                if(x==j)nxt[i][j]=i;
                else nxt[i][j]=nxt[i+1][j];
            }
        }
        res j=1,sum=0,p=0;
        for(res i=1;i<=nt;i++){
            res x=t[i]-'a';
            if(!nxt[j][x]){puts("-1");return;}
            if(nxt[j][x]>=j)j=nxt[j][x];
            else sum++,j=nxt[j][x];
            p=j;
            j++;
            if(j==ns+1)j=1,sum++;
        }
        printf("%lld\n",1LL*sum*ns+j-1);
    }
}
int main(){
//    srand(19260817);
//    freopen("signin.in","r",stdin);
//    freopen("signin.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
using namespace std;

int main(int argc, const char * argv[]) {
  int n;
  vector<int> a(3);
  cin >> n;
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }
  
  int ans = 1 << 29;
  
  vector<int> bit(3);
  for(bit[0] = 1; bit[0] < (1<<n); bit[0]++){
    for(bit[1] = 1; bit[1] < (1<<n); bit[1]++){
      if(bit[0] & bit[1]) continue;
      for(bit[2] = 1; bit[2] < (1<<n); bit[2]++){
        if(bit[0] & bit[2] || bit[1] & bit[2]) continue;
        vector<int> sums(3,0), nums(3,0);
        for(int i = 0; i < n; i++){
          for(int j = 0; j < 3; j++){
            if(bit[j] & (1<<i)){
              sums[j] += l[i];
              nums[j]++;
            }
          }
        }
        
        int score = 0;
        for(int i = 0; i < 3; i++){
          score += abs(sums[i] - a[i]);
          score += (nums[i] -1) * 10;
        }
        ans = min(ans, score);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <map>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int N;
	map<string, bool> mp;
	string S;
	cin >> N;
	rep(i, N) {
		cin >> S;
		if (mp[S] == 1) {
			cout << "NO";
			return 0;
		}
		mp[S] = 1;
	}
	cout << "YES";
}

Measured memory_bytes: 19208
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

iA = [i+n for i, n in enumerate(A)]
jA = [i-n for i, n in enumerate(A)]
dict1 = Counter(iA)
dict2 = Counter(jA)

ans = 0
for key, value in dict1.items():
    ans += value * dict2[key]
print(ans)

Measured memory_bytes: 143248
a_1_1, a_1_2, a_1_3 = map(int, input().split())
a_2_1, a_2_2, a_2_3 = map(int, input().split())
a_3_1, a_3_2, a_3_3 = map(int, input().split())
n = int(input())
b = [int(input()) for _ in range(n)]
a = []
a.extend((a_1_1, a_1_2, a_1_3, a_2_1, a_2_2, a_2_3, a_3_1, a_3_2, a_3_3))
for _ in range(len(a)):
    if a[_] in b:
        a[_] = 0

def is_bingo(num_1, num_2, num_3):
    if num_1 == num_2 == num_3:
        return True

if is_bingo(a[0], a[1], a[2]) or is_bingo(a[3], a[4], a[5]) or is_bingo(a[6], a[7], a[8]) or is_bingo(a[0], a[3], a[6]) or is_bingo(a[1], a[4], a[7]) or is_bingo(a[2], a[5], a[8]) or is_bingo(a[0], a[4], a[8]) or is_bingo(a[2], a[4], a[6]):
    print("Yes")
else:
    print("No")


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  bool b = false;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++) {
    if(A.at(i)%2==0) {
      if(A.at(i)%3==0 || A.at(i)%5==0) {
        b = false;
      }
      else {
        b = true;
        break;
      }
    }
  }
  if(b == true) {
    cout << "DENIED" << endl;
  }
  else {
    cout << "APPROVED" << endl;
  }
}


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

int main() {

    int N;
    cin >> N;

    int A[N];
    int B[N];
    int C[N - 1];

    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N-1) cin >> C[i];

    int ans = 0;
    rep(i, N)
    {
        ans += B[A[i] - 1];
        if (i == 0) continue;
        if (A[i] - A[i-1] == 1)
        {
            ans += C[A[i] - 2];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cmath>

int main()
{
	int n;
	std::cin >> n;
	
	double* x = new double[n];
	double* y = new double[n];
	
	for (int i=0; i<n; i++) std::cin >> x[i];
	for (int i=0; i<n; i++) std::cin >> y[i];
	
	// L1 distance
	double d1 = 0.0;
	for (int i=0; i<n; i++) {
		d1 += std::abs(x[i] - y[i]);
	}
	
	// L2 distance
	double d2 = 0.0;
	for (int i=0; i<n; i++) {
		d2 += (x[i] - y[i]) * (x[i] - y[i]);
	}
	d2 = sqrt(d2);
	
	//L3 distance
	double d3 = 0.0;
	for (int i=0; i<n; i++) {
		d3 += std::abs( (x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]) );
	}
	d3 = cbrt(d3);
	
	//L-infty distance
	double d_max = 0.0;
	for (int i=0; i<n; i++) {
		if (std::abs(x[i]-y[i]) > d_max) d_max = std::abs(x[i] - y[i]);
	}
	
	std::cout << std::fixed << d1 << std::endl << d2 << std::endl << d3 << std::endl << d_max << std::endl; 
	
	return 0;
}




Measured memory_bytes: 3428
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=0;
int k,n;
int a[111111],sum[111111];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n){
		sum[i+1]=sum[i]+a[i];
	}
	int cnt=1;
	for(int i=n-2;i>=0;i--){
		if(sum[i+1]*2>=a[i+1]){
			cnt++;
		}
		else break;
	}
	cout<<cnt<<endl;
	
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
n, a, b = [int(x) for x in input().strip().split()]
mod = 10 ** 9 + 7
ans = pow(2, n, mod) - 1

num = 1
den = 1
for i in range(a):
    den = (den * (i+1)) % mod
    num = (num * (n-i)) % mod
ans = (ans - (num * pow(den, mod-2, mod)) % mod ) % mod

for i in range(a, b):
    den = (den * (i+1)) % mod
    num = (num * (n-i)) % mod
ans = (ans - (num * pow(den, mod-2, mod)) % mod ) % mod

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<iomanip>
#include<queue>
#include<cstring>

using namespace std;

const int MAX_X = 100000;

int dp[MAX_X+1];
int m[6]={1000000,1000000,1000000,1000000,1000000,1000000};
int a[6]={100,101,102,103,104,105};
int main() {
    int x;
    cin >> x;

    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    for (int i=0;i<6;i++) {
        for(int j=0; j<=x; j++) {
            if(dp[j] >= 0) {
                dp[j] = m[i];
            } else if (j < a[i] || dp[j-a[i]] <= 0) {
                dp[j] = -1;
            } else {
                dp[j] = dp[j-a[i]] - 1;
            }
        }
    }
    if(dp[x] >= 0) cout << "1" << endl;
    else cout << "0" << endl;

}

Measured memory_bytes: 640
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>
const long long INF=1e18;

using namespace std;

int main(void) {
    char A;
    cin>>A;

    if(isupper(A)){
     cout<<"A"<<endl;
    }else{
        cout<<"a"<<endl;
    }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

int main() {
    int n, m;
    cin >> n >> m;
    cout << n*(n - 1) / 2 + m*(m - 1) / 2 << endl;
}


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

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

using namespace std;

const int MAXN = 100010;
vector <int> ve[MAXN];
int bio[MAXN];
vector <int> out;

int nadi(int x) {
  for (int y : ve[x]) {
    if (!bio[y]) return y;
  }
  return -1;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  
  int A, B;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    A = a, B = b;
    ve[a].push_back(b);
    ve[b].push_back(a);
  }

  bio[A] = 1;
  bio[B] = 1;
  out.push_back(A);
  out.push_back(B);

  while (nadi(B) != -1) {
    int bb = nadi(B);
    out.push_back(bb);
    bio[bb] = 1;
    B = bb;
  }
  
  reverse(out.begin(), out.end());

  while (nadi(A) != -1) {
    int aa = nadi(A);
    out.push_back(aa);
    bio[aa] = 1;
    A = aa;
  }

  cout << out.size() << "\n";
  for (int x : out) cout << x << " "; cout << "\n";

  return 0;
}

Measured memory_bytes: 7160
#include <stdio.h>

int main(void){
  double d;
  while(scanf("%lf",&d)!=EOF){
    if(d<=48)printf("light fly\n");
    else if(d<=51)printf("fly\n");
    else if(d<=54)printf("bantam\n");
    else if(d<=57)printf("feather\n");
    else if(d<=60)printf("light\n");
    else if(d<=64)printf("light welter\n");
    else if(d<=69)printf("welter\n");
    else if(d<=75)printf("light middle\n");
    else if(d<=81)printf("middle\n");
    else if(d<=91)printf("light heavy\n");
    else printf("heavy\n");
  }
  return 0;
}



Measured memory_bytes: 2064
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N, capacity = inputIntList()
    w = [0 for _ in range(N)]
    v = [0 for _ in range(N)]
    for i in range(N):
        w[i], v[i] = inputIntList()

    dp = [[0 for _ in range(capacity + 1)] for _ in range(N + 1)]
    for i in range(N):
        for j in range(capacity + 1):
            if j < w[i]:
                dp[i + 1][j] = dp[i][j]
            else:

                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j])
            # print(dp)

    return dp[N][capacity]


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 171344
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  if(S=="RRR"){
    cout<<3<<endl;
  }
  else if(S=="RRS"){
    cout<<2<<endl;
  }
  else if(S=="RSR"){
    cout<<1<<endl;
  }
  else if(S=="SRR"){
    cout<<2<<endl;
  }
  else if(S=="SSR"){
    cout<<1<<endl;
  }
  else if(S=="SRS"){
    cout<<1<<endl;
  }
  else if(S=="RSS"){
    cout<<1<<endl;
  }
  else if(S=="SSS"){
    cout<<0<<endl;
  }
}
      

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, n;
  cin >> x >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  int res = -100;
  ll minv = INT_MAX;
  for (int i = -6; i < 500; ++i) {
    bool flag = false;
    for (int j = 0; j < n; ++j) {
      if(v[j] == i) flag = true;;
    }
    if(!flag && minv > abs(i - x)){
      res = i;
      minv = abs(i-x);
    }
  }

  cout << res << endl;

}


Measured memory_bytes: 3656
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def solve():
    n, k = read_h()
    arr = read_v(n)

    cumul = [sum(arr[:i]) for i in range(len(arr) + 1)]
    #  print(cumul)

    ans = 0
    for i in range(n - k + 1):
        s = cumul[i + k] - cumul[i]
        ans = max(ans, s)

    print(ans)


def main():
    while True:
        n, k = read_h()
        if (n, k) == (0, 0):
            break

        arr = read_v(n)

        cumul = [0]
        for i in range(n):
            cumul.append(cumul[i] + arr[i])

        ans = 0
        for i in range(n - k + 1):
            s = cumul[i + k] - cumul[i]
            ans = max(ans, s)

        print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 13548