akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
 
typedef struct{
  double x;
  double y;
}Point;
 
void koch(int,Point,Point);
 
int main ( void ){
 
  int num;
 
  scanf("%d" , &num );
 
  Point a = {0.0, 0.0};
  Point b = {100.0, 0.0};
 
  printf("%.8f %.8f\n" , a.x , a.y );
  koch( num , a , b );
  printf("%.8f %.8f\n" , b.x , b.y );
 
  return 0;
}
 
 
 
 
void koch( int num , Point a , Point b ){
  if( num == 0 ){return ; }
 
  Point c,d,e;
 
 
  c.x = ( 2.0 * a.x + 1.0 * b.x ) / 3.0;
  c.y = ( 2.0 * a.y + 1.0 * b.y ) / 3.0;
  d.x = ( 1.0 * a.x + 2.0 * b.x ) / 3.0;
  d.y = ( 1.0 * a.y + 2.0 * b.y ) / 3.0;
  e.x = ( d.x - c.x ) * cos( M_PI/3 ) - (d.y - c.y ) * sin( M_PI/3 ) + c.x;
  e.y = ( d.x - c.x ) * sin( M_PI/3 ) + (d.y - c.y ) * cos( M_PI/3 ) + c.y;
 
  koch( num - 1 , a , c );
  printf("%.8f %.8f\n" , c.x , c.y );
  koch( num - 1 , c , e );
  printf("%.8f %.8f\n" , e.x , e.y );
  koch( num - 1 , e , d );
  printf("%.8f %.8f\n" , d.x , d.y );
  koch( num - 1 , d , b );
}

Measured memory_bytes: 640
from scipy.ndimage import distance_transform_cdt


def main():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()


Measured memory_bytes: 55700
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
s = [0] * (m-1)
for i in range(m-1):
  s[i] = x[i+1] - x[i]
s.sort()
if n != 1:
  print(sum(s[:-n+1]))
else:
  print(sum(s))

Measured memory_bytes: 13968
S = input()
T = input()

num_S = len(S)
num_T = len(T)

N = num_S - num_T + 1
C = [0]*N
for i in range(N):
  A = S[i:i+num_T]
#  print(S[i:i+num_T])
  count = num_T
  for j in range(num_T):
    if T[j] == A[j]:
      count = count - 1
    else:
      None
  C[i] = count
print(min(C))

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

using namespace std;

#define ll long long
#define ar array
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))

int N, tmp;
int L[100];

void solve(){
    cin >> N;
    
    for (int  i = 0; i < N; i++)
    {
        cin >> tmp;
        L[i] = tmp;
    }
    
    sort(L, L+ N);

    int count = 0;
    for (int i = 0; i < N-2; i++)
    {
        for (int j = i+1; j < N-1; j++)
        {
            for (int h = j+1; h < N; h++)
            {
                if(L[i] == L[j] || L[j] == L[h]) continue;
                if(L[h] < L[i] + L[j])
                {
                    count++;
                }
            }            
        }        
    }
   cout << count << endl; 

    
   
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define llu unsigned long long
#define U unsigned int
#define ff first
#define ss second
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define pair pair<ll,ll>
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define INF 1000000000000005
#define N 10000
vector<ll>vec;
map<string,ll> mps;
map<ll,string> mpss;
set<ll>s1;
set<string>s2;
map<string,ll>::iterator str;
set<ll>::iterator itr;
/*
std::cout << std::fixed;
std::cout << std::setprecision(1);
std::cout << VALUE NAME<<endl;
*/
ll tra[100006],tra1[100006];


int main()
{
    fast_cin;
    ll t;
    //cin>>t;
   /* while(t--)
    {*/
        map<ll,ll>mp;
        map<ll,ll>::iterator it;
        string s;
        ll n;
        //cin>>n;
         n=5;
         ll str[n+4],save=0;
         for(int i=1;i<=n;i++)
         {
              cin>>str[i];
              if(str[i]==0)
                save=i;
         }
         cout<<save<<endl;








        s1.clear();
        vec.clear();
    //}
}



Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next(), t = sc.next();
		int diffCount = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != t.charAt(i))
				++diffCount;
		}
		System.out.println(diffCount);
		sc.close();
	}
}


