akhauriyash/Code-Regression huggingface dataset:
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

n = inp[0]
a = inp
t = na(n)
n.times do |i|
  t[a[i]-1] = i+1
end
puts t.join(" ")


Measured memory_bytes: 13196
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	map<int,int> mp;
	vector<int> t(n);
	for(int i=0;i<n;++i) {cin>>t[i];mp[t[i]]++;}
	sort(t.begin(), t.end());
	
	int ans=0;
	for(int j=0;j<=100100;++j) {
		int cans=mp[j]+mp[j-1]+mp[j+1];
		ans=max(ans, cans);
	}
	
	cout<<ans<<"\n";
	return 0;
	
}



Measured memory_bytes: 5376
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
    exit()

ans = min(h,w)

for i in range(2):
    tmp = h//3 + i
    p = [0]*3
    p[0] = tmp*w
    p[1],p[2] = (h-tmp)*(w//2), (h-tmp)*((w+1)//2)
    p.sort()
    ans = min(ans,p[2]-p[0])

    tmp = w//3 + i
    p = [0]*3
    p[0] = tmp*h
    p[1],p[2] = (w-tmp)*(h//2), (w-tmp)*((h+1)//2)
    p.sort()
    ans = min(ans,p[2]-p[0])
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        long sum = Long.parseLong(s);

        for (long i = 1; i < Math.pow(2, s.length() - 1); i++) {
            long nowBit = i;
            int start = 0;
            while (true) {
                long value = Long.lowestOneBit(nowBit);
                if (value == 0) {
                    sum += Long.parseLong(s.substring(start));
                    break;
                }
                int index = (int)(Math.log(value) /  Math.log(2)) + 1;
                sum += Integer.parseInt(s.substring(start, index));
                start = index;
                nowBit -= value;
            }
        }

        System.out.println(sum);
    }
}


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

pm = sum(a)
e = 1
te = 1
for i in a:
    pm -= i
    e = min((e-i)*2, pm)
    if e < 0:
        break
    te += e
if e < 0:
    print(-1)
else:
    print(te)

Measured memory_bytes: 20060
N = int(input())
nlist = []
for i in range(N):
    nlist.append([])
for i in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    w = (w % 2 == 1)
    nlist[u].append([v, w])
    nlist[v].append([u, w])

color = [-1] * N
color[0] = 0
nextlist = [0]
while nextlist:
    tmp = []
    for proc in nextlist:
        for n in nlist[proc]:
            if color[n[0]] != -1:
                continue
            color[n[0]] = (color[proc] + n[1]) % 2
            tmp.append(n[0])
    nextlist = tmp

for c in color:
    print(c)


Measured memory_bytes: 41804
x = int(input())

if x < 600:
    print(8)
elif x < 800:
    print(7)
elif x < 1000:
    print(6)
elif x < 1200:
    print(5)
elif x < 1400:
    print(4)
elif x < 1600:
    print(3)
elif x < 1800:
    print(2)
else:
    print(1)


