akhauriyash/Code-Regression huggingface dataset:
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream>
 #include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
  long long N;
  cin >> N;
  long long data[N];
  bool tf =false;
  REP(i,N)cin >> data[i];
  sort(data,data+N);
  for(int i=0;i<N-1;i++){
    if(tf==true)break;
        if(data[i]==data[i+1]){
         tf=true;
         break;
        }
    }
  
  
  if(tf==true)cout << "NO" << endl;
  else cout << "YES" << endl;  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int N;
	cin>>N;
	VI a(N);
	REP(i,N)cin>>a[i];
	int ans=INF;
	FOR(i,-100,100){
		int ret=0;
		REP(j,N){
			ret+=(i-a[j])*(i-a[j]);
		}
		ans=min(ans,ret);
	}
	cout<<ans<<endl;

		return 0;
}


Measured memory_bytes: 3668
[K,N]=[int(item) for item in input().split()]
array = [int(item) for item in input().split()]
max_=0
for i in range(N-1):
    dist=abs(array[i] - array[i + 1])
    if dist > max_:
        max_=dist

dist=array[0] + (K-array[N-1])
if dist > max_:
    max_=dist
print(K-max_)

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

typedef long long ll;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

vector<int> grafo[MAXN];
ll dp[MAXN][2];
int N;

ll solve(int v,int c,int p)
{
	if(dp[v][c] != -1) 
        return dp[v][c];

	ll tot = 1;
	
    for(int u : grafo[v])
    {
		if(u == p) 
            continue;
		
        if(c == 0) 
            tot = (tot * (solve(u,0,v) + solve(u,1,v))) % MOD;
		else 
            tot = (tot * solve(u,0,v)) % MOD;
	}

	return dp[v][c] = tot;
}

int main(){

	memset(dp,-1,sizeof(dp));

	scanf("%d",&N);

	for(int i = 1;i<N;i++)
    {
		int u,v;
		scanf("%d %d",&u,&v);
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}

	printf("%lld\n", (solve(1,0,-1) + solve(1,1,-1)) % MOD );

	return 0;
}

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

lli n, m;

int main(void){
	cin >> n >> m;
	lli c = 1;
	rep(i, m) c*=2;
	cout << c*(1900*m+100*(n-m)) << endl;
	return 0;
}


Measured memory_bytes: 3552
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int a = nextInt(sc);
        int b = nextInt(sc);
        int c = nextInt(sc);

        if (a == b) {
            out(c);
        } else if (a == c) {
            out(b);
        } else {
            out(a);
        }

    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

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

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }


    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}



Measured memory_bytes: 21716
sum = 0
n = int(input())
l = [list(map(int, input().split())) for i in range(3)]

for i in range(n-1):
  sum = sum + l[1][i]
  if l[0][i+1] - l[0][i] == 1:
    sum = sum + l[2][l[0][i]-1]
sum = sum + l[1][n-1]
print(sum)

Measured memory_bytes: 3060
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = 300005;
const int logn = 20;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//    freopen("in_a.txt", "r", stdin);
//    freopen("out_a.txt", "w", stdout);
    string s, t; cin>>s>>t; int n = s.size(), p = t.size();
    int mn = p;
    f0(i,n)
    {
        int m = 0;
        f0(j, p) if(i+p-1>=n) break;
        else if(s[i+j]==t[j]) ++m;
        mn = min(mn, p-m);
    }
    cout << mn << "\n";
    return 0;
}


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

using namespace std;
using ll = long long int;

int main()
{
    ll a,b;
    cin>>a>>b;
    if(a<=5) cout<<0<<endl;
    else if(a>=6 && a<=12) cout<<b/2<<endl;
    else cout<<b<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string dec2bin(long long decimal, int size){
  long long binary = 0;
  for(int i=0; decimal>0; i++){
    binary += decimal % 2 * pow(10, i);
    decimal = decimal / 2;
  }
  string str_binary;
  str_binary = to_string(binary);
  while(str_binary.size() != size){
    str_binary = "0" + str_binary; 
  }
  return str_binary;
}

int main() {
  string S;
  cin >> S;
  long long sum = 0;
  int num_cases = pow(2, S.size()-1);
  //vector<int> binary(num_cases);
 // string bin = dec2bin(18, 10);
 // printf("%s\n", bin.c_str()); 
  
  string e = "";
  
  if(S.size() == 1){
    cout << S << endl;
    return 0;
  }
  for(int i=0; i<num_cases; i++){
    e = S.at(0);
    string str_bin = dec2bin(i, S.size()-1);
    //cout << "str_bin: " << str_bin << endl;
    
    for(int j=0; j<S.size()-1; j++){
     // printf("j: %d, e: %s\n", j, e.c_str());
      if(str_bin.at(j) == '0'){
        e += S.at(j+1);
      }else{
      //  printf("sum <- %s\n", e.c_str());
    	//printf("e: %d\n", stoll(e));    
        sum += (long long) stoll(e);
        e = S.at(j+1);
      }
    }
    sum += (long long) stoll(e);
   // printf("sum: %d\n", sum);
  }
  
  cout << sum << endl;
}

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

int main()
{
    long long n;
    cin>>n;
    long long count=0;
    for(long long i=1;i<=n;i++){
        if((i%3 == 0) && (i%5==0))
            {//cout<<"FizzBuzz\n";
            count+=i;}
        else if(i%3 == 0)
            {//cout<<"Fizz\n";
            count+=i;}
        else if(i%5 == 0)
            {//cout<<"Buzz\n";
            count+=i;}
     }
     cout<<(n*(n+1))/2-count<<endl;
    return 0;
}  

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;

bool dfs(int n) {
  if (n == 0) return true;
  if (n < 0) return false;
  return dfs(n-7) || dfs(n-4);
}

int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  cout << (dfs(N) ? "Yes" : "No") << endl;
  return 0;
}


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

