akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N = int(input())
X = input()
Xint = int(X, 2)
Xcount = X.count("1")

"""
0010
1010 10(mod2) -> 0
i = n-1の時だけ +1
0011 -> 3 -> 1->0
0110 -> 6(mod2) -> 0
"""

if Xcount == 1:
    for i in range(N):
        if X[i] == "1":
            print(0)
        elif i == N-1:
            print(2)
        else:
            print(1)
    exit()

Modplus, Modminus = Xint%(Xcount+1), Xint%(Xcount-1)

def f(x):
    if x == 0:
        return 0
    return f(x%bin(x).count("1"))+1

for i in range(N):
    if X[i] == "1":
        print(1+f((Modminus-pow(2, N-1-i, Xcount-1))%(Xcount-1)))
    else:
        print(1+f((Modplus+pow(2, N-1-i, Xcount+1))%(Xcount+1)))


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

int main(){
    int n,m,a[10],s,c;
    map<int,int>q;
    cin>>n>>m;
    int flag=1;
    memset(a,-1,sizeof(a));
    while(m--){
        cin>>s>>c;
        if(q.count(s)==0){
            q[s]=c;
            a[s]=c;
        }
        else{
            if(q[s]!=c) flag=0;
        }
    }
    if(a[1]==0 && n>1) flag=0;
    if(flag==0) puts("-1");
    else{
        if(n>1){
            for(int i=1;i<=n;i++){
                if(a[i]==-1 && i==1) cout<<1;
                else if(a[i]==-1 && i>1) cout<<0;
                else cout<<a[i];
            }
        }
        else{
            if(a[1]==-1) cout<<0;
            else cout<<a[1];
        }
    }
    return 0;
}


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