Measured memory_bytes: 9168
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main() {
  int N,i;
  cin>>N;
  vector<int> A(N);
  for (i=0;i<N;i++) {
    cin>>A[i];
  }
  sort(A.begin(), A.end());
  ll ans=A[N-1];
  for (i=2;i<N;i++) {
    ans+=A[N-1-i/2];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3676
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    int n;
    scan(n);
    auto p = readln.split.to!(int[]);

    auto a = new int[](n);
    auto b = new int[](n);

    foreach (i ; 0 .. n) {
        a[i] = (i + 1) * 30000;
        b[i] = (n - i) * 30000;
    }

    p[] -= 1;

    foreach (int i, pi; p) {
        a[pi] += i;
    }

    writefln("%(%s %)", a);
    writefln("%(%s %)", b);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 3324
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){ 
  // 入力
  int n;
  
  while(1){
    cin >> n;
    vector<int> vec(n);
    
    double m = 0;
    double v = 0;
    double ans = 0;
    int s = 0;

    if(n == 0){
      break;
    }
    // 入力を受け付ける
    for(int i = 0; i < n; i++){
      cin >> s;
      vec.at(i) = s;
      m += s;
    }

    // 平均を出す
    m = m / n;
    
    // 分散を出す
    for(int i = 0; i < n; i++){
      v += (vec.at(i) - m) * (vec.at(i) - m);
    }
    v = v / n;
    
    // 標準偏差を出す
    ans = sqrt(v);
    
    // 出力する
    printf("%lf\n",ans);
  }
  
  return 0;
}  


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll 	coordinate[10][5];
int main() {
    ll N; cin >> N;
    long double sum = 0;
    for (ll i = 0; i < N; i++){
        cin >> coordinate[i][0] >> coordinate[i][1];
    }
    vector<ll> num;
    for (ll i = 0; i < N; i++){
        num.push_back(i);
    }
    
    do{
        for(ll i = 0; i < N-1; i++){
            ll x = coordinate[num[i+1]][0] - coordinate[num[i]][0], y = coordinate[num[i+1]][1] - coordinate[num[i]][1];
            sum += sqrt(x*x + y*y);
        }
    }while(next_permutation(num.begin(), num.end()));

    ll q = 1;
    for (ll i = 0; i < N; i++){
        q = q*(i + 1);
    }
    
    printf("%.8Lf\n", sum/(double)q);
    return 0;    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
typedef pair<int, int> pii;
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
const int N = 2010;
int n;
char a[N], b[N], c[N];
int main() {
	scanf("%s", a); n = strlen(a);
	scanf("%s", b);

	bool a0 = true, b0 = true;
	Rep(i,n) { a0 = a0 && a[i] == '0'; b0 = b0 && b[i] == '0'; }

	if (a0 && b0) { printf("0\n"); return 0; }
	else if (b0) { printf("-1\n"); return 0; }

	int mn = 3 * n;

	static int pre[N], nxt[N];
	Rep(j,n) if (!j) {
		pre[j] = 0;
		while (b[pre[j]] != '1') pre[j] = (pre[j] - 1 + n) % n;
	} else pre[j] = b[j] == '1' ? j : pre[j - 1];
	dep(j,n - 1,0) if (j == n - 1) {
		nxt[j] = n - 1;
		while (b[nxt[j]] != '1') nxt[j] = (nxt[j] + 1) % n;
	} else nxt[j] = b[j] == '1' ? j : nxt[j + 1];

	Rep(i,n) {
		memcpy(c, b, n * sizeof(b[0]));
		rotate(c, c + (n - i) % n, c + n);
		int ans = 0;
		Rep(j,n) if (c[j] != a[j]) ans++;

		//0->i
		int tot1 = i;	
		static int mx[N]; memset(mx, 0, sizeof(mx));
		Rep(j,n) if (c[j] != a[j]) {
			int r = (j - pre[j] + n) % n, l = (j - nxt[j] + n) % n;
			if (l > i && r > i) mx[n - l - 1] = max(mx[n - l - 1], r - i);
		}
		dep(i,n - 2,0) mx[i] = max(mx[i], mx[i + 1]);
		int mnshift = 2 * n;
		Rep(i,n) mnshift = min(mnshift, mx[i] + i);
		tot1 += 2 * mnshift;

		//0->n - 1->i
		int tot2 = n - i;
		memset(mx, 0, sizeof(mx));
		Rep(j,n) if (c[j] != a[j]) {
			int r = (j - pre[j] + n) % n, l = (j - nxt[j] + n) % n;
			if (l < i && r < i && l > 0 && r > 0) mx[r - 1] = max(mx[r - 1], i - l);
		}
		dep(i,n - 2,0) mx[i] = max(mx[i], mx[i + 1]);
		mnshift = 2 * n;
		Rep(i,n) mnshift = min(mnshift, mx[i] + i);
		tot2 += 2 * mnshift;

		//hole circle
		ans += min(tot1, tot2);
		mn = min(mn, ans);
	}
	printf("%d\n",mn);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int H, N;
    int S = 0;
    cin >> H >> N;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a; 
        S += a; 
    }
    if(H <= S){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 380
// #include "testlib.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<ll,ll>
#define se second
#define double long double
#define mod 1000000007
#define popcount __builtin_popcountll
const double PI = acos(-1.0);
using namespace std;
#define MXN 3005
int n, m;
int a[88][88];
int b[88][88];
int dp[80][80][88*88];
int cal(int i, int j, int s){
    if(i==n || j==m || s>=(88*88))return 1e8;
    if(i==n-1 && j==m-1){
        int d = a[i][j]-b[i][j];
        return min(abs(s+d), abs(s-d));
    }
    int &ret = dp[i][j][s];
    if(ret!=-1)return ret;
    ret = 1e8;
    int d = a[i][j]-b[i][j];
    ret = cal(i+1, j, abs(s+d));
    ret = min(ret, cal(i+1, j, abs(s-d)));
    ret = min(ret, cal(i, j+1, abs(s+d)));
    ret = min(ret, cal(i, j+1, abs(s-d)));
    return ret;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &a[i][j]);
        }
    }
 
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &b[i][j]);
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<cal(0,0, 0)<<endl;
}