typedef long long lint;
#define fint register int
#define flint register lint

inline int ty()
{
	fint a=0,b=1,c=getchar();
	while(!isdigit(c))b^=c=='-',c=getchar();
	while(isdigit(c))a=a*10+c-48,c=getchar();
	return b?a:-a;
}

const int _ = 200007 , inf = 0x3f3f3f3f;
const lint linf = 0x3f3f3f3f3f3f3f3f;

struct sgt
{
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)
	static const int _t = _<<2;

	lint t[_t],tag[_t];

	void up(int x){t[x]=min(t[lc],t[rc]);}
	void puttag(int x,lint dlt){tag[x]=min(tag[x],dlt),t[x]=min(t[x],dlt);}
	void dwn(int x){if(tag[x]<linf)puttag(lc,tag[x]),puttag(rc,tag[x]),tag[x]=linf;}
	void change(int x,int l,int r,int tl,int tr,lint dlt)
	{
		if(tl<=l && r<=tr){puttag(x,dlt);return;}
		dwn(x);
		if(tl<=mid)change(lc,l,mid,tl,tr,dlt);
		if(tr>mid)change(rc,mid+1,r,tl,tr,dlt);
		up(x);
	}
	lint finder(int x,int l,int r,int tl,int tr)
	{
		if(tl<=l && r<=tr)return t[x];
		dwn(x);
		if(tr<=mid)return finder(lc,l,mid,tl,tr);
		if(tl>mid)return finder(rc,mid+1,r,tl,tr);
		return min(finder(lc,l,mid,tl,tr),finder(rc,mid+1,r,tl,tr));
	}
	
	void cls(){memset(t,63,sizeof(t)),memset(tag,63,sizeof(tag));}
	sgt(){cls();}
#undef lc
#undef rc
#undef mid
}tmi,tmx;

int n,m,A,B,tar[_];
lint f[_],sum[_],ans=linf;

void finder()
{
	tmi.cls(),tmx.cls();
	f[1]=abs(A-tar[1]),tar[0]=B;
	tmi.change(1,1,n,tar[0],tar[0],f[1]-tar[0]);
	tmx.change(1,1,n,tar[0],tar[0],f[1]+tar[0]);
	for(fint i=2;i<=m;i++)
	{
		f[i]=min(tmi.finder(1,1,n,1,tar[i])+tar[i],tmx.finder(1,1,n,tar[i],n)-tar[i])+sum[i-1];
		tmi.change(1,1,n,tar[i-1],tar[i-1],f[i]-sum[i]-tar[i-1]);
		tmx.change(1,1,n,tar[i-1],tar[i-1],f[i]-sum[i]+tar[i-1]);
	}
	for(fint i=1;i<=m;i++)ans=min(ans,f[i]+sum[m]-sum[i]);
}

int main()
{
	n=ty(),m=ty(),A=ty(),B=ty();
	for(fint i=1;i<=m;i++)tar[i]=ty();
	for(fint i=2;i<=m;i++)sum[i]=sum[i-1]+abs(tar[i]-tar[i-1]);
	finder(),swap(A,B),finder();
	printf("%lld\n",ans);

	return 0;
}


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