int main() {
    int l, r, d;
    cin >> l >> r >> d;

    int c = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) c++;
    }

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3644
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
Map<Integer,Integer> h=new HashMap<Integer,Integer>();
for(int i=0;i<n;i++)
{a[i]=sc.nextInt();
h.put(i+1,a[i]);}
List<Map.Entry<Integer, Integer> > list = 
               new LinkedList<Map.Entry<Integer, Integer> >(h.entrySet()); 
  
       
        Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { 
            public int compare(Map.Entry<Integer, Integer> o1,  
                               Map.Entry<Integer, Integer> o2) 
            { 
                return (o1.getValue()).compareTo(o2.getValue()); 
            } 
        }); 
          
        // put data from sorted list to hashmap  
        HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); 
        for (Map.Entry<Integer, Integer> aa : list) { 
            temp.put(aa.getKey(), aa.getValue()); 
        } 
	for (Map.Entry<Integer, Integer> val : temp.entrySet()) { 
            System.out.print(val.getKey()+" "); }




}
}



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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    char a;
    cin >> a;
    if(a >= 'a' && a <= 'z') {
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

string S;

bool check(string str) {
    int N = str.length();
    for (int i = 0; i < N; i++) {
        if (str[i] != str[N - 1 - i]) return false;
    }
    return true;
} 

int main() {
    cin >> S;

    int n = S.length();
    string f = "";
    for (int i = 0; i < (n-1)/2; i++) {
        f += S[i];
    }
    string b = "";
    for (int j = (n+3)/2 - 1; j < n; j++) {
        b += S[j];
    }
    
    if (check(S) && check(f) && check(b)) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int main(void)
{
	int n;//たこ焼きの個数
	int a[N];//おいしさ
	int sum=0;//総和

	//scanf_s("%d", &n);
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		//scanf_s("%d", &a[i]);
		scanf("%d", &a[i]);
	}
	

	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			sum += a[i] * a[j];
			//printf("%d * %d = %d\n", a[i], a[j], sum);
		}
	}
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  int sum=0;
  rep(i, 5) { int a;
  cin >> a;
  sum += a;
  }
  cout << 15-sum << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vstr s(2);
    cin>>s[0]>>s[1];
    ll ans=3;
    if(s[0][0]!=s[1][0])ans*=2;
    rep2(i,1,n){
        if(s[0][i-1]==s[1][i-1]&&s[0][i]==s[1][i]){
            ans*=2;
            ans%=inf;
        }
        else if(s[0][i-1]==s[1][i-1]&&s[0][i]!=s[1][i]){
            ans*=2;
            ans%=inf;
        }
        else if(s[0][i-1]!=s[1][i-1]&&s[0][i]!=s[1][i]&&s[0][i-1]!=s[0][i]&&s[1][i-1]!=s[1][i]){
            ans*=3;
            ans%=inf;
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
	int a, b, c, d, e, f;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);

	vector<bool> sugar(f + 1, false), water(f + 1, false);
	sugar[0] = water[0] = true;
	for (int i = 0; i <= f; i++)
	{
		if (sugar[i])
		{
			if (i + c <= f)
				sugar[i + c] = true;
			if (i + d <= f)
				sugar[i + d] = true;
		}
		if (water[i])
		{
			if (i + a * 100 <= f)
				water[i + a * 100] = true;
			if (i + b * 100 <= f)
				water[i + b * 100] = true;
		}
	}

	int p = 0, argmx1, argmx2;
	double mx = 0;
	for (int i = 0; i <= f; i++)
		if (sugar[i])
		{
			while (!water[p] || i > p * e / 100)
			{
				if (i + p > f) break;
				p++;
			}
			if (i + p > f) break;
			if (1.0 * i / (i + p) > mx)
			{
				mx = 1.0 * i / (i + p);
				argmx1 = i + p, argmx2 = i;
			}
		}
	if (argmx1 == 0 && argmx2 == 0)
		argmx1 = a * 100;
	printf("%d %d\n", argmx1, argmx2);

	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;

void main() {
    auto x = readln.chomp.to!ulong;
    auto ans = x / 11;
    x -= ans * 11;
    ans *= 2;
    if (0 < x && x <= 6) ans += 1;
    else if (x > 6) ans += 2;
    writeln(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/

//=================================================
int N;
int D;
//=================================================
void input()
{
    cin>>N>>D;
}

//=================================================
void solve()
{
    int s = 0;
    int i;
    for (i = 1; ; ++i){
        s += (2*D) + 1;
        if (N <= s) break;
    }
    cout<<i<<endl;
}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  int x, t;
  cin >> x >> t;

  cout << max(0, x-t) << endl;

  return 0;
}

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

using namespace std;

const int N_ = 100500;

int N;
char S[N_];

bool ans[N_];

bool good() {
  for(int i = 2; i < N; i++) {
    if(ans[i-1]) {
      if(S[i-1] == 'o') ans[i] = ans[i-2];
      else ans[i] = !ans[i-2];
    }else {
      if(S[i-1] == 'x') ans[i] = ans[i-2];
      else ans[i] = !ans[i-2];
    }
  }

  for(int i = 0; i < N; i++) {
    int l = ans[(i+N-1)%N], r = ans[(i+1)%N];
    if(ans[i]) {
      if(l == r && S[i] == 'x') return false;
      if(l != r && S[i] == 'o') return false;
    }else {
      if(l == r && S[i] == 'o') return false;
      if(l != r && S[i] == 'x') return false;
    }
  }
  return true;
}

int main() {
#ifdef IN_MY_COMPUTER
  freopen("d.in", "r", stdin);
#endif

  scanf("%d%s", &N, S);

  for(int i = 1; i >= 0; i--) {
    for(int j = 1; j >= 0; j--) {
      ans[0] = i;
      ans[1] = j;
      if(good()) {
        for(int x = 0; x < N; x++) putchar(ans[x] ? 'S' : 'W');
        return 0;
      }
    }
  }

  puts("-1");
  return 0;
}

Measured memory_bytes: 512
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var com = Console.ReadLine();
		var c = com.ToArray();
		var N = c.Length;
		var I = G();
		var dx = new List<int>();
		var dy = new List<int>();
		Action<int,int> f = (d, l) => {
			if (d % 2 == 0) dx.Add(l);
			else dy.Add(l);
		};
		var dir = 0;
		var i = 0;
		while (i < N && c[i] == 'F') i++;
		I[0] -= i;
		while (i < N)
		{
			var l = 0;
			while (i < N && c[i] == 'F') { i++; l++; }
			if (l > 0) f(dir, l);
			while (i < N && c[i] == 'T') { i++; dir++; }
		}
		Console.WriteLine(Calc(dx, I[0]) && Calc(dy, I[1]) ? "Yes" : "No");
	}
	bool Calc(List<int> dx, int sum)
	{
		var s = new HashSet<int>{ 0 };
		foreach (var d in dx)
		{
			var t = new HashSet<int>();
			foreach (var x in s)
			{
				t.Add(x + d);
				t.Add(x - d);
			}
			s = t;
		}
		return s.Contains(sum);
	}
}


