akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    vector<long long> dp(n + 1);
    for (int i = 0; i <= n; i++) {
      if (i == 0) dp[i] = 1;
      else if (i == 1) dp[i] = 1;
      else if (i == 2) dp[i] = 2;
      else dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
    }
    cout << ((dp[n] + 9) / 10 + 364) / 365 << endl;
  }
}


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

typedef vector <int> vi;
typedef pair< int , int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{

	char t;
	cin >> t;
	if (t >= 'A' && t <= 'Z') cout << "A";
	else cout << "a";
	
	return 0;

}

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

int main(){
  long N;
  cin >> N;
  vector<long> v(N);
  for(long i=0;i<N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  cout << v.at(N/2)-v.at((N/2)-1) << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	}
}

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

int main() {
  int N,K,n;
  string s;
  cin >> N >> K >> s;
  if(s.at(K-1)=='A'){
    s.at(K-1)='a';
  }else if(s.at(K-1)=='B'){
    s.at(K-1)='b';
  }else{
    s.at(K-1)='c';
  }
    cout << s << endl;
}





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

int main() {
    int H, N;
    cin >> H >> N;

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

    for (int i = 0; i < N; i++) {
        H -= a[i];
        if (H <= 0) {
            break;
        }
    }

    if (H <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  int sum = 0, mini = 10000;
  for(int i = 0; i < n; i++){
    cin >> m[i];
    sum += m[i];
  }
  for(int i = 0; i < n; i++){
    if(m[i] < mini) mini = m[i];
  }
  int ans = n + (x - sum) / mini;
  
  cout << ans << endl;
  return 0;
}

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

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int p, q;
    cin >> p >> q;
    q /= gcd(p, q);
    for (int i = 2; i * i <= q; i++) {
        while (q % (i * i) == 0) q /= i;
    }
    cout << q << endl;
    return 0;
}



Measured memory_bytes: 3092
from itertools import accumulate

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

dp = [[0 for _ in range(N+1)] for _ in range(N)]
acc = [0] + list(accumulate(A))

for w in range(2, N+1):
    for l in range(N-w+1):
        r = l + w
        dp[l][r] = min([dp[l][m] + dp[m][r] for m in range(l+1, r)]) + acc[r] - acc[l]

print(dp[0][N])

Measured memory_bytes: 42844
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

struct Node{
	Node(){
		value = -1;
		left_child = -1;
		right_child = -1;
	}

	int value,left_child,right_child;
};

class Tree{

public:
	Tree(int M){
		table = new Node[M];
		size = M;
		index = 0;
	}

	bool add(int num){
		if(index == 0){
			table[index++].value = num;
			return true;
		}else{
			if(index == size)return false;

			int current = 0;

			while(true){
				if(num < table[current].value){
					if(table[current].left_child == -1){
						table[current].left_child = index;
						table[index++].value = num;
						return true;
					}else{
						current = table[current].left_child;
					}
				}else if(num > table[current].value){
					if(table[current].right_child == -1){
						table[current].right_child = index;
						table[index++].value = num;
						return true;
					}else{
						current = table[current].right_child;
					}

				}else{ //num == table[current].value
					return false;
				}
			}
			return false;	//must not reach here
		}
	}
private:
	Node* table;
	int size,index;
};

int main(){

	int N,M,tmp;
	scanf("%d %d",&N,&M);
	Tree tree(M);

	stack<int> S;

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		S.push(tmp);
	}

	printf("%d\n",S.top());
	tree.add(S.top());
	S.pop();

	int count = 1;

	while(count < M && S.empty() == false){
		if(tree.add(S.top())){
			printf("%d\n",S.top());
			count++;
		}
		S.pop();
	}

    return 0;
}

Measured memory_bytes: 4680
#include <cstdio>
#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

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

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
vector<int> G[10010];
vector<int> c(10010, 0);
int num[10010];
bool used[10010];
int now_c = 0;

int dfs(int s) {
    if (used[s]) {
        return 0;
    } else {
        used[s] = true;
    }

    num[s] = c[now_c];
    now_c++;

    for (int i = 0; i < G[s].size(); i++) {
        dfs(G[s][i]);
    }
    return 0;
}

