akhauriyash/Code-Regression huggingface dataset:
import numpy as np

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

out = []

for i, a in enumerate(A):
    for j in range(a):
        out.append(i + 1)

# print(out)
out = np.array(out).reshape((H, W))
# print(out, out.shape)

sign = 1
for li in out:
    print(*li[::sign])
    sign *= -1


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

using namespace std;

typedef long long ll;

int main(){
  string s; cin >> s;
  int cnt=0;
  for(int i=0;i<s.size()-1;i++){
    if(s[i] != s[i+1]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512
def prepare(n,MOD):
    f=1
    factorials=[1]
    for m in range(1,n+1):
        f*=m
        f%=MOD
        factorials.append(f)
    inv=pow(f,MOD-2,MOD)
    invs=[1]*(n+1)
    invs[n]=inv
    for m in range(n,1,-1):
        inv*=m
        inv%=MOD
        invs[m-1]=inv

    return factorials,invs

def solve(n,k,i,facts,invs,MOD):
    m=n-k-(i-1)
    if m<0:
        return 0
    h=k-i
    ans=facts[i+m]*invs[i]*invs[m]%MOD
    ans=ans*facts[i+h-1]*invs[i-1]*invs[h]%MOD
    return ans

n,k=list(map(int,input().split()))
MOD=10**9+7
facts,invs=prepare(n,MOD)
buf=[]
for i in range(1,k+1):
    buf.append(solve(n,k,i,facts,invs,MOD))
print("\n".join(map(str,buf)))

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

typedef long long lli;
typedef pair<lli,lli> pll;
typedef vector<lli> vcL;
typedef vector<pll> vPL;


void solve() {
	lli n, cnt = 0;
	cin >> n;
	
	for (int i = 105; i <= n; i += 2 ) {
		int div = 0;
		
		for (int j = 1; j <= i; j += 2 ) {
			if ( i%j == 0 ) div++ ;
		}
		
		if ( div == 8 ) cnt++ ;
	}
	
	cout << cnt << '\n';
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
dist=[]
for i in range(n-k+1):
  if a[i+k-1]<=0:
    dist.append(-a[i])
  elif a[i]>=0:
    dist.append(a[i+k-1])
  else:
    dist.append(min(2*a[i+k-1]-a[i],a[i+k-1]-2*a[i]))

print(min(dist))

Measured memory_bytes: 14252
import java.util.*;

public class Main {
    public static void main(String args[]) {
//        System.out.println(playStones(new int[] { 1}, 100000));
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int K = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        scan.close();

        System.out.println(playStones(A, K));
    }
    private static String playStones(int[] A, int K) {
        boolean[] dp = new boolean[K + 1];

        for (int k = 1; k <= K; k++) {
            for (int a : A) {
                int leftover = k - a;
                if (leftover < 0) continue;
                if (!dp[leftover]) {
                    dp[k] = true;
                    break;
                }
            }
        }

        return dp[K] ? "First" : "Second";
    }

}

Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;
struct Info{int par, weight;};
const int MAX = 100005;

class UnionFind{
public:
  
  Info info[MAX];

  void init(int n){
    for(int i = 0; i < n; i++) info[i] = (Info){i,0};
  }
 
  Info find(int x){
    if(info[x].par == x) return info[x];
    
    Info tmp = find(info[x].par);
    info[x].weight += tmp.weight;
    info[x].par = tmp.par;
    return info[x];
  }

   void unite(int x, int y, int w){
    Info X = find(x);
    Info Y = find(y);
    //W[x]+w = W[y]
    
    info[Y.par].par = X.par;
    info[Y.par].weight += w+info[x].weight-info[y].weight;
  }
   
  bool same(int x, int y){
    return find(x).par == find(y).par;
  }

  int getValue(int x){return info[x].weight;}
};
 
int N,M;
UnionFind uf;
 
void update(){
  int a,b,c;
  scanf("%d %d %d\n",&a,&b,&c);
  uf.unite(a,b,c);
}
 
void print(){
  int a,b;
  scanf("%d %d\n",&a,&b);
  if(uf.same(a,b)) printf("%d\n",uf.getValue(b)-uf.getValue(a));
  else printf("UNKNOWN\n");
}
 
int main(){
   
 
  while(scanf("%d %d\n",&N,&M) && N+M){
    uf.init(N+1);
    for(int i = 0; i < M; i++){
      char c;
      scanf("%c",&c);
      if(c == '!') update();
      else print();
    }
  }
  return 0;
}

Measured memory_bytes: 2808
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin >> s;
	ll sum=0;
	for(int i=0;i<s.length();i++){
		sum=sum+s[i]-'0';
	}
	if(sum%9==0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 2e5+233;
int f[305][305][305];
char s[305];
int K,n;
int main(){
	scanf("%s",s+1);
	n = strlen(s+1);
	K = rd();
	mem(f,0);
	Rep(i,1,n){
		Rep(k,0,K) f[i][i][k] = 1;
	}
	Rep(len,2,n){
		for(int i=1;i+len-1<=n;++i){
			int j=i+len-1;
			Rep(k,0,K){
				if(k)f[i][j][k] = max(f[i][j][k],f[i][j][k-1]);
				f[i][j][k] = max(f[i][j][k],f[i+1][j][k]);
				f[i][j][k] = max(f[i][j][k],f[i][j-1][k]);
				if(s[i]==s[j]) f[i][j][k] = max(f[i][j][k],f[i+1][j-1][k]+2);
				if(k)f[i][j][k] = max(f[i][j][k],f[i+1][j-1][k-1]+2);
			}
		}
	}writeln(f[1][n][K]);
	return 0;
}


Measured memory_bytes: 111104
n,m= map(int,input().split())
par = [-1]*(n)
def find(x):
    if par[x]<0:return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    px,py=find(x),find(y)
    if px==py:return False
    else:
        if px<py:px,py=py,px
        par[px]+=par[py]
        par[py]=px
        return True
p= list(map(int,input().split()))
gl=[[] for _ in range(n)]
for i in range(m):
    x,y= map(int,input().split())
    unite(x-1,y-1)
for c in range(n):#par:
    ap=find(c)
    gl[ap].append(c)
g=0
for sg in gl:
    temp=[p[index]-1 for index in sg]
    newset = set(sg) & set(temp)
    g+=len(newset)
print(g)

Measured memory_bytes: 43608
/**
 * D - Floor Function
 * https://atcoder.jp/contests/abc165/tasks/abc165_d
 */
#include <bits/stdc++.h>
using namespace std;

long long A, B, N;

long long calc(long long x) {
    long long floor1 = A * x / B;
    long long floor2 = x / B;
    return floor1 - A * floor2;
} 
 
int main() {
    // 整数 A, B, N が与えられます。
    cin >> A >> B >> N;
    // N 以下の非負整数 x に対する floor(Ax/B)−A×floor(x/B)の最大値を求めてください。
    // ただし、floor(t)とは、実数 t 以下の最大の整数のことを表します。

    long long keisu =  N / B;
    long long maxNum1 = calc(B * keisu - 1);
    long long maxNum2 = calc(N);
    cout << (maxNum1 > maxNum2 ? maxNum1 : maxNum2);
}
 

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

int main() {
  int64_t N;
  cin>>N;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<N;i++){
    cin>>B.at(i);
  }
  int64_t sumA=0;
  int64_t sumB=0;
  for(int i=0;i<N;i++){
    sumA+=A.at(i);
  }
  for(int i=0;i<N;i++){
    sumB+=B.at(i);
  }
  if(sumA<sumB) cout<<-1<<endl;
  else{
    vector<int64_t> C(N);
    for(int i=0;i<N;i++){
      C.at(i)=A.at(i)-B.at(i);
    }
    int64_t M=0;
    int64_t sumM=0;
    for(int i=0;i<N;i++){
      if(C.at(i)<0){
        M++;
        sumM-=C.at(i);
      }
    }
    sort(C.begin(),C.end());
    reverse(C.begin(),C.end());
    for(int i=0;i<N;i++){
      if(sumM==0){
        cout<<M<<endl;
        return 0;
      }
      else if(sumM>C.at(i)){
        M++;
        sumM-=C.at(i);
      }
      else{
        M++;
        cout<<M<<endl;
        return 0;
      }
    }
  }
    
}
  

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

int main() {
	int N;
  cin>>N;
  vector<int>vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int ans=0;
  for(int ia=0 ;ia<N-1;ia++){
for(int ib=ia+1; ib<N ;ib++){
  ans+=vec.at(ia)*vec.at(ib);
}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	double a, b; cin >> a >> b;
	double k = (max(a, b) - min(a, b)) / 2 + min(a, b);
	if (abs(a - k) < 90)cout << k << endl;
	else {
		k += 180;
		if (k >= 360)k -= 360;
		cout << k << endl;
	}
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a*n,b)<< endl;

}


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

int main()
{
	int n, W;
	std::cin >> n >> W;
	std::vector<int> v(n);
	std::vector<int> w(n);
	std::vector<std::vector<int> > dp(n + 1, std::vector<int> (W + 1, 0));
	for (int i = 0; i < n ;i++)
	{
		std::cin >> v[i] >> w[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= W; j++)
		{
			if (j < w[i])
			{
				dp[i + 1][j] = dp[i][j];
			}
			else
				dp[i + 1][j] = std::max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
		}
	}
	std::cout << dp[n][W] << '\n';
	return (0);
}


Measured memory_bytes: 6756
#include<bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define name "main"
#define ll long long
#define maxn 405
#define oo 100000000000000

using namespace std;

int n,a[maxn];
ll res[maxn][maxn],b[maxn];
bool xd[maxn][maxn];

ll sol(int x,int y)
{
    if(x==y)
    {
        return 0;
    }
    if(xd[x][y]!=0)
    {
        return res[x][y];
    }
    xd[x][y]=1;
    res[x][y]=oo;
    f(i,x,y-1)
    {
        res[x][y]=min(res[x][y],sol(x,i)+sol(i+1,y)+b[y]-b[x-1]);
    }
    return res[x][y];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen(name".inp","r",stdin);
   // freopen(name".out","w",stdout);

    cin>>n;
    f(i,1,n)
    {
        cin>>a[i];
        b[i]=b[i-1]+a[i];
        fd(j,i-1,1)
        {
            res[j][i]=oo;
            f(t,j,i-1)
            {
                res[j][i]=min(res[j][i],res[j][t]+res[t+1][i]+b[i]-b[j-1]);
            }
        }
    }
    cout<<res[1][n];




}


Measured memory_bytes: 4816
import math
def f(s):
    if len(s)%2==0: p=len(s)//2-1
    else: p=len(s)//2
    
    q=p
    while  q<len(s) and s[p]==s[q]:
        q+=1
    return q



s=input()
l=len(s)
ans=l
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans=min(ans, max(i+1,l-i-1) )
print(ans)

Measured memory_bytes: 3188
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b, c;
	cin>>a>>b>>c;
	if(a==b) cout<<c<<endl;
	else if(a==c) cout<<b<<endl;
	else cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut sv: Vec<String> = Vec::new();
    for _ in 0..n {
        sv.push(read(&mut stdin_lock, &mut buf, b'\n'));
    }

    let mut cv = vec![0i32; 5];
    for i in 0..n {
        let s: Vec<char> = sv[i].chars().collect();
        match s[0] {
            'M' => cv[0] += 1,
            'A' => cv[1] += 1,
            'R' => cv[2] += 1,
            'C' => cv[3] += 1,
            'H' => cv[4] += 1,
            _ => {}
        }
    }

    let mut ans = 0i64;
    for i in 0..2usize.pow(5) {
        let mut c = 0;
        let mut x = 1i64;
        for j in 0..cv.len() {
            if i & (1 << j) != 0 {
                x *= cv[j] as i64;
                c += 1;
            }
        }
        if c == 3 {
            ans += x;
        }
    }
    println!("{}", ans);
}


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

const double PI=acos(-1.0);

int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    ll a2 = (a == 0 ? 0 : (a - 1) / x + 1);
    ll b2 = b / x + 1;

    cout << b2 - a2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
// #define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007LL
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
    if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int MAXN = 2e5+5;

// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const double eps=1e-8;
int dblcmp(double d){if (fabs(d)<eps)return 0;return d>eps?1:-1;}
ll euclid(ll x,ll y,ll a,ll b)
{
  return (a-x)*(a-x)+(b-y)*(b-y);
}
// Constants //
void solve()
{
  ll total,n,i;
  cin>>total>>n;
  vector<ll> v(n);
  for(i=0;i<n;i++)
  {
    cin>>v[i];
    total-=v[i];
  }
  if(total>=0)
    cout<<total;
  else
    cout<<-1;
}
int main()
{ 
  // ios;
  // freopen("inputt.txt", "w", stdout);
  ll t,i;
  t=1;

  while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
    cout << fixed << setprecision(10);
    int n;
       long double d;
    cin >> n >> d;

    int cnt = 0;
    REP(i, n)
    {
        long double x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d)cnt++;
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

bool kaibun(string s,ll x,ll y){
    for (ll i=x;i<y;i++){
        if (s[i]!=s[y-1-i]){
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    cin >> s;
    if (kaibun(s,0,s.size())){
        if (kaibun(s,0,(s.size()-1)/2)){
            if (kaibun(s,(s.size()+3)/2,s.size())){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
    int  i,n,m;
    float a[1002],sum=0;
    cin>>n;
    for(i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    i=2;
    sum=(float)(a[0]+a[1])/2;
    while(i<n)
    {
        sum=(float)(sum+a[i])/2;
        i++;
    }

    cout<<sum;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int K,N,hebi,tmp1,tmp2,suuzi,i,k,I[60];
  hebi=0;
  scanf("%d %d",&N,&K);

  for(i=0; i<60; i++){
    I[i]=0;
  }

  
  for(i=1; i<=N; i++){
    scanf("%d",&I[i]);
  }

  for(k=1; k<=K; k++){
    tmp1=0;
    for(i=k; i<=N; i++){
      if(tmp1 < I[i]){
	tmp1=I[i];
	suuzi=i;
      }
    }
    tmp2=I[k];
    I[k]=tmp1;
    I[suuzi]=tmp2;
  }
  
  
  for(i=1; i<=K; i++){
    hebi=hebi+I[i];
  }

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

  return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
const double PI = 4*atan(1);

int x1, x2, Y1, y2, N;
vector<pii> fo;

bool comp(pii a, pii b) {
    return a.s<b.s;
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> x1 >> Y1 >> x2 >> y2 >> N; 
    cout << fixed << setprecision(13);
    
    if (x1 > x2) {
        swap(x1,x2);
        swap(Y1,y2);
    }
    
    x2 -= x1, y2 -= Y1;
    F0R(i,N) {
        pii z; cin >> z.f >> z.s;
        z.f -= x1, z.s -= Y1;
        if (z.f < 0 || z.f > x2) continue;
        if (z.s < min(y2,0) || z.s > max(0,y2)) continue;
        fo.pb(z);
    }
    
    if (y2 < 0) {
        for (auto& a: fo) a.s *= -1;
        y2 *= -1;
    }
    
    sort(fo.begin(),fo.end(),comp);
    set<pii> vals; vals.insert({0,0});
    
    int ans = 0;
    for (auto a: fo) {
        pii x = *prev(vals.ub({a.f,MOD}));
        pii t = {a.f,x.s+1};
        vals.insert(t);
        while (1) {
            auto it = vals.find(t);
            if (next(it) == vals.end()) break;
            if (next(it)->s == x.s+1) vals.erase(next(it));
            else break;
        }
    }
    
    ans = prev(vals.end())->s;
    if (ans != min(x2,y2)+1) {
        cout << 100.0*(x2+y2)-ans*(20-5*PI);
    } else {
        cout << 100.0*(x2+y2)-(ans-1)*(20-5*PI)+(10*PI-20);
    }
}

// read!
// ll vs. int!

Measured memory_bytes: 11248
type
  pair = record
    a : int64;
    b : integer;
  end;
	pairArray = array[1..100000] of pair;
var i,n,m:integer;
    input:pairArray;
    sum : int64;

procedure	swap(var a,b:pair);
var tmp:pair;
begin
	tmp:=a;
	a:=b;
	b:=tmp
end;

procedure QuickSort(var a:pairArray;start_index,end_index:integer);
var i,j,x:int64;
begin
	x:=a[(start_index+end_index)div 2].a;
	i:=start_index;
	j:=end_index;
	while(true)do
	begin
		while(a[i].a<x)do i:=i+1;
		while(x<a[j].a)do j:=j-1;
		if(i<j)then
		begin
			swap(a[i],a[j]);
			i:=i+1;
			j:=j-1;
		end else
		begin
			if(start_index<i-1)then QuickSort(a,start_index,i-1);
			if(j+1<end_index)then QuickSort(a,j+1,end_index);
			exit;
		end;
	end;
end;

begin
  sum := 0;
  readln(n,m);
  for i := 1 to n do read(input[i].a,input[i].b);
  QuickSort(input,1,n);
  for i := 1 to n do begin
    if m > input[i].b then begin
      sum := sum + input[i].b * input[i].a;
      m := m - input[i].b
    end else begin
      sum := sum + m * input[i].a;
      m := 0
    end;
    if m = 0 then break;
	end;
  writeln(sum)
end.

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	ll d = abs(a - b);
	ll x = v - w;
	cout << (d <= t * x ? "YES" : "NO") << endl;
	return 0;
}



Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(a) (a).begin(),(a).end()

int N, M;
string s[1002];
int K;

struct state {
  int j, o, i;
  state() {
    j = o = i = 0;
  }
  void init() {
    j = o = i = 0;
  }
  state operator+=(const state& other) {
    j += other.j;
    o += other.o;
    i += other.i;
    return *this;
  }
  state operator+(const state& other) {
    state s;
    s.j = j + other.j;
    s.o = o + other.o;
    s.i = i + other.i;
    return s;
  }
  state operator-(const state& other) {
    state s;
    s.j = j - other.j;
    s.o = o - other.o;
    s.i = i - other.i;
    return s;
  }
};

state sts[1002][1002];

void solve() {
  rep(i,N) rep(j,M) sts[i][j].init();

  rep(i,N) {
    // cout << s[i] << endl;
    rep(j,M) {
      const char op = s[i][j];
      if (op == 'J') {
        sts[i+1][j+1].j++;
      } else if (op == 'O') {
        sts[i+1][j+1].o++;
      } else {
        sts[i+1][j+1].i++;
      }
    }
  }

  // rep(i,N+1) {
  //   rep(j,M+1) {
  //     printf("[%2d,%2d,%2d]", sts[i][j].j, sts[i][j].o, sts[i][j].i);
  //   }
  //   puts("");
  // }puts("");
  
  rep(i,N+1) {
    state init;
    rep(j,M+1) {
      const state cop = sts[i][j];
      sts[i][j] += init;
      init += cop;
      if (i) {
        sts[i][j] += sts[i-1][j];
      }
    }
  }

  // rep(i,N+1) {
  //   rep(j,M+1) {
  //     printf("[%2d,%2d,%2d]", sts[i][j].j, sts[i][j].o, sts[i][j].i);
  //   }
  //   puts("");
  // }

  rep(z,K) {
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    state s = sts[a-1][b-1] - sts[a-1][d] - sts[c][b-1] + sts[c][d];
    printf("%d %d %d\n", s.j, s.o, s.i);
  }
}

int main() {
  while(cin>>N>>M>>K) {
    rep(i,N) cin>>s[i];
    solve();
  }
  return 0;
}

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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
}


Measured memory_bytes: 256
n=int(input())
a=0
b=1
c=0
d=n**0.5+1
d=int(d)
for i in range(2,d):
  while(n%i==0):
    a+=1
    n/=i
  while(1):
    if a>=b:
      c+=1
      a-=b
      b+=1
    else: break
  a=0
  b=1
if n>1: c+=1
print(c)

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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    if (1000 - n % 1000 == 1000){
        cout << 0 << endl;
    }
    else{
        cout << 1000 - n % 1000 << endl;
    }

    
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n;
  while(cin >> n) {
    n %= 39;
    if(n == 0) n = 39;
    if(n < 10) cout << "3C0" << n << endl;
    else cout << "3C" << n << endl;
  }
}

Measured memory_bytes: 1156
/*  -*- coding: utf-8 -*-
 *
 * c.cc: E: Ball Coloring
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef pair<int,int> pii;
typedef map<int,int> mii;

/* global variables */

pii rbs[MAX_N];
mii rs, bs;

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }
inline void setmax(int &a, int b) { if (a < b) a = b; }

void mreplace(mii &m, int a, int b) {
  mii::iterator mit = m.lower_bound(a);
  if (--mit->second == 0) m.erase(mit);
  m[b]++;
}

/* main */

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

  int rmin = INF, rmax = 0, bmin = INF, bmax = 0;
  for (int i = 0; i < n; i++) {
    int &ri = rbs[i].first, &bi = rbs[i].second;
    scanf("%d%d", &ri, &bi);
    if (ri > bi) swap(ri, bi);
    setmin(rmin, ri); setmax(rmax, ri);
    setmin(bmin, bi); setmax(bmax, bi);
    rs[ri]++;
    bs[bi]++;
  }
  sort(rbs, rbs + n);

  ll mulmin = (ll)(rmax - rmin) * (bmax - bmin);

  for (int i = 0; i < n; i++) {
    int &ri = rbs[i].first, &bi = rbs[i].second;
    mreplace(rs, ri, bi);
    mreplace(bs, bi, ri);

    ll mul =
      (ll)(rs.rbegin()->first - rs.begin()->first) *
      (bs.rbegin()->first - bs.begin()->first);
    if (mulmin > mul) mulmin = mul;
  }

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


Measured memory_bytes: 20608
/*A - Apple Pie*/
#include <bits/stdc++.h>
using namespace std;

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

	int apples;
	int pieces;

	cin >> apples >> pieces;

	int ans = 0;
	ans = apples * 3;
	ans += pieces;

	ans /= 2;

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
const ll L = 1e5 + 5;
ll arr[L];
ll lef[L];
ll rit[L];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n, k;
	cin >> n >> k;
	for (ll i = 0; i < n; i++) {
		cin >> arr[i];
	}
	set <ll> as;
	for (ll i = 0; i < k; i++) {
		as.insert(arr[i]);
	}
	for (ll i = 0; i < n; i++) {
		if (i == 0) lef[i] = 0;
		else if (i < k - 1) lef[i] = 1;
		else lef[i] = 1 + lef[i - k + 1];
	}
	for (ll i = n - 1; i >= 0; i--) {
		if (i == n - 1) rit[i] = 0;
		else if (i > n - k) rit[i] = 1;
		else rit[i] = rit[i + k - 1] + 1;
	}
	ll ans = 1e18;
	for (ll i = k; i < n + 1; i++) {
		ll ind = i - 1;
		if (as.find(1) != as.end()) {
			ll l1 = ind - k + 1;
			ll temp = lef[l1] + rit[ind];
			ans = min(ans, temp);
		}
		if (i < n) {
			as.insert(arr[i]);
			as.erase(arr[i - k]);
		}
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll d[1111111],c[1111111];
void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) {
    R a[i];
    d[a[i]]++;
  }
  int ans=0;
  REP(i,1,1111111) {
    if(d[i]) {
      for(ll j=i*2; j<=1111111; j+=i) c[j]=1;
    }
  }
  rep(i,n) {
    if(d[a[i]]==1&&!c[a[i]]) ans++;
  }
  pr(ans);
}

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


Measured memory_bytes: 21664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
 

vector <int > H;
int A; 

int main()
{
  cin >> A;
  H.resize(A);
  REP(i,A){
    cin >> H[i];
  }
  long ans = 0;
  REP(i,A-1){
    FOR(j,i+1,A){
      ans += H[i] * H[j];
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

template <class T>
class FT
{
    vector<T> ft;
public:
    FT(int n = 500000) : ft(n + 1)
    {
    }
    T rsq(int b)
    {
        T sum = 0;
        for (; b; b -= (b & (-b)))
            sum += ft[b];
        return sum;
    }
    T rsq(int a, int b)
    {
        a++; b++;
        return rsq(b) - rsq(a - 1);
    }
    void adjust(int k, T v)
    {
        k++;
        for (; k < ft.size(); k += (k & (-k)))
            ft[k] += v;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    FT<int> ft[26];
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    for (int i = 0; i < n; ++i)
        ft[s[i] - 'a'].adjust(i, 1);
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        b--;
        if (a == 1)
        {
            char c;
            cin >> c;
            ft[s[b] - 'a'].adjust(b, -1);
            s[b] = c;
            ft[s[b] - 'a'].adjust(b, 1);
        }
        else
        {
            int c;
            cin >> c;
            c--;
            int sol = 0;
            for (int i = 0; i < 26; ++i)
                if (ft[i].rsq(b, c))
                    sol++;
            cout << sol << '\n';
        }
    }
}


Measured memory_bytes: 51988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine().Split(' ');
            var four = false;
            foreach(var s in S)
            {
                if (s == "Y") four = true;
            }

            Console.WriteLine(four ? "Four" : "Three");
        }
    }
}

Measured memory_bytes: 13140
from copy import deepcopy

N = int(input())
D = list(map(int,input().split()))
T = [0 for _ in range(13)]
ans = 0

for i in range(N):
    if D[i]==0:
        print(0)
        break
    T[D[i]] += 1
    if T[D[i]] >=3:
        print(0)
        break
        
else:
    C = [0]
    S = []
    for j in range(13):
        if T[j]==2:
            C.append(j)
            C.append(-j)
        elif T[j]==1:
            S.append(j)

    for j in range(2**len(S)):
        CC = deepcopy(C)
        for k in range(len(S)):
            if ((j >> k) & 1):
                CC.append(S[k])
            else:
                CC.append(-S[k])
                
        mind = 25
        for p in range(N):
            for q in range(p+1,N+1):
                mind = min(mind,min(abs(CC[p]-CC[q]),24-abs(CC[p]-CC[q])))
        ans = max(ans,mind)
        
    print(ans)

Measured memory_bytes: 43116
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;

int K;

int main(void) {
    while (1) {
        cin >> K;
        if (K == 0) break;
        int sum = 0;
        int k = K * (K-1) / 2;
        for (int i = 0; i < k; i++) {
            int c;
            cin >> c;
            sum += c;
        }
        cout << sum / (K-1) << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	
	string s;
	
	cin >> s;
	
	bool ans = true;
	
	for (int i = 1; i < s.length()+1; i++){
		if (i % 2 != 0){
			if (s[i-1] != 'R' && s[i-1] != 'U' && s[i-1] != 'D'){
				ans = false;
			}
		} else if (i % 2 == 0){
			if (s[i-1] != 'L' && s[i-1] != 'U' && s[i-1] != 'D'){
				ans = false;
			}
		}
		
	}
	
	if (ans){
		cout << "Yes";
	} else {
		cout << "No";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1000005;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int D, T, S;
    cin >> D >> T >> S;
    bool can = D <= T*S;
    if (can) cout << "Yes\n";
    else cout << "No\n";
    
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll K;
  cin >> K;

  queue<ll> que;

  rep2(i, 1, 10) que.push(i);

  ll cnt = 0;
  ll ans;

  while(cnt < K){
    ans = que.front();
    cnt++;

    que.pop();

    ll rem = ans % 10;

    rep(j, 10){
      if(abs(rem - j) <= 1) que.push(10 * ans + j);
    }
  }

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

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

int main(){
  int n;
  int id,h,w;
  double b,bb;
  int bid;
  double t1,t2;

  while(1){
    cin >> n;
    if(!n)break;


    bb = 200000001.0;
    bid = 1000001;
    for(int i=0;i<n;i++){
      cin >> id >> h >> w;
      b = (double)w / ( (double)h/100 * (double)h/100 );
      t1 = abs(22.0-b);
      t2 = abs(22.0-bb);
      if( abs(t1-t2) < 1e-10){
	if(id<bid){
	  bb = b;
	  bid = id;
	}
      }else if(t1 < t2){
	bb = b;
	bid = id;
      }
    }
    cout << bid << endl;
  }
}

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

using namespace std;

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

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

    vector<int> r(a);
    sort(r.begin(), r.end());

    vector<int> x(0), y(0);
    for (vector<int>::iterator i = (r[0] < 0 ? lower_bound(r.begin(), r.end(), 0) : r.begin() + 1); i != r.end(); i++) {
        if (i + 1 == r.end()) {
            x.push_back(*i);
            y.push_back(r[0]);
            r[0] = *i - r[0];
        } else {
            x.push_back(r[0]);
            y.push_back(*i);
            r[0] = r[0] - *i;
        }
    }

    sort(r.begin(), lower_bound(r.begin(), r.end(), 0), greater<int>());
    for (vector<int>::iterator i = r.begin() + 1; *i < 0; i++) {
        x.push_back(r[0]);
        y.push_back(*i);
        r[0] = r[0] - *i;
    }

    cout << r[0] << endl;
    for (int i = 0; i < n - 1; i++) {
        cout << x[i] << " " << y[i] << endl;
    }
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  bool b[4];
  
  char c;
  for(int i = 0 ; i < N ; i++){
    cin >> c;
    if (c == 'G'){
      b[0] = 1;
    }else if(c == 'W'){
      b[1] = 1;
    }else if(c == 'Y'){
      b[2] = 1;
    }else if(c == 'P'){
      b[3] = 1;
    }
  }

  int ans = 0;
  for(int i = 0 ; i < 4 ; i++){
    if(b[i] == 1){
      ans++;
    }
  }

  switch(ans){
  case 3:
    cout << "Three" << endl;
    break;
  case 4:
    cout << "Four" << endl;
  }

}


Measured memory_bytes: 3580
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var b = o.l();
  var ans = [];
  if(f(b) === false)return -1;
  return ans.reverse().join("\n");

  function f(a){
    if(a.length === 0)return true;
    for(var i = a.length-1; i >= 0; i--){
      if(a[i] === i+1){
        ans.push(a[i]);
        return f(a.slice(0,i).concat(a.slice(i+1)));
      }
    }
    return false;
  }
}

Measured memory_bytes: 7372
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int,input().split())

n = (N+1)*max(v)

inf = 10**14

dp = [[inf]*n for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    dp[i+1][0] = 0
    for j in range(n-2,0,-1):
        dp[i+1][j] = min(dp[i+1][j+1], dp[i][j], dp[i][j-v[i]]+w[i])

ans = 0
for i in range(n):
    if dp[N][i] <= W:
        ans = i
    else:
        break

print(ans)

Measured memory_bytes: 119404
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int sq[1002],cb[102];
	for(int i=0;i<=1001;i++)	sq[i]=i*i;
	for(int i=0;i<=101;i++)		cb[i]=i*i*i;

	for(int e;scanf("%d",&e),e;){
		int m=1<<30;
		for(int z=0;cb[z]<=e;z++)for(int y=0;sq[y]<=e-cb[z];y++){
			int x=e-cb[z]-sq[y];
			m=min(m,x+y+z);
		}
		printf("%d\n",m);
	}

	return 0;
}

Measured memory_bytes: 764
N,x=map(int,input().split())
a=list(map(int,input().split()))
count=0
count+=max(0,a[0]-x)
a[0]-=max(0,a[0]-x)
for i in range(N-1):
  count+=max(0,a[i]+a[i+1]-x)
  a[i+1]-=max(0,a[i]+a[i+1]-x)
print(count)

Measured memory_bytes: 14060
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

int n;ll a[25]; 
ll solve(int l,int r,ll x,ll y) {
	if(r-l<=1) return 0;
	ll ans=1e18;
	for(int i=l+1;i<=r-1;++i)
		ans=min(ans,solve(l,i,x,x+y)+solve(i,r,x+y,y)+(x+y)*a[i]);
	return ans;
}
int main() {
	IN(n);
	for(int i=1;i<=n;++i) IN(a[i]);
	printf("%lld\n",a[1]+a[n]+solve(1,n,1,1));
	return 0;
}

Measured memory_bytes: 384
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            if(b % a == 0)
            {
                Console.WriteLine(b + a);
            }
            else
            {
                Console.WriteLine(b - a);
            }

        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  string t("keyence");

  const int M = s.size() - t.size();
  bool result = false;
  for (int i = 0; i + M <= s.size(); i++) {
    bool match = true;
    for (int j = 0; j < i; j++) {
      match = match && (s[j] == t[j]);
    }
    for (int j = i + M; j < s.size(); j++) {
      match = match && (s[j] == t[j - (i + M) + i]);
    }
    result = result || match;
  }

  cout << (result ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m;cin>>n>>m;
    int left =1,right=n;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        left=max(left,a);
        right=min(right,b);
    }
    cout<<max(right-left+1,0)<<endl;
}

Measured memory_bytes: 256
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')


def main():
    l, r, d = ria()
    cnt = 0
    for x in range(l, r+1):
        if x % d == 0:
            cnt += 1
    wi(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61788
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int s ;//sheep;
    cin>>s;
    int w ; //wolves
    cin>>w;

    if(s<=w){
        cout<<"unsafe\n";
    }
    else {
        cout<<"safe\n";
    }
}


Measured memory_bytes: 3636