Measured memory_bytes: 35392
#include <stdio.h>

typedef long long ll;

ll mod=1000000007ll;

int main(){

	ll N,M;

	scanf("%lld %lld",&N,&M);

	ll i;

	ll ans=1ll;

	if(N==M){

		for(i=1ll;i<=N;i+=1ll){
			ans*=i;
			ans%=mod;
		}

		for(i=1ll;i<=M;i+=1ll){
			ans*=i;
			ans%=mod;
		}

		ans*=2;
		ans%=mod;
	}
	else{
		if(N>M){
			if(N-1==M){
				for(i=1ll;i<=N;i+=1ll){
					ans*=i;
					ans%=mod;
				}

				for(i=1ll;i<=M;i+=1ll){
					ans*=i;
					ans%=mod;
				}
			}
			else{ans=0ll;}
		}
		else{
			if(N==M-1){
				for(i=1ll;i<=N;i+=1ll){
					ans*=i;
					ans%=mod;
				}

				for(i=1ll;i<=M;i+=1ll){
					ans*=i;
					ans%=mod;
				}
			}
			else{ans=0ll;}
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc079_d():
    inp = iter(map(int, read().split()))
    H, W = next(inp), next(inp)
    adj_mtx = [[next(inp) for _ in range(10)] for _ in range(10)]
    grid = [[next(inp) for _ in range(W)] for _ in range(H)]

    import heapq
    def dijkstra(start, W):
        ''' スタート地点から到達可能なすべての頂点への最短距離を返す
            Pythonで学ぶアルゴリズムとデータ構造 P.111 一部変更
        '''
        # 仮の最短距離をinfに設定
        inf = 10**9
        distance_list = [inf] * len(W)
        # スタートの頂点だけ距離を0にする
        distance_list[start] = 0
        # 最短距離が確定した点
        done_list = []
        # 次に処理する頂点を決めるためのヒープ
        wait_heap = []
        for i, d in enumerate(distance_list):
            # (スタートからの距離, 頂点) のタプル
            heapq.heappush(wait_heap, (d, i))
        # ヒープが空になるまで処理を続ける
        while wait_heap:
            p = heapq.heappop(wait_heap)
            i = p[1]
            if i in done_list:
                continue
            # この時点でスタートからiへの距離が確定する
            done_list.append(i)
            # iに隣接するすべての頂点に対する処理
            for j, x in enumerate(W[i]):
                if x > -1 and j not in done_list:
                    # 緩和
                    d = min(distance_list[j], distance_list[i] + x)
                    distance_list[j] = d
                    # jへの仮の最短距離をdとしてヒープに追加
                    heapq.heappush(wait_heap, (d, j))
        return distance_list

    # 各点から1への距離(コスト)
    dist_to_1 = [None] * 10
    for i in range(10):
        dist_to_1[i] = dijkstra(i, adj_mtx)[1]

    # グリッドの数字が-1と1以外はコスト発生するため足していく
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == -1 or grid[i][j] == 1:
                continue
            ans += dist_to_1[grid[i][j]]
    print(ans)

abc079_d()

Measured memory_bytes: 5260
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int k;
  cin >> k;
  int x = 7%k;

  set<int> s;
  int cnt = 1;
  while(s.count(x) == 0){//同じ余りが存在したら，ループになる．
    if(x == 0){
      cout << cnt << endl;
      return 0;
    }
    s.insert(x);
    x = (x*10 + 7) % k;
    ++cnt;
  }

  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 50448
const input = require("fs").readFileSync("/dev/stdin", "utf8").split(/\n/);
const num = input[0].split(/\s/).map(Number);
const postCode = input[1].split("");

if (num[0] + num[1] + 1 != postCode.length) {
  console.log("No");
  return;
}

const n = postCode.filter((i) => i === "-");
if (n.length != 1) {
  console.log("No");
  return;
}

if (postCode.indexOf("-") != num[0]) {
  console.log("No");
  return;
}

console.log("Yes");

Measured memory_bytes: 7372
#!/usr/bin/env python3

N = int(input())
tf = [[] for _ in range(N)]
pl = []
for i in range(N):
    p = int(input())
    pl.append(p)
    for j in range(p):
        tf[i].append(list(map(int, input().split())))

ans = 0
import itertools
for flags in itertools.product([1, 0], repeat=N):
    f = True
    for i in range(N):
        for j in range(pl[i]):
            if flags[i] == 1:
                if flags[tf[i][j][0] - 1] != tf[i][j][1]:
                    f = False
            # elif flags[i] == 0:
            #     if flags[tf[i][j][0] - 1] == tf[i][j][1]:
            #         print(i)
            #         print(tf[i][j][0] - 1)
            #         print(flags)
            #         f = False
            if not f:
                break
        if not f:
            break
    if f:
        ans = max(sum(flags), ans)

print(ans)


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

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

    rep(i, n-k) {
        if(a[i] < a[k+i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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

int main(){
	string s;
	cin>>s;
	int MAX=0,acgt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
			acgt++;
		}else{
			MAX=max(MAX,acgt);
			acgt=0;
		}
	}
	MAX=max(MAX,acgt);
	cout<<MAX;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; ++i)
#define Forn(i, a) for(int i=1; i<=a; ++i)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, par[1000010], ranks[1000010], a, b, c, dist[1000010], all, newNode[1000010], q[500005], l, r;
vector<pi> e[1000010];
vi adj[1000010];
bool used[1000010];

inline int find(int x)
{
	return par[x]==x?x:par[x]=find(par[x]);
}

inline void unite(int x, int y)
{
	x=find(x), y=find(y);
	if(x==y)
		return;
	if(ranks[x]<ranks[y])
		par[x]=y;
	else
	{
		par[y]=x;
		if(ranks[x]==ranks[y])
			ranks[x]++;
	}
}

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		while(M--)
		{
			a=in(), b=in();
			e[in()].eb(mp(a, b));
		}
		all=N;
		Forn(i, 1000000)
		{
			if(!e[i].size())
				continue;
			int pa;
			foreach(it, e[i])
	        {
	            used[it->f]=used[it->s]=false,
	            newNode[it->f]=newNode[it->s]=-1,
	            ranks[it->f]=ranks[it->s]=0;
	            par[it->f]=it->f;
				par[it->s]=it->s;
	        }
			foreach(it, e[i])
				unite(it->f, it->s);
			foreach(it, e[i])
	        {
	            if(!used[it->f])
	            {
	                used[it->f]=true;
	                pa=find(it->f);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->f].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->f);
	            }
	            if(!used[it->s])
	            {
	                used[it->s]=true;
	                pa=find(it->s);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->s].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->s);
	            }
	        }
		}
		q[0]=1;
		l=0, r=1;
		memset(dist, -1, sizeof(dist));
		dist[1]=0;
		while(l<r)
		{
			int cur=q[l++];
			foreach(it, adj[cur])
				if(dist[*it]<0)
					dist[*it]=dist[cur]+1, q[r++]=*it;
		}
		if(dist[N]<0)
			puts("-1");
		else
			printf("%d\n", dist[N]>>1);
		forn(i, all+1)
	    {
	    	e[i].clear();
	    	adj[i].clear();
	    	used[i]=0;
	    	newNode[i]=0;
	    }
	}
	return 0;
}