Measured memory_bytes: 40932
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    string s;
    cin >> s;
    
    ll ans = 0, A_num = 0;
    for (ll i = 0; i < (ll)s.size() - 1; i++) {
        if (s[i] == 'A') {
            A_num++;
        } else if (A_num > 0 && s[i] == 'B' && s[i + 1] == 'C') {
            ans += A_num;
            i += 1;
        } else {
            A_num = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import sys
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    h, w = map(int, input().split())
    t = [[(c == "#") * 1 for c in input()] for _ in range(h)]
    b0 = sum(sum(tk) for tk in t)
    # print(b0)
    hp = []
    # p2D(t)
    heappush(hp, (1, 0, 0))
    while hp:
        d, i, j = heappop(hp)
        if (i, j) == (h - 1, w - 1):
            print(h * w - d - b0)
            exit()
        for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            ni, nj = i + di, j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if t[ni][nj]: continue
            t[ni][nj] = 1
            heappush(hp, (d + 1, ni, nj))
    print(-1)

main()


Measured memory_bytes: 3188
def shortest_path(V,uvc,start=0):
    distances = [INF]*V
    distances[start] = 0
    parents = list(range(V))

    for _ in range(V):
        modified = False
        for src,dst,cost in uvc:
            if distances[dst] > distances[src] + cost:
                distances[dst] = distances[src] + cost
                parents[dst] = src
                modified = True
        if modified == False:
            return distances,parents
    return None,None
import sys
INF = float("inf")
N = int(sys.stdin.readline())
G = tuple(tuple(map(int,sys.stdin.readline().rstrip().split()))[2:] for _ in range(N))
uvc = []
for i in range(N):
    for j in range(0,len(G[i]),2):
        uvc.append([i,G[i][j],G[i][j+1]])  
a,_ = shortest_path(N,uvc,0)
for i,v in enumerate(a):
    print(i,v)


Measured memory_bytes: 6136
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define ll long long int

int main(int argc, const char * argv[]) {
	ll N,P;
	cin >> N >> P;
	if(N==1){
		cout << P << endl;
		return 0;
	}
	ll max = (int)pow(1.0*P,1.0/N);
	ll ret = 1;
	for (ll divider = 2; divider <= max && P!=1; ++divider) {
		ll count=0;
		while(P % divider == 0){
//			cerr << divider;
			count++;
			P /= divider;
		}
		if(count > 0){
//			cerr << divider << "**" << count << endl;
		}
		while(count>=N){
//			cerr << divider << endl;
			ret *= divider;
			count -= N;
		}
	}
	cout << ret << endl;
}


Measured memory_bytes: 256
import math 
import fractions
a, b, c, d= map(int,input().split())
e = b//c-(a-1)//c
f = b//d-(a-1)//d
cd = c * d // fractions.gcd(c,d)
g = b//cd -(a-1)//cd
print(b-a-e-f+g+1)

Measured memory_bytes: 5048
class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数
        self.rank = [0] * (n + 1)

    def find(self, x):  # xの根となる要素番号を返す
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def getNodeLen(self, x):
        return -self.root[self.find(x)]


n, m = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(m)]
bridge = bridge[::-1]

uf = UF_tree(n)
ans = [0] * (m + 1)
ans[0] = n * (n - 1) // 2

for i in range(m):
    x, y = bridge[i]
    if uf.isSame(x, y):
        ans[i + 1] = ans[i]
        continue

    tmp = uf.getNodeLen(x) * uf.getNodeLen(y)
    uf.unite(x, y)
    ans[i + 1] = ans[i] - tmp

ans = ans[::-1][1:]
print(*ans, sep="\n")


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

using namespace std;

vector<int> v;

void p(int n,int sum){
	if(n == sum){
		for(int i=0;i<v.size()-1;i++){
			cout << v[i] << " ";
		}
		cout << v.back() << endl;
		return;
	}

	if(v.empty()){
		for(int i=n;i>=1;i--){
			v.push_back(i);
			p(n,sum+i);
			v.pop_back();
		}
	}else{
		for(int i=v.back();i>=1;i--){
			if(sum+i<=n){
				v.push_back(i);
				p(n,sum+i);
				v.pop_back();
			}
		}
	}
}

int main(void){
	int n;
	while(cin >> n && n){
		p(n,0);
		v.clear();
	}
}

Measured memory_bytes: 908
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

int main(){
    int n, m;
    vector<string> b;
    vector<int> num;

    cin >> n;
    int size = 1;
    for(int i=0; i < n; i++){
        string temp = "a";
        cin >> temp;
        int flag = 1;
        if(i == 0){
            b.push_back(temp);
            num.push_back(1);
        }
        else{
            for(int j=0; j < size; j++){
                if(b[j] == temp){
                    num[j] += 1;
                    flag = 0;
                }
            }
            if(flag){
                b.push_back(temp);
                num.push_back(1);
                size += 1;
            }
        }
    }

    cin >> m;
    for(int i=0; i < m; i++){
        string temp = "a";
        cin >> temp;
        for(int j=0; j < size; j++){
            if(b[j] == temp) num[j] -= 1;
        }
    }

    int max = -100000000;
    for(int i=0; i < size; i++){
        if(max < num[i]) max = num[i];
    }
    if(max < 0) max = 0;
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
long int A, B;
ll gcd(ll , ll);
int main() {
    cin >> A >> B;
    long int X = A * B;
    cout << X / gcd(A, B) << endl;
}
ll gcd(ll x, ll y) {
    return y ? gcd(y, x % y) : x;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    string s; cin >> s;

    ll a = (s[0]-'0')*10 + (s[1]-'0');
    ll b = (s[2]-'0')*10 + (s[3]-'0');

    if(((a>=1 && a<=12) && (b>=0 && b<=99)) && ((b>=1 && b<=12) && (a>=0 && a<=99))){
        cout << "AMBIGUOUS" << endl;
    }
    else if((a>=1 && a<=12) && (b>=0 && b<=99)){
        cout << "MMYY" << endl;
    }
    else if((b>=1 && b<=12) && (a>=0 && a<=99)){
        cout << "YYMM" << endl;
    }
    else{
        cout << "NA" << endl;
    }
    
    return 0;
}

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

int R, C, i, j;

int main() {
//  freopen("inp", "r", stdin);
  cin >> R >> C >> i >> j;
  for(int r = 0; r < R; r++) {
    for(int c = 0; c < C; c++) {
      int ut = (c < i) ^ (r < j);
      putchar(ut + '0');
    } 
    putchar('\n');
  }
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++) {
			num[i]= sc.nextInt();
			if(num[i] > max) {
				max = num[i];
			}
			if(num[i] < min) {
				min = num[i];
			}
		}
		System.out.println(max-min);
	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

vector<bool> isPrime(int n){
  vector<bool> p(n+1, true);
  p[0] = false;
  p[1] = false;
  for(int i=2; i<=sqrt(n); i++){
    if( p[i] == false ) continue;
    for(int j=i+i; j<n; j+=i){
      p[j] = false;
    }
  }
  return p;
}

int main(void) {

  vector<bool> p = isPrime(10000000);

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    int cnt = 0;
    long long int sum = 0;
    for(int i=0; i<p.size(); i++){
      if( p[i] ){
        cnt++;
        sum += i;
      }
      if( cnt == n ){
        cout << sum << endl;
        break;
      }
    }
  }

  return 0;
}

// EOF

Measured memory_bytes: 3860
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>

#define ll long long
using namespace std; 

void solve(){
  int n ,k;
  cin >> n>>k ; 
  vector<int> a(n); 
  for(int i=0 ; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end()); 
  bool dp[k+1]; 
  int curr = 0; 
  dp[0] = false; 
  for(int i=1; i<=k; i++){
    dp[i] = false; 
    for(int j=0; j<n; j++){
      if(i-a[j]<0){
        break; 
      }
      dp[i] |= !(dp[i-a[j]]);  
    }
  }
  std::cout <<  (dp[k]? "First\n" : "Second\n");
}

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

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
    int A,B,x;
    cin >>A>>B;
    x=0;
    for(int i=0;i<2;i++){
    if(A>=B){
        x +=A;
        A -=1;
    }
    else{
        x+=B;
        B-=1;
    }
    }
    cout << x <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++)cin >> L.at(i);
  
  int sum=0;
  sort(L.begin(),L.end());
  
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(L.at(k)>=(L.at(j)+L.at(i))){
          break;
        }else if(L.at(k)>(L.at(j)-L.at(i))){
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
    
  
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value == hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value < hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value > hoge2.value;
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(N);
  REP(i,N) IN(A[i]);
  vll x(N);
  REP(i,N){
    if(i%2==0) x[0] += A[i];
    else x[0] -= A[i];
  }

  FOR(i,1,N){
    x[i] = 2*A[i-1]-x[i-1];
  }

  REP(i,N){
    printf("%lld ", x[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2944
N, M = list(map(int, input().split()))
sc = []
for i in range(M):
  s, c = list(map(int, input().split()))
  sc.append([s, c])
for i in range(10**N):
  stri = str(i)
  if len(stri) == N:
    for j in range(M):
      k = sc[j][0]
      if not stri[k-1] == str(sc[j][1]):
        break
    else:
      print(i)
      break
else:
  print(-1)

Measured memory_bytes: 62920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;


int main(){
    int n;
    cin>>n;
    int countover=0;
    vector<bool> flg(9,false);
    for (int i=0; i<n; i++){
        int x;
        cin>>x;
        if(1<=x&&x<400)flg[0]=true;
        else if(400<=x&&x<800)flg[1]=true;
        else if(800<=x&&x<1200)flg[2]=true;
        else if(1200<=x&&x<1600)flg[3]=true;
        else if(1600<=x&&x<2000)flg[4]=true;
        else if(2000<=x&&x<2400)flg[5]=true;
        else if(2400<=x&&x<2800)flg[6]=true;
        else if(2800<=x&&x<3200)flg[7]=true;
        else if(3200<=x){flg[8]=true;countover++;}
    }
    int count=0;
    for (int i=0; i<8; i++){
        if(flg[i])count++;
    }
    int countmax=count+countover;
    if(count==0&&countover!=0)count=1;
    cout<<count<<" "<<countmax;
    return 0;
}

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

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

  for (int c = 1; c <= 3; c++) {
    if ((a * b * c) % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s; cin >> s;
	vector<int> al(26, 0);
	for (int i = 0; i < s.size(); i++)
	{
		al[s[i] - 'A']++;
	}
	if(count(al.begin(), al.end(), 2) == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    ans_list = []
    for i in range(k):
        d = int(input())
        num_list = list(map(int, input().split()))
        for j in range(d):
            ans_list.append(num_list[j])

    ans_list = list(set(ans_list))

    print(n - len(ans_list))

if __name__ == '__main__':
    main()

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

struct Card{char suit,value;};

void Bubble(struct Card C[],int N){
    for(int i =0;i<N;i++){
        for(int j=N-1;j>i;j--){
            if(C[j].value < C[j-1].value){
                // swapで書いて良いのかは知らない
                swap(C[j],C[j-1]);
            }
        }
    }
}

void selection(struct Card C[],int N){
    int minj;
    for(int i=0;i<N;i++){
        minj = i;
        for(int j=i;j<N;j++){
            if(C[j].value<C[minj].value){
                minj = j;
            }
        }
        swap(C[i],C[minj]);
    }
}
// 出力
void output(struct Card C[],int N){
    for(int i=0;i<N;i++){
        if(i>0) cout << " ";
        cout << C[i].suit << C[i].value;
    }
    cout << endl;
}

bool is_stable(struct Card C1[],struct Card C2[],int N){
    for(int i=0;i<N;i++){
        if(C1[i].suit != C2[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
    int N;
    cin >> N;
    struct Card C1[N],C2[N];
    for(int i=0;i<N;i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    for(int i=0;i<N;i++){
        C2[i] = C1[i];
    }
    selection(C1,N);
    Bubble(C2,N);

    output(C2, N);
    cout << "Stable" << endl;
    output(C1,N);
    if(is_stable(C1,C2,N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct edge {
    int to, cost;
    edge(int to, int cost) :to(to), cost(cost) {}
};

vector<edge> g[101010];
ll dist[101010];

void dfs1(int idx, int par) {
    for (edge& e : g[idx]) {
        if (e.to == par) continue;
        dfs1(e.to, idx);
        dist[idx] = max(dist[idx], dist[e.to] + e.cost);
    }
}

int dfs2(int idx, int d_par, int par) {
    vector<P> d_child;
    d_child.emplace_back(0, -1);
    for (edge &e : g[idx]) {
        if (e.to == par) d_child.emplace_back(d_par + e.cost, e.to);
        else d_child.emplace_back(e.cost+dist[e.to], e.to);
    }
    sort(d_child.rbegin(), d_child.rend());
    int ret = d_child[0].first + d_child[1].first;
    for (edge &e : g[idx]) {
        if (e.to == par) continue;
        ret = max(ret, dfs2(e.to, d_child[d_child[0].second == e.to].first, idx));
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    rep(i, N-1) {
        int a, b, w;
        cin >> a >> b >> w;
        g[a].emplace_back(b, w);
        g[b].emplace_back(a, w);
    }
    dfs1(N/2, -1);
    cout << dfs2(N/2, 0, -1) << endl;
}



Measured memory_bytes: 20200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define int long long


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

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

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}



signed main() {
	int x, y;
	cin >> x >> y;
	int ans = INF;
	int X = x, Y = y;
	if (X <= Y)ans = min(ans, Y - X);
	X = -x, Y = y;
	if (X <= Y)ans = min(ans, Y - X+1);
	X = x, Y = -y;
	if (X <= Y)ans = min(ans, Y - X + 1);
	X = -x, Y = -y;
	if (X <= Y)ans = min(ans, Y - X + 2);
	p(ans);
}

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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var o = Console.ReadLine();
            var e = Console.ReadLine();

            var maxlen = Math.Max(o.Length, e.Length);
            var password = "";
            for (var i = 0; i < maxlen; i++)
            {
                if (i < o.Length)
                {
                    password += o[i];
                }
                if (i < e.Length)
                {
                    password += e[i];
                }
            }

            Console.WriteLine(password);
        }
    }
}


Measured memory_bytes: 13140
s=input()[::-1]
p=[1]+[0]*12
q=1
t=[[(i*k)%13 for i in range(10)]for k in range(13)]
for i in s:
    if i!="?":
        i=int(i)
        g=t[q][i]
        p=p[-g:]+p[:-g]
    else:
        d=[0]*13
        for j in t[q]:
            r=p[-j:]+p[:-j]
            d=[(r[i]+d[i])%(10**9+7)for i in range(13)]
        p=d
    q=(q*10)%13
print(p[5]%(10**9+7))


Measured memory_bytes: 44124
#include <stdio.h>

int main(void){
    int a, b, c, d, e, k;
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
    printf("%s\n", (e-a <= k) ? "Yay!" : ":(");
    return 0; 
}

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

vector<ll> u, v;
int n, m, a[3];

main()
{
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[0] * a[1] / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}


template <typename T> T power(T n, LLI p, const T &e, const function<T(T,T)> &f){
  T ret = e;
  while(p>0){
    if(p&1) ret = f(ret, n);
    n = f(n, n);
    p /= 2;
  }
  return ret;
}



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

  int N;
  while(cin >> N){
    vector<double> x(N); cin >> x;

    int M; cin >> M;
    LLI K; cin >> K;

    vector<int> a(M); cin >> a;
    for(auto &i : a) --i;

    vector<int> b(N-1);
    REP(i,N-1) b[i] = i;

    for(auto i : a){
      swap(b[i-1], b[i]);
    }

    dump(b);

    auto f = [N](const vector<int> &a, const vector<int> &b){
	       vector<int> ret(N-1);
	       REP(i,N-1){
		 ret[i] = a[b[i]];
	       }
	       return ret;
	     };

    vector<int> e(N-1);
    REP(i,N-1) e[i] = i;
    
    auto c = power<vector<int>>(b, K, e, f);
    
    dump(c);

    vector<double> diff(N-1);
    REP(i,N-1) diff[i] = x[i+1] - x[i];

    vector<double> diff2(N-1);
    REP(i,N-1) diff2[i] = diff[c[i]];

    vector<double> ans(N);
    ans[0] = x[0];
    REP(i,N-1) ans[i+1] = ans[i] + diff2[i];
    
    for(auto i : ans) cout << setprecision(15) << i << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6104
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = iss().split(' ')
    print('Three' if len(set(S)) == 3 else 'Four')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/*
 * @Date: 2020-03-12 16:40:50
 * @LastEditors: BeckoninGshy
 * @LastEditTime: 2020-03-12 16:45:35
 */
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int dp[2][3];
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a,b,c;
    cin >> a >> b >> c;
    dp[1][0] = max(dp[0][1],dp[0][2]) + a;
    dp[1][1] = max(dp[0][0],dp[0][2]) + b;
    dp[1][2] = max(dp[0][0],dp[0][1]) + c;
    dp[0][0] = dp[1][0];
    dp[0][1] = dp[1][1];
    dp[0][2] = dp[1][2];
  }
  cout << max(dp[0][0],max(dp[0][1],dp[0][2]));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  vector<int> c(26);
  for(int i=0;i<26;i++)
    cin>>c.at(i);
  vector<vector<int>> s(d,vector<int>(26));
  for(int i=0;i<d;i++)
    for(int j=0;j<26;j++)
      cin>>s.at(i).at(j);
  vector<set<int>> l(26);
  for(int i=0;i<26;i++)
    l.at(i).insert(0);
  vector<int> t(d);
  int64_t p;
  for(int i=1;i<=d;i++){
    vector<int> x(26,0);
    int m=0;
    for(int j=0;j<26;j++){
      int64_t pi=s.at(i-1).at(j);
      for(int k=0;k<26;k++)
        pi-=c.at(k)*(k==j?0:i-*rbegin(l.at(k)));
      x.at(j)=pi;
      if(x.at(j)>x.at(m))
        m=j;
    }
    t.at(i-1)=m;
    p=x.at(m);
    l.at(m).insert(i);
  }
  for(int i=0;i<26;i++)
    l.at(i).insert(d+1);
  for(int i=0;i<1000000;i++){
    int pn=p;
    int di=rand()%d+1;
    int qn=rand()%26;
    int qo=t.at(di-1);
    l.at(qo).erase(di);
    auto io=lower_bound(l.at(qo).begin(),l.at(qo).end(),di);
    auto in=lower_bound(l.at(qn).begin(),l.at(qn).end(),di);
    pn+=s.at(di-1).at(qn)-s.at(di-1).at(qo);
    pn+=(di-*prev(in,1))*(*in-di)*c.at(qn)-(di-*prev(io,1))*(*io-di)*c.at(qo);
    if(pn>p){
      l.at(qn).insert(di);
      t.at(di-1)=qn;
    }else
      l.at(qo).insert(di);
  }
  for(int i=0;i<d;i++)
    cout<<t.at(i)+1<<endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC50(void);
void ABC51(void);
void ABC52(void);
void ABC53(void);
void ABC54(void);
void ABC55(void);
void ABC56(void);
void ABC57(void);
void ABC58(void);
void ABC59(void);

int main(void){
    ABC59();
}

void ABC59(){
    int da,db;
    vector<string> a(2);
    cin>>a[0]>>a[1];
    da=a.at(0).length();
    db=a.at(1).length();
    if(da>db)cout<<"GREATER"<<endl;
    else if(da<db)cout<<"LESS"<<endl;
    else if(da=db){
        if(a[0]>a[1])cout<<"GREATER"<<endl;
        else if(a[0]<a[1])cout<<"LESS"<<endl;
        else if(a[0]==a[1])cout<<"EQUAL"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main(){
   int n,i,j;
   int hyo[20][20];
   
   for(;;){
      cin>>n;
      if(n==0) break;
      
      memset(hyo,0,sizeof(hyo));
      
      for(i=0;i<n;i++){
         for(j=0;j<n;j++){
            cin>>hyo[i][j];
         }
      }
      //ツ可。ツづーツ堕ォツつキ
      for(i=0;i<n;i++){
         for(j=0;j<n;j++){
            hyo[i][n] += hyo[i][j];
         }
      }
      //ツ縦ツづーツ堕ォツつキ
      for(j=0;j<n+1;j++){
         for(i=0;i<n;i++){
            hyo[n][j] += hyo[i][j];
         }
      }
      
      for(i=0;i<n+1;i++){
         for(j=0;j<n+1;j++){
            printf("%5d",hyo[i][j]);
         }
         puts("");
      }
   }
   return 0;
}

Measured memory_bytes: 0
def main():
	import sys
	input=sys.stdin.readline
	n=int(input())
	num=[0]*(10**5+2)
	a=list(map(int,input().split()))
	for x in a:
		num[x-1]+=1
	q=int(input())
	ans=0
	for i in range(len(num)):
		ans+=(i+1)*num[i]
	for i in range(q):
		b,c=map(int,input().split())
		ans+=num[b-1]*(c-b)
		num[c-1]+=num[b-1]
		num[b-1]=0
		print(ans)
if __name__ == '__main__':
	main()

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

int main() {
  vector<int> vec(5);
  
  for (int i = 0; i < 5; i++) {
    cin >> vec.at(i);
  }
  
 vector <int> fd(5);
  
  for(int i = 0; i < 5; i++) {
    fd.at(i) = vec.at(i) % 10;
  }
  
  int zx = 0;
  for(int i = 0; i < 5; i++) {
    zx += fd.at(i);
  }
  
  int cv = 0;
  for(int i = 0; i < 5; i++) {
    cv += vec.at(i);
  }

  for(int i = 0; i < 5; i++) {
    if(fd.at(i) == 0) {
      fd.at(i) += 12343;
    }
  }
  
  sort(fd.begin(), fd.end());
  
  int sum = 0;
  
  for(int i = 0; i < 5; i++) {
    if(vec.at(i) % 10 == 0) {
    sum += vec.at(i);
    } else {
      sum += vec.at(i) + (10 - vec.at(i) % 10);
    }
  }
  
  if (zx == 0) {
    cout << cv << endl;
  } else {
    cout << sum + fd.at(0)  - 10 << endl;
  }

  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n' 
#define ull unsigned long long
 
using namespace std;

map < int ,  int > m ; 

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

    cin >> n ;

    int a[n] ; 

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

    ll f[100001] ;

    f[0] = 0 ;
    f[1] = abs(a[1] - a[0]) ;

    for(int i = 2 ; i < n ; i++){
        f[i] = min(f[i - 2] + abs(a[i - 2] - a[i]) , f[i - 1] + abs(a[i - 1] - a[i])) ; 
    }

    cout << f[n - 1] << endl ;


     return 0 ;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll>x(n);
    vector<ll>y(n);
    vector<ll>h(n);
    for(ll i=0;i<n;i++) cin>>x[i]>>y[i]>>h[i];
	for(ll i=0;i<=100;i++){
		for(ll j=0;j<=100;j++){
			ll high;
			for(ll k=0;k<n;k++){
				if(h[k]!=0){
					high=h[k]+abs(x[k]-i)+abs(y[k]-j);
					if(high<=0){
						continue;
					}
					break;
				}
			}
			for(ll k=0;k<n;k++){
				if(h[k]==max(high-abs(x[k]-i)-abs(y[k]-j),0LL)){
					continue;
				}else{
					goto Exit;
				}
			}
			cout<<i<<" "<<j<<" "<<high<<"\n";
			return 0;
			Exit:;
		}
	}
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] minsL = new int[n+2];
		int[] maxsL = new int[n+2];
		int[] maxsR = new int[n+2];
		int[] minsR = new int[n+2];
		int[] kawase = new int[n+2];

		minsL[0] = Integer.MAX_VALUE;
		maxsL[0] = 0;
		for(int i=1;i<=n;i++) {
			kawase[i] = in.nextInt();
			minsL[i] = Math.min(minsL[i-1], kawase[i]);
			maxsL[i] = Math.max(maxsL[i-1], kawase[i]);
		}
		minsR[n+1] = Integer.MAX_VALUE;
		maxsR[n+1] = 0;
		for(int i=n;i>=1;i--) {
			minsR[i] = Math.min(minsR[i+1], kawase[i]);
			maxsR[i] = Math.max(maxsR[i+1], kawase[i]);
		}

		int ans = Integer.MIN_VALUE;
		for(int i=1;i<n;i++) {
			ans = Math.max(ans, maxsR[i+1] - minsL[i]);
//			ans = Math.max(ans, Math.abs(maxsL[i] - minsR[i+1]));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 108648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  vector<vector<int>> M(H, vector<int>(W, 0));
  queue<int> X;
  queue<int> Y;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
      if (A.at(i).at(j) == '#') {
        X.push(i);
        Y.push(j);
      }
    }
  }
  vector<int> vx = {1, -1, 0, 0};
  vector<int> vy = {0, 0, 1, -1};
  //下準備完了
  while (X.size() > 0) {
    for (int i = 0; i < 4; i++) {
      if ((X.front() + vx.at(i)) >= 0 && (Y.front() + vy.at(i)) >= 0 
          && (X.front() + vx.at(i)) < H && (Y.front() + vy.at(i)) < W
          && A.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) == '.' 
          && M.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) == 0) {
            X.push(X.front() + vx.at(i));
            Y.push(Y.front() + vy.at(i));
            A.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) = '#';
            M.at(X.front() + vx.at(i)).at(Y.front() + vy.at(i)) 
              = M.at(X.front()).at(Y.front()) + 1;
      }
    }
    X.pop();
    Y.pop();
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, M.at(i).at(j));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 16468
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

using namespace std;
int n,k;
long double tk;
long double a[2000005];
long double num=0;
int main()
{
	cin>>n>>k;
	a[0]=0;
	rep2(i,1,n+1)
	{
		cin>>tk;
		a[i]=a[i-1]+tk;
		if(i>=k&&(a[i]-a[i-k]+k)/2.0>num) num=(a[i]-a[i-k]+k)/2.0;
	}
	printf("%.12Lf\n",num);
	return 0;}


Measured memory_bytes: 4352
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import GHC.Magic (oneShot)


main :: IO ()
main = do
  n <- read <$> getLine
  ls <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  print $ binSearch 0 n ls

{-# INLINE binSearch #-}
binSearch :: Int -> Int -> VU.Vector Int -> Int
binSearch ng ok !ls | ok - ng <= 1 = ok
binSearch ng ok !ls =
  if isPossibleWith mid ls then
    binSearch ng mid ls
  else
    binSearch mid ok ls
  where
    mid = (ng + ok) `shiftR` 1

{-# INLINE isPossibleWith #-}
isPossibleWith :: Int -> VU.Vector Int -> Bool
isPossibleWith 1 !ls = VU.and $ VU.zipWith (<) ls (VU.tail ls)
isPossibleWith numChars !ls
  = VU.foldr loop (\_ _ -> True) ls 0 Nil
  where
    {-# INLINE loop #-}
    loop = \ !reqLen cont -> oneShot $ \ !wordLen !chars ->
      if reqLen > wordLen
      then cont reqLen chars
      else countUpCps (cont reqLen) numChars (cutOff chars reqLen) (reqLen-1) 

data List = Nil | Snoc !List {-# UNPACK #-} !Int {-# UNPACK #-} !Int
 deriving Show

{-# INLINE countUpCps #-}
countUpCps :: (List -> Bool) -> Int -> List -> Int -> Bool
countUpCps cont !numChars = go
  where
    go !xs !ind | ind < 0 = False
    go xs@(Snoc xs' i e) ind
      | i == ind = if | e < numChars - 1 -> cont $! Snoc xs' i (e+1)
                      | otherwise        -> go xs' (ind-1)
    go xs ind = cont $! Snoc xs ind 1

{-# INLINE cutOff #-}
cutOff :: List -> Int -> List
cutOff !xs !till = go xs
  where
    go (Snoc xs i e) | i >= till = go xs
    go xs = xs

Measured memory_bytes: 7036
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// 
int A[3];
int ans = 0;

int main(){
    cin >> A[0] >> A[1] >> A[2];

    sort(A, A+3, greater<int>());
    int ans = A[0]*10 + A[1] + A[2];

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




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

int w,h;

int dd[5]={0,1,0,-1,0};

void dfs_aux(int sx, int sy, int map[WMAX][HMAX],int *min,int count){
  rep(r,4){
    int nx=sx,ny=sy;
    if(map[nx+dd[r]][ny+dd[r+1]]==1)
      continue;
    while(0<=nx+dd[r] && nx+dd[r]<w && 0<=ny+dd[r+1] && ny+dd[r+1]<h){
      nx+=dd[r];
      ny+=dd[r+1];
      if(map[nx][ny]==3)
	if(*min > count){
	  *min = count;
	  break;
	}
      if(map[nx][ny]==1){
	break;
      }
    }
    
    if(map[nx][ny]==1 && count <10){
      map[nx][ny]=0;
      nx-=dd[r];ny-=dd[r+1];
      dfs_aux(nx,ny,map,min,count+1);
      nx+=dd[r];ny+=dd[r+1];
      map[nx][ny]=1;
    }
  }
}  

int dfs(int sx, int sy, int map[WMAX][HMAX]){
  int min=11;
  dfs_aux(sx,sy,map,&min,1);
  if(min>10)
    return -1;
  return min;
}

int main(){
  for(;;){
    scanf("%d %d",&w,&h);
    if(!(w+h)) break;
    int map[WMAX][HMAX],sx,sy;
    rep(i,h){
      rep(j,w){
	scanf("%d",&map[j][i]);
	if(map[j][i]==2){
	  sx=j;
	  sy=i;
	}
      }
    }
    printf("%d\n",dfs(sx,sy,map));
  }
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        double x = scanner.nextDouble();
        double h = scanner.nextDouble();
        if (x == 0 && h == 0) {
          return;
        }
        SquarePyramid squarePyramid = new SquarePyramidImpl(x, h);
        System.out.println(squarePyramid.calcSurfaceArea());
      }
    }
  }
}

interface SquarePyramid {
  double calcSurfaceArea();
}

final class SquarePyramidImpl implements SquarePyramid {

  private final double x;
  private final double h;

  SquarePyramidImpl(double x, double h) {
    this.x = x;
    this.h = h;
  }

  private double getTriangleHeight() {
    return Math.sqrt(Math.pow(x / 2, 2) + Math.pow(h, 2));
  }

  @Override
  public double calcSurfaceArea() {
    return Math.pow(x, 2) + getTriangleHeight() * x * 2.0;
  }
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void print(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	auto lcm = [](const ll a, const ll b) -> ll { return a / __gcd(a, b) * b; };
	int n; cin >> n;
	vector<ll> v(n);
	rep(i, 0, n) read(v[i]);
	rep(i, 1, n) v[0] = lcm(v[0], v[i]);
	print(v[0]);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

void sit(vector<int>&seats, int who) {
	if (who == 1) {
		for (int i = 0; i < seats.size(); ++i) {
			if (!seats[i]) {
				seats[i] = who;
				return;
			}
		}
	}
	else if (who == 2) {
		for (int i = seats.size()-1; i >= 0; --i) {
			if (!seats[i]) {
				bool ok = true;
				for (int k = i+1; k >= i-1; k -= 2) {
					if (k >= 0 && k < seats.size()) {
						if (seats[k] == 1)ok = false;
					}
				}
				if (ok) {
					seats[i] = who;
					return;
				}
			}
		}
		for (int i = 0; i < seats.size(); ++i) {
			if (!seats[i]) {
				seats[i] = who;
				return;
			}
		}
	}
	else if (who == 3) {
		for (int i = 0; i < seats.size(); ++i) {
			if (seats[i]) {
				if (i!=seats.size()-1&&!seats[i+1]) {
					seats[i+1] = who;
					return;
				}
				else if (i != 0 && !seats[i - 1]) {
					seats[i - 1] = who;
					return;
				}
			}
		}
		seats[seats.size() / 2] = who;
		return;
	}
	else {
		vector<int>diss(seats.size(), 1000);
		for (int i = 0; i < seats.size(); ++i) {
			if (seats[i]) {
				diss[i] = 0;
				for (int j = i - 1; j >= 0; --j) {
					diss[j] = min(diss[j], i-j);
				}
				for (int j = i + 1; j < seats.size(); ++j) {
					diss[j] = min(diss[j], j - i);
				}
			}
		}
		int maxdis = -1;
		int ans = -1;
		for (int i = 0; i < seats.size(); ++i) {
			if (maxdis < diss[i]) {
				maxdis = diss[i];
				ans = i;
			}
		}
		seats[ans] = who;
		return;
	}
	assert(false);
}

int main() {
	while (1) {
		int a, b; cin >> a >> b;
		if (!a&&!b)break;
		else {
			if (a % 2 && b % 2) {
				cout << "no" << endl;
			}
			else {
				cout << "yes" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,K;
    cin >> N >> K;
    vector<int> sticklength(N);
    for (int i = 0; i < N; ++i) {
        cin >> sticklength.at(i);
    }
    for (int i = 0; i < N; ++i) {
        sort(sticklength.begin(), sticklength.end());
        reverse(sticklength.begin(),sticklength.end());
    }
    int length = 0;
    for (int i = 0; i < K; ++i) {
        length += sticklength.at(i);
    }
    cout << length;
    return 0;
}

Measured memory_bytes: 256