using namespace std;
int a[1000],n;
long sum;
string s[1000],x;
int main()
{cin>>n;
 int b;
for(int i=0;i<n;i++){
    cin>>s[i];
    cin>>a[i];}
    cin>>x;
    for(int i=0;i<n;i++)
        if(s[i]==x){b=i;
    break;}
    for(int i=b+1;i<n;i++)
        sum+=a[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
w = list(map(int, input().split()))
ans = []
sum_w = sum(w)
Cumulative_sum = w[0]
for i in range(1, n-1):
    Cumulative_sum += w[i]
    ans.append(abs(sum_w-2*Cumulative_sum))
print(min(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
#define D

#ifdef D
int A[100 + 1][100 + 1] = { 0 };
int b[100 + 1] = { 0 };

void mul(int i,  int M)
{
	int res = 0;
	for (size_t m = 0; m < M; m++)
	{
		res += A[i][m] * b[m];
	}
	cout << res << endl;
}

int main(void)
{
	int N, M;
	cin >> N >> M;
	for (size_t n = 0; n < N; n++)
	{
		for (size_t m = 0; m < M; m++)
		{
			cin >> A[n][m];
		}

	}
	for (size_t m = 0; m < M; m++)
	{
		cin >> b[m];
	}
	for (size_t i = 0; i < N; i++)
	{
		mul(i, M );
	}

	return 0;
}
#endif // D

Measured memory_bytes: 3136
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
int h, w;
int n;

void ReadInput()
{
    cin >> h >> w;
    cin >> n;
}

void Solve()
{
    int mx = max(h, w);;
    cout << n / mx + (n % mx != 0) << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int h,w;
    while(cin>>h>>w,1){
        if(h==0&&w==0)return 0;
        for(int i=1;i<=h;i++){
            for(int n=1;n<=w;n++){
                cout<<"#";
            }cout<<endl;
        }cout<<endl;
    }
}


Measured memory_bytes: 3068
import heapq

def minus_int(s):
  return -1 * int(s)

N, M = map(int, input().split())
A = list(map(minus_int, input().split()))
heapq.heapify(A)
for _ in range(M):
  tmp = int(heapq.heappop(A) / 2)
  heapq.heappush(A, tmp)

print(sum(A) * (-1))

Measured memory_bytes: 14180
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
        long k = in.nextLong();
        if(k%2 == 0) {
            System.out.println(a - b);
        } else {
            System.out.println(b - a);
        }
    }
}   

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	ll ans = 0;
	map<int,int> mp;
	rep(i,n){
		ans += mp[i-a[i]];
		mp[i+a[i]]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 21120
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val aList = readLine()!!.split(" ").map { it.toInt() }
  val map = mutableMapOf<Int, Int>()
  for (i in 0 until n) {
    map[aList[i]] = i + 1
  }
  val result = mutableListOf<Int>()
  for (i in 1..n) {
    result.add(map[i]!!)
  }
  println(result.joinToString(" "))
}



Measured memory_bytes: 59712
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){

    int n;

    cin >>n;

    int a[n];

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

    int s=0;

    sort(a,a+n);

    if(n%2==0){
        for(int i=0;i<n/2;i++){
            s += a[2*i+1]-a[2*i];
        }
    }
    else{
        s += a[0];
        for(int i=0;i<n/2;i++){
            s+=a[2*i+2]-a[2*i+1];
        }
    }

    cout << s << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<ll> P;

int main() {
	cin >> N;
	P.resize(N+1);
	for(ll n = 0; n < N; n++) {
		cin >> P[n];
		P[n]--;
	}
	P[N] = -1;
	ll ans = 0;
	for (ll n = 0; n < N;) {
		if (P[n] != n)n++;
		else if (P[n] == n) {
			if (P[n + 1] != n + 1) {
				n++;
			}
			else n += 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#C

#デバッグ
debug=1
def pront(*n):
    if debug==1:
        print(n)
        
#10**9+7を底とした処理

base=10**9+7

def add(a,b):#a+b
    return (a+b)%base

def sub(a,b):#a-b
    return (a-b)%base

def multi(a,b):#a*b
    return (a*b)%base

def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

#入力

N=int(input())
S=[input() for i in range(N)]


#処理

X={}
for i in S:
    if i in X:
        pass
    else:
        X[i]=1
print(len(X))


Measured memory_bytes: 38424
#include <stdio.h>
int main(void){
  int N;
  int i;
  int S=0;
  scanf("%d",&N);
  
  for(i=1;i<=N;i++){
    int l,r;
    scanf("%d %d",&l,&r);
    int a;
    a=r-l+1;
    S=S+a;
  }
  
  printf("%d",S);
 return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }

  ll total = accumulate(all(a), 0);
  put(total - N);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[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 T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		string s;
		int a[3] = { 1,2,3 }, sum = 1;
		for (int i = 0; i < n; i++) {
			cin >> s;
			if (s == "North") {
				int b = a[1];
				a[1] = 7 - a[0];
				a[0] = b;
			}
			else if (s == "East") {
				int b = a[0];
				a[0] = 7 - a[2];
				a[2] = b;
			}
			else if (s == "West") {
				int b = a[2];
				a[2] = 7 - a[0];
				a[0] = b;
			}
			else if (s == "South") {
				int b = a[0];
				a[0] = 7 - a[1];
				a[1] = b;
			}
			else if (s == "Right") {
				int b = a[2];
				a[2] = 7 - a[1];
				a[1] = b;
			}
			else if (s == "Left") {
				int b = a[1];
				a[1] = 7 - a[2];
				a[2] = b;
			}
			sum += a[0];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3132
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<u32> = read::<String>()
        .chars()
        .map(|x| x.to_digit(10).unwrap())
        .collect();

    let mut minv = std::u32::MAX;
    let tn = 753;

    for i in 0..s.len() - 2 {
        let a = s[i];
        let b = s[i + 1];
        let c = s[i + 2];
        let x = 100 * a + b * 10 + c;
        if x > tn {
            if minv > x - tn {
                minv = x - tn;
            }
        } else {
            if minv > tn - x {
                minv = tn - x;
            }
        }
    }
    println!("{}", minv);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    static long INF = (long)1e18;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        
        // ans: 「1+2+...+k」がnの倍数である最小のk
        // -> k(k+1)/2 % n = 0
        // -> k(k+1) % 2n = 0
        // ex. 10*11 % 2*11 = 0
        
        // how:
        // a = 2nの約数, b = 2n/aとして、 (ex. n,a,b = 11,11,2)
        // ax + by = 1なる(x,y)を求めて、 (ex. 11*1 + 2*-5 = 1)
        // y < 0であるmin(-by)を求める。
        // <- これを全てのaで行いmin(min(-by))を出力する。
        
        if (n == 1) {
            System.out.println(1);
            return;
        }
        
        List<Long> list = divisorList(2*n);
        
        long ans = INF;
        for (Long a : list) {
            long b = 2*n/a;
            
            long[] eg = extgcd(a, b);
            
            long g = eg[0];
            long x = eg[1];
            long y = eg[2];
            
            if (x == 0 || y == 0) continue;
            
            if (g == 1) {
                if (y < 0) {
                    ans = Math.min(ans, -b*y);
                }
                // System.out.println(a + "*" + x + "+" + b + "*" + y + "=" + g);
            }
        }
        System.out.println(ans);
    }
    
    public static List<Long> divisorList(long n) {
        List<Long> res = new ArrayList<Long>();
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                res.add(i);
                
                long j = n / i;
                if (j != i) {
                    res.add(j);
                }
            }
        }
        res.sort(Comparator.naturalOrder());
        
        return res;
    }
    
    // 拡張ユークリッド法: ax + by = gcdを解く
    public static long[] extgcd(long a, long b) {
        long x0 = 1, x1 = 0;
        long y0 = 0, y1 = 1;
        
        while (b != 0) {
            long q = a / b;
            long r = a % b;
            long x2 = x0 - q * x1;
            long y2 = y0 - q * y1;
        
            a = b; b = r;
            x0 = x1; x1 = x2;
            y0 = y1; y1 = y2;
        }
        
        return new long[]{a, x0, y0};
    }
}

Measured memory_bytes: 39884
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

b = []
f = []
for k,v in c.items():
    if v >= 2:
        b.append(k)
    if v >= 4:
        f.append(k)

b.sort(reverse=True)
f.sort(reverse=True)

d = 0
if len(f) != 0:
    d = max(f)**2

if len(b) >= 2:
    print(max(b[0]*b[1],d))
else:
    print(0)

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

int a[300010];
int main(){
    int n;
    cin >> n;

    typedef pair<int, int> P;
    priority_queue<P, vector<P>, greater<P> > que;

    multiset<int> st;

    int ma = 0;
    for(int i = 0;i < (1<<n);i++){
        cin >> a[i];
        st.insert(-a[i]);
        ma = max(ma, a[i]);
    }

    st.erase(st.begin());

    que.push({0, -ma});

    while(!que.empty()){
        int cnt = que.top().first;
        int num = que.top().second;
        que.pop();
        if(cnt == n){
            continue;
        }
        que.push({cnt+1, num});

        auto itr = st.upper_bound(num);
        if(itr == st.end()){
            cout << "No" << endl;
            return 0;
        }

        que.push({cnt+1, *itr});
        st.erase(itr);
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 15736
#include <iostream>
using namespace std;
int A[3][3],N,B[3][3] = {};
bool sub(){
	for (int i = 0; i < 3; ++i)
  {
  	bool atom = true;
  	for (int j = 0; j < 3; ++j)
  	{
  		if(B[i][j] == false){
  			atom = false;
  		}
  	}
  	if(atom){
  		return true;
  	}
  }
  for (int i = 0; i < 3; ++i)
  {
  	bool atom = true;
  	for (int j = 0; j < 3; ++j)
  	{
  		if(B[j][i] == false){
  			atom = false;
  		}
  	}
  	if(atom){
  		return true;
  	}
  }
  if(B[0][0] && B[1][1] && B[2][2]){
  	return true;
  }else if(B[2][0] && B[1][1] && B[0][2]){
  	return true;
  }
  return false;
}


int main(){
  bool answer = false;
  for (int i = 0; i < 3; ++i)
  {
  	for (int j = 0; j < 3; ++j)
  	{
  		cin >> A[i][j];
  	}
  }
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
  	int C;
  	cin >> C;
  	for (int j = 0; j < 3; ++j)
  	{
  		for (int k = 0; k < 3; ++k)
  		{
  			if(A[j][k] == C){
  				B[j][k] = 1;
  			}
  		}
  	}
  }
  answer = sub();
  if(answer){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
s=list(map(ord,list(input())))
for i in range(n):s[i]-=97

from random import randint
roli_mod=1370757747362922367
roli_r=randint(2,roli_mod-2)
roli=[0]
roli_rr=1
for i in range(n):
  roli.append((roli[-1]+roli_rr*s[i])%roli_mod)
  roli_rr*=roli_r
  roli_rr%=roli_mod
def roli_hash(i,j):return ((roli[j+1]-roli[i]+roli_mod)%roli_mod)*pow(roli_r,roli_mod-1-i,roli_mod)%roli_mod
def roli_check(i1,j1,i2,j2):return roli_hash(i1,j1)==roli_hash(i2,j2)

ok=0
ng=(n+1)//2+1
while ok+1!=ng:
  i=(ok+ng)//2
  d={}
  f=False
  for j in range(n-i+1):
    h=roli_hash(j,j+i-1)
    if h in d:
      if j-d[h]>=i:
        f=True
        break
    else:d[h]=j
  if f:ok=i
  else:ng=i
print(ok)

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

using namespace std;

#pragma GCC optimize "-O3"

#define watch(x) cout << (#x) << " is " << (x) << endl

#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a-1;i>=b;i--)
#define nl          cout<<endl;
#define test()      lli t;cin>>t;while(t--)
#define sp(n)       setprecision(n)

#define lli     long long int
#define ulli    unsigned long long int
#define ld      long double
#define uld     unsigned long double
#define S       string
#define C       char
#define elif    else if
 
#define pb      push_back
#define pp      pop_back
#define plli    pair<lli,lli>
#define vlli    vector<lli>
#define vulli   vector<ulli>
#define vld     vector<ld>
#define vs      vector<string>

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define vsort(v) sort(v.begin(),v.end())

// #define max1 1000001    //10^6 + 1
// #define max2 10000001   //10^7 + 1
// #define max3 1000000007 //10^9 + 7
#define inf  1000000009 //10^9 + 9

const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n,w;
 	cin >> n >> w;
 	vector<lli> dp(w+1,0);
 	// dp[i] stores max value when weight is i
 	for (int i = 0; i < n; ++i)
 	{
 		int weight, value;
 		cin >> weight >> value;
 		for (int weight_alr=w-weight; weight_alr >= 0 ; --weight_alr)
 		{
 			dp[weight_alr + weight] = max(dp[weight_alr+weight], dp[weight_alr] + value);
 		}
 	}
 	lli ans=0;
 	for (int i = 0; i <= w; ++i)
 	{
 		ans = max(dp[i],ans);
 	}
 	cout << ans << '\n';
 	// lli a[n],b[n],c[n];
 	// lli ite[n];
    
    return 0;
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String str = br.readLine();
        int num = Integer.parseInt(str);

        int hh = num / 3600;
        int mm = (num - hh * 3600) / 60;
        int ss = ((num - hh * 3600) - mm * 60);

        System.out.println(hh + ":" + mm + ":" + ss);
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int K,N;
vector<int> V;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>N;
	FOR(i,N) {
		cin>>x;
		V.push_back(x);
		V.push_back(x+K);
	}
	sort(ALL(V));
	int mi=1<<30;
	FOR(i,N) mi=min(mi,V[i+N-1]-V[i]);
	cout<<mi<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,A) for(int i = 0;i < A;i++)

int main() {
  int A;
  cin >> A;
  if(A % 111 == 0){
  cout << A << endl;
  }
  else{
    cout << 111 + A / 111 * 111 << endl;
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int maxn =1e5+1;
int f[maxn];
typedef long long ll;
int main(){
	int k,n;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		scanf("%lld",&f[i]);
	}
	sort(f+1,f+n+1);
	int mn=0x3f3f3f3f;
	for(int i=1;i<=n-k+1;i++){
		if(f[i+k-1]-f[i]<mn){
			mn=f[i+k-1]-f[i];
		}
	}
	cout<<mn<<"\n";
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <string>
#include<iostream>

using namespace std;

string s1;
string s2;

int main(void){
    cin>>s1>>s2;
    bool flag=false;
    for(int i=0;i<s1.size();i++){
        int j=0;
        int idx=i;
        while(j<s2.size()){
            if(s1[idx]!=s2[j]){
                break;
            }
            if(j==s2.size()-1)
                flag=true;
            idx=(idx+1)%s1.size();
            j++;
        }
    }
    if(flag==true){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
ans = 0
for i in range(2 ** (n-1)):
    tmp = 0
    for j in range(n-1):
        if i >> j & 1:
            tmp += int(s[j])
            tmp *= 10
        else:
            ans += tmp + int(s[j])
            tmp = 0
    ans += tmp
    ans += int(s[n-1])

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int N;
	int ans = 1000000000;

	cin >> N;

	for (int i = 0; i < N; i++) {
		int tmp,cnt;
		cin >> tmp;
		cnt = 0;
		while (tmp % 2 == 0 && tmp != 0) {
			cnt++;
			tmp /= 2;
		}
		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll INF = 5e15;

struct I {
    ll i, cnt;
};

vector<ll> calc(const vector<ll> &v){
    vector<ll> ret(v.size(), 0);
    ll pre = v[0];
    stack<I> st;
    for(ll i = 1; i < v.size(); i++){
        ret[i] = ret[i - 1];
        if(v[i] <= pre){
            ll cnt = 0;
            ll tmp = v[i];
            while(tmp * 4 <= pre){
                tmp *= 4;
                cnt++;
            }
            if(cnt) st.push(I{i, cnt});
        }else{
            ll cnt = 0;
            ll tmp = pre;
            while(tmp < v[i]){
                tmp *= 4;
                cnt++;
            }
            while(cnt && st.size()){
                I tmp = st.top();
                st.pop();
                if(cnt > tmp.cnt){
                    cnt -= tmp.cnt;
                    ret[i] += (i - tmp.i) * tmp.cnt;
                }else{
                    tmp.cnt -= cnt;
                    ret[i] += (i - tmp.i) * cnt;
                    cnt = 0;
                    if(tmp.cnt) st.push(tmp);
                }
            }
            if(cnt) ret[i] += cnt * i;
        }
        pre = v[i];
    }
    return ret;
}

template<typename T>
void print_vec(const vector<T> &v){ for(const T &e : v) cout << e << ", "; cout << endl;  }

int main(){
    ll N;
    cin >> N;
    vector<ll> V(N);
    for(ll &v : V) cin >> v;
    vector<ll> plus, minus;
    for(ll &v : V) v *= 2;
    minus = calc(V);
    for(ll &v : V) v /= 2;
    reverse(V.begin(), V.end());
    plus = calc(V);
    //reverse(plus.begin(), plus.end());
    ll ans = min(2 * plus[N - 1], 2 * minus[N - 1] + N);
    //print_vec(plus); print_vec(minus);
    //cout << plus[N - 1] << ", " << minus[N - 1] << endl;
    for(ll i = 1; i < N; i++){
        ans = min(ans, 2 * plus[N - i - 1] + 2 * minus[i - 1] + i);
        //cout << 2 * plus[N - i - 1] << " + " << minus[i - 1] << " + " << i << " = " << 2 * plus[N - i - 1] + 2 * minus[i - 1] + i << endl;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.precision(10); cout << fixed;
    int n,m;
    while (cin >> n >> m) {
        multiset<int> A;
        FOR(i,0,n) {
            int a; cin >> a;
            A.insert(a);
        }
        while (m && A.size()) {
            const int x = *A.rbegin()/2;
            A.erase(--A.end()); 
            if (x)
                A.insert(x);
            m--;
        }
        LL ans = 0;
        FOR_ALL(a,A)
            ans += *a;
        cout << ans << endl;
    }    
    return 0;
}


Measured memory_bytes: 4992
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
res = 0
f = [True for _ in range(n)]
for i in range(n):
    m = t[i]
    if i >= k:
        if m == t[i - k]:
            if f[i - k]:
                f[i] = False
                continue
    if m == "r":
        res += p
    elif m == "s":
        res += r
    else:
        res += s
print(res)


Measured memory_bytes: 45424
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense,dijkstra,floyd_warshall
H, W = map(int, input().split())

A = []
for _ in range(10):
  A.append(list(map(int, input().split())))
A = np.array(A)
c = []
for _ in range(H):
  c.append(list(map(int, input().split())))
c = np.array(c)
A = floyd_warshall(A)
C = A[0:,1]

ans = 0
for i in c:
  for j in i:
    if j != -1:
      ans += C[j]
print (int(ans))  

Measured memory_bytes: 14412
#include <stdio.h>
int main(void)
{
    int a,b,c,x,cnt=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(int i=0;i<=a&&500*i<=x;i++)    
        for(int j=0;j<=b&&100*j+500*i<=x;j++)       
            for(int k=0;k<= c&&50*k+100*j+500*i<=x;k++)           
                if(500*i+100*j+50*k==x)cnt++;                           
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Main
{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];
		int a1[] = new int[n + 1];
		int a2[] = new int[n + 1];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			a1[i + 1] = a[i] + i + 1;
			a2[i + 1] = -a[i] + (i + 1);
		}

		HashMap<Integer, Integer> set1 = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> set2 = new HashMap<Integer, Integer>();

		for(int i = 1; i <= n; i++ ){
			if(!set1.containsKey(a1[i])){
				set1.put(a1[i], 1);
			}
			else {
				set1.put(a1[i], set1.get(a1[i]) + 1);
//				System.out.println("update for "+a1[i]);
			}

			if(!set2.containsKey(a2[i])){
				set2.put(a2[i], 1);
			}
			else {
				set2.put(a2[i], set2.get(a2[i]) + 1);
			}
		}

		Iterator<Integer> it = set1.keySet().iterator();

		long result = 0;

		while(it.hasNext()){
			int tmp = it.next();

			if(set2.containsKey(tmp)){
				result += (long)set1.get(tmp) * set2.get(tmp);
			}

//			System.out.println("tmp "+tmp + " result "+result);
		}


		System.out.println(result);
	}

}


Measured memory_bytes: 67164
#include <cstdio>
#include <cmath>
#include <vector>
#include <limits>

using namespace std;

int main(int argc, char const *argv[]) {
  long N;
  long r = 0;
  scanf("%ld", &N);
  if (N == 0) {
    printf("0\n");
    return 0;
  }
  // for (long i = 1; i < 100; i++) {
    // prlongf("%d %d\n", i, (long)(log2(3*i) / 2 - 1) + 1);
    // prlongf("%d  %d\n", i, (long)(log2(3*i/2) / 2 - 1) + 1);
  // }
  while (N) {
    if (N == 0) break;
    bool pm = N >= 0;
    long w = pm ? 1 : -2;
    long k;
    if (pm) {
      k = (long)(log2(3*N) / 2 - 1) + 1;
    } else {
      k = (long)(log2(-3*N/2) / 2 - 1 + 1);
    }
    // long k = (long)(log2(3*N/w) / 2 - 1) + 1;
    if (N == -1 || N == 1) k = 0;
    // prlongf("%d %d\n", w, k);
    N -= pow(4, k)*w;
    // prlongf("%d\n", N);

    long x = pm ? 1 : 0;
    r += pow(2, (k+1)*2 - x - 1);
    // prlongf("---%d---keta\n", ((k+1)*2) - x);
    // break;

    // prlongf("%d %d\n", i, (long)(log2(3*i) / 2 - 1) + 1);
    // prlongf("%d  %d\n", i, (long)(log2(3*i/2) / 2 - 1) + 1);
  }
  // prlongf("%d\n", r);
  for (long i = (long)log2(r); i >= 0; i--) {
    // prlongf("aaa");
    long z = (long)pow(2, i);
    if (r / z) {
      r -= z;
      printf("1");
    } else {
      printf("0");
    }
  }
  printf("\n");
  return 0;
}


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

int main()
{
    vector<int> n = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << n[k - 1] << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#define MAX 5000
using namespace std;

int main(void){
	int i,j,k,n,ans;
	bool f[5][MAX];
	while(1){
		cin >> n;
		if(n == 0) break;
		for(i=0;i<5;i++){
			for(j=0;j<MAX;j++) f[i][j] = false;
		}
		ans = 0;
		for(i=0;i<n;i++){
			int d,p,q;
			cin >> d >> p >> q;
			q--;
			ans += p;
			if(d == 2){
				for(j=MAX-1;j>=0;j--){
					if(j == 0 || f[q][j-1] == true){
						for(k=j;k<j+p;k++) f[q][k] = true;
						break;
					}
				}
			}
			else{
				for(j=MAX-1;j>=0;j--){
					k=5;
					if(j != 0){
						for(k=q;k<q+p;k++) if(f[k][j-1] == true) break;
					}
					if(j == 0 || k != q+p){
						for(k=q;k<q+p;k++) f[k][j] = true;
						break;
					}
				}
			}
			for(j=0;j<MAX;j++){
				for(k=0;k<5;k++) if(f[k][j] == false) break;
				if(k == 5){
					ans -= 5;
					for(k=0;k<5;k++){
						for(int t=j;t<MAX-1;t++) f[k][t] = f[k][t+1];
						f[k][MAX-1] = false;
					}
					j--;
				}
			}
		//			cout << endl;
		//		for(int ii=7;ii>=0;ii--){
		//	for(j=0;j<5;j++) cout << f[j][ii] << " ";
		//	cout << endl;
		//}
		//cout << endl;
		}
		cout << ans << endl;


	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
#include <string.h>
int main (void){
        char S;
        int ans=0;
        for (int i = 0; i < 4; i++) {
          scanf("%c",&S);
          if (S=='+') {
            ans++;
          }else{
            ans--;
          }
        }
        printf("%d\n",ans );

        return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define vvll vecror<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
 
 
 

void solve()
{
	ll k,i,n,m=0,c=0,ans=0;
	cin>>k>>n;
	ll a[n],dif[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(ll i=0;i<n-1;i++)
	    dif[i]=a[i+1]-a[i];
	dif[n-1]=k-a[n-1]+a[0];
    sort(dif,dif+n);
    for(ll i=0;i<n-1;i++)
        ans+=dif[i];
    cout<<ans;
	return;
}
 
int main()
{
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3328
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		int flag = 0;
		
		for(int count = K;count > 0;count--){
			if(flag == 0){
				if(A % 2 == 1 || A == 1){
					A = A - 1;
				}
				B = B + A / 2;
				A = A - A / 2;
				flag = 1;
			}else{
				if(B % 2 == 1 || B == 1){
					B = B - 1;
				}
				A = A + B / 2;
				B = B - B / 2;
				flag = 0;
			}
		}
		
		
		
		
		
		System.out.println(A+" "+B);
	}
}


Measured memory_bytes: 22228
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

//#include <vector>
//#include <set>
//#include <map>
//#include <iostream>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

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

int main(void)
{
	//変数の宣言
	int n,m,q;
	int a[2050];
	int b[2050];
	int c[2050];
	int l,r;
//
	//よく使う変数
	int i,j,k;
	int flag=0;
	int ans=0;
	int count=0;
	ll int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;


	//データの読み込み
	scanf("%d %d %d",&n,&m,&q);
//	scanf_s("%d %d %d",&n,&m,&q);

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

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	ans=1500000000;

	for(i=0;i<n;i++){
		temp=a[i];
		l=-1;r=-1;
		count=0;
		for(j=0;j<=n;j++){
			if(a[j]<temp||j==n){
				l=r;
				r=j;

				for(k=1;k<r-l;k++){
					b[k-1]=a[l+k];
				}

				qsort(b,r-l-1,sizeof(int),compare_int);
				
				for(k=0;k<r-l-m;k++){
					c[count]=b[k];
					count++;
				}
			}
		}

		if(count>=q){
			qsort(c,count,sizeof(int),compare_int);
			temp=c[q-1]-c[0];
			ans=min(ans,temp);
		}
	}


	//	printf("計算部分終了\n");

	//出力

	printf("%d",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int h,f,turu,kame;
    cin >> h >> f;
    if((f%2==0)&&(f>=h*2)){
        kame=(f/2)-h;
        turu=h-kame;
        if(turu>=0){
            if ((h == kame + turu) && (f == 2 * turu + 4 * kame))
            {
                cout << "Yes";
            }else{
                cout << "No";
            }
        }else{
            cout << "No";
        }
    }else{
        cout << "No";
    }

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<ll> par(100000);
vector<ll> rnk(100000);
 
void init(ll n){
  rep(i, n){
    par.at(i) = i;
    rnk.at(i) = 0;
  }
}
 
ll root(ll x){
  if(par.at(x) == x){
    return x;
  }
  else{
    par.at(x) = root(par.at(x));
    return par.at(x);
  }
}
 
bool same(ll x, ll y){
  if(root(x) == root(y)){
    return true;
  }
  else{
    return false;
  }
}
 
void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if(rnk.at(x) < rnk.at(y)){
    par.at(x) = y;
  }
  else{
    par.at(y) = x;
    if(rnk.at(x) == rnk.at(y)){
      rnk.at(x)++;
    }
  }
}

int main(){
  ll N, M;
  cin >> N >> M;
  vector<ll> a(M), b(M);
  rep(i, M){
    cin >> a.at(i) >> b.at(i);
    a.at(i)--;
    b.at(i)--;
  }
  ll ans = 0;
  rep(i, M){
    init(N);
    rep(j, M){
      if(j == i){
        continue;
      }
      unite(a.at(j), b.at(j));
    }
    rep(j, N-1){
      if(!same(0, j+1)){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792