akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 5e5 + 5, mod = 1e9 + 7;
const int inf = 1e9;
void solve(){
    int ans = 0, l, r, d;
    cin >> l >> r >> d;
    for(int i = l; i <= r; i++){
        if(i % d == 0){
            ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
int main(){ cin.sync_with_stdio(0);
	string S, T; cin >> S >> T;

	ll ans = 0;
	FOR(i, 0, 3) if (S[i] == T[i]) ans ++;
	cout << ans << endl;
} //cin.tie(0) bei schnellem Wechseln


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

s = list(raw_input())

cs = []
for i in range(n):
	if s[i] == 'E':
		s[i] = 1
	else :
		s[i] = 0

cs.append(s[0])

for i in range(1,n):
	cs.append(cs[i-1]+s[i])

ans = cs[n-1]-cs[0]
for i in range(1,n):
	ans = min( cs[n-1]-cs[i] + i-cs[i-1],ans)

print ans

Measured memory_bytes: 27568
#include<bits/stdc++.h>
using namespace std;
#define test(t) int t;cin>>t;while(t--)
#define lli long long int
#define pb push_back
#define MAX 10000007
#define mod 1000000007
//a.push_back(i+'0');convert i to char;
//cout << fixed << setprecision(2) << pi ;
const lli infl=0x3f3f3f3f3f3f3f3fLL;
int prime(lli n)
{int f=1;
    for(lli i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {f=0;break;}
    }if(f==0) return 0;
    return 1;

}
int power(int a,int b)
{
   int result=1;
    while(b>0)
    {  if(b%2)
        result=(a*result)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return result%mod;
}
int find_par(int parent[],int d)
{
    if(parent[d]==d)
        return d;
   return parent[d]=find_par(parent,parent[d]);

}
void union_(int parent[],int x,int y,lli a[])
{
    int c=find_par(parent,x);
    int d=find_par(parent,y);
    if(c==d)return;
    if(c!=d) parent[d]=c;

}
int main()
{  ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
    //test(t)
    {
       lli ans=infl,c,d,x,y,z,n,q,m,r,f=0,i=0,j=0,odd=0,even=0;
      lli sum=0,sum1=0,sum2=0,res=0,cur,l,k,area,maxm=-infl,minm=infl,low,high=0,r1,r2,c1,c2;
       string s1,s2,s3,str,s;
       vector<int>v,u;
       cin>>n;
       lli a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        int pre[n]={0};
        pre[0]=0;
        pre[1]=abs(a[1]-a[0]);
        for(i=2;i<n;i++)
        {
           pre[i]=min(pre[i-1]+abs(a[i-1]-a[i]),pre[i-2]+abs(a[i-2]-a[i]));
        }cout<<pre[n-1];
       cout<<endl;
    }
}


Measured memory_bytes: 4820
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((x - a) % b);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int>V(2*N);

  for(int i=0;i<2*N;i++){
    cin>>V.at(i);
  }
  
  sort(V.begin(),V.end());

  int ans=0;
  for(int i=0;i<2*N;i+=2){
    ans+=V.at(i);
  }
  cout<<ans<<endl;
}

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

int main(){
  int H, W;
  while(cin >> H >> W){
    if(H==0 && W==0){
      return 0;
    }
    else{
      for(int i=0; i<W; i++){
	cout << "#";
      }
      cout << endl;
      for(int j=0; j<(H-2); j++){
	cout << "#";
	for(int k=0; k<(W-2); k++){
	  cout << ".";
	}
	cout << "#" << endl;
      }
      for(int l=0; l<W; l++){
	cout << "#";
      }
      cout << endl << endl;
    }
  }
}

Measured memory_bytes: 1152
#include <stdio.h>

typedef long long ll;
int main(){
  ll N;
  ll a;
  ll b = 1e15+1;
  scanf("%lld",&N);
  for(int i = 0;i < 5;i++){
    scanf("%lld",&a);
    b = (b>a)?a:b;
  }
  ll t;
  if(N==1){
    t=1;
  }else{t = (N-1)/b+1;}
  t += 4;
  printf("%lld\n",t);
}

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

int main(){

int x[3];
int temp;
for(int i = 0; i < 3; i++){
    cin >> x[i];
}
for(int i = 0; i < 3; i++){
    for(int j = i+1;j < 3; j++){
        if(x[i] > x[j]){
            temp = x[i];
            x[i] = x[j];
            x[j] = temp;
        }
    }
}
cout << x[0] << " " << x[1] << " " << x[2] << endl;
return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int D;
  cin >> D;
  vector<string> vec;
  rep(i,0,21) vec.push_back("");
  vec.push_back("Christmas Eve Eve Eve");
  vec.push_back("Christmas Eve Eve");
  vec.push_back("Christmas Eve");
  vec.push_back("Christmas");
  cout << vec[D] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

#define int long long

struct item {
    int weight,value;
};

int32_t main() {
	int n,w;
	cin>>n>>w;
	vector<item> a(n+1);
	for(int i=1;i<=n;i++) {
	    cin>>a[i].weight>>a[i].value;
	}
	int max_val = n*1000;
	vector<vector<int> > dp(n+1,vector<int>(max_val+1));
	dp[1][0] = 0;
	for(int j=1;j<=max_val;j++) {
	    dp[1][j] = INT_MAX;
	}
	dp[1][a[1].value] = a[1].weight;
	for(int i=2;i<=n;i++) {
	    for(int j=0;j<=max_val;j++) {
	        dp[i][j] = dp[i-1][j];
	        if(a[i].value > j) {
	            continue;
	        }
	        else {
	            dp[i][j] = min(dp[i-1][j],a[i].weight + dp[i-1][j-a[i].value]);
	        }
	    }
	}
	int ans = 0;
	for(int j=0;j<=max_val;j++) {
	    if(dp[n][j] <= w) {
	        ans = j;
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 83248
n = int(input())
list_A = list(map(int, input().split()))
list_A.append(0)
list_A.insert(0, 0)
sum_value = 0

for i in range(1, n+2):
    sum_value += abs(list_A[i]-list_A[i-1])

ans = 0
for i in range(1, n+1):
    min_value = min(list_A[i+1], list_A[i-1])
    max_value = max(list_A[i+1], list_A[i-1])
    if min_value <= list_A[i] <= max_value:
        ans = sum_value
        print(ans)
    else:
        ans = sum_value + abs(max_value-min_value) - abs(list_A[i]-max_value) - abs(list_A[i]-min_value)
        print(ans)

Measured memory_bytes: 14172
N = input()

dic = {}

bf = raw_input()
dic[bf] = 1

frag = True

for i in range(N - 1):
    nw = raw_input()
    if bf[len(bf) - 1] != nw[0] or nw in dic:
        frag = False
    else:
        dic[nw] = 1
        bf = nw

if frag:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2568
#include <stdio.h>

int main(){
    int h = 0,
        w = 0,
        i = 0,
        j = 0;
    while(1){
        scanf("%d %d", &h, &w);
        if(h==0&&w==0)break;
        for(i=1;i<=h;i++){
            for (j=1;j<=w;j++){
                if((i+j)%2==0){
                    printf("#");
                } else if ((i+j)%2==1){
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep (i ,n) for(int i=0;i<(n);i++) 
ll gcd (ll a,ll b) {return b?gcd(b,a%b):a;}   
ll lcm (ll a,ll b) {return a/gcd(a,b)*b;} 
const int mod=1e9+7;
int main(){
	ll n,m;
	cin>>n>>m;
	vector<pair<ll,ll>>vp;
	for(ll i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		vp.emplace_back(a,b);
	}
	sort(vp.begin(),vp.end());
	ll ans=0;
	for(auto p:vp){
		ll cnt=min(m,p.second);
		ans+=cnt*p.first;
		m-=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int dp[130][130];//i段目j個目まで選んだ時の最大値
string str1;
vector<vector<int> > data;
int main()
{
  memset(dp,0,sizeof(dp));
  while(cin>>str1){
    replace(str1.begin(),str1.end(),',',' ');
    vector<int> v;
    stringstream ss(str1);
    while(ss>>str1){
      v.push_back(atoi(str1.c_str()));
    }
    data.push_back(v);
  }

  dp[0][0] =data[0][0];
  for(int i = 1;i <data.size();i++){
    for(int j = 0;j <data[i].size();j++){
      if(i <=data.size()/2)
	dp[i][j] =max(dp[i-1][j-1],dp[i-1][j])+data[i][j];
      else
	dp[i][j] = max(dp[i-1][j],dp[i-1][j+1])+data[i][j];
    }
  }
  cout <<dp[data.size()-1][0]<<endl;

  return 0;
}

Measured memory_bytes: 1328
import itertools
N = int(input())
L = [int(i) for i in input().split()]
count = 0
c = itertools.combinations([i for i in range(N)], 3)
for i, j, k in c:
  if not (L[i] == L[j] or L[j] == L[k] or L[k] == L[i]):
    a, b, c = sorted([L[i], L[j], L[k]])
    if a + b > c:
      count += 1
print(count)


Measured memory_bytes: 74068
#include <stdio.h>

int main(){
	int N;
	scanf("%d", &N);
	char s[10000];
	scanf("%s", s);
	
	for(int i = 0; s[i] != '\0'; i++){
		if(s[i] + N > 90){
		s[i] = s[i] + N - 26;
		}else{
			s[i] += N;
		}
	}
	printf("%s", s);
	return 0;
}

Measured memory_bytes: 1672
<?php
list($S) = sscanf(trim(fgets(STDIN)), "%s");
list($T) = sscanf(trim(fgets(STDIN)), "%s");
$d = [];
for ($i = 0; $i < strlen($S) - strlen($T) + 1; $i++) {
    $cnt = 0;
    for ($j = 0; $j < strlen($T); $j++) {
        if ($S[$i+ $j] != $T[$j]) {
            $cnt++;
        }
    }
    $d[$i] = $cnt;
}
asort($d);
//var_dump($d);
//$first = array_shift($d);
print(array_shift($d));


Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,C;
    cin >> N >> C;
    vector<ll> s(N), t(N), c(N);
    vector<vector<ll>> tvp(C, vector<ll>(100005));
    rep(i,N){
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
        tvp[c[i]][s[i]]++;
        tvp[c[i]][t[i]]--;
    }
    //PR(tvp[0],20);
    //PR(tvp[1],20);
    vector<ll> v(100005);
    rep(i,C){
        rep(j,100004){
            if(tvp[i][j] > 0){
                v[j] += tvp[i][j];
            }else{
                v[j+1] += tvp[i][j];
            }
        }
    }
    //PR(v,100005);
    rep(i,100005){
        v[i+1] += v[i];
    }
    ll ans = 0;
    rep(i,100005){
        cmax(ans, v[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 29780
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string, core.stdc.stdlib;

void main() {
    immutable long INF = 1L << 59;
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto L = s[2].to!long;
    auto G = new long[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) G[i][j] = i == j ? 0 : INF;
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        auto a = s[0] - 1;
        auto b = s[1] - 1;
        auto c = s[2].to!long;
        G[a][b] = c;
        G[b][a] = c;
    }
    auto dist1 = warshall_floyd!(long, INF)(G);

    auto dist2 = new long[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) dist2[i][j] = i == j ? 0 : INF;
    foreach (i; 0..N) foreach (j; 0..N) if (dist1[i][j] <= L) dist2[i][j] = 1;
    auto dist3 = warshall_floyd!(long, INF)(dist2);

    auto Q = readln.chomp.to!int;
    while (Q--) {
        s = readln.split.map!(to!int);
        auto a = s[0] - 1;
        auto b = s[1] - 1;
        auto ans = dist3[a][b];
        writeln(ans >= INF ? -1 : ans - 1);
    }
}

T[][] warshall_floyd(T, T inf)(const T[][] graph) {
    import std.conv : to;

    int n = graph.length.to!int;
    auto dist = new T[][](n, n);
    foreach (i; 0..n) foreach (j; 0..n) dist[i][j] = graph[i][j];

    foreach (i; 0..n)
        foreach (j; 0..n)
            foreach (k; 0..n)
                if (dist[j][i] != inf && dist[i][k] != inf)
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);

    return dist;
}

Measured memory_bytes: 8828
#include<bits/stdc++.h>
using namespace std;
const int mo=1e9+7,N=5e5+5;
void Inverse(int p,int a[],int n){//ÏßÐÔÇó<=nµÄÊý%pÒâÒåÏÂµÄÄæÔª 
	a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=1ll*(p-p/i)*a[p%i]%p;
	}
}
int inv[N],fac[N];
void init(int n){
	fac[0]=inv[0]=1;Inverse(mo,inv,n);
	for(int i=1;i<=n;i++)inv[i]=1ll*inv[i-1]*inv[i]%mo,fac[i]=1ll*i*fac[i-1]%mo;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}
int P(int n,int m){return 1ll*fac[n]*inv[n-m]%mo;}
int main(){
	int n,m;scanf("%d%d",&n,&m);
	init(max(n,m));
	long long ans=0;
	for(int i=0;i<=n;i++)
		(ans+=(i&1?-1ll:1ll)*P(m,i)*C(n,i)%mo*P(m-i,n-i)%mo*P(m-i,n-i)%mo)%=mo;
	printf("%d",(ans+mo)%mo);
	return 0;
}

Measured memory_bytes: 7592
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    vector<string> S = {"dream", "dreamer", "erase", "eraser"};
    REP(i,S.size()) reverse(ALL(S[i]));
    reverse(ALL(s));
    int pos = 0;
    bool ok = true;
    while(pos < s.size() && ok) {
        REP(i,S.size() +1) {
            if (i == S.size()) {
                ok = false;
                break;
            }
            if (S[i] == s.substr(pos,S[i].size())) {
                pos += S[i].size();
                break;
            }
        }
    }

    CFYN(ok)

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int p[n+1][2];
    int sum_p = 0;

    rep(i,n+1)
    {
        int cur = i==0 ? 0 : a[i-1];
        int next = i==n ? 0 : a[i];
        int next2 = i>=n-1 ? 0 : a[i+1];
        p[i][0] = abs(next-cur);
        p[i][1] = abs(next2-cur);
        sum_p += p[i][0];
    }

    rep(i,n)
        cout << sum_p - p[i][0] - p[i+1][0] + p[i][1] << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))
	
template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }

void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;

//=========================

void run_test() {
	string s; read(s);
	int n = sz(s);
	if(s[n-1] == 's') s += "es";
	else s += "s";
	println(s);
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


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

using namespace std;

int main(){
    int n, i;
    scanf("%d",&n);
    int height[n+5];
    for(i = 1; i <= n; i++){
        scanf("%d",&height[i]);
    }
    int ans = 1e9;
    int dp[n+5];
    for(i = 1; i<=n; i++){
        dp[i] = 1e9;
    }
    dp[1] = 0;
    for(i = 2; i<=n; i++){
        if(i > 1) dp[i] = min(dp[i], dp[i-1] + abs(height[i] - height[i-1]));
        if(i > 2) dp[i] = min(dp[i], dp[i-2] + abs(height[i] - height[i-2]));
    }
    printf("%d\n", dp[n]);
    return 0;
}


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

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

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


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

const int MOD = 1000000007;
const int MAX = 1001001;


long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int X, Y;
    cin >> X >> Y;
    COMinit();
    if ((X+Y)%3!=0) {
        cout << 0 << endl;
        return 0;
    }
    int n = (X+Y) / 3;
    ll ans = COM(n, X-n);
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N,sum;
    cin >> N;
    
    if (N%1000 == 0){
        sum = 0;   
    }else{
        sum = 1000 - N%1000;
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 3596
#include<stdio.h>

int main()
{
	int n,b = 0,w = 0,i;
	scanf("%d",&n);
  
  	char c[n];
	scanf("%s",c);
	
	for(i = 0;i < n;i++){
		if(c[i] == '.') w++;
	}
	
	int min = w;
  
	for(i = 0;i < n;i++){
		if(c[i] == '#') b++;
		else w--;
		if(b + w < min) min = b + w;
	}
	printf("%d",min);
	return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        pq.push({a[i], i});
    }
    for (int i = 0; i < n; i++){
        if (pq.top().second == i){
            auto tmp = pq.top();
            pq.pop();
            cout << pq.top().first << endl;
            pq.push(tmp);
        } else {
            cout << pq.top().first << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4080
def Print(numlist):
	for t in range(len(numlist)):
		print(numlist[t], end = '')
		if t != len(numlist) - 1:
			print(end = ' ')
	print()

n = eval(input())
numlist = [eval(item) for item in input().split()]
Print(numlist)
for i in range(1, n):
	tmp = numlist[i]
	for j in range(i, -1, -1):
		if tmp > numlist[j - 1]:
			break
		numlist[j] = numlist[j - 1]
	numlist[j] = tmp
	Print(numlist)

Measured memory_bytes: 8044
import java.util.Scanner;

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

		Scanner s = new Scanner(System.in);

		while (true) {
			int n = s.nextInt();
			if (n == 0)
				break;

			int ans = 0;
			int count = 0;

			for (int i = 1; i < n; i++) {
				for (int j = i; j < n; j++) {
					ans += j;
					if (ans == n)
						count++;
					if (ans >= n)
						break;
				}
				ans = 0;
			}
			System.out.println(count);
		}
		s.close();
	}
}

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



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;
    static void Main(string[] args)
    {
        Solve();
    }




    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        int[] X = sc.intarr;
        int ans1 = -1;
        int ans2 = 1;
        for(int i = 0; i <=100; ++i)
        {
            for(int j = 0; j <= 100; ++j)
            {
                for(int k = 0; k <= 100; ++k)
                {
                    for(int l = 0; l <= 100; ++l)
                    {
                        int x = 100 * X[0] * i + 100 * X[1] * j ;
                        int y = X[2] * k + X[3] * l;
                        if (x == 0||x+y>X[5]||x*X[4]<y*100)
                        {
                            continue;
                        }
                        else if (ans1*(x+y)<=ans2*y)
                        {
                            ans1 = y;
                            ans2 = x+y;
                        }

                    }
                }
            }
        }
        wr.wri(ans2 + " " + ans1);


    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

    int n, m;
    cin >> n >> m;
    vll a(m);
    rep(i, m) cin >> a[i];

    if (n >= m) {
        cout << 0 << endl;
    } else {
        sort(a.begin(), a.end());

        vll b;
        rep(i, m - 1) {
            b.emplace_back(a[i + 1]-a[i]);
        }

        sort(b.begin(), b.end(), greater<ll>());

        ll sum = 0;
        rep(i, n - 1) {
            sum += b[i];
        }

        cout << a[m - 1] - a[0] - sum << endl;
    }
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main () {
	string s; cin >> s;
	if (s.size() & 1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != (i & 1 ? 'i' : 'h')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
internal class Program
    {
        public static void Main(string[] args)
        {
            bool[] x = new bool[3];
            var num1 = Convert.ToInt32(Console.ReadLine());
            var num2 = Convert.ToInt32(Console.ReadLine());
            x[num1-1] = true;
            x[num2-1] = true;
            
            var t = Array.FindIndex(x,  b => b == false);
            Console.WriteLine(t+1);
        }
    }

Measured memory_bytes: 11220
n = int(input())
a_list = list(map(int, input().split()))
first = a_list[0]

def check(m0):
    arr = [0] * (n + 1)
    arr[0] = m0
    for j in range(0, n):
        curr = arr[j]
        nxt = int((a_list[j] - curr / 2) * 2)
        arr[j + 1] = nxt
    return arr

r = (0, first)
while r[0] <= r[1]:
    mid = (r[0] + r[-1]) // 2
    m0 = mid * 2
    arr = check(m0)
    mn = arr[n]
    if m0 == mn:
        print(*arr[:n])
        break
    elif mn > m0:
        r = (mid + 1, r[1])
    else:
        r = (r[0], mid - 1)

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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
void out_sequence(vector<ll> &out) { REP(i, out.size()) { cout << out[i]; if (i == out.size() - 1) cout << endl; else cout << " "; } }



int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	cout << ((odd(N))?N * 2:N) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#define N 210000
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
int e[N][2],len,fir[N],n,sa,sb,dep[N],dfn[N],las[N],id,f[N],p[N],tail,d[N],ans;
bool b[N],v[N];
vector<int> A[N];
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void dfs(int x,int fa)
{
	f[x]=fa;
	dfn[x]=++id;
	dep[x]=dep[fa]+1;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	las[x]=id;
}
bool check(int x,int y)
{
	if(dep[x]>dep[y]) swap(x,y);
	if(dfn[x]<=dfn[y] && las[x]>=dfn[y])
	{
		if(dep[y]-dep[x]>2) return 1;
		return 0;
	}
	if(f[x]==f[y]) return 0;
	return 1;
}
void bfs()
{
	v[sa]=1;p[1]=sa;tail=1;
	for(int i=1;i<=tail;i++)
	{
		int x=p[i],siz=A[x].size();
		for(int k=0;k<siz;k++)
		{
			int y=A[x][k];
			d[y]=d[x]+1;
			if(d[y]<dep[y] && v[y]==0) {v[y]=1;p[++tail]=y;}
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&sa,&sb);
	for(int i=1;i<n;i++) scanf("%d%d",&e[i][0],&e[i][1]);
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	dfs(sb,0);
	for(int i=1;i<=n;i++) dep[i]--;
	for(int i=1;i<n;i++)
	{
		int x=e[i][0],y=e[i][1];
		if(check(x,y)) 
			b[x]=b[y]=1;
		else A[e[i][0]].pb(e[i][1]),A[e[i][1]].pb(e[i][0]);
	}
	bfs();
	for(int i=1;i<=n;i++) 
	{
		if(v[i] && b[i]) {printf("-1\n");return 0;}
		if(v[i]) ans=max(ans,dep[i]*2);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 30336
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define vi vector<int>
#define vii vector<vector<int>>
#define mod 1000000007
#define fo(i,n) for(int i=0;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pb(x) push_back(x)
typedef long long ll;

void print_Array(int arr[],int start,int end){
    for(int i=start;i<end;i++){
        printf("%d ",arr[i]);
    }
}


int main(){
    int N;
    cin>>N;
    vi A(N);
    fo(i,N) cin>>A[i];
    sort(A.begin(),A.end());
    ll f=0;
    int ind=N-1;
    int b=1;
    fo(i,N-1){
        f+=A[ind];
        b^=1;
        if(b==0) ind--;
    }
    cout<<f<<endl;
}



Measured memory_bytes: 4044
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.16lf ", sqrt(d));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

using namespace std;

ll n,a,b;
ll h[100001];

bool f(ll x)
{
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        ll val=(ceil)(((ld)h[i]-b*x)/(a-b));
        if(val>0) cnt+=val;
    }
    if(cnt<=x) return true;
    return false;
}

int main()
{
    IOS;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    ll st=1,en=1e9,mid,ans=en;
    while(st<=en)
    {
        mid=st+(en-st)/2;
        if(f(mid))
        {
            ans=min(ans,mid);
            en=mid-1;
            //cout<<1<<endl;
        }
        else st=mid+1;
    }
    cout<<ans<<endl;
    return 0;
    
}


Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    ll median, ans=0;
    if(n%2) median = a[n/2];
    else median= (a[n/2] + a[n/2 -1]) / 2;
    REP(i, n) ans += llabs(a[i] - median);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,m,q;
    cin >> n >> m >> q;
    VVI ru(n+1,VI(n+1));
    int l,r;
    REP(i,0,m) {
        cin >> l >> r;
        ++ru[l][r];
    }
    REP(i,0,n) REP(j,0,n+1) ru[i+1][j] += ru[i][j];
    REP(i,0,n+1) REP(j,0,n) ru[i][j+1] += ru[i][j];
    REP(i,0,q) {
        cin >> l >> r;
        cout << ru[n][r] - ru[l-1][r] << endl;
    }
    /*
    REP(i,0,n+1) {
        REP(j,0,n+1) cerr << ru[i][j] << " ";
        cerr << endl;
    }
    */
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
   ll h,w;
   cin >> h >> w;
   vector<string> a(h);
   rep(i,h)cin >> a[i];
   vector<vector<ll>> dp(h,vector<ll>(w,0));
   dp[0][0] =1 ;
   rep(i,w)
   {
      if(a[0][i]=='#')break;
      dp[0][i] = 1;
   }
   rep(i,h)
   {
      if(a[i][0]=='#')break;
      dp[i][0] = 1;
   }
   for(int i = 1;i < h;i++)
   {
      for(int j = 1;j<w;j++)
      {
         if(a[i][j]=='.')
         {
            dp[i][j] = dp[i-1][j]+dp[i][j-1];
            dp[i][j]%=INF;
         }
      }
   }

   cout<<dp[h-1][w-1]<<endl;
   return 0;
}

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

A = [0]
B = [0]
ans = 0

for i in range(n):
    A.append(A[i] + a[i])

for i in range(m):
    B.append(B[i] + b[i])

j = m

for i in range(n + 1):
    if A[i] > k:
        break
    while A[i] + B[j] > k:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47680
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	if (a * b % 2 == 0)
	{
		cout << "Even" << endl;
	}
	else
	{
		cout << "Odd" << endl;
	}

	return 0;
}


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

typedef long long ll;

using namespace std;

ll pow(ll a, ll b) {
	if(b==1) return a;
	ll half = pow(a,b/2);
	if(half==-1) return -1;
	ll ret = half*half;
	if(b%2==1) ret*=a;
	if(ret>1000000000000LL) return -1;
	return ret;
}

int main() {
	ll n,p;
	cin >> n >> p;
	if(n==1) {
		cout << p << endl;
	}else if(n<100) {
		ll ans = 1;
		for(int i = 2; i <= ceil(sqrt(p)); i++) {
			ll ret = pow(i,n);
			//cout << ret << endl;
			if(ret==-1) break;
			if(p%ret==0) {
				ans = i;
			}
		}
		cout << ans << endl;
	}else {
		cout << 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define RANGE_R(i,a,b) for(int i=(int)b-1,_a=(int)(a);(i)>=_a;--i)
#define MIN_UPDATE(target, value) target = min(target, value)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT(v) __builtin_popcountll((ll)(v))
#define IN_RANGE(v, a, b) ((a)<=(v) && (v)<(b))
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }


/*

*/
int main() {
	ll N;
	while(1) {
		cin>>N;
		if(!N)break;
		VI w(N);
		REP(i, N) cin>>w[i];
		double minX=0, maxX=0;
		vector<double> x(N+1);
		REP(i, N) {
			REP(j, i) {
				double X=x[j] + sqrt(pow(w[j]+w[i], 2) - pow(fabs(w[j]-w[i]), 2));
				x[i]=max(x[i], X);
			}
			minX=min(minX, x[i]-w[i]);
			maxX=max(maxX, x[i]+w[i]);
		}
		printf("%.10f\n", maxX-minX);
		break;
	}
	return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
bool vis[1003][1003];
int n, D1, D2;
void init(int dis) {
    int tmp = 0;
    while (!(dis & 3)) dis >>= 2, ++tmp;
    if (dis & 1)
        for (int i = 0; i < (n << 1); ++i)
            for (int j = 0; j < (n << 1); ++j)
                (i >> tmp) + (j >> tmp) & 1 ? vis[i][j] = 1 : 0;
    else
        for (int i = 0; i < (n << 1); ++i)
            for (int j = 0; j < (n << 1); ++j)
                if ((i >> tmp) & 1) vis[i][j] = 1;
}
int main() {
    scanf("%d%d%d", &n, &D1, &D2);
    init(D1), init(D2);
    int cnt = n * n;
    for (int i = 0; i < (n << 1); ++i)
        for (int j = 0; j < (n << 1); ++j) {
            if (!vis[i][j]) printf("%d %d\n", i, j), --cnt;
            if (!cnt) return 0;
        }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll n, t, x, y, ct, cx, cy;
	cin >> n;
	ct = cx = cy = 0;
	REP(i, n) {
		cin >> t >> x >> y;
		if (abs(x-cx) + abs(y-cy) > t-ct || (t-ct - (abs(x-cx) + abs(y-cy))) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
		ct = t; cx = x; cy = y;
	}
	cout << "Yes" << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

int solve(char* s, int l, int r, int k, int n, vector<int>& memo)
{
	if(r - l <= 0) return 0;
	if(r - l == 1) return 1;

	int n1 = n + 1;
	int idx = k * n1 * n1 + l * n1 + r;
	int& val = memo[idx];

	if(val != -1)
		return val;
	val = 0;

	if(s[l] == s[r - 1]) {

		val = solve(s, l + 1, r - 1, k, n, memo) + 2;

	} else {

		if(k > 0) {
			val = solve(s, l + 1, r - 1, k - 1, n, memo) + 2;
		}

		int t1 = solve(s, l, r - 1, k, n, memo);
		int t2 = solve(s, l + 1, r, k, n, memo);
		val = max(val, max(t1, t2));
	}

	return val;
}

int main()
{
	char s[512];
	int k;

	scanf("%s%d", s, &k);

	int n = strlen(s);
	vector<int> memo;
	memo.resize((n + 1) * (n + 1) * (n + 1), -1);

	int ans = solve(s, 0, n, k, n, memo);

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

	return 0;
}

/* waffle */


Measured memory_bytes: 106880
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
	int n,m,i,x,y,pd=0;
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y;
		if(a[x]&&a[x]!=y||x==1&&y==0&&n!=1)
		{
			pd=1;
			cout<<"-1";
			break;
		}
		a[x]=y;
	}
	if(pd==0)
	{
		if(a[1]==0&&n!=1)
		a[1]=1;
		for(i=1;i<=n;i++)
		{
			cout<<a[i];
		}
	}
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# Input#
n = int(input())
# n, k = map(int, input().split())

memo = [[-1] * 3 for i in range(n)]
a = []
b = []
c = []


def dp(i):
    if i != 0:
        memo[i][0] = max(memo[i - 1][1], memo[i - 1][2]) + a[i]
        memo[i][1] = max(memo[i - 1][0], memo[i - 1][2]) + b[i]
        memo[i][2] = max(memo[i - 1][0], memo[i - 1][1]) + c[i]
    return max(memo[i][0], memo[i][1], memo[i][2])


for i in range(n):
    a_in, b_in, c_in = map(int, input().split())
    a.append(a_in)
    b.append(b_in)
    c.append(c_in)
    if i == 0:
        memo[0][0] = a_in
        memo[0][1] = b_in
        memo[0][2] = c_in
    else:
        ans = dp(i)


ans = dp(n - 1)

print("{}".format(ans))


Measured memory_bytes: 104956
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);



		System.out.println(3*N*N);

	}


}


Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    bool ok = true;
    map<char,char> ma, ima;
    for (int i = 0; i < S.size(); ++i) {
        char s = S[i], t = T[i];
        if (ma.count(s)) if (ma[s] != t) ok = false;
        if (ima.count(t)) if (ima[t] != s) ok = false;
        ma[s] = t; ima[t] = s;
    }
    if (ok) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	swap(a[0],a[1]);
	swap(a[0],a[2]);
	cout<<a[0]<<" "<<a[1]<<" "<<a[2];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N= 2e5 + 5;
const ll MOD=1e9 + 7;

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


    ll k;
    cin>>k;
    string str;
    cin>>str;
    ll n = str.size();

    char ch;
    for(ll i=0;i<n;i++){
        ch = (str[i]-'A' + k )%26;
        cout<<char(ch+'A');
    }
}


Measured memory_bytes: 256
import sys

while True:
    n = int(input())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = input().split()
        x[k] = v
    y = []
    for i in range(int(input())):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Measured memory_bytes: 8516
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define endl '\n'
#define int ll
// #define gcd __gcd
#define popcount(x) __builtin_popcountll(x)
#define fill(x, y) memset(x, y, sizeof(x))
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
// default binary search returns a bool
 
// int dx[]={1,0,-1,0}; 
// int dy[]={0,1,0,-1}; //4 Direction 
 
// int dx[]={1,1,0,-1,-1,-1,0,1}; 
// int dy[]={0,1,1,1,0,-1,-1,-1};  // 8D

void solve(){

    int n;
    cin >> n;
    vi a(n);
    for (int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    int maxi = a[0] , ans = 0;
    for (int i = 1 ; i < n ; i++){
        if (a[i] > maxi){
            maxi=a[i];
        }
        else{
            ans += maxi-a[i];
        }
    }
    cout << ans << endl;
}

 
int32_t main(){

    #ifndef ONLINE_JUDGE 
  
    freopen("input.txt", "r", stdin); 
  
    // freopen("output.txt", "w", stdout); 
  
    #endif 
 
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    int t = 1;
    // cin >> t;
    for (int tt = 0 ; tt < t ; tt++){
        
        // cout << "Case " << (tt+1) <<": " << endl;
        solve();
    }
    
}

Measured memory_bytes: 4788