Measured memory_bytes: 74624
using System;

class Program {
  static void Main(string[] args) {
    string[] s = Console.ReadLine().Split(' ');
    int a = int.Parse(s[0]);
    int b = int.Parse(s[1]);
    int c = int.Parse(s[2]);
    int d = int.Parse(s[3]);
  
    int max = System.Math.Min(b, d);
    int min = System.Math.Max(a, c);
    if (max - min > 0) {
      Console.WriteLine(max-min);
      return;
    }
    Console.WriteLine(0);
  }
}

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

const int INF = 1e9;

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

  list<pair<int, int> > all_edge;
  for (int i=0; i<M; i++) {
    int k,j;
    cin >> k>> j;
    all_edge.push_back(make_pair(k, j));
  }
  int numbers0[N-1];
  for (int i=2; i<N+1; i++) {
    numbers0[i-2] = i;
  }
  int ans = 0;
  do {
    int numbers[N];
    numbers[0] = 1;
    for (int i=1; i<N; i++) {
      numbers[i] = numbers0[i-1];
    }
    int i = 0;
    while (i<N-1) {
      int a = numbers[i];
      int b = numbers[i+1];
      if (numbers[i]<numbers[i+1]) {
        a = numbers[i];
        b = numbers[i+1];
      } else {
        b = numbers[i];
        a = numbers[i+1];
      }
      bool flag = false;
      for (pair<int, int> edge: all_edge) {
        if (edge.first == a && edge.second == b) {
          flag = true;
          break;
        }
      }
      if (flag) {
        ++i;
        continue;
      }
      break;
    }
    if (i == N-1) {
      ++ans;
    }
  } while(next_permutation(numbers0, numbers0+N-1));
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int head, tail;

