akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		//String s = sc.next();
		/*
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);*/
		int[] x = new int[n];


		for(int i=0;i<n;i++) {
			x[i] = sc.nextInt();
		}

		//boolean flag = true;
		int currentBest = 300000000;

		for(int i=0;i<n-k+1;i++) {
			if(x[i+k-1]<=0) {
				if(currentBest>Math.abs(x[i])) {
					currentBest = Math.abs(x[i]);
				}
			}else {
				if(x[i]>=0) {
					if(currentBest>Math.abs(x[i+k-1])) {
						currentBest = Math.abs(x[i+k-1]);
					}
				}else {
					int a = Math.max(Math.abs(x[i]), Math.abs(x[i+k-1]));
					a += Math.min(Math.abs(x[i]), Math.abs(x[i+k-1]))*2;
					if(currentBest>a) {
						currentBest = a;
					}
				}
			}



		}
		System.out.println(currentBest);
	}
	/*
	static boolean check(int t,int x,int y) {
		if(Math.abs(x)+Math.abs(y)>t)return false;
		if((Math.abs(x)+Math.abs(y)-t)%2==0) {
			return true;
		}else {
			return false;
		}

	}
	*/
}

Measured memory_bytes: 48756
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#define INF (1LL << 60)
using namespace std;
bool used[200000]; long long dist[200000];
void dijkstra(int V, int E, int s, vector<pair<int, long long> > X[]) {
	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q;
	for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
	dist[s] = 0; Q.push(make_pair(0, s));
	int cnt = 0;
	while (!Q.empty()) {
		if (cnt > E) return;
		pair<long long, int> p = Q.top(); used[p.second] = true; Q.pop();
		for (int i = 0; i < X[p.second].size(); i++) {
			int to = X[p.second][i].first; long long leng = X[p.second][i].second;
			if (dist[to] > dist[p.second] + leng && !used[to]) {
				dist[to] = dist[p.second] + leng;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
}
int V, E, a, b, c, d, f1, f2, g1, g2; vector<pair<int, long long> > G[200000];
int main() {
	scanf("%d%d", &V, &E);
	for(int i = 0; i < E; i++) {
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		G[a - 1].push_back(make_pair(b - 1, c));
		G[b - 1].push_back(make_pair(a - 1, d));
	}
	scanf("%d,%d,%d,%d", &f1, &f2, &g1, &g2); g1 -= g2;
	dijkstra(V, E, f1 - 1, G); g1 -= dist[f2 - 1];
	dijkstra(V, E, f2 - 1, G); g1 -= dist[f1 - 1];
	printf("%d\n", g1);
}

Measured memory_bytes: 7288
#include<bits/stdc++.h>
using namespace std;
char a[5]={'a','e','i','o','u'};
int main(){
    char c;
    cin>>c;
    for(int i=0;i<5;i++)
    {
        if(c==a[i])
        {
            cout<<"vowel"<<endl;
            return 0;
        }
    }
    cout<<"consonant"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    map<int, long> v;
    int buf = 0;
    for(int i = n-1; i >= 0;){
        int buf1 = a[i];
        while(buf1 == a[i] && i >= 0){
            buf++;
            i--;
        }
        if(i < 0){
            v[buf] = buf1;
        }else{
            v[buf] = buf1-a[i];
        }
    }
    int tmp = 0;
    for(auto e: v){
//        cout << e.first << " " << e.second << endl;
        if(e.second % 2 != 0) {
            tmp = e.first;
        }
    }
    if(tmp != 0){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }
    return 0;
}


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

int main () {
    int n, k, q;
    std::cin >> n >> k >> q;
    std::vector<int> a(q),b(n, k - q);
    for(int i = 0; i < q; ++i) {
        std::cin >> a[i];
        ++b[a[i] - 1];
    }
    for(int i = 0; i < n; ++i) {
        if(b[i] > 0) std::cout << "Yes" << std::endl;
        else std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 1408
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N;
    scan(N);
    auto d = readln.split.to!(int[]);
    int ans;
    foreach (i ; 0 .. N){
        foreach (j ; i + 1 .. N) {
            ans += d[i] * d[j];
        }
    }
    writeln(ans);
}






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

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<ll, ll> P;
int main() {
	ll x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	int N;
	cin >> N;
	vector<P> pos;
	for (int i = 0; i < N; i++) {
		ll X, Y;
		cin >> X >> Y;
		if (x1 > X || X > x2) continue;
		if (y1 <= y2) {
			if (y1 > Y || Y > y2) continue;
			pos.emplace_back(X, Y);
		}
		else {
			if (y2 > Y || Y > y1) continue;
			pos.emplace_back(X, -Y);
		}
	}
	sort(pos.begin(), pos.end());
	int n = pos.size();
	vector<int> dp(n);
	fill(dp.begin(), dp.end(), 1 << 30);
	for (int i = 0; i < n; i++) {
		*lower_bound(dp.begin(), dp.end(), pos[i].second) = pos[i].second;
	}
	int cnt = lower_bound(dp.begin(), dp.end(), 1 << 30) - dp.begin();
	double ans = (abs(x2 - x1) + abs(y2 - y1)) * 100;
	if (cnt == min(abs(x1 - x2), abs(y1 - y2)) + 1) {
		ans += (5 * PI - 20)*(cnt - 1) + (10 * PI - 20);
	}
	else {
		ans += (5 * PI - 20)*cnt;
	}
	printf("%.15lf\n", ans);
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int a,b,res=0; cin>>a>>b;
 res=max(max(a+b,a-b),a*b);

 cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
vector<ll> paths[205000];
vector<ll> children[205000];
ll parent[205000];
ll SIZE[205000];
ll N;
ll ans;

void dfs(int now) {
    SIZE[now] = 1;
    for(auto to : paths[now]) {
        if(to == parent[now]) continue;
        parent[to] = now;
        children[now].push_back(to);
        dfs(to);
        SIZE[now] += SIZE[to];
    }
}

ll beki(ll a, ll b) {
    if(b == 0) return 1 % mod;
    ll ret = beki(a, b / 2);
    ret = ret * ret % mod;
    if(b & 1) ret = ret * a % mod;
    return ret;
}

ll inv(ll a) {
    return beki(a, mod - 2);
}

void f(int now) {
    for(auto to : children[now]) f(to);
    vector<ll> v;
    for(auto to : children[now]) {
        v.push_back(SIZE[to]);
    }
    if(parent[now] != 0) {
        v.push_back(N - SIZE[now]);
    }
    ll val = 0;
    //cerr << "---" << now << "---" << endl;
    for(auto a : v) {
        //cerr << a << endl;
        val += beki(2, a);
    }
    val -= v.size() - 1;
    val = beki(2, N - 1) - val;
    val %= mod;
    val += mod;
    val %= mod;
    //cerr << val << endl;
    ans += val;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }
    dfs(1);
    f(1);
    ans %= mod;
    cout << (ans * beki(inv(2), N)) % mod << endl;
    return 0;
}


Measured memory_bytes: 38656
x, k, d = map(int, input().split())
x = abs(x)
div, mod = divmod(x, d)
c = div - k
if c == 0:
    ans = mod
elif c > 0:
    ans = x - d * k
else:
    if c%2 == 1: ans = d - mod
    else: ans = mod
print(ans)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

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

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    REP(i, tx-sx){
        cout << 'R';
    }
    REP(i, ty-sy){
        cout << 'U';
    }
    REP(i, tx-sx){
        cout << 'L';
    }
    REP(i, ty-sy){
        cout << 'D';
    }
    cout<<'D';
    REP(i, tx-sx+1){
        cout << 'R';
    }
    REP(i, ty-sy+1){
        cout << 'U';
    }
    cout << 'L';
    cout << 'U';
    REP(i, tx-sx+1){
        cout << 'L';
    }
    REP(i, ty-sy+1){
        cout << 'D';
    }
    cout << 'R' << endl;
    return 0;
}



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}



use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
        r:usize,
        d:usize,
        x:usize
    }

    let mut x_2000 = x;

    for i in 0..10 {
        println!("{}", r * x_2000 - d);
        x_2000 =  r * x_2000 - d;
        
    }
}



Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<string.h>
typedef long long int ll;
using namespace std;
struct  node{ int x,y;
}k;
queue<node> q;
const int MAX=105;
int d[4][2]={0,1,1,0,-1,0,0,-1};
int vis[MAX][MAX];
char s[MAX][MAX];
int n,m,ss=0;
void bfs(int x,int y)
{   int i;
   memset(vis,-1,sizeof(vis));
	q.push({x,y});
	vis[x][y]=0;
	while(!q.empty())
	{   k=q.front();
	    q.pop();
	    if(ss<vis[k.x][k.y])
				ss=vis[k.x][k.y];
		for(i=0;i<4;i++)
		{    
			int xx=k.x+d[i][0];
			int yy=k.y+d[i][1];
			if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]!='#'&&vis[xx][yy]==-1)
			{
				vis[xx][yy]=vis[k.x][k.y]+1;
				q.push({xx,yy});
			}
		}
	}
}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	cin>>s[i];
	for(i=0;i<n;i++)
	for(j=0;j<m;j++)
	{
		if(s[i][j]=='.')
		bfs(i,j);
	}
	printf("%d\n",ss);
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
row = 1
aim = A[0]
ans = 0
for i in range(1, N):
    if A[i] == aim:
        row += 1
    else:
        ans += row//2
        row = 1
        aim = A[i]
