akhauriyash/Code-Regression huggingface dataset:
data Vec2 = Vec2 Double Double deriving Eq

(/--) :: Vec2 -> Vec2 -> Vec2
(/--) (Vec2 a1 a2) (Vec2 b1 b2) = (Vec2 (a1 - b1) (a2 - b2))

-- Cross Product
(/**) :: Vec2 -> Vec2 -> Double
(/**) (Vec2 a1 a2) (Vec2 b1 b2) = a1 * b2 - a2 * b1

inTriangle :: [Double] -> String
inTriangle [x1, y1, x2, y2, x3, y3, xp, yp]
    | pa > 0 && pb > 0 && pc > 0 = "YES"
    | pa < 0 && pb < 0 && pc < 0 = "YES"
    | otherwise                  = "NO"
    where
        oa = Vec2 x1 y1
        ob = Vec2 x2 y2
        oc = Vec2 x3 y3
        op = Vec2 xp yp
        pa = (oa /-- oc) /** (op /-- oa)
        pb = (ob /-- oa) /** (op /-- ob)
        pc = (oc /-- ob) /** (op /-- oc)

main :: IO ()
main = putStr . unlines . map inTriangle . map (map read) . map words . lines =<< getContents

Measured memory_bytes: 4496
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int x,h;
  while(cin >> x >> h){
    if(x==0&&h==0) break;
    double res = pow((double)x,2);
    double height = sqrt( pow((double)x/2,2) + pow((double)h,2));
    res += x * height / 2 * 4;
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
import copy
h,w = map(int,input().split())
a = [input() for  i in range(h)]
index = 1
ans = copy.copy(a)
for i in range(h):
    bool = True
    for j in range(w):
        if a[i][j] == '#':
            bool = False
    if bool:
        index -= 1
        del ans[index + i]
ans_1 = copy.copy(ans)
key = 1
for i in range(w):
    bool = True
    for j in range(h - (1 - index)):
        if ans[j][i] == '#':
            bool = False
    if bool:
        key -= 1
        for k in range(h - (1 - index)):
            ans_1[k] = ans_1[k][:(i + key)] + ans_1[k][(i + key + 1):]
for i in range(len(ans_1)):
    print(ans_1[i])

Measured memory_bytes: 9292
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll a, b;
    cin >> a >> b;
    if(a<=0&&b>=0)cout << "Zero";
    else if(a>0)cout << "Positive";
    else {
        if((b-a)&1)cout << "Positive";
        else cout << "Negative";
    }
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a,b;
    scanf("%d %d", &a, &b);
    if ((a + b) % 2 == 1)
    {
        printf("%d", (a + b) / 2 + 1);
    }
    
    else 
    {
        printf("%d", (a + b) / 2);
    }
    
}

Measured memory_bytes: 1704
#include <iostream>
#include <vector>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

struct Node {
    int id;
    int parent;
    int depth;
    int height;
    int left;
    int right;
};

std::vector<Node> nodes;

void set_depths(int id, int depth) {
    if (id != -1) {
        Node& node = nodes[id];
        node.depth = depth;
        set_depths(node.left, depth + 1);
        set_depths(node.right, depth + 1);
    }
}

int set_heights(int id) {
    if (id != -1) {
        Node& node = nodes[id];
        int h_left = 0, h_right = 0;
        if (node.left != -1) {
            h_left = set_heights(node.left) + 1;
        }
        if (node.right != -1) {
            h_right = set_heights(node.right) + 1;
        }
        node.height = std::max(h_left, h_right);
        return node.height;
    }
}

int main() {
    int n;
    std::cin >> n;
    nodes.assign(n, {-1, -1, -1, -1, -1, -1});

    for (int i = 0; i < n; i ++) {
        int id, left, right;
        std::cin >> id >> left >> right;
        nodes[id].id = id;
        nodes[id].left = left;
        nodes[id].right = right;
        if (left != -1) nodes[left].parent = id;
        if (right != -1) nodes[right].parent = id;
    }

    Node root = *std::find_if(nodes.begin(), nodes.end(), [](Node node){return node.parent == -1;});

    set_depths(root.id, 0);
    set_heights(root.id);

    for (Node& node : nodes) {
        std::cout << "node " << node.id;
        std::cout << ": parent = " << node.parent;
        if (node.parent != -1) {
            Node parent = nodes[node.parent];
            std::cout << ", sibling = " << ((parent.left != node.id) ? parent.left : parent.right);
        } else {
            std::cout << ", sibling = " << -1;
        }
        std::cout << ", degree = " << (node.left != -1) + (node.right != -1);
        std::cout << ", depth = " << node.depth;
        std::cout << ", height = " << node.height;
        if (node.parent == -1) {
            std::cout << ", root";
        } else if (node.left == -1 && node.right == -1) {
            std::cout << ", leaf";
        } else {
            std::cout << ", internal node";
        }
        std::cout << std::endl;
    }
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
int i=0;
int ansx[10002];
int ansy[10002];
while(cin>>x>>y,x || y)
{
  ansx[i]=x;
  ansy[i]=y;
  i++;
}
for(int k=0;k<i;k++)
{
  if(ansx[k]<ansy[k])
  {
    cout<<ansx[k]<<" "<<ansy[k]<<endl;
  }else{
    cout<<ansy[k]<<" "<<ansx[k]<<endl;
  }
}
return 0;
}



Measured memory_bytes: 3028
#include<iostream>
using namespace std;
typedef long long ll;
#define MOD 1000000007

ll mul(ll n){
    ll p;
    p = 1;
    for(int i = 1;i < n+1;i++){
        p = p*i%MOD;
    }
    return p;
}

ll modinv(long long a) {
    long long b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD; 
    if (u < 0) u += MOD;
    return u;
}

int main(){
    ll x,y;
    cin >> x >> y;
    if((2*x-y)%3 == 0 && (2*y-x)%3 == 0 && 2*x-y >=0 && 2*y-x>=0){
        ll n = (2*x-y)/3;
        ll m = (2*y-x)/3;
        cout << mul(n+m)%MOD*modinv(mul(n))%MOD*modinv(mul(m))%MOD << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<limits>
#include<iomanip>
using namespace std;
 
int main(void) {
  int n, m, i;
  double tmp, ans=0;
  cin >> n >> m;
  double a[n], b[n+1];
  b[0] = 0.0;
  for(i=0;i<n;i++) { 
    cin >> tmp;
    a[i] = (0.5 * tmp*(tmp+1)) /tmp;
  }
  for(i=1; i < n+1; i++) b[i] = a[i - 1] + b[i - 1];
  for(i=m;i<n+1;i++) ans = max(ans, b[i] - b[i - m]);
 
  cout << std::setprecision (std::numeric_limits<double>::digits10 + 1) << ans << endl;
}

Measured memory_bytes: 3328
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
# include <unordered_map>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

int main()
{
	
	int x, y;
	while (cin >> x >> y&&x&&y)
	{
		x++; y++;
		int n; cin >> n;
		vector<int> m[15][15];
		for (int i = 0; i < n; i++)
		{
			int X, Y;
			cin >> X >> Y; X++; Y++;
			int DX[9] = { -1,0,1,-1,0,1,-1,0,1 },
				DY[9] = { 1,1,1,0,0,0,-1,-1,-1 };
			for (int j = 0; j < 9; j++)
			{
				m[X + DX[j]][Y + DY[j]].push_back(i);
			}
		}

		int dx[] = { -1,0,1,2,2,2,1,0,-1,-2,-2,-2 },
			dy[] = { 2,2,2,1,0,-1,-2,-2,-2,-1,0,1 };
		vector< pair<int,int> > a;
		a.push_back(pair<int, int>(x, y));
		for (int i = 0; i < n; i++)
		{
			vector< pair<int, int> > b;
			for (int j = 0; j < a.size(); j++)
			{
				for (int k = 0; k < 12; k++)
				{
					pair<int, int> next = a[j];
					next.first += dx[k];
					next.second += dy[k];
					if (next.first < 0 || next.second < 0)continue;
					if (count(all(m[next.first][next.second]),i))
					{
						b.push_back(next);
					}
				}
			}
			a = b;
		}
		if (a.size())cout << "OK" << endl;
		else cout << "NA" << endl;
	}



}

Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<stdio.h>



using namespace std;


int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a - b * 2 <= 0)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << a - b * 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = deque(list(input()))
B = deque(list(input()))
C = deque(list(input()))

# while len(A) == 0 or len(B) == 0 or len(C) == 0:
p = A.popleft()
while 1:
    if p == "a":
        if len(A) == 0:
            print("A")
            exit()
        else:
            p = A.popleft()
    if p == "b":
        if len(B) == 0:
            print("B")
            exit()
        else:
            p = B.popleft()

    if p == "c":
        if len(C) == 0:
            print("C")
            exit()
        else:
            p = C.popleft()
    
    



Measured memory_bytes: 10480
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<int> v;
int num[10];
int main()
{
	int zyo=1,out=0,n;
	cin>>n;
	REP(i,1,10){
		zyo*=3;
		rep(j,zyo){
			memset(num,0,sizeof(num));
			int now=0,a=j;
			rep(j,i){
				int b=a%3;a/=3;
				num[b]++;now*=10;now+=b*2+3;
			}
			if(num[0]*num[1]*num[2]>0 && now<=n) out++;
		}
	}
	cout<<out<<endl;
}


Measured memory_bytes: 888
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long L,R;
long long ans,md=1000000007;
long long dp[70][2][2][2][2];
long long dfs(int ws,bool ltb,bool rtb,bool lrtb,bool los){
	if(ws==-1)	return 1;
	if(dp[ws][ltb][rtb][lrtb][los])	return dp[ws][ltb][rtb][lrtb][los];
	int l=(L>>ws)&1,r=(R>>ws)&1;
	long long ret=0;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			if(!((j&i)!=j || (!ltb && j<l) || (!rtb && i>r) || (!lrtb && i<j) || (!los && i && i!=j)))
				(ret+=dfs(ws-1,ltb | (j>l),rtb | (i<r),lrtb | (j<i),los | j))%=md;
	dp[ws][ltb][rtb][lrtb][los]=ret;
	return ret;
}
int main(){
	scanf("%lld%lld",&L,&R);
	printf("%lld\n",dfs(62,false,false,false,false));
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
    int N, D;
    double **X;
    double r;
    int i,j,k; 
    scanf("%d %d", &N, &D);
    X = malloc(sizeof(double *)*N);
    for(i=0;i<N;i++)
        X[i] = malloc(sizeof(double)*D);
    for(i=0; i < N; i++){
        for(j=0; j < D; j++){
            scanf("%lf", &r);
            X[i][j] = r;
        }
    } 
    int count=0;
    double dist;
    for(i=0; i<N; i++){
        for(k=0; k<N; k++){
            if(i==k)continue;
            dist = 0.0;
            for(j=0; j<D; j++){
                dist += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
            }
            dist = sqrt(dist);
            double ch = dist - (double)((int)dist);
            if(ch==0.0)
                count+=1;
        }
    }
    printf("%d\n", count/2);
    free(X);
    return 0;
}

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

using namespace std;

const int maxn = 3010;
const int mod = 1000000007;

long long dp[maxn][maxn];
long long sums[maxn][maxn];

long long absm(long long x){
	return (x % mod + mod)% mod;
}

int main(){
	int n;
	cin >> n;
	string a;
	cin >> a;
	for (int i = 0; i < n; i++){
		dp[0][i] = 1;
		sums[0][i] = i + 1;
	}
	
	for (int i = 1; i < n; i++){
		for (int j = 0; j <= i; j++){
			if (a[i-1] == '<'){
				if (j > 0){
					dp[i][j] = sums[i-1][j-1];
				}
				else {
					dp[i][j] = 0;
				}
			}
			else {
				if (j > 0){
					dp[i][j] = absm(sums[i-1][i-1] - sums[i-1][j-1]);
				}
				else {
					dp[i][j] = sums[i-1][i-1];
				}
			}
			if (j > 0){
				sums[i][j] = (dp[i][j] + sums[i][j-1])% mod;
			}
			else {
				sums[i][j] = dp[i][j];
			}
		}
	}
	cout << sums[n-1][n-1] << endl;
	return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int> > to(N);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
    }

    int f = to[0].size();
    queue<int> q;
    for (int i = 0; i < f; i++){
        q.push(to[0][i]);
    }

    bool ok = false;
    while(!q.empty()){
        int x = q.front(); q.pop();
        int y = to[x].size();
        for (int i = 0; i < y; i++){
            if(to[x][i] == N-1){
                ok = true;
            }
        }
    }

    if(ok){
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 11960
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanFloat64() float64 {
	sc.Scan()
	i, _ := strconv.ParseFloat(sc.Text(), 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a, b := scanInt64(), scanFloat64()

	fmt.Println((a * int64(math.Round(b*100))) / 100)
}


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

int main() {
  
  	int N;
	cin >> N;
  
  	int count=0;
  	if(N/100==1){
    	count++;
    }
  	if(N/10==1 || N/10==11){
    	count++;
    }
  	if(N%2==1){
    	count++;
    }
  
  	cout << count << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool ap = true;
    rep(i, n)
    {
        if (a[i] % 2 == 0)
        {
            if (!(a[i] % 3 == 0 || a[i] % 5 == 0))
                ap = false;
        }
    }
    if (ap)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#define pi 3.14159265358979323846
using namespace std;

int main() {
    double r = 0;
    double S, C;
    cin >> r;

    S = pi * r * r;
    C = pi * r * 2;

    printf("%.5lf %.5lf\n", S, C);
}

Measured memory_bytes: 3196
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0176

"""
import sys
from sys import stdin
from collections import namedtuple
from math import sqrt
input = stdin.readline


color = namedtuple('color', ['name', 'r', 'g', 'b'])
def main(args):
    references = [color('black',   0x00, 0x00, 0x00), color('blue', 0x00, 0x00, 0xff), color('lime',    0x00, 0xff, 0x00),
                  color('aqua',    0x00, 0xff, 0xff), color('red',  0xff, 0x00, 0x00), color('fuchsia', 0xff, 0x00, 0xff),
                  color('yellow', 0xff, 0xff, 0x00), color('white', 0xff, 0xff, 0xff)]

    while True:
        data = input().strip()
        if data[0] == '0':
            break
        my_r = int(data[1:3], 16)
        my_g = int(data[3:5], 16)
        my_b = int(data[5:7], 16)

        distances = []
        for c in references:
            d = sqrt((c.r - my_r)**2 + (c.g - my_g)**2 + (c.b - my_b)**2)
            distances.append(d)

        closest_distance = min(distances)
        closest_color = distances.index(closest_distance)
        print(references[closest_color].name)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7972
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
    }

    ll ans = 0;
    ll count = 0;
    rep(i, n){
        if(i == 0){
            continue;
        }
        if(vec[i] <= vec[i-1]){
            count++;
        }else{
            ans = max(ans, count);
            count = 0;
        }

        //cout << i << " " << count << endl;
    }
    ans = max(ans, count);

    cout << ans << endl;


}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>L(n);
rep(i,n)cin>>L[i];
sort(L.begin(),L.end());
int ans=0;
rep(i,n){
    int a=L[i];
    reps(j,n,i+1){
        int b=L[j];
        auto it = lower_bound(L.begin(),L.end(),a+b);
        int cnt = distance(L.begin()+j,it)-1;
        ans+=cnt;
    }
}
cout<<ans<<endl;
return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N, M, K;

signed main() {
	cin >> N >> M >> K;

	for (int x = 0; x <= N; x++) {
		for (int y = 0; y <= M; y++) {
			int t = x*M + y*N - 2*x*y;
			if (t == K) {
				puts("Yes");
				return 0;
			}
		}
	}

	puts("No");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll, ll> P;

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

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

#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
	ll n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	ll low = 0;
	rep(i, n) {
		chmax(low, uf.size(i));
	}
	cout << low << endl;
	return 0;
}


Measured memory_bytes: 6316
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

bool is_palindrome(string s,int begin,int end)
{
    string sub=s.substr(begin-1,abs(end-begin+1));
    string buf=sub;
    reverse(sub.begin(),sub.end());
    if(buf==sub)return true;
    return false;
}

int main()
{
    string s;
    cin>>s;
    bool flag=false;
    int end=(s.size()-1)/2;
    int begin=(s.size()+3)/2;
    if(is_palindrome(s,1,s.size()) && is_palindrome(s,1,end) && is_palindrome(s,begin,s.size()))flag=true;
    if(flag)cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))
h=sorted(h)
ans=10**10
for i in range(n-k+1):
    ans=min(ans,h[k-1+i]-h[i])
print(ans)
    
    
            
            
        
    
        
        
        
          


Measured memory_bytes: 14144
import org.w3c.dom.ls.LSOutput;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String T = scanner.next();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        String U = scanner.next();
        if(U.equals(S)) {
            A--;
        } else {
            B--;
        }
        System.out.println(A + " " + B);
    }
}


Measured memory_bytes: 22996
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
 
int main() {
  int N;
  int a[100];
  i_i W, H;
  
  W.first = 0;
  H.first = 0;
  cin >> W.second >> H.second >> N;
 
  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
 
    switch (a) {
      case 1:
        if (W.first < x)
          W.first = x;
        break;
      case 2:
        if (W.second > x)
          W.second = x;
        break;
      case 3:
        if (H.first < y)
          H.first = y;
        break;
      case 4:
        if (H.second > y)
          H.second = y;
        break;
      default:
        break;
    }
  }
 
  if ((W.second - W.first) > 0 && (H.second - H.first) > 0)
    printf("%d", (W.second - W.first) * (H.second - H.first));
  else printf("0");
  
}

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

signed main() {
  int N;
  cin >> N;
  
  int ans = 0;
  for( int i = 1; i <= sqrt(N); i++ ){
    if( i*i > ans && i*i <= N ){
      ans = i*i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
string s,t;
void Solve() {
    read(N);
    cin >> s >> t;
    for(int i = N ; i >= 1 ; --i) {
        if(s.substr(N - i,i) == t.substr(0,i)) {
            out(2 * N - i);enter;return;
        }
    }
    out(2 * N);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
typedef long long ll;
int main() {
	char s[200000];
	scanf("%s", s);
	int len = strlen(s);
	ll ans = 0;
	int w = 0, b = 0;
	for (int i = 0; i < len; i++) {
		if (s[i] == 'W') {
			ans += b;
		} else {
			b++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
function main(input){
  const lines = input.split('\n');
  const NW = lines.shift().split(' ').map(x => parseInt(x));
  const N = NW[0]
  const W = NW[1]
  const items = lines.map(line => line.split(' ').map(x => parseInt(x)) );

//console.log(N);
//console.log(W);
//console.log(items);

  dp = []
  for(var i=0;i<W+1;i++){
    dp.push( Array(N+1).fill(0) );
  }

  var result = 0;
  for(var i=0;i<N;i++){
    for(var w=0;w<=W;w++){

      var weight = items[i][0]
      var value = items[i][1]

      if(weight <= w){
        dp[w][i+1] = Math.max(dp[w][i], dp[w-weight][i] + value);
      }else{
        dp[w][i+1] = dp[w][i];
      }

      if(dp[w][i+1] > result){result = dp[w][i+1];}

    }
  }

//  const result = Math.max( ...dp.map(arr => Math.max(...arr)) )
  console.log(result);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 198688
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S;
  cin >> S;

  int prevR = -1;  // 前回のR位置
  int os = 0, es = 0; // 右に進んでいる軍勢
  vector<int> rs(S.size());
  F0R(i, S.size()) {
    if (S[i] == 'L') {
      // 進んできた軍勢を処理
      if (es || os) {
        rs[i] += (i & 1) ? os : es;
        rs[i - 1] += (i & 1) ? es : os;
        os = es = 0;
      }

      // 前回のRまで移動する
      int n = ((i - prevR) & 1) ? prevR + 1 : prevR;
      rs[n]++;
      //debug(n);
    }
    else {  // R
      if (i & 1) {
        os++;
      }
      else {
        es++;
      }
      prevR = i;
    }
  }

  F0R(i, S.size()) {
    cout << rs[i] << ' ';
  }
}
#endif


Measured memory_bytes: 4032
#!/usr/bin/env python3
"""
ソートテク関連の基本的な関数の詰め合わせ (命名は C++ STL algorithm による)


stable_partition(seq, func):
    O(n)
    空間計算量も O(n)
    述語が True を返す全ての要素が、述語が False を返す全ての要素よりも前になるようにシーケンスを並び替える (破壊、安定)


nth_element(seq, k, begin, end):
    O(n)
    E = seq[k] とする
    特定の要素 E よりも小さい全ての要素が E よりも前になり、 E 以上の全ての要素がEよりも後になるように seq[begin:end] を並び替える (破壊、不安定)
    heapq の nlargest とは異なるので注意


ith_order_statistic(seq, i, begin, end):
    O(n)
    nth_element を用いて (seq[begin:end] に存在することがわかっている) i 番目の順序統計量を求める (i = 0, 1, ..., n-1)


simple_quick_sort(seq, begin, end):
    O(nlgn)
    nth_element を用いて seq[begin:end] をソートする (破壊、不安定)


modified_merge_sort(seq, begin, end):
    O(nlgn)
    _modified_merge を用いて seq[begin:end] をソートする (非破壊、安定)
    転倒数とソート済み配列を返す


count_inversion(seq):
    O(nlgn)
    modified_merge_sort を用いて seq の転倒数を求める
    (転倒数: seq[i] > seq[j] (i < j) なる (i, j) の組み合わせの数のこと)
"""


import random
from typing import TypeVar, Callable, List, Tuple, Union
T = TypeVar('T')
Num = Union[int, float]




def _modified_merge(left: List[Num], right: List[Num]) -> Tuple[int, List[Num]]:
    """
    ソート済み配列 left, right を受け取り、全体のソート済み配列を生成する (O(n))
    マージの過程で転倒数をメモして返す

    Args:
        left (list): ソート済み
        right (list): ソート済み

    Returns:
        inv (int): 転倒数
        sorted_list (list): ソート済み
    
    Examples:
        >>> _modified_merge([1, 5, 7], [2, 3, 3])
        (6, [1, 2, 3, 3, 5, 7])
    """
    sorted_list = []
    i, j, inv = 0, 0, 0
    buf_1 = left[:] + [float('inf')]
    buf_2 = right[:] + [float('inf')]
    for _ in range(len(left) + len(right)):
        if buf_1[i] < buf_2[j]:
            sorted_list.append(buf_1[i])
            i += 1
        else:
            sorted_list.append(buf_2[j])
            j += 1
        inv += 1
    return inv, sorted_list


def modified_merge_sort(L, begin, end):
    """
    L[begin:end] を 非破壊的かつ安定にマージソートする (O(nlgn))
    マージソートの過程で転倒数をメモして返す

    Args:
        L (list)
        begin, end (int)
    
    Returns:
        inv (int): 転倒数
        sorted_list (list): ソート済み
    
    Examples:
        >>> modified_merge_sort([3, 5, 2, 1, 0], 0, 5)
        (9, [0, 1, 2, 3, 5])
    """
    if end - begin == 1:
        return 0, [L[begin]]
    mid = (begin + end) // 2
    left_inv_cnt, left = modified_merge_sort(L, begin, mid)
    right_inv_cnt, right = modified_merge_sort(L, mid, end)
    merge_inv_cnt, sorted_list = _modified_merge(left, right)
    return left_inv_cnt + right_inv_cnt + merge_inv_cnt, sorted_list



# verified @AOJ ALDS1_5_D
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D&lang=ja
def count_inversion(L):
    """
    modified_merge_sort() を用いて L の要素の転倒数を求める (O(nlgn))

    Examples:
        >>> count_inversion([1, 9, 2, 7, 5, 6, 4, 8, 3, 0])
        26
    """
    cnt, _ = modified_merge_sort(L, 0, len(L))
    return cnt



if __name__ == "__main__":
    n = int(input())
    L = list(map(int, input().split()))
    num, seq = modified_merge_sort(L, 0, n)
    print(*seq, sep=' ')
    print(num)    


Measured memory_bytes: 65224
#include<stdio.h>
int main(void)
{
	int a[5],i,j,n;
	//int k;
	for(i=0;i<5;i++){
		scanf("%d",&a[i]);
	}
	//for(i=0;i<5;i++)	printf("%d ",a[i]);
	//printf("\n");
	
	for(i=0;i<4;i++){
		for(j=i+1;j<5;j++){
			//printf("i=%d j=%d\n",i,j);
 			//printf("a[i]=%d a[j]=%d\n",a[i],a[j]);
			if(a[i]<a[j]){
				n=a[i];
				a[i]=a[j];
				a[j]=n;
			}
			/*for(k=0;k<5;k++)	printf("%d ",a[k]);
			printf("\n\n");*/
		}
	}
	//for(i=0;i<5;i++){
		//printf("%d\n",a[i]);}
	printf("%d",a[0]);
	for(i=1;i<5;i++){
		printf(" %d",a[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2112
// AOJ ITP1_11_B Dice II
// 2018.4.29 bal4u
 
#include <stdio.h>
 
int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];
 
int main()
{
    int q, i, t, f;
 
    for (i = 1; i <= 6; i++) scanf("%d", assign+i);
    scanf("%d", &q);
    while (q--) {
        scanf("%d%d", &t, &f);
        for (i = 1; i <= 6; i++) {
            if (assign[i] == t) t = i;
            if (assign[i] == f) f = i;
        }
        printf("%d\n", assign[face[t][f][3]]);
    }
    return 0;
}


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

using namespace std;
typedef  long long ll;
int main() {
  ll ans = 0;
  const ll MOD = 1000000000 + 7;
  int N, M;
  cin >> N >> M;
  if(abs(N-M) <= 1) {
      ans = 1;
      if(M<N) swap(M,N);
      if(M==N) ans = 2;
      while(M > 1) {
        ans *= M;
        ans %= MOD;
        ans *= N;
        ans %= MOD;
        M--; N--;
      }
  }

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


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

map<ll, int>  prime_factorization_map(ll x) {
  map<ll, int> res;
  for(ll i = 2; i*i <= x; ++i) {
    while(x % i == 0) {
      if(res.find(i) == res.end()) res[i] = 0;
      ++res[i];
      x /= i;
    }
  }
  if(x != 1) res[x] = 1;

  return res;
}

int main()
{
  ll n; cin >> n;
  if(n == 2) {
    cout << 1 << endl;
    return 0;
  }
  ll m = n-1;
  ll ans = 0;
  for(ll i = 1; i*i <= m; ++i) {
    if(m%i==0) {
      if(i == 1 || i*i ==m) ++ans;
      else ans += 2;
    }
  }

  for(ll i = 1; i*i <= n; ++i) {
    if(n%i==0) {
      ll a = i, b = n/i;

      if(a > 1) {
        m = n;
        while(m%a==0) m/=a;
        if(m%a==1) ++ans;
      }

      if(b > 1 && b!=a) {
        m = n;
        while(m%b==0) m/=b;
        if(m%b==1) ++ans;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i, m) {
        ll a;
        cin >> a;
        sum += a;
    }
    if ( sum > (ll)n ) {
        cout << -1 << endl;
    }
    else {
        cout << (ll)n - sum << endl;
    }
    return 0;
}


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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  
  int r,tot;
  r = N / X;
  if(N % X != 0) {
    r++;
  }
  tot = r * T;
  cout << tot << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <string>
#include <cstdio>


using namespace std;

bool judge(map<int, int> &mapBuff, int l){
  if(mapBuff[l] >1) return false;
  return true;
}

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> v;
  int min_A = INT_MAX;
  int max_A = 0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    v.push_back(a);
    min_A = min(v[i],min_A);
    max_A = max(v[i],max_A);
  }
  if(max_A < K){
    cout << "IMPOSSIBLE" << endl;
    return 0;
      }
  int min_tmp = min_A;
  while(1){
  map<int, int> m;
  for(int i=0; i<N; i++){
    if(v[i]%min_A > 0){
      if(judge(m, v[i]%min_A))
      m[v[i]%min_A] = 1;
    }
    else{
      if(judge(m, min_A)){
      m[min_A] = 1;
      }
    }
  }
  //  cout << "here" << endl;
  v.clear();
  min_tmp = min_A;
  map<int, int>::iterator ite;
  for(ite =m.begin(); ite!=m.end();ite++){
    if(ite->second == 1)
    v.push_back(ite->first);
  }
  for(auto itr = v.begin(); itr != v.end(); itr++) {
    min_A =min(min_A, ((int)*itr));
  }
  if(min_A == min_tmp) break;
  }

  if(K%min_tmp==0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

}


Measured memory_bytes: 1784
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int neigh[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

char a[1000][1000];
int d[1000][1000];

int main()
{
  int i,j,n,m,x,y,xx,yy,k,ans,dis;
  vector<pair<int,int> > q;
  scanf("%d%d%d",&m,&n,&k);
  for (i=0;i<m;i++)
    scanf("%s",a[i]);
  q.clear();
  memset(d,-1,sizeof(d));
  for (i=0;i<m;i++)
    for (j=0;j<n;j++)
      if (a[i][j]=='S')
      {
        q.push_back(make_pair(i,j));
        d[i][j]=0;
      }
  for (i=0;i<q.size();i++)
  {
    x=q[i].first;
    y=q[i].second;
    if (d[x][y]==k) continue;
    for (j=0;j<4;j++)
    {
      xx=x+neigh[j][0];
      yy=y+neigh[j][1];
      if ((xx>=0)&&(xx<m)&&(yy>=0)&&(yy<n)&&(a[xx][yy]=='.')&&(d[xx][yy]==-1))
      {
        q.push_back(make_pair(xx,yy));
        d[xx][yy]=d[x][y]+1;
      }
    }
  }
  ans=2000000000;
  for (i=0;i<m;i++)
    for (j=0;j<n;j++)
      if (d[i][j]!=-1)
      {
        dis=i;
        if (dis>0) dis=((dis-1)/k)+1;
        if (dis+1<ans) ans=dis+1;

        dis=j;
        if (dis>0) dis=((dis-1)/k)+1;
        if (dis+1<ans) ans=dis+1;

        dis=m-1-i;
        if (dis>0) dis=((dis-1)/k)+1;
        if (dis+1<ans) ans=dis+1;

        dis=n-1-j;
        if (dis>0) dis=((dis-1)/k)+1;
        if (dis+1<ans) ans=dis+1;
      }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 14572
using System;
using System.Linq;
using System.Collections.Generic;

class program
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int n = nk[0], k = nk[1];
        var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var roop = new List<List<int>>();
        roop.Add(new List<int>());
        var rmx = new List<List<long>>();
        rmx.Add(new List<long>());
        var rct = new List<int>();
        var rsm = new List<long>();
        var isr = new int[n];
        int ct = 0;
        for (int i = 0; i < n; i++)
        {
            if (isr[i] == 0)
            {
                var pre = i;
                long s = 0;
                var mx = long.MinValue;
                roop.Add(new List<int>());
                rmx.Add(new List<long>());
                ct++;
                rmx[ct - 1].Add(0);
                for (int j = 0; j <= n; j++)
                {
                    pre = p[pre] - 1;
                    if (isr[pre] != 0)
                    {
                        rmx[ct - 1].Add(mx);
                        rct.Add(j);
                        rsm.Add(s);
                        break;
                    }
                    else
                    {
                        s += c[pre];
                        roop[ct - 1].Add(c[pre]);
                        mx = c[pre] > mx ? c[pre] : mx;
                        isr[pre] = ct;
                    }
                }
            }
        }
        long ans = long.MinValue;
        for (int i = 0; i < ct; i++)
        {
            for (int j = 0; j < rct[i]; j++)
            {
                rmx[i].Add(rmx[i][1]);
            }
            for (int j = 0; j < rct[i]; j++)
            {
                if (roop[i][j] > 0)
                {
                    long sm = roop[i][j];
                    for (int sn = 1; sn < rct[i]; sn++)
                    {
                        sm += (sn + j) >= rct[i] ? roop[i][sn + j - rct[i]] : roop[i][sn + j];
                        rmx[i][sn + 1] = Math.Max(rmx[i][sn], rmx[i][sn + 1]);
                        rmx[i][sn + 1] = Math.Max(rmx[i][sn + 1], sm);
                    }
                }
            }
            rmx[i][rct[i]] = Math.Max(rmx[i][rct[i] - 1], rmx[i][rct[i]]);
            rmx[i][rct[i]] = Math.Max(rsm[i], rmx[i][rct[i]]);

            if (rct[i] > k)
            {
                ans = Math.Max(rmx[i][k], ans);
            }
            else
            {
                ans = Math.Max(rmx[i][rct[i]], ans);
                long kr = k / rct[i];
                ans = Math.Max(rmx[i][k % rct[i]] + kr * rsm[i], ans);
                ans = Math.Max(rmx[i][rct[i]] + (kr-1) * rsm[i], ans);
            }
        }
        Console.Write(ans);

    }
}


Measured memory_bytes: 29848
package main

import "fmt"

func main() {
	var a,b,c,d,e int
	fmt.Scan(&a,&b,&c,&d,&e)
	if a==0{
		fmt.Print(1)		
	}else if b == 0{
		fmt.Print(2)
	}else if c == 0{
		fmt.Print(3)
	}else if d == 0{
		fmt.Print(4)
	}else if e == 0{
		fmt.Print(5)
	}
}


Measured memory_bytes: 1816
#include<stdio.h>
int main()
{
    int i,n;
    long int h;
    scanf("%ld",&h);
    scanf("%d",&n);
    int a[n],s=0;
    for(i=0;i<n;i++)
    {
     scanf("%d",&a[i]);
     s=s+a[i];
    }
    if(h>s)
        printf("No");
    else
       printf("Yes");
    return 0;
}

Measured memory_bytes: 2076
fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut s: Vec<&str> = buf.split_whitespace().collect();

  let mut n: i32 = s[0].parse().unwrap();

  let mut lucas: Vec<i64> = Vec::new();
  lucas.push(2);
  lucas.push(1);

  for i in 2..n+1 {
    let u = i as usize;
    let mut new = lucas[u-2];
    new = new + lucas[u-1];
    lucas.push(new);
  }
  
  let n = n as usize;
  println!("{}",lucas[n]);
}


Measured memory_bytes: 4352
#include <cstdio>

/**
	I'm not sure whether this works or not.
*/

int N;
int cost[300][300];
bool mark[300][300];

int main(void)
{
	//freopen("input.txt", "r", stdin);
	scanf("%d", &N);
	for (int n = 0; n < N; ++n)
		for (int m = 0; m < N; ++m)
			scanf("%d", &(cost[n][m]));
	for (int n = 0; n < N; ++n)
		for (int m = n + 1; m < N; ++m)
		{
			mark[n][m] = true;
			for (int k = 0; k < N; ++k)
			{
				if (k == n || k == m)
					continue;
				if (cost[n][m] == cost[n][k] + cost[k][m])
					mark[n][m] = false;
				else if (cost[n][m] > cost[n][k] + cost[k][m])
				{
					printf("-1");
					return 0;
				}
			}
		}
	long long sum = 0;
	for (int n = 0; n < N; ++n)
		for (int m = n + 1; m < N; ++m)
			if (mark[n][m])
				sum += cost[n][m];
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i,n,m) for(int i = m;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define ll long long
#define INF (1e9)
#define PI (acos(-1))
int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };
using namespace std;
int k;
string s;
int a, b, c;
int main() {
	cin >> a >> b >> c >> k;
	int m = max(a, max(b, c));
	int mcopy = m;
	rep(i, k)mcopy *= 2;
	cout << a + b + c + mcopy - m << endl;
	return 0;
}


Measured memory_bytes: 256