typedef struct task {
    int rest;
    char name[10];
} Task;

Task tasks[100000];
int n, q;

void push(Task t) {
    tail = (tail + 1) % n;
    tasks[tail] = t;
};

Task pop() {
    Task t = tasks[head];
    head = (head + 1) % n;
    return t;
}

int main() {

    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> tasks[i].name >> tasks[i].rest;
    }

    head = 0;
    tail = n-1;
    int elapsed = 0;
    int complete = 0;

    while (1) {
        Task t = pop();
        if (t.rest - q > 0) {
            t.rest -= q;
            push(t);
            elapsed += q;
        } else {
            elapsed += t.rest;
            cout << t.name << " " << elapsed << endl;
            complete++;
            if(complete == n) {
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
typedef unsigned long long ull;
const int INF = 100000000;
const double EPS = 1e-8;
const ll MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  const ull B = 1000000007;
  int N, M;
  while(cin>>N>>M && N){
    string s; cin>>s;
    vector<ull> hash(s.size() + 1, 0);
    vector<ull> bpow(s.size() + 1, 1);
    for(int i = 0; i < N; i++){
      hash[i + 1] = hash[i] * B + s[i];
      bpow[i + 1] = bpow[i] * B;
    }
    int b = 0, e = 0;
    set<ull> h_set;
    REP(iter, M){
      string q;
      cin>>q;
      if(q == "R++"){
        e++;
      }else if(q == "R--"){
        e--;
      }else if(q == "L++"){
        b++;
      }else if(q == "L--"){
        b--;
      }
      ull h = hash[e + 1] - hash[b] * bpow[e - b + 1];
      //printf("%s s = %s h = %llu\n", q.c_str(), s.substr(b, e - b + 1).c_str(), h);
      h_set.insert(h);
    }
    cout<<h_set.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 20024
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n;
    cin >> n;
    int t[100001] = {}, x[100001] = {}, y[100001] = {};
    t[0] = x[0] = y[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    bool f = 1;
    for (int i = 0; i < n; i++) {
        if (abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i] )> t[i + 1] - t[i] || ((x[i + 1] - x[i]) + (y[i + 1] - y[i]) - (t[i + 1] - t[i])) % 2 != 0) f = 0;
    }
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 1408
#include <iostream>
#define int long long
using namespace std;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int p,r,q;
	cin >> p >> r >> q;
	cout << min(q+p,min(p+r,r+q));
	return 0;
}

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

class Dice{
public:
	int d[6];
	void MoveN();
	void MoveS();
	void MoveE();
	void MoveW();
	void Shift();
};

void Dice::MoveN(){
	swap(d[0],d[1]);
	swap(d[1],d[4]);
	swap(d[1],d[5]);
}
void Dice::MoveS(){
	swap(d[0],d[1]);
	swap(d[0],d[4]);
	swap(d[4],d[5]);
}
void Dice::MoveE(){
	swap(d[0],d[3]);
	swap(d[2],d[3]);
	swap(d[3],d[5]);
}
void Dice::MoveW(){
	swap(d[0],d[2]);
	swap(d[2],d[3]);
	swap(d[2],d[5]);
}
void Dice::Shift(){
	swap(d[1],d[2]);
	swap(d[3],d[4]);
	swap(d[1],d[4]);
}
int main(){
	Dice dc1,dc2;
	bool ans=false;
	for(int i=0;i<6;i++) cin>>dc1.d[i];
	for(int i=0;i<6;i++) cin>>dc2.d[i];
	for(int i=0;i<2;i++){
		for(int j=0;j<4;j++){
			dc2.MoveN();
			for(int k=0;k<4;k++){
				dc2.Shift();
				bool f=true;
				for(int l=0;l<6;l++){
					if(dc1.d[l]!=dc2.d[l]) f=false;
				}
				if(f) ans=true;
			}
		}
		dc2.MoveE();
	}
	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    priority_queue<ll> que;
    ll ans = 0;
    rep(i, N) {
        ll a = A[i];
        if (que.empty()) {
            que.push(a);
        }else {
            ll s = que.top();
            que.pop();
            que.push(a);
            que.push(a);
            ans += s;
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 6896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
int now = 0;

int main() {
	cin >> n;
	bool f = 1;
	rep(i, n) {
		string s;
		cin >> s;
		if (s == "A")now++;
		else now--;
		if (now < 0)f = 0;
	}
	if (now == 0 && f)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int,int>
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,b,a) for (int i=(b);i>=(a);--i)
typedef long long LL;
inline int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const int MAXN=100005;
int n,m,a[MAXN];
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	sort(a+1,a+1+n);
	int x=-1,y=-1;
	ROF(i,n-1,1)
	if (a[i]==a[i+1]) { x=i; break; }
	ROF(i,x-2,1)
	if (a[i]==a[i+1]) { y=a[i]; break; }
	if (y==-1) cout<<0<<endl;
	else cout<<1LL*a[x]*y<<endl;
	return 0;
}

/*
*/


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong();
            long y = in.nextLong();


            int ans = 1;
            long next = x * 2;

            while (next <= y) {
                ans++;
                next *= 2;
            }

            out.print(ans);


        }

    }
}



Measured memory_bytes: 22868
Q = 1000000007
n, m = map(int, input().split())
a = set(int(input()) for _ in range(m))
dp = {
    0: 1,
    1: 0 if 1 in a else 1,
}

for k in range(2, n + 1):
    dp[k] = (0 if k in a else (dp[k - 1] + dp[k - 2])) % Q

print(dp[n])


Measured memory_bytes: 25320
package main

import "fmt"

type infant struct{
	value int
	pos int
}

func printdp(dp []int, n int) {
	for i:=0 ; i<n; i++ {
		for j:=0 ; j<n ; j++ {
			fmt.Printf("%v ",dp[i*n+j])
		}
		fmt.Println("")
	}
}

func returnhappy(sort []infant, num int, n int, turn int) int { // turn 0:up, 1:left
	if num < n {
		return sort[num-1].value*(sort[num-1].pos-(num-1))
	} else if num%n == 0 {
		return sort[num/n-1].value*((n-1-num/n)-sort[num/n-1].pos)
	} else if turn == 0{
		i := int(num/n)
		j := int(num%n)
		return sort[i+j-1].value*((n-1-i)-sort[i+j-1].pos)
	} else {
		i := int(num/n)
		j := int(num%n)
		return sort[i+j-1].value*(sort[i+j-1].pos-(j-1))
	}
}

func dynamic(n int, sort []infant) int { // n = len(a)+1
	dp := make([]int,n*n) //dp(i,j) = dp[i*n+j]
	dp[0] = 0
	for i:=1 ; i<n-1; i++ {
		dp[i] = dp[i-1] + returnhappy(sort,i,n,1)
		dp[i*n] = dp[(i-1)*n] + returnhappy(sort,i*n,n,0)
	}
//printdp(dp,n)
	max := 0
	for i:=1 ; i<n-1 ; i++ {
		for j:=1 ; i+j < n ; j++ {
			//dp(i,j)
			temp_up := dp[(i-1)*n+j] + returnhappy(sort,i*n+j,n,0)
			temp_left := dp[i*n+j-1] + returnhappy(sort,i*n+j,n,1)
			if temp_up <= temp_left {
				dp[i*n+j] = temp_left
			} else {
				dp[i*n+j] = temp_up
			}
			if i+j == n-1 {
				if max < dp[i*n+j] {
					max = dp[i*n+j]
				}
			}
		}
//printdp(dp,n)
	}
	return max
}


func slide (sort []infant, x infant, p int) []infant {
//fmt.Println("slide")
//fmt.Println(sort,x,p)
	a := x
	b := sort[p]
	for i:=p ; i<len(sort) ;i++ {
		sort[i] = a
		if i != len(sort)-1 {
			a = b
			b = sort[i+1]
		}
	}
//fmt.Println(sort)
//fmt.Println("slide finish")
	return sort
}

func sorted(sort []infant, x infant) []infant {
	for i:=0 ; i<=x.pos ; i++ {
		if sort[i].value <= x.value {
			return slide(sort,x,i)
		}
	}
	sort[x.pos+1] = x
	return sort
}

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]infant,n)
	sort := make([]infant,n)
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&a[i].value)
		a[i].pos = i
		sort = sorted(sort,a[i])