print(str(ans + row//2))

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    b+=60*a;
    d+=60*c;
    if(b<=d){
        cout<<d-b-e<<endl;
    }
    else{
        cout<<60*24+(d-b)-e<<endl;
    }
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7816
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Around Square
	var N int
	fmt.Scanf("%d", &N)

	for i := N; i > 0; i-- {
		if math.Round(math.Sqrt(float64(i))) == math.Sqrt(float64(i)) {
			fmt.Println(i)
			break
		}
	}
}


Measured memory_bytes: 1836
#include<iostream>
using namespace std;
int main() 
{
  unsigned long int h,n;
  cin>>h;
  cin>>n;
  unsigned long int i=0,a,sum=0;
  for(i=0;i<n;i++){
  	cin>>a;
    sum=sum+a;
  }
  if(sum>=h){
    cout<<"Yes";
  }
  else{
  	cout<<"No";
  }
    return 0; 
}  

Measured memory_bytes: 256
A, B = map(int, input().split())
LA, LB = [], []
i = 1
if A == 0:
  A += 1
while (A-1) // i != 0 or B // i != 0:
  if (A-1)%(2*i) >= i:
    LA.append(i*((A-1)//(2*i)) + (A-1) % (2*i) - i + 1)
  else:
    LA.append(i*((A-1)//(2*i)))
  if B%(2*i) >= i:
    LB.append(i*(B//(2*i)) + B % (2*i) - i + 1)
  else:
    LB.append(i*(B//(2*i)))
  i *= 2
S = 0
m = 1
for i in range(len(LA)):
  S += m * ((LB[i] - LA[i]) % 2)
  m *= 2
print(S)

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


int GCD(int x, int y) {
  int w = x;
  int r = y;
  while(r) {
    int c = w%r;
    w = r;
    r = c;
    
    if (r == 0) {
      return w;
    }
  }
}
    
int main() {
  ll A, B;
  cin >> A >> B;
  
  ll G = GCD(A, B);
  ll X = A * B;
  ll L = X / G;
  
  cout << L << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;


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

    int l = L;
    int r = l + (N - 1);
    int eat = 0;

    //cout  << "l:" << l << "r:" << r << endl;

    if(0 < l){
        eat = l;
    } else if(r < 0){
        eat = r;
    }else{
        eat = 0;
    }

    int ans = (r + l)*(N)/2 - eat;

    cout << ans << endl;

}


Measured memory_bytes: 256
def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    Reval = {}
    Geval = {}
    Beval = {}
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            Reval[2*i] = 2*i
        elif S[i] == "G":
            G.append(i)
            Geval[2*i] = 2*i
        elif S[i] == "B":
            B.append(i)
            Beval[2*i] = 2*i
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if (a + b) in Beval:
                count -= 1
    for a in G:
        for b in B:
            if (a + b) in Reval:
                count -= 1
    for a in B:
        for b in R:
            if (a + b) in Geval:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()


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

using namespace std;

const int N = 10;
int n, m, edge[N][N];
vector<int> a;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        edge[a][b] = 1;
        edge[b][a] = 1;
    }

    int cnt = 0;
    for(int i = 2; i <= n; i++){
        a.push_back(i);
    }
    do {
        int cur = 1;
        bool can = true;
        for(auto x : a){
            if(!edge[cur][x]){
                can = false;
            }
            cur = x;
        }
        if(can){
            cnt++;
        }
    } while(next_permutation(a.begin(), a.end()));
    cout << cnt << '\n';
    return 0;
}

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

int main(){
	int k,a,b;
	scanf("%d%d%d",&k,&a,&b);
	if(a>=b-2||a+1>k)printf("%d\n",k+1);
	else printf("%lld\n",max(k+1ll,a+1ll*(k-(a-1))/2*(b-a)+(k-(a-1))%2));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
 
const int MAX_N = 1<<18;
 
int A[MAX_N];
 
int main(){
    int N;
    cin>>N;
    for(int i=0;i<(1<<N);i++){
        cin>>A[i];
    }
    int d=1;
    while(true){
        for(int i=0;i<(1<<N);i+=2*d){
            if(A[i]<A[i+d]){
                A[i]=A[i+d]-A[i];
            }else if(A[i]>A[i+d]){
                A[i]=A[i]-A[i+d];
            }else{
                A[i]=A[i];
            }
        }
        d*=2;
        if(d==(1<<N)) break;
    }
    cout<<A[0]<<endl;
}

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

#define ll long long
#define M 1000000007
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
	 ll n,m,k,a,b;
    cin>>n>>k;
    long long sum=0,prod=1;
    for( ll i=k;i<=1+n;i++)
    {
        sum=(sum+((i*(n-i+1)+1))%1000000007)%1000000007;
    }
    cout<<sum;
    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t gcd(int64_t x, int64_t y) {
    if (x > y) {
        swap(x, y);
    }

    if (x == 0) {
        return y;
    }

    return gcd(y % x, x);
}

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<int64_t> a(n);
    for (auto i : irange(0L, n)) {
        cin >> a[i];
    }

    int64_t lcm = 1;
    for (auto i : irange(0L, n)) {
        auto g = gcd(lcm, a[i] / 2);
        lcm *= (a[i] / 2) / g;

        if (lcm > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    for (auto i : irange(0L, n)) {
        if (lcm / (a[i] / 2) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << m / lcm - m / (2 * lcm) << endl;
}

Measured memory_bytes: 1024
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

// ll N, M, K, Q, i, j, k, l, tmp, ans;

int main(){
    int N, M, ans = 0;
    cin >> N >> M;
    // 標高保持 H , MAiはその展望台から行ける展望台の標高の最大値を保持する
    vector<int> H(N, 0), MA(N, 0);
    // 標高を格納
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    // A, B を受け取り、標高の最大値MAを更新する
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        A--; B--;
        // A側、B側それぞれお互いの標高が高ければ自分自身を更新する
        MA[A] = max(MA[A], H[B]);
        MA[B] = max(MA[B], H[A]);
    }

    for(int i = 0; i < N; i++){
        ans += H[i] > MA[i];
    }

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

Measured memory_bytes: 3992
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#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++)

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

typedef long long ll;

#define MAX_N 10000
#define ORD_MONEY 1000000000000000

struct Edge {
    int from;
    int to;
    ll cost;
    Edge(int f, int t, ll c)
        : from(f)
        , to(t)
        , cost(c)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P; // first:最短距離，second:頂点番号

typedef pair<ll, ll> P_dij;

ll dijkstra(int s, int g, Graph_e G)
{
    ll d[110];
    fill(d, d + 110, INF_64);
    d[s] = 0;

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first)
            continue;
        for (auto e : G.at(v)) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

    if (d[g] != INF_64) {
        return d[g];
    } else {
        return -1;
    }
}

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

    vector<Edge> edge;
    vector<ll> d(N, INF_64);
    vector<bool> negative(N, false);
    d.at(0) = 0;

    rep(i, M)
    {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        edge.push_back(Edge(a, b, -c));
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            Edge e = edge.at(j);

            if (d.at(e.to) > d.at(e.from) + e.cost) {
                d.at(e.to) = d.at(e.from) + e.cost;
                if (i == N - 1) {
                    negative.at(e.to) = true;
                }
            }
        }
    }

    rep(i, M)
    {
        if (negative.at(edge.at(i).from) == true) {
            negative.at(edge.at(i).to) = true;
        }
    }

    if (negative.at(N - 1)) {
        cout << "inf" << endl;
    } else {
        cout << -d.at(N - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <utility>
#include <map>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
vector<ll> a;
const ll INF = 1e16;

int main()
{
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int cnt=1;
    for(int i=1;i<n;i++)
    {
        bool can=true;
        for(int j=0;j<i;j++)
        {
            if(h[j]>h[i])
                can=false;
        }
        if(can==true)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    using ll = long long int;
    ll arr[2010] = {};
     
    int main(void){
    ll n,z,w;
    cin >> n >> z >> w;
    arr[0] = w; 
    for(int i = 1; i <= n; i++)
    cin >> arr[i];
    
    cout << max(abs(arr[n]-w),abs(arr[n-1] - arr[n])) << endl;
    }

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int h,w;
  cin >> h >> w;
  int n;
  cin >> n;
  vvi mp(h,vi(w));
  int a;
  vi b;
  REP(i,n){
    cin >> a;
    REP(j,a) b.eb(i+1);
  }
  REP(i,h)REP(j,w){
    if(i%2==0) mp[i][j] = b[i*w+j];
    else mp[i][w-j-1] = b[i*w+j];
  }
  REP(i,h){
    REP(j,w){
      cout << mp[i][j];
      if(j!=w-1) cout << " ";
    }
    cout << endl;
  }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[105][101010];
ll S[101011];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 105)REP(j, 101010) dp[i][j] = 0;
    dp[0][0] = 1;

    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    REP(i, N){
    	S[0] = 0;
    	REP(j, 101010){
    		S[j+1] = S[j] + dp[i][j];
    		S[j+1] %= mod;
    	}
    	REP(j, 101010){
    		ll lb = max(0ll, j-a[i]);
    		ll add = (S[j+1] - S[lb] + mod)%mod;
    		dp[i+1][j] += add;
    		dp[i+1][j] %= mod;
    	}
    }
    cout << dp[N][K] << endl;
    return 0;
}

Measured memory_bytes: 83968
#include <iostream>
#include <string>
#include <cstring>
int dp[4001][4001];
using namespace std;
int main(){
  string s,str;
  int ans;
  while(cin >> s >> str){
    ans = 0;
    memset(dp,0,sizeof(dp));
    for(int i=0,l=s.size();i<l;i++){
      for(int j=0,ll=str.size();j<ll;j++){
        if(s[i] == str[j]){
          dp[i+1][j+1] = dp[i][j]+1;
          ans = max(ans,dp[i+1][j+1]);
        }else dp[i+1][j+1] = 0;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 63748
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

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

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int u[10001];
int o[10001];
int root(int s){
  while(o[s]>=0)
    s=o[s];
  return u[s];
}

void merge(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y)return;
  o[x]=y;
}
int main(){
  int n,q;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    u[i]=i;
    o[i]=-1;
  }
  for(int i=0;i<q;i++){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      if(root(x)==root(y))
	cout<<1<<endl;
      else
	cout<<0<<endl;
    }else{
merge(x,y);
    }
  }
  return 0;
}

Measured memory_bytes: 3148
// file creato da gio il 2020-04-07 18:40:06.953635

#include <bits/stdc++.h>
#define FAST 

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int main(){
	//freopen("output","w",stdout);
	//freopen("input","r",stdin);
#ifdef FAST
	ios::sync_with_stdio(0);
  	cin.tie(0);
#endif

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

	cout <<c<<" "<<a<<" "<<b;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
using namespace std;
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){return x+y-min(x,y);}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
//ARC098
bool color[10000];//white=true,black=false
int main()
{
    long long n;
    cin>>n;
    long long a[n],cnt[21];
    rep(i,n)
    {
        cin>>a[i];
    }
    rep(i,21)
    {
        cnt[i]=0;
    }
    long long  fl=0,fl2=0,val,ans=0,last=0;
    bool flag=-1;
    rep(i,n)
    {
        val=a[i];
        rep(j,21)
        {
            if(val%2==1)
            {
                if(cnt[j]==1)
                {
                    fl2++;
                }
                cnt[j]++;
            }
            else{}
            val=val/2;
        }
        if(fl2!=0)
        {
            if(last-fl>=2)
            {
                ans-=((last-fl)*(last-fl-1))/2;
            }
            ans+=((i-fl)*(i-fl-1))/2;
            while(fl2!=0)
            {
                val=a[fl];
                rep(j,21)
                {
                    if(val%2==1)
                    {
                        if(cnt[j]==2)
                        {
                            fl2--;
                        }
                        cnt[j]--;
                    }
                    else{}
                    val=val/2;
                }
                fl++;
            }
            last=i;
        }
    }
    if(last-fl>=2)
    {
        ans-=((last-fl)*(last-fl-1))/2;
    }
    ans+=((n-fl-1)*(n-fl))/2+n;
    W(ans)
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll calc (ll x) {
  if (x <= 0) return 0;
  // 4のときに、0,1,2,3,4までになるので、これは5つの整数まで
  // なので帳尻合わせで1を足す
  x++;
  // 10^3 < 2^10
  // 1000 < 1024
  // 10^12 < 2^40
  // 10^12 < 2進数40桁くらい

  ll res = 0;
  // i桁目の偶奇を調べる
  rep(i,50) {
    // 0桁目 -> 周期2
    // 1桁目 -> 周期4
    // 2桁目 -> 周期8
    ll loop = (1LL<<(i+1));
    // cnt = (何loopしたか)*(1loopあたりの1の個数は半分)
    ll cnt = (x/loop)*(loop/2);
    // 00000.....0011111.....11
    // 残りを足す
    cnt += max(0LL, (x%loop)-(loop/2));

    // その桁の1の数が奇数だったら足し算
    if (cnt%2 == 1) {
      res += 1LL << i;
    }
  }
  return res;
}

int main () {
  ll a, b;
  cin >> a >> b;
  ll ans = calc(b)^calc(a-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main(){
	int n;
	cin >> n;
	cout << n / 3 << endl;

 	return 0;
}



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

char s[1000][1000];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int c1[1000000],c2[1000000];
int main(){
	int h,w;cin>>h>>w;
	rep(i,h)cin>>s[i];
	UnionFind uf(h*w);
	rep(i,h)rep(j,w){
		rep(k,4){
			int nx=i+dx[k],ny=j+dy[k];
			if(0<=nx&&nx<h&&0<=ny&&ny<w){
				if(s[i][j]=='#'&&s[nx][ny]=='.'){
					uf.unite(i*w+j,nx*w+ny);
				}
			}
		}
	}
	rep(i,h)rep(j,w){
		if(s[i][j]=='.'){
			c1[uf.find(i*w+j)]++;
		}
		else{
			c2[uf.find(i*w+j)]++;
		}
	}
	ll ans=0;
	rep(i,h)rep(j,w){
		ans+=c1[i*w+j]*(ll)c2[i*w+j];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;

ll ksm(ll x,ll y)
{
    ll ans=1;
    for(;y;x=(x*x)%mod,y>>=1) if(y&1) ans=(ans*x)%mod;
    return ans;
}

ll getcs(ll n,ll m)
{
    if(m==0||n==m) return 1;
    if(n<m) return 0;
    if(m>n-m) m=n-m;
    ll s1=1,s2=1;
    for(int i=0;i<m;i++)
    {
        s1=s1*(n-i)%mod;
        s2=s2*(i+1)%mod;
    }
    return s1*ksm(s2,mod-2)%mod;
}
ll lucas(ll n,ll m)
{
    if(m==0) return 1;
    return getcs(n%mod,m%mod)*lucas(n/mod,m/mod)%mod;
}
int main()
{
    ios::sync_with_stdio(false);
    ll n,a,b;cin>>n>>a>>b;
    ll reu=ksm(2,n)-lucas(n,a)-lucas(n,b)-1;
    while(reu<0)
        reu+=mod;

    cout<<reu<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	set<int>st;
	int s,i=0;
	cin>>s;
	while(++i)
	{
		st.insert(s);
		if(st.size()<i)
		{
			cout<<i;
			return 0;
		}
		if(s%2)
		s=s*3+1;
		else
		s/=2;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号  (例) par[3] = 2 : 3の親が2
    vector<ll> rank; // 木の深さ

    UnionFind(ll N) : par(N), rank(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        x = root(x);
        y = root(y);
        if (x == y) return; //xとyの根が同じ(=同じ木にある)時はそのまま

        if(rank[x] < rank[y]){
            par[x] = y;
        }
        else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(void)
{
    ll N, K, L, i, p[100001], q[100001], r[100001], s[100001];

    cin >> N >> K >> L;

    UnionFind road(N+1), rail(N+1);

    map<pair<ll,ll>, ll> mp;

    for(i=1; i<=K; i++){
        cin >> p[i] >> q[i];
        road.unite(p[i], q[i]);
    }

    for(i=1; i<=L; i++){
        cin >> r[i] >> s[i];
        rail.unite(r[i], s[i]);
    }

    for(i=1; i<=N; i++){
        mp[{road.root(i), rail.root(i)}]++;
    }

    for(i=1; i<=N; i++){
        cout << mp[{road.root(i), rail.root(i)}] << " ";
    }
    cout << endl;

    return 0;
}

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

int main(){
        map<string, int> mp; 
        string S;
        int N;
        cin >> N;
        for(int i = 0; i < N; ++i){
                cin >> S;
                mp[S]++;
        }

        int ans = 0;
        for(auto itr = mp.begin(); itr != mp.end(); ++itr){
                ans++;
        }

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


Measured memory_bytes: 19204
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(n+1):
	if i==0:
		b.append(abs(a[0]))
	elif i==n:
		b.append(abs(a[-1]))
	else:
		b.append(abs(a[i]-a[i-1]))
for i in range(n):
	if i==0:
		c.append(abs(a[1]))
	elif i==n-1:
		c.append(abs(a[-2]))
	else:
		c.append(abs(a[i+1]-a[i-1]))
sum_b=sum(b)
for i in range(n):
	print(sum_b-b[i]-b[i+1]+c[i])


Measured memory_bytes: 16132
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a = make_divisors(N)
i = len(a)-1
if len(a)%2==0:
  print(a[i-1]+a[i]-2)
else:
  print(a[i]*2-2)


Measured memory_bytes: 3264
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=200007;

int n,flag,l,r,mid,ans,a[N];
int tp,stk[N],num[N];

int check(){
	tp=num[0]=0;
	for(int i=1;i<=n;++i){
		if(a[i]>a[i-1])continue;
		if(!tp)stk[++tp]=a[i],num[tp]=1;
		else{
			while(tp>0&&stk[tp]>a[i])--tp;
			if(tp>0&&stk[tp]==a[i]){
				++num[tp];
				while(tp>0&&num[tp]==mid){
					int nxt=stk[tp]-1;
					--tp;
					if(stk[tp]==nxt)++num[tp];
					else stk[++tp]=nxt,num[tp]=1;
				}
			}else stk[++tp]=a[i],num[tp]=1;
		}
		if(num[0]>0)return 0;
	}
	return 1;
}

int main(){
	//freopen("c.in","r",stdin);
	scanf("%d",&n),flag=1;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),flag&=a[i]>a[i-1];
	if(flag)printf("1\n");
	else{
		l=2,r=1000000;
		while(l<=r){
			mid=l+r>>1;
			if(check())r=mid-1,ans=mid;
			else l=mid+1;
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 2444
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897

vector<ll> facts, invfacts;

ll extended_gcd(ll a, ll b, ll &x, ll &y) {
    if(a==0) {
        x = 0;
        y = 1;
        return b;
    }

    ll x1, y1;
    ll g = extended_gcd(b%a, a, x1, y1);

    x = y1-(b/a)*x1;
    y = x1;
    return g;
}

ll nck(ll n, ll k) {
    if(k>n)
        return 0;
    return (facts[n]*invfacts[k]%N*invfacts[n-k]%N+N)%N;
    // return (((((facts[n]*invfacts[k])%N)*invfacts[n-k])%N)+N)%N;
}

void initialize_facts(ll n, ll mod) {
    facts.resize(n+1);
    invfacts.resize(n+1);
    facts[0] = 1;
    invfacts[0] = 1;

    for(ll i=1;i<=n;i++) {
        facts[i] = (facts[i-1]*i)%N;
        ll x,y;
        extended_gcd(facts[i],mod,x,y);
        invfacts[i] = x;
    }
}


int main() {

    initialize_facts(2*Nmax+5,N);

    get3(h,w,n);
    vector<pll> A(n);
    rep(i,n) {
        get2(a,b);
        A[i] = {a,b};
    }

    sort(ALL(A));

    vector<ll> res(n,0);
    for(ll i=0;i<n;i++) {
        res[i] = nck(A[i].fi+A[i].se-2, A[i].fi-1);
    }

    ll ans = 0;

    for(ll i=0;i<n;i++) {
        ll val = res[i];

        for(ll j=i+1;j<n;j++) {
            ll m1 = A[j].fi-A[i].fi, n1 = A[j].se-A[i].se;
            if(m1>=0 && n1>=0)
                res[j] = (res[j]-val*nck(m1+n1, n1)%N+N)%N;
        }

        ans = (ans + val*nck(h-A[i].fi+w-A[i].se,w-A[i].se))%N;
        // cout<<ans<<endl;
    }

    // rep(i,n)
    // printf("%lld-%lld = %lld\n", A[i].fi, A[i].se, res[i]);

    printf("%lld\n", ((nck(h+w-2,h-1) - ans)%N+N)%N);

    return 0;  
}

Measured memory_bytes: 3456
def main():
    q = int(input())
    s = set()

    for _ in range(q):
        op, x = map(int, input().split())

        if op == 0:
            s.add(x)
            print(len(s))
        elif op == 1:
            if x in s:
                print("1")
            else:
                print("0")
        elif op == 2:
            s.discard(x)
main()



Measured memory_bytes: 23300
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> A(N), B(N), C(N);
  for (auto& ai: A) scanf("%d", &ai);
  for (auto& bi: B) scanf("%d", &bi);
  for (auto& ci: C) scanf("%d", &ci);

  std::sort(A.begin(), A.end());
  std::sort(B.begin(), B.end());
  std::sort(C.begin(), C.end());

  intmax_t res = 0;
  for (size_t i = 0; i < N; ++i) {
    intmax_t a = std::lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    intmax_t c = C.end() - std::upper_bound(C.begin(), C.end(), B[i]);
    res += a*c;
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 1408
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if (S.charAt(0) != S.charAt(1) && S.charAt(0) != S.charAt(2) && S.charAt(1) != S.charAt(2)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 20948
a,b,c,x,y = map(int,input().split())


if a+b <= 2*c:
    print(a*x+b*y)
else:
    if x>=y:
        if a <= 2*c:
            print(y*(2*c)+a*(x-y))
        else:
            print(2*c*x)
    else:
        if b<= 2*c:
            print(x*2*c+b*(y-x))
        else:
            print(2*c*y)

Measured memory_bytes: 3060
using System;

namespace lisson2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int C = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            if (X % 50 != 0 && X <= 50 && X >= 20000) return;
            int num = 0;
            for (int i = 0; i <= A; i++)
            {
                for (int j = 0; j <= B; j++)
                {
                    for (int k = 0; k <= C; k++)
                    {
                        if (500 * i + 100 * j + 50 * k == X)
                        {
                            num++;
                        }
                    }
                }
            }
            Console.WriteLine(num);
        }
    }
}

Measured memory_bytes: 11092