int main() {
    int N; cin >> N;
    vector<string> s(N);

    map<string, lli>mp;
    rep(i,N){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        mp[s[i]]++;
    }

    lli ans=0LL;
    for(auto p : mp){
        ans+=p.second*(p.second-1)/2;
    }

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

Measured memory_bytes: 10624
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();
		String t = sc.next();
		char[] sch = s.toCharArray();
		char[] tch = t.toCharArray();
		int result = 0;
		for (int i = 0; i < 3; i++) {
			if (sch[i] == tch[i]) result++;
		}
		
		System.out.println(result);
		
	}
	
	private static int kaijo(int x) {
		int result = 1;
		for(int i = 1; i <= x; ++i) result *= 2;
		return result;
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21076
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

s = S()
t = S()

s = list(s)
s.sort()
t = list(t)
t.sort(reverse=True)

if s<t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 95168
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long s;
    scanf("%ld", &s);
    long x1 = 1000000000;
    long x2 = 1;
    long y2 = ceil(double(s) / x1);
    long y1 = y2 * x1 - s;
    printf("0 0 %ld %ld %ld %ld", x1, x2, y1, y2);
    return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
#include <cmath>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define abs(X) ((X) < 0 ? -1 * (X) : (X))

using namespace std;

typedef long long ll;

map<string, int> mp;

int main()
{
    ll x1, y1;
    ll x2, y2;

    ll x, y;

    cin >> x1 >> y1;
    cin >> x2 >> y2;

    x = x2 - x1;
    y = y2 - y1;

    //printf("%lld %lld %lld %lld\n", y2 + x, x2 - y, y1 + x, x1 - y);
    printf("%lld %lld %lld %lld\n", x2 - y, y2 + x, x1 - y, y1 + x);
        
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
constexpr ll mod = 1000000007;

struct union_find{
    vector<ll> parent;
    vector<ll> nums;
    union_find(ll n){
        parent.resize(n);
        nums.resize(n, 1LL);
        rep(i, 0, n) parent[i] = i;
    }

    ll root(ll x){
        if(parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx != ry){
            parent[rx] = ry;
            nums[ry] += nums[rx];
        }
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return true;
        return false;
    }

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    struct union_find t(n);
    rep(i, 0, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        t.unite(a, b);
    }
    set<ll> st;
    rep(i, 0, n) st.insert(t.root(i));
    cout << st.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 8340
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string s;
    string t="AB";
    int N;
    cin >> N;
    int res=0,a=0,b=0,c=0;
    for(int i=0;i<N;i++){
        cin >> s;
        if(s[0]!='B'&& s[s.length()-1]=='A') a++;
        if(s[0]=='B'&& s[s.length()-1]!='A') b++;
        if(s[0]=='B'&& s[s.length()-1]=='A') c++;
        
        for(string::iterator ptr = s.begin();ptr != s.end();){
            ptr = std::search(ptr,s.end(),t.begin(),t.end());
            if(ptr != s.end()){
                res++;
                ptr+=2;
            } 
        }
        
    }
    
    
    if(c==0){
        res+=std::min(a,b);
    }else{
        if(a+b==0){
            res+=c-1;
        }else{
            res+=c+std::min(a,b);
        }
    } 
   
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector< vector<int> > edg, dst;

void f(int x, int y, int z){
    if(y == -1) dst[z][x] = 0;
    else dst[z][x] = dst[z][y] + 1;

    for(int i=0;i<edg[x].size();i++){
        int v = edg[x][i];
        if(v != y){
            f(v, x, z);
        }
    }
}

int main(void){
    int n, fnc = 0;
    cin >> n;
    edg.assign(n, vector<int>());
    dst.assign(2, vector<int>(n, 0));

    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    f(0, -1, 0);
    f(n-1, -1, 1);
    for(int i=0;i<n;i++){
        if(dst[0][i] <= dst[1][i]) fnc++;
    }
    if(fnc*2 > n) puts("Fennec");
    else puts("Snuke");
}


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

int n,k;
int num(int x){
	int cnt=0;
	int ret=1;
 while(x<k){
	ret*=2;
	x*=2;
	cnt++;}
	return ret;
}
	double ans=0.0;
signed main(){
	cin >>n>>k;
	for(int i=1;i<=n;i++){
	ans+=1.0/num(i)/n;
}
	cout<<fixed<<setprecision(15)<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define bit(n) (1LL<<(n))

typedef pair<i64,i64> P;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;

void Main()
{
  string s,t;
  cin >> s >> t;
  vvi dp(sz(s),vi(sz(t),0));

  rrep(i,sz(s)-1,-1) rrep(ii,sz(t)-1,-1){
    if(s[i]==t[ii]){
      if(i+1<sz(s) && ii+1<sz(t))
        dp[i][ii] = dp[i+1][ii+1]+1;
      else
        dp[i][ii] = 1;
    }else{
      if(i+1<sz(s))
        maxs(dp[i][ii],dp[i+1][ii]);
      if(ii+1<sz(t))
        maxs(dp[i][ii],dp[i][ii+1]);
    }
  }

  i64 i=0,ii=0;
  string ans = "";
  while(i<sz(s) && ii<sz(t)){
    if(i+1<sz(s) && dp[i+1][ii]==dp[i][ii]){
      i++;
      continue;
    }else if(ii+1<sz(t) && dp[i][ii+1]==dp[i][ii]){
      ii++;
      continue;
    }else if(i+1<sz(s) && ii+1<sz(t)){
      ans = ans + s[i];
      i++;
      ii++;
      continue;
    }else if(i+1<sz(s) && dp[i+1][ii]==dp[i][ii]){
      i++;
      continue;
    }else if(ii+1<sz(t) && dp[i][ii+1]==dp[i][ii]){
      ii++;
      continue;
    }else if(s[i]==t[ii]){
      ans = ans + s[i];
      i++;
      ii++;
    }else break;
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 70784
n = int(input())
an = list(map(int, input().split()))

ans = 1

if(0 in an):
    print(0)
    
else:
    for i in an:
        
        ans *= i
        if(ans > 10 ** 18):
            print(-1)
            break
        
    else:
        print(ans)

Measured memory_bytes: 21644
#include <cstdio>

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

using namespace std;

// なぜか cctype のものを使うと 3 倍くらい遅くなる...
#define isupper(c) (c<='Z')
#define islower(c) (c> 'Z')
#define toupper(c) (c<='Z'?c:c-'a'+'A')

int sw[128];
enum{ON,OFF,UNKNOWN};

int m;
char clause[8000][3]; // clause[i][j] := ( i 個目の clause の j 個目の literal ( lowercase なら押す, uppercase なら押さない ) )

bool is_tautology(int i){
	rep(j,3){
		char c=clause[i][j];
		if(sw[toupper(c)]==ON  && islower(c)) return true;
		if(sw[toupper(c)]==OFF && isupper(c)) return true;
	}

	char c0=clause[i][0];
	char c1=clause[i][1];
	char c2=clause[i][2];
	if(toupper(c0)==toupper(c1) && c0!=c1) return true;
	if(toupper(c1)==toupper(c2) && c1!=c2) return true;
	if(toupper(c2)==toupper(c0) && c2!=c0) return true;

	return false;
}

bool dfs(int i){
	if(i==m) return true;

	if(is_tautology(i)) return dfs(i+1);

	rep(j,3){
		int n=0;
		char a[3],c;
		bool ok=true;
		rep(k,j){
			c=clause[i][k];
			if(sw[toupper(c)]==UNKNOWN){
				sw[toupper(c)]=(isupper(c)?ON:OFF);
				a[n++]=toupper(c);
			}
		}
		c=clause[i][j];
		if(sw[toupper(c)]==UNKNOWN){
			sw[toupper(c)]=(isupper(c)?OFF:ON);
			a[n++]=toupper(c);

			if(dfs(i+1)) return true;
		}

		rep(k,n) sw[a[k]]=UNKNOWN;
	}
	return false;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		char B[3][3010];
		rep(i,3) scanf("%s",B[i]);

		// set clauses
		m=0;
		rep(j,n) rep(S,8) {
			rep(i,3){
				int x=3*j+((S&1<<i)?1:2);
				clause[m][i]=B[i][x];
			}
			m++;
		}

		rep(c,128) sw[c]=UNKNOWN;
		bool res=dfs(0);
		if(!res) puts("-1");
		else{
			int m=0;
			rep(c,128) if(sw[c]==ON) m++;
			printf("%d",m);
			rep(c,128) if(sw[c]==ON) printf(" %c",c);
			puts("");
		}
	}

	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> a(H);
  REP(i, H) cin >> a[i];
  vector<vector<int>> S(H);
  int num = 0;  //いちごの番号
  REP(i, H) {
    bool first = true;
    char c;
    REP(j, W) {
      if (a[i][j] == '#') {
        num++;
        if (first) {
          REP(k, j) { S[i].push_back(num); }
        }
        S[i].push_back(num);
        first = false;
      } else {
        if (first == true) {
          continue;
        }
        S[i].push_back(num);
      }
    }
    if (first == true) {
    }
  }
  REP(i, H) {
    if (S[i].size() == 0) {
      if (i == 0) {
        int id = 0;
        for (int j = 1; j < H; j++) {
          id = j;
          if (S[id].size() != 0) break;
        }
        REP(j, W) { S[i].push_back(S[id][j]); }
      } else {
        REP(j, W) { S[i].push_back(S[i - 1][j]); }
      }
    }
    REP(j, W) cout << S[i][j]<<" ";
    cout << "\n";
  }
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

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

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
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; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 10000010;

// [1, n] の範囲の各値について、約数の個数を vector に格納して返す
// ret[i]: i の約数の個数
// O(n log log n)
vector<int> DivCount(int n) {
    vector<int> ret(n + 1, 1);
    int cnt = 0;
    for(int i = 2; i <= n; ++i) {
        for(int j = i; j <= n; j += i) {
            ret[j]++;
            cnt++;
        }
    }
    return ret;
}

int N;

signed main() {
    IOS;

    cin >> N;

    int ans = 0;
    auto div = DivCount(N);
    for(int i = 1; i <= N; ++i) {
        ans += i * div[i];
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 81344
import math
N=int(input())
nmax = math.ceil(math.sqrt(N))
i = 1
Bdigimin = 10
while ( i <= nmax):
	if N % i == 0:
		Bdigi = math.floor(math.log10(N/i))
		if Bdigimin > Bdigi:
			Bdigimin = Bdigi
	i += 1
print(int(Bdigimin+1))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int solve(){
  string s, t; cin >> s >> t;
  cout << t+s << endl;
}

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


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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  
  vector<set<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace(y);
    G[y].emplace(x);
  }
  using P = pair<Int, Int>;
  queue<P> q;
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    if(G[x].count(y)) q.emplace(x,y);
    G[x].emplace(y);
    G[y].emplace(x);
  }

  UnionFind uf(n);
  while(!q.empty()){
    Int x,y;
    tie(x,y)=q.front();q.pop();
    if(uf.same(x,y)) continue;
    x=uf.find(x);y=uf.find(y);
    
    if(G[x].size()<G[y].size()) swap(x,y);

    uf.unite(x,y);
    
    for(Int z:G[y]){
      if(G[x].count(z)) q.emplace(x,z);
      G[x].emplace(z);
      G[z].emplace(x);
    }
  }
  cout<<(uf.r[uf.find(0)]==n?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 55424
IDENTIFICATION DIVISION.
PROGRAM-ID. 161B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(6000).
01 N          PIC 9(3).
01 M          PIC 9(3).
01 KS         PIC 9(3). 
01 GK         PIC 9(5) COMP.
01 I          PIC 9(4) COMP.
01 J          PIC 9(4) COMP.
01 P1         PIC 9(4) COMP.
01 P2         PIC 9(4) COMP.
01 S          PIC 9(4).
01 T-TBL.
   03 A-T     PIC 9(3) OCCURS 1000.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N M.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 1000
    MOVE 0  TO A-T(I)
  END-PERFORM.
*>
  MOVE 0 TO GK.
  ACCEPT INP.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO J
    ADD 1 TO A-T(J)
    ADD J TO GK
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  MOVE 0 TO KS.
  COMPUTE S = GK / (4 * M) + 0.999.
  PERFORM VARYING I FROM S BY 1 UNTIL I > 1000
    ADD A-T(I) TO KS
  END-PERFORM.
*>
  IF (KS >= M)
    DISPLAY 'Yes'
  ELSE 
    DISPLAY 'No'
  END-IF.
  STOP RUN.


Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A*N, B) << endl;

    return 0;
}

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

typedef long long ll;
int n;
ll a[100005],x,Out;

int main(){
	cin>>n>>x;
	for(int i = 1; i <= n; i++) cin>>a[i];
	for(int i = 1; i <= n; i++){
		if(a[i] + a[i - 1] > x){
			Out += (1LL * a[i] + 1LL * a[i - 1] - 1LL*x);
			a[i] = x - a[i - 1];
		}
	}
	cout<<Out;
	return 0;
} 


Measured memory_bytes: 1024
while True:
    t, h, s = map(int, input().split())
    if t == -1:
        break
    rest = []
    rest.append(7200 - (3600*t + 60*h + s))
    rest.append(rest[0]*3)
    for r in rest:
        t = 0
        h = 0
        if r >= 3600:
            t = r//3600
            r -= 3600*t
        if r >= 60:
            h = r//60
            r -= 60*h
        print("{0:02d}:{1:02d}:{2:02d}".format(t, h, r))



Measured memory_bytes: 5608
#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(){
    ll n,x;
    cin >> n >> x;
    vector <ll> a(n);
    rep(i,n){
        cin >> a[i];
    }

    ll ans=0;

    rep(i,n){
        if(i==0){
            if(a[0]>x){
                ans+=a[0]-x;
                a[0]=x;
            }
        }
        else{
            if((a[i]+a[i-1])>x){
                ans+=a[i]+a[i-1]-x;
                a[i]-=(a[i]+a[i-1]-x);
            }
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 4024
#include <stdio.h>

int A[20];
int n;

int solve(int p, int t);
int sort(void *a, void *b);

int main(void) {
	int i, q, M;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	
	qsort(A, n, sizeof(A[0]), sort);
	
	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &M);
		if (solve(-1, M)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

int solve(int p, int t) {
	if (p == n) return t == 0;
	if (t == 0) return 1;
	if ((t >= A[p + 1]) && (solve(p + 1, t - A[p + 1]))) return 1;
	return solve(p + 1, t);
}

int sort(void *a, void *b) {
	return *(int*)b - *(int*)a;
}

Measured memory_bytes: 584
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll T;
ll N, A, B, C, D;
std::map<ll, ll> memo;

ll rec( ll n )
{
  if( memo.count( n ) )
    return memo[n];

  if( !n )
    return memo[n] = 0;

  if( n == 1 )
    return memo[n] = D;

  ll ret = INF;

  chmin( ret, rec( n/2 )+A+(n%2)*D );
  chmin( ret, rec( (n+1)/2 )+A+(2-(n%2))*D );
  chmin( ret, rec( n/3 )+B+(n%3)*D );
  chmin( ret, rec( (n+2)/3 )+B+(3-(n%3))*D );
  chmin( ret, rec( n/5 )+C+(n%5)*D );
  chmin( ret, rec( (n+4)/5 )+C+(5-(n%5))*D );
  
  if( n < ret/D )
    chmin( ret, n*D );

  return memo[n] = ret;
}

int main()
{
  std::cin >> T;

  rep( t, T )
  {
    memo.clear();

    std::cin >> N >> A >> B >> C >> D;

    std::cout << rec( N ) << std::endl;
  }

  return 0;
}

Measured memory_bytes: 4020
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

string ChangeFromIntToString(int, int);
int ChangeFromStringToInt(const string);

int main(){
  int i, j, x, l, max, min;
  vector<int> data;
  string s, maxs, mins;

  while(1){
    cin >> x >> l;
    if(x == 0 && l == 0) break;
    data.push_back(x);

    while(1){
      s = ChangeFromIntToString(x, l);
      maxs = s;
      mins = s;
      sort(maxs.begin(), maxs.end(), greater<int>());
      sort(mins.begin(), mins.end());
      max = ChangeFromStringToInt(maxs);
      min = ChangeFromStringToInt(mins);
      x = max - min;

      for(i=0, j=-1; i<data.size(); ++i){
	if(x == data[i]){
	  j = i;
	  break;
	}
      }
      if(j != -1) break;
      data.push_back(x);
    }

    cout << j << " " << data[j] << " " << data.size()-j << endl;
    data.clear();
  }
  return 0;
}

string ChangeFromIntToString(int x, int l){
  int i, d;
  char c;
  string s;
  for(i=1, d=1; i<l; ++i) d *= 10;
  for(i=d; i>=1; i/=10){
    c = x/i + 48;
    s.push_back(c);
    x %= i;
  }
  return s;
}

int ChangeFromStringToInt(const string s){
  int i, x, d;
  for(i=s.size()-1, x=0, d=1; i>=0; --i){
    x = x + (s[i] - 48) * d;
    d *= 10;
  }
  return x;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
vector<int> adj[MAXN];
int dp[MAXN],vis[MAXN];
int solve(int vertex){
if(vis[vertex])
  return dp[vertex];
  vis[vertex]=1;
  int maxl=0;
  for(int u:adj[vertex])
  {
    maxl=max(maxl,solve(u)+1);
  }
  dp[vertex]=maxl;
  return dp[vertex];
}
int main(){
int N,M;
  cin>>N>>M;
  for(int edges=0;edges<M;edges++){
  int a,b;
    cin>>a>>b;
    adj[a].push_back(b);
  }
  int maxans=0;
  for(int i=1;i<=N;i++){
  maxans=max(maxans,solve(i));
  }
  cout<<maxans;
  return 0;
}

Measured memory_bytes: 8576
#include<cstdio>
#define N 20002
int n,a[N],b[N];
signed main()
{
	scanf("%d",&n);int t;
	for(register int i(1);i<=n;i++)
		a[i]=i*N,b[i]=(n-i+1)*N;
	for(register int i(1);i<=n;i++)
		scanf("%d",&t),a[t]-=(n-i+1);
	for(register int i(1);i<=n;i++)
		printf("%d ",a[i]);
	puts("");
	for(register int i(1);i<=n;i++)
		printf("%d ",b[i]);
	return puts(""),0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
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"
long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}
int dp[14400000];
int N, M;
int to_hash(const vector<int>&nums) {
	int hash = 0;
	for (auto n : nums) {
		hash = 3 * hash + n;
	}
	return hash;
}
int getans(vector<int>&starts) {
	queue<pair<vector<int>, int>>que;
	que.emplace(starts, 0);
	while (!que.empty()) {
		auto v = que.front();
		que.pop();
		vector<int>nums = v.first;
		int now = v.second;
		const int hash = to_hash(nums);
		if (dp[hash] == false) {
			continue;
		}else {
			dp[hash] = false;
			if (now >= M+1) {
				return M + 1;
			}
			if (to_hash(nums) == 0||hash+1==powint(3,N)) {
				return now;
			}
			else {
				dp[hash] = false;
				vector<int>tops(3, -1);
				for (int i = 0; i < N; ++i) {
					tops[nums[i]] = i;
				}
				int ans = M;
				if (tops[0] < tops[1]) {
					nums[tops[1]] = 0;
					que.emplace(nums, now + 1);
					nums[tops[1]] = 1;
					
				}
				else {
					nums[tops[0]] = 1;
					que.emplace(nums, now + 1);
					nums[tops[0]] = 0;
				}
				if (tops[1] < tops[2]) {
					nums[tops[2]] = 1;
					que.emplace(nums, now + 1);
					nums[tops[2]] = 2;
				}
				else {
					nums[tops[1]] = 2;
					que.emplace(nums, now + 1);
					nums[tops[1]] = 1;
				}
			}
		}
	}
	return M+1;

}

int main() {
	while (1) {
		for (int i = 0; i < 14400000; ++i) {
			dp[i] = true;
		} cin >> N >> M;
		if (!N)break;
		vector<int>nows(N);
		for (int i = 0; i < 3; ++i) {
			int a; cin >> a;
			for (int j = 0; j < a; ++j) {
				int b; cin >> b; b--;
				nows[b] = i;
			}
		}
		int ans = getans(nows);
		if (ans == M+1)ans = -1;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 59264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
const long long INF = 1LL<<60;


int main(){	
	int N;
	cin >> N;
	int ans = 0;
	for(int i = 1; i <= N; i+=2){
		int cnt = 0;
		for(int j = 1; j <= N; j++){
			if(i % j == 0){
				cnt++;
				if(cnt == 8){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N,M; cin >> N >> M;
    vector<vector<int>> S(M);
    for (int i=0;i<M;i++){
        int k; cin >> k;
        S[i].resize(k);
        for (int j=0;j<k;j++) {
        cin >> S[i][j];
        --S[i][j];   
        }
    }
    vector<int> p(M);
    for (int i=0;i<M;i++) cin >> p[i];
    int res = 0;
    for (int bit=0;bit<(1<<N);bit++){
        bool can = true;
        for (int i=0;i<M;i++){
            int q = 0;
            for (int j=0;j<S[i].size();j++){
                if (bit & (1<<S[i][j])) q++;
            }
            if (q%2!=p[i]) can = false;
        }
        if (can) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $n, $k);
fscanf(STDIN, "%s", $S);

$h = 0;
for ($i = 0; $i < $n - 1; ++$i) {
    if ($S[$i] == $S[$i + 1]) {
        ++$h;
    }
}

echo min($n - 1, $h + 2 * $k);


Measured memory_bytes: 4604
import numpy as np
import sys

def main():
  S = input()
  T = input()
  lenS = len(S)
  lenT = len(T)
  for i in range(lenS-lenT,-1,-1):
    sub = S[i:i+lenT]
    for j in range(lenT):
      if sub[j]!=T[j] and sub[j]!="?":
        break
    else:
      S = S[:i]+T+S[i+lenT:]
      S=S.replace("?","a")
      print(S)
      sys.exit()
      break
    continue
  print("UNRESTORABLE")

main()

Measured memory_bytes: 14532
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> L(N+1);
    L[0] = 2; L[1] = 1;
    for(int i = 2; i <= N;i++){
        L[i] = L[i-1] + L[i-2];
    }
    cout << L[N] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

struct position {
    double x;
    double y;
};

int main() {
    int n;
    cin >> n;
    int count = 0;
    vector<position> pos(n);
    vector<int> perm(n);

    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x;
        cin >> y;
        pos[i] = position{x, y};
        perm[i] = i;
    }

    double sum = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            sum += sqrt(pow(pos[perm[i + 1]].x - pos[perm[i]].x, 2)
                        + pow(pos[perm[i + 1]].y - pos[perm[i]].y, 2));
        }
        count++;
    } while (next_permutation(perm.begin(), perm.end()));

    printf("%lf",sum/count);
}

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

using namespace std;

int main()
{
  int N, M;
  int deg[50] = {};

  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    ++deg[a];
    ++deg[b];
  }

  for(int i = 0; i < N; i++) {
    cout << deg[i] << endl;
  }
}

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

#define REP(i,n) for(int i=0;i<n;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 pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7

using namespace std;

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

int32_t main(){
    int n;
    cin >> n;
    vector<int> v(n);
    int sum=0;
    REP(i, n){
        cin >> v[i];
        sum+=v[i];
    }
    SORT(v);

    if(sum%10){
        cout << sum << endl;
        return 0;
    }

    REP(i, n){
        if(v[i]%10){
            cout << sum-v[i] << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
minA = min(A)
for i in range(N):
    A[i] -= i+1 
minA = min(A)
for i in range(N):
    A[i] -= minA
A.sort()
#print(A)

if N %2 == 1:
    ans = A[(N-1)//2]
    t = 0
    for i in range(N):
        t += abs(A[i]-ans)
    ans = t

else:
    ans1 = A[(N)//2]
    ans2 = A[(N)//2 -1]
    t = 0
    for i in range(N):
        t += abs(A[i]-ans1)
    s = 0
    for i in range(N):
        s += abs(A[i]-ans2)
    ans = min(t, s)

print(ans)



Measured memory_bytes: 25744
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        for (int i = 0 ; i < m ; i++) {
            if (i % 2 == 0) {
                int a = i / 2 + 1;
                int b = m - i / 2 + 1;
                System.out.println(a + " " + b);
            } else {
                int a = n - i / 2;
                int b = n - m + i / 2 +1;
                System.out.println(a + " " + b);
            }

        }
    }

}

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

# それぞれの猫の発言からありえる色の種類を計算
b = [0 for i in range(n+1)]
for i in range(n):
    b[a[i]]+=1
    b[a[i]+1]+=1

for i in range(1,n+1):
    # n匹の猫がありえると言った、b[i]==nとなるi色だけ可能性がある
    if b[i]==n:
        # a[j]==i-1であれば、自分は固有の色
        unique = 0
        for j in range(n):
            if a[j]==i-1:
                unique+=1
        # 固有じゃない猫の数
        common = n-unique
        # 固有じゃないのが1匹はありえない
        if common==1:
            break
        # 全部固有の時
        elif common==0:
            if unique==i:
                print('Yes')
                exit()
        # 固有じゃないのが2匹以上いる時
        elif unique+1<=i<=common//2+unique:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 56388
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define mod 998244353
vector<vector<ll > > adj;
void dfs(ll src,vector<ll > &arr,ll sum){
    arr[src]=sum;
    for(auto itr: adj[src]){
        dfs(itr,arr,sum+arr[itr]);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,q,a,b,root,val;
    cin>>n>>q;
    adj.clear();
    adj.resize(n+1);
    vector<ll > arr(n+1);
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        adj[a].push_back(b);
    } 
    while(q--){
        cin>>root>>val;
        arr[root]+=val;
    }
    dfs(1ll,arr,arr[1]);
    for(int i=1;i<=n;i++) cout<<arr[i]<<" ";
    return 0;
}


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

int a[222222];
int main() {
    long n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i + 1];
    vector<int> b = {1};
    int i = 1, x = 1;
    for(;; i++) {
        b.push_back(x = a[x]);
        if(i % 2 == 0 && b[i / 2] == b[i])
            break;
    }
    cout << b[k < i ? k : k % (i / 2) + i / 2] << endl;
    return 0;
}


Measured memory_bytes: 6088
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]

w = [xy[i][0] - xy[i][1] for i in range(n)]
z = [xy[i][0] + xy[i][1] for i in range(n)]
print(max((max(w) - min(w)), (max(z)-min(z))))

Measured memory_bytes: 130552
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

   
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var s = Read();
        bool b = true;
        var l = new List<long>
        {
            s
        };
        while (b)
        {
            if (l[l.Count - 1] % 2 == 0)
                l.Add(l[l.Count - 1] / 2);
            else
                l.Add(3 * l[l.Count-1] + 1);
            for(int i=0;i<l.Count-1;i++)
            {
                if (l[i] == l[l.Count - 1])
                {
                    b = false;
                    break;
                }
            }
        }
            Console.WriteLine(l.Count);


        Console.Out.Flush();
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;

int main(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  if(abs(a-c) <= d){
    printf("%s", "Yes");
    return 0;
  }else if((abs(a-b) <= d) and (abs(c-b) <= d)){
    printf("%s", "Yes");
    return 0;
  }else{
    printf("%s", "No");
    return 0;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e4+10,D=110,mod=1e9+7;
int n,d;
ll dp[N][D][2];
string s;
ll solve(int i,int mo,bool les){
    if(i==n){
        return (mo==0);
    }
    ll &ret = dp[i][mo][les];
    if(ret!=-1)return ret;
    ret = 0;
    if(les){
        for(int j=0;j<10;j++){
            ret += solve(i+1,(mo+j)%d,1);
            ret %= mod;
        }
    }
    else{
        for(int j=0;j<=s[i]-'0';j++){
            ret += solve(i+1,(mo+j)%d,(j<s[i]-'0'));
            ret %= mod;
        }
    }
    return ret;
}

int main ()
{
    FASTIO
    memset(dp,-1,sizeof dp);
    cin >> s >> d;
    n = s.si;
    cout << (solve(0,0,0)-1+mod)%mod << endl;
    return 0;
}
/**

*/


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

using namespace std;

#define ll long long


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

    int a, b, c;
    cin >> a >> b >> c;

    if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) cout << "Yes"; else cout << "No";

    return 0;
}

Measured memory_bytes: 256