//fmt.Println(sort)
	}
//fmt.Println(sort)
	ans := dynamic(n+1,sort)
	fmt.Println(ans)
}


Measured memory_bytes: 25848
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>d;
    int ret = 0;
    if(a>b){
        ret += b;
    }else{
        ret += a;
    }
    
    if(c>d){
        ret += d;
    }
    else{
        ret += c;
    }
    
    cout<<ret<<endl;
    return 0;
}

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

using namespace std;

int main(void)
{

	int N, K;

	cin >> N;
	cin >> K;
	if (K % 100 == 0)
	{
		K += 1;
	}
	if (N == 0)
	{	
		cout << K;
	}
	if (N == 1)
	{
		cout << K * 100;
	}
	if (N == 2)
	{
		cout << K * 10000;
	}

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
    public static void main(String [] args) {
        Solver s = new Solver();
        s.solve();
    }
}

class Solver {
    Reader in = new Reader ();
    Writer out = new Writer ();

    void solve () {
        long a = in.nextLong();
        long b = in.nextLong();
        System.out.println((a + b - 1) / b);
    }
}

class Reader {
    private StringTokenizer a;
    private BufferedReader b;
    Reader () {
        a = null;
        try {
            b = new BufferedReader (new InputStreamReader (System.in)); // for file IO, replace this with new FileReader ("in.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String next () {
        while(a == null || !a.hasMoreTokens()) {
            try {
                a = new StringTokenizer (b.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(this.next());
    }
    public long nextLong () {
        return Long.parseLong(this.next());
    }
    public double nextDouble () {
        return Double.parseDouble(this.next());
    }
    public String nextLine() {
        try {
            return b.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
class Writer {
    private PrintWriter a;
    private StringBuffer b;
    Writer () {
        try {
            a = new PrintWriter (System.out); // for file IO, replace this with new FileWriter ("out.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
        b = new StringBuffer ("");
    }
    public void write (Object s) {
        b.append(s);
    }
    public void writeln(Object s) {
        b.append(s).append('\n');
    }
    public void flush () {
        a.print(b);
        a.flush();
        a.close();
    }
}


Measured memory_bytes: 22100
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
long a=scan.nextInt();
long b=1;
long i=1;
do {

b=b%1000000007;
	if(i==a+1) {break;}
	b=b*i;
	i++;
}while(true);
System.out.println(b);
}
}

Measured memory_bytes: 21460
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  cout<<(100000-n)%1000<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;
P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

int main(){
	while(1){
		int n,d;
		cin >> n >> d;
		if(n == 0) break;

		P lw(-d,0), rw(d,0);
		for(int i=0; i<n; i++){
			double l,r,t;
			cin >> l >> r >> t;
			if(l == r){
				P dir = unit(rw-lw) *P(0,1) *(l*t *PI/180);
				lw += dir;
				rw += dir;
			}else{
				P c;
				int sign;
				if((l>=0) == (r>=0)){
					c = (-abs(r)*lw +abs(l)*rw) / (abs(l) -abs(r));
					sign = ((abs(lw-c)<abs(rw-c)) == (l>=0))? 1: -1;
				}else{
					c = (abs(r)*lw +abs(l)*rw) / (abs(l) +abs(r));
					sign = (l<0)? 1: -1;
				}
				double angle = sign *abs(l)*t/abs(lw-c) *(PI/180);
				if(abs(lw-c) < EPS){
					angle = sign *abs(r)*t/abs(rw-c) *(PI/180);
				}
				lw = c +rotate(lw-c, angle);
				rw = c +rotate(rw-c, angle);
			}
		}
		P mid = (lw +rw) /2.0;
		cout << fixed << setprecision(5);
		cout << mid.X << endl;
		cout << mid.Y << endl;
	}
	return 0;
}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
int n,m,r[2003][2003],d[2003][2003],ans;
char str[2003][2003];
int main(){
    int i,j;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%s",str[i]+1);
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(str[i][j]=='.'){
                r[i][j]=r[i][j-1]+1;
                d[i][j]=d[i-1][j]+1;
            }
            else r[i][j]=d[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        for(j=m;j>=1;j--){
            if(r[i][j]) r[i][j]=max(r[i][j+1],r[i][j]);
        }
    }
    for(i=n;i>=1;i--){
        for(j=1;j<=m;j++){
            if(d[i][j]) d[i][j]=max(d[i+1][j],d[i][j]);
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            ans=max(ans,d[i][j]+r[i][j]);
        }
    }
    printf("%d",ans-1);
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

vector<int> v(pow(2,18)+1,0),w(pow(2,18)+1,0);
vector<vector<int>> dp(512,vector<int>(1e5+1,0));

int dfs(int V,int W,int C){
  if(W<0){
    return 0;
  }
  if(V<512){
    return dp[V][W]+C;
  }
  int s=dfs(V/2,W-w[V],C+v[V]),t=dfs(V/2,W,C);
  return max(s,t);
}

int main() {
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> v[i+1] >> w[i+1];
  }
  dp[1][w[1]]=v[1];
  for(int i=1;i<min(N+1,512);i++){
    for(int j=1;j<1e5+1;j++){
      if(i==1&&j==w[1]){
        continue;
      }
      if(j>=w[i]){
        dp[i][j]=max(dp[i/2][j],dp[i/2][j-w[i]]+v[i]);
      }
      else{
        dp[i][j]=dp[i/2][j];
      }
    }
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int V,W;
    cin >> V >> W;
    cout << dfs(V,W,0) << endl;
  }
}

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    ll ans=0;
    ll h,w;
    cin >> h >> w;
    ans = (h*w)/2 + (h*w)%2;
    if(h == 1 || w == 1) ans=1;
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll u500 = 0;
    u500 = x / 500;
    x %= 500;
    ll u5 = 0;
    u5 = x / 5;
    x %= 5;
    ll u1 = 0;
    u1 = x;
    cout << u500 * 1000 + u5 * 5 << endl;
}

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

int main() {
    long long n, ret = 0, tmp;
    std::cin >> n;
    for (auto i = 0ll; i < n; i++) {
        std::cin >> tmp;
        ret += tmp - 1;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

vector<vector<int> > G;
int N, M;

int main() {
    while (cin >> N >> M) {
        G.clear(); G.resize(N);
        int a = -1, b = -1;
        for (int i = 0; i < M; ++i) {
            cin >> a >> b;
            --a, --b;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        
        vector<bool> used(N, 0);
        deque<int> res;
        res.push_back(a);
        res.push_back(b);
        used[a] = true;
        used[b] = true;
        
        int s = a;
        while (true) {
            bool exist = false;
            for (auto e : G[s]) {
                if (used[e]) continue;
                else {
                    exist = true;
                    res.push_front(e);
                    s = e;
                    used[e] = true;
                    break;
                }
            }
            if (!exist) break;
        }
        int t = b;
        while (true) {
            bool exist = false;
            for (auto e : G[t]) {
                if (used[e]) continue;
                else {
                    exist = true;
                    res.push_back(e);
                    t = e;
                    used[e] = true;
                    break;
                }
            }
            if (!exist) break;
        }
        
        
        cout << res.size() << endl;
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i] + 1;
            if (i != (int)res.size() - 1) cout << " ";
        }
        cout << endl;
    }
}










Measured memory_bytes: 6656
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;

int main(){
    char c;
    int cnt=0;
    
    for(int i=0; i<3; i++) {
        cin >> c;
        if(c == '1') cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256