Measured memory_bytes: 193920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"    "<<"HERE"<<en

int main(){
  set<int> s;
  for(int i=1; i<=30; i++){
    s.insert(i);
  }
  
  for(int i=1; i<=28; i++){
    int j;
    cin>>j;
    s.erase(j);
  }
  
  for(set<int>::iterator i=s.begin(); i!=s.end(); i++){
    cout<<*i<<en
  }
  
}


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

using namespace std;

template <class T>inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>inline T updmin(T &a, T b) { return a = min(a, b); }

int no(){
	cout << "No\n";
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n, 0);
	for(int i=0; i<n; i++)cin >> a[i];
	int k = -1;
	for(int i=0; i < n; i++){
		if(k > a[i])return no();
		if(k < a[i])k = a[i] - 1;
		else k = a[i];
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 640
n = int(input())
sozai_lst = list(map(int,input().split()))

sort_lst = sorted(sozai_lst)

for i in range(n-1):
    t = (sort_lst[0]+sort_lst[1])/2
    del sort_lst[1]
    sort_lst[0] = t

print(sort_lst[0])


Measured memory_bytes: 3064
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,v;
  char c;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    v = s[i]-'A';
    v = (v+n)%26;
    c = 'A'+v;
    cout << c;
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	static StringBuilder sb = new StringBuilder("");
	static Node root = null;	//根っこ
	
	//名ばかりメイン
	public static void main(String args[]) {
		run();
	}
	
	//実質メイン
	public static void run() {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		String ope;
		
		//入力
		for (int i = 0; i < num; i++) {
			ope = scanner.next();
			//命令分岐
			switch( Operate.getEnumName(ope) ){
			case in:
				insert( new Node( scanner.nextInt() ) );
				break;
			case find:
				if(find( scanner.nextInt() ) ){
					sb.append("yes\n");
				}else{
					sb.append("no\n");
				}
				break;
			case print:
				print();
			}
		}
		
		output();//出力関数
		
		scanner.close();
	}
	
	//挿入処理
	public static void insert(Node node){
		Node parent = null;				// x の親
		Node child = root;
		while (child != null) {
			parent = child;				// 親を設定
			if (node.key < child.key) {
				child = child.left;		// 左の子へ移動
			} else {
				child = child.right;	// 右の子へ移動
			}
		}
		
		//親か子か
		if (parent == null) {
			root = node;
		} else if (node.key < parent.key) {
			parent.left = node;
		} else {
			parent.right = node;
		}
	}
	
	//先行巡回
	public static void preParse(Node node) {
		if (node == null) return;
		
		sb.append(" ").append(node.key);
		preParse(node.left);
		preParse(node.right);
	}
	//中間巡回
	public static void inParse(Node node) {
		if (node == null) return;
		
		inParse(node.left);
		sb.append(" ").append(node.key);
		inParse(node.right);
	}
	
	//見つける
	public static boolean find(int key) {
		Node node = root;
		//見つかるまで掘る
		while (node != null) {
			if (key == node.key) {
				return true;
			} else if (key < node.key) {
				node = node.left;
			} else {
				node = node.right;
			}
		}
		//なければfalse
		return false;
	}
	
	//出力準備
	public static void print() {
		inParse(root);
		sb.append("\n");
		preParse(root);
		sb.append("\n");
	}
	
	//出力
	public static void output(){
		System.out.print(sb);
	}
	
	//enum宣言
	public static enum Operate{
		in("insert"),
		find("find"),
		print("print");
		
		private final String name;
		
		Operate(String name){
			this.name = name;
		}
		
		String getName(){
			return this.name;
		}

		public static Operate getEnumName(String str){
			for(Operate v : values()){
				if(v.getName().equals(str)){
					return v;
				}
			}
			throw new IllegalArgumentException("undefined : " + str);
		}
	}

}
//クラス
class Node{
	public int key;
	public Node left;
	public Node right;
	
	public Node(int key) {
		this.key = key;
		left = right = null;
	}
	
}



Measured memory_bytes: 205084
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int cnt = 0;
  for(int i=1;i<=n;i++){
    if((1<=i&&i<10)||(100<=i&&i<1000)||(10000<=i&&i<100000)) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

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

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

bool vector_finder(std::vector<int> vec, int number) { // vector 内にnumberがあるかどうか
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance( vec.begin(), itr );
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}

int main() {
	int k;
	cin >> k;
	if (k % 2 == 0) {
		cout << "-1" << endl;
		return 0;
	}
	ll x = 0;
	for (ll i = 1; i < 1e6 + 5; i++) {
		x = (x*10 + 7) % k;
		if (!x) {
			return cout << i, 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	int n, m, k;
	cin >> n >> m >> k;
	ll arr[n + 1], brr[m + 1];
	arr[0] = brr[0] = 0;
	for (int i = 1; i <= n; ++i)
		cin >> arr[i], arr[i] += arr[i - 1];
	for (int i = 1; i <= m; ++i)
		cin >> brr[i], brr[i] += brr[i - 1];
	int ans = 0;
	for (int i = 0; i <= n and arr[i] <= k; ++i) {
		int temp = lower_bound(brr, brr + m + 1, k - arr[i]) - brr;
		if (temp <= m) {
			//cout << brr[i] << " " << k << " " << arr[i] << endl;
			if (brr[temp] > k - arr[i])
				--temp;
			//cout << i << " " << temp << endl;
			ans = max(ans, i + temp);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6760
N=int(input())
T=[0]
X=[0]
Y=[0]

for i in range(N):
    t,x,y=map(int,input().split())
    T.append(t)
    X.append(x)
    Y.append(y)
flag=True
for i in range(N):
    t=T[i+1]-T[i]
    x=abs(X[i+1]-X[i])
    y=abs(Y[i+1]-Y[i])
    z=x+y
    if t>=z and (t-z)%2==0:
        flag=True
    else:
        flag=False
        break
print("Yes") if flag else print("No")

Measured memory_bytes: 11816
#include<stdio.h>

int main(void)
{
	int n[5];
	int i;
	int avr = 0;
	for(i = 0;i < 5;i++)
	{
		scanf("%d",&n[i]);
	}
	for(i = 0;i < 5;i++)
	{
		if(n[i] < 40)
		{
			n[i] = 40;
		}
	}
	for(i = 0;i < 5;i++)
	{
		avr += n[i];
	}
	avr = avr / 5;
	printf("%d\n",avr);
	return 0;
}

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

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

    map<pair<int, int>, ll> m;
    vector<vector<int> > v(n);
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[b].push_back(a);
        v[a].push_back(b);
        int k;
        cin >> k;
        if(a < b){
            m[make_pair(a, b)] = k;
        }else{
            m[make_pair(b, a)] = k;
        }
    }

    int q, k;
    cin >> q >> k;
    k--;
    int x[q], y[q];
    for(int i = 0; i < q; i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    ll dis[n];
    for(int i = 0; i < n; i++){
        dis[i] = 0;
    }

    queue<int> t;
    t.push(k);
    while(!t.empty()){
        int o = t.front();
        t.pop();
        for(int i = 0; i < v[o].size(); i++){
            if(o < v[o][i]){
                auto itr = m.find(make_pair(o, v[o][i]));
                if(dis[v[o][i]] == 0){
                    dis[v[o][i]] = dis[o] + itr->second;
                    t.push(v[o][i]);
                } 
            }else{
                auto itr = m.find(make_pair(v[o][i], o));
                if(dis[v[o][i]] == 0){
                    dis[v[o][i]] = dis[o] + itr->second;
                    t.push(v[o][i]);
                }
            }
        }
    }

    for(int i = 0; i < q; i++){
        cout << dis[x[i]] + dis[y[i]] << endl;
    }
}

Measured memory_bytes: 17364
#include "bits/stdc++.h"
using namespace std;

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

    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        while (vec.at(i) % 2 == 0) {
            vec.at(i) /= 2;
            res++;
        }
    }

    cout << res << endl;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int x;
    cin>>x;
    for(int i=x;;++i){
        bool ok=true;
        for(int j=2;j*j<=i;++j){
            if(i%j==0){
                ok=false;
                break;
            }
        }
        if(ok){
            cout<<i;
            return 0;
        }
    }
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("5");
            WillReturn.Add("3");
            WillReturn.Add("1");
            WillReturn.Add("3");
            WillReturn.Add("4");
            WillReturn.Add("3");
            //3
            //価格が1のとき買って
            //4のときに売ると4-1=3で最大3の利益を得ることができます。
            //最初の5を使うと5-1=4となりますが、
            //これは5の方が時間が前なので許されません。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("4");
            WillReturn.Add("3");
            WillReturn.Add("2");
            //-1
            //価格が減少しているケースですが、
            //この問題ではJ > I という条件から、
            //買って売る作業を1回は行う必要があるので、
            //最大利益は-1となります。
        }
        else if (InputPattern == "Input3") { //最悪計算量
            WillReturn.AddRange(Enumerable.Repeat("100000000", 200000));
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] R = InputList.Skip(1).Select(X => int.Parse(X)).ToArray();

        int MinValue = R[0]; //最小価格
        int MaxProfit = int.MinValue; //最大利益

        for (int I = 1; I <= R.GetUpperBound(0); I++) {
            int CurrProfit = R[I] - MinValue;

            //最大利益の更新
            if (MaxProfit < CurrProfit)
                MaxProfit = CurrProfit;

            //最小価格の更新
            if (MinValue > R[I])
                MinValue = R[I];
        }
        Console.WriteLine(MaxProfit);
    }
}




Measured memory_bytes: 40168
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>

using namespace std;

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

  vector<int> aa(100001, 0);
  vector<int> ab(100001, 0);


  for (int i=0; i<n; i++) {
    if (i%2==0) aa[a[i]]++;
    else ab[a[i]]++;
  }

  vector<pair<int, int>> va;
  vector<pair<int, int>> vb;

  for (int i=0; i<100001; i++) {
    if (aa[i] != 0) va.push_back({aa[i], i});
    if (ab[i] != 0) vb.push_back({ab[i], i});
  }

  if (va.size() == 1) va.push_back({0, 0});
  if (vb.size() == 1) vb.push_back({0, 0});

  sort(va.begin(), va.end(), greater<pair<int, int>>());
  sort(vb.begin(), vb.end(), greater<pair<int, int>>());

  int res;

  if (va[0].second == vb[0].second) {
    int tmpres1 = n - va[0].first - vb[1].first;
    int tmpres2 = n - va[1].first - vb[0].first;

    if (tmpres1 < tmpres2) res = tmpres1;
    else res = tmpres2;
  } else {
    res = n - va[0].first - vb[0].first;
  }

  cout << res << endl;

}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, x, d;
	cin >> n >> x >> d;

	if (d == 0)
	{
		if (x == 0)
			cout << "1\n";
		else
			cout << n+1 << "\n";
		return 0;
	}

	map<ll, vector<pair<ll, ll>>> mp;
	for (ll k = 0; k <= n; ++k)
		mp[k*x % d].push_back({ k*x / d + k*(k-1)/2, k*x / d + (k*(n-1) -k*(k-1)/2) });

	ll ans = 0;
	for (auto &i : mp)
	{
		auto &a = i.S;
		sort(a.begin(), a.end());
		auto cur = a[0];
		a.push_back({ (ll)1e18, 0 });
		for (auto i : a)
		{
			if (i.F <= cur.S)
				cur.S = max(cur.S, i.S);
			else
				ans += cur.S - cur.F + 1, cur = i;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rpt(i,a,b) for(int i=a;i<(int)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<ll>& vec) {
    for (ll value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    IO;

    string str; cin>>str;
    ll K; cin>>K;
    set<string> bubun;

    int a=str.size();
    int b=min(5,a);
  
    rep(i,a){
       rpt(j,1,min(b+1,a-i+1)){
         bubun.insert(str.substr(i,j));
       }
    }

    auto itr=bubun.begin();
    rep(i,K-1) itr++;
    cout<<*itr<<endl;

}


Measured memory_bytes: 4720
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int AA = Integer.parseInt(S.substring(0, 2));
        int BB = Integer.parseInt(S.substring(2, 4));
        
        if ( (0 < AA && AA <= 12) ){
            
            if( (0 < BB && BB <= 12) ){
                System.out.println("AMBIGUOUS");
            } else {
                System.out.println("MMYY");
            }
            
        } else {
            
            if( (0 < BB && BB <= 12) ){
                System.out.println("YYMM");
            } else {
                System.out.println("NA");
            }            
            
        }
    }
}


Measured memory_bytes: 22868
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      for (int i = 1; i<=n; i++) {
        if((int)(i*1.08)==n){
          System.out.println(i);
          System.exit(0);
        }
      }
        System.out.println(":(");
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
/////////////////////////



//Answer


int main() {

long K;
cin>>K;
long now;//777%K
long ten;//700%K
long count=1;
now=7%K;
ten=now;
if(K%2==0||K%5==0){
    count=-1;
}else{
    while(now!=0&&count<K+3){
    ten=(ten*10)%K;
    now=(now+ten)%K;
    count++;
}
if(count>K+1){
    count=-1;
}

}

cout<<count<<endl;

}


Measured memory_bytes: 3628
#include <stdio.h>
 
int main(void)
{
    int a, b;
     
    while (scanf("%d %d", &a, &b) != EOF){
        a = a + b;
        b = 0;
        do{
            b++;
            a /= 10;
        }while (a != 0);
        printf("%d\n", b);
    }
     
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N=2e5+10;
int a[N];
int main()
{
	int n,k,i;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=k+1;i<=n;i++)
	{
		if(a[i]>a[i-k])
			printf("Yes\n");
		else
			printf("No\n");
		}
	return 0;
 } 

Measured memory_bytes: 4540
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int a,b,c,d;
  scanf("%d %d %d",&a,&b,&c);
  d=MAX(a,MAX(b,c));
  printf("%s\n",a==b&&b==c?"Yes":"No");
  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    int x, n;
    cin>>x>>n;
    set<int> ss;
    for (int i=0; i<n; i++) {
	int q;
	cin>>q;
	ss.insert(q);
    }

    int res=1e9;
    for (int val=-1000; val<=1000; val++) {
	if (abs(val-x)<abs(res-x)) {
	    if (!ss.count(val)) {
		res=val;
	    }
	}
    }

    out(res);
    
    return 0;
}


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

int main() {
    cout << fixed << setprecision(10);
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    int ans = 0;
    REP(i, N - 1) {
        if(s[i] == s[i + 1]) {
            ans++;
        }
    }
    ans += 2 * K;
    cout << min(ans,N-1);

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
#include <atcoder/all>
using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 T>
inline void dump(T &v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U> &v) {
    irep(i, v) { cout << i->first << " " << i->second << '\n'; }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */


int main() {

    int n,m;
    cin>>n>>m;
    vll a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    vll v = convolution(a,b);
    dump(v);
}


Measured memory_bytes: 27280
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <ll, pair <ll, ll>>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 5e2 + 100;
const ll inf = 1e15;

ll n, m, k, t;

ll dp[maxn][maxn][2];

ll A[maxn][maxn];

ll getdp(ll l, ll r, ll i) {
    if (dp[l][r][i] != -1) {
        return dp[l][r][i];
    }
    if (i == 0) {
        ll dd = 0;
        ll q;
        for (q = l; q <= r; q++) {
            dd += A[q][r];
        }
        dp[l][r][i] = dp[l][r - 1][i] + dd;
    }
    else {
        ll q;
        ll dd = 0;
        for (q = r + 1; q < n; q++) {
            dd += A[q][l - 1];
        }
        dp[l][r][i] = dp[l - 1][r][i] + dd;
    }
    return dp[l][r][i];
}

ll D[maxn][maxn];

ll get_in(ll l, ll r) {
    while (r >= n) {
        r--;
    }
    while (l >= n) {
        l--;
    }
    if (l > r) {
        return 0;
    }
    ll ans = getdp(l, r, 0); 
    // cout << "IN " << l << " " << r  << " " << ans << endl;
    return ans;
}

ll get_out(ll l, ll r) {
    while (r >= n) {
        r--;
    }
    while (l >= n) {
        l--;
    }
    while (l > r) {
        r++;
    }
    ll ans = getdp(l, r, 1);
    // cout << "OUT " << l << " " << r  << " " << ans << endl;
    return ans;
}

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b;
    cin >> n;
    for (q = 0; q < n; q++) {
        for (w = 0; w < n; w++) {
            if (w == q) {
                continue;
            }
            cin >> A[q][w];
        }
    }
    for (q = 0; q < maxn; q++) {
        for (w = 0; w < maxn; w++) {
            for (e = 0; e < 2; e++) {
                dp[q][w][e] = -1;
            }
        }
    }
    for (q = 0; q < maxn; q++) {
        dp[q][q][0] = 0;
    }

    for (q = 0; q < maxn; q++) {
        dp[0][q][1] = 0;
    }
    for (q = 0; q < maxn; q++) {
        dp[q][n - 1][1] = 0;
    }

    // ll ans = 0;
    for (q = 0; q < maxn; q++) {
        for (w = 0; w < maxn; w++) {
            D[q][w] = inf;
        }
    }
    D[0][0] = 0;
    for (q = 1; q <= n + 1; q++) {
        for (w = 0; w < q; w++) {
            D[q][w] = inf;
            for (e = 0; e <= w; e++) {
                ll dans = D[w][e];
                ll d = get_in(w, q - 1);
                ll d1 = get_out(w, q - 1) - get_out(e, q - 1);
                dans += d + d1;
                D[q][w] = min(D[q][w], dans);
            }
            // cout << q << " " << w << " " << "D " << D[q][w] << endl << endl;
        }
    }
    ll ans = inf;
    for (q = 0; q <= n; q++) {
        ans = min(ans, D[n + 1][q]);
    }
    cout << ans;
    return 0;
}

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

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

  if (a < b) {
    cout << "a < b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a == b" << endl;
  }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	ll x;
	cin >> x;
	ll diff = INT_MAX;
	while (x > 0)
	{
		ll tmp = x % 1000;
		diff = min(diff, abs(753 - tmp));
		x /= 10;
	}
	cout << diff << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#define N 1000000000

int c=0;
void m(int A[], int left,int mid,int right){
  int i,j,k,x,y,*L,*R;
  x=mid-left;
  y=right-mid;
  L=(int *)malloc(sizeof(int)*(x+1));
  R=(int *)malloc(sizeof(int)*(y+1));
  for(i=0;i<=x-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=y-1;j++){
    R[j]=A[mid+j];
  }
  L[x]=N;
  R[y]=N;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      c++;
    }
    else{
      A[k]=R[j];
      j++;
      c++;
    }
  }
  free(L);
  free(R);
}
void ms(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    ms(A,left,mid);
    ms(A,mid,right);
    m(A,left,mid,right);
  }
}
int main(){
  int A[500000];
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  ms(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 5440
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define rep(i, n)      for (int i=0; i<int(n); i++)
#define rep3(i, s, n)  for (int i=int(s); i<int(n); i++)
#define rev_rep(i, n)  for (int i=int(n)-1; i>=0; i-=1)

string N;
int table_j[1000100];
int table_o[1000100];
int table_i[1000100];

int main() {
  cin >> N;
  int len = N.length();
  char last = '/';
  int cont = 0;
  rep(i, len) {
    if (N[i] != last) cont = 1;
    else              cont += 1;
    if (N[i] == 'J') table_j[i] = cont;
    if (N[i] == 'O') table_o[i] = cont;
    if (N[i] == 'I') table_i[i] = cont;
    last = N[i];
  }
  int ans = 0;
  rep(i, len) {
    int x = table_o[i];
    if (x > 0) {
      if (i>=x && i+x<len && table_j[i-x] >= x && table_i[i+x] == x) {
        ans = max(ans, x);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
pi a[100];
int cnt[100];
ll d = 0;
double dist(int x1, int y1, int x2, int y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> a[i].fi >> a[i].se;
        cnt[i] = i;
    }
    double res = 0;
    do
    {
        FOR(i, 1, n - 1)
            res += dist(a[cnt[i]].fi, a[cnt[i]].se, a[cnt[i + 1]].fi, a[cnt[i + 1]].se);
        d++;
        //cout << endl;
    }
    while(next_permutation(cnt + 1, cnt + 1 + n));
    cout << prec(7) << res / d;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
typedef long long int lli;
typedef unsigned long long int uli;
using namespace std;
int main(){
  int sn,c;
  string s;
  cin>>s;
  if(s[0]!='A'){
    ou("WA");
    return 0;
  }
  sn=0;
  rep(i,2,s.size()-1){
    if(s.at(i)=='C'){
      ++sn;
      c=i;
    }
  }
  if(sn!=1){
    ou("WA");
    return 0;
  }
  rep(i,1,s.size()){
    if(i!=c&&s.at(i)<=90){
      ou("WA");
      return 0;
    }
  }
  ou("AC");
}

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

using namespace std;

vector<int> point[100001],vec;
int N,M,sum[100001],x,y,dep[100001],fa[100001],U,V,g[100001],len;
long long ans;
bool vis[100001];

void dfs1(int u,int f,int d){
	if(d&1)sum[u]=-1;else sum[u]=1;
	for(int v:point[u])if(v!=f)dfs1(v,u,d+1),sum[u]+=sum[v];
}

void solve1(){
	for(int i=1;i<=M;++i)scanf("%d%d",&x,&y),point[x].push_back(y),point[y].push_back(x);
	dfs1(1,0,0);
	if(sum[1])puts("-1");else{int ans=0;for(int i=1;i<=N;++i)ans+=abs(sum[i]);printf("%d",ans);}
}

void dfs2(int u,int f){
	vis[u]=true;
	for(int v:point[u])if(v!=f){if(vis[v]){U=u,V=v,len=dep[u]-dep[v]+1;return;}dep[v]=dep[u]+1;dfs2(v,u);}
}

void solve2(vector<int> &vec){
	sort(vec.begin(),vec.end());
	long long x=vec[vec.size()-1>>1];
	ans+=abs(x);
	for(int i:vec)ans+=abs(x-i);
	printf("%lld",ans);
}

void dfs3(int u,int d){
	vis[u]=true;
	if(d&1)sum[u]=-1;else sum[u]=1;
	for(int v:point[u])if(!vis[v]){fa[v]=u,dfs3(v,d+1),sum[u]+=sum[v];}
}

void dfs4(int u,int d){
	vis[u]=true;
	if(d&1)sum[u]=-1;else sum[u]=1;
	for(int v:point[u])if(!vis[v])dfs4(v,d+1),sum[u]+=sum[v],g[u]+=g[v];
	if(!g[u])ans+=abs(sum[u]);else vec.push_back(g[u]==1?-sum[u]:sum[u]);
}

void work(){
	for(int i=1;i<=M;++i)scanf("%d%d",&x,&y),point[x].push_back(y),point[y].push_back(x);
	dfs2(1,0);
	if(len&1){
		memset(vis,false,sizeof(vis));
		dfs3(U,0);
		if(sum[U]&1)puts("-1");else{
			int d=-sum[U]>>1;for(int i=V;i;i=fa[i])sum[i]+=d;sum[U]+=d;
			ans=abs(d);
			for(int i=1;i<=N;++i)ans+=abs(sum[i]);
			printf("%lld",ans);
		}
	}else{
		memset(vis,false,sizeof(vis));
		++g[U],--g[V];dfs4(U,0);
		if(sum[U])puts("-1");else solve2(vec);
	}
}

int main(){
	scanf("%d%d",&N,&M);
	if(M==N-1)solve1();else work();
}

Measured memory_bytes: 13820
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.regex.*;

public class Main {
    
    private static PrintWriter out;
    
    private static <T> void mprintln(T ... ar){
        for(T i: ar) out.print(i + " ");
        out.println();
    }
    
    public static void main(String[] args) throws FileNotFoundException{

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close(); 
    }
    
//  Global Variables  
    
    private static void getAns(MyScanner sc){
       char[] ar = sc.nn().toCharArray();
       boolean good = true;
       for(int i = 1; i < 4; i++) good &= ar[i] != ar[i - 1];
       out.println(good? "Good": "Bad");
    }
    
    static class MyScanner{
        BufferedReader br;
	StringTokenizer st;

	MyScanner(FileReader fileReader){
            br = new BufferedReader(fileReader);
	}

	MyScanner(){
            br = new BufferedReader(new InputStreamReader(System.in));
	}

	String nn(){
            while(st == null || !st.hasMoreElements()){
		try{
                    st = new StringTokenizer(br.readLine());
		}catch(IOException e){
                    e.printStackTrace();
		}
            }
            return st.nextToken();
	}
        
        String nextLine(){
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

	char nc(){
            return nn().charAt(0);
	}

	int ni(){
            return Integer.parseInt(nn());
	}

	long nl(){
            return Long.parseLong(nn());
	}

	double nd(){
            return Double.parseDouble(nn());
	}

	int[] niArr0(int n){
            int[] ar = new int[n];
            for(int i = 0; i < n; i++) ar[i] = ni();
            return ar;
	}

        int[] niArr1(int n){
            int[] ar = new int[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = ni();
            return ar;
	}

        long[] nlArr0(int n){
            long[] ar = new long[n];
            for(int i = 0; i < n; i++) ar[i] = nl();
            return ar;
        }

        long[] nlArr1(int n){
            long[] ar = new long[n + 1];
            for(int i = 1; i <= n; i++) ar[i] = nl();
            return ar;
        }
    }
}

Measured memory_bytes: 22356