akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

vector< vector<int> > P;
int Color[100000];

bool bfs( int s ) {
    
    Color[s] = 1;
    
    queue<int> Q;
    
    for ( int i = 0; i < P[s].size(); i++ ) {
        Q.push(P[s][i]);
        Color[P[s][i]] = 0;
    }
    
    while ( !Q.empty() ) {        
        int c = Q.front();
        Q.pop();
        
        int color = 1-Color[c];
        
        for ( int i = 0; i < P[c].size(); i++ ) {
            int n = P[c][i];
            
            if ( Color[n] != -1 && Color[n] != color ) { return false; }
            if ( Color[n] == -1 ) { Q.push(n); }
            Color[n] = color;
        }
        
    }
    
    return true;
}

bool dfs( int v, int pre, int color ) {
    
    Color[v] = color;
    bool ret = true;
    
    for ( int i = 0; i < P[v].size(); i++ ) {
        int n = P[v][i];
        
        if ( n == pre ) { continue; }
        if ( Color[n] == 1-color ) { continue; }
        if ( Color[n] != -1 && Color[n] != 1-color ) { return false; }        
        
        bool t = dfs( n, v, 1-color );
        if ( !t ) { ret = t; }
    }
    
    return ret;
}



int main() {
        
    long long N,M;
    cin >> N >> M;
    P.resize(N);
    
    fill( Color, Color+N, -1 );
    
    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        P[a].push_back(b);
        P[b].push_back(a);
    }
    
    // if ( bfs(0) ) {
     if ( dfs(0,-1,0) ) {
        long long a,b;
        a = b = 0;
        for ( int i = 0; i < N; i++ ) {
            Color[i] ? a++ : b++;
        }
        cout << a*b-M << endl;
    }
    else { cout << N*(N-1)/2 - M << endl; }
    
    return 0;
}

Measured memory_bytes: 6912
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream source)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray()
    {
        Next();
        Index = S.Length;
        return S.ToArray();
    }
    public int[] IntArray()
    {
        return StringArray().Select(int.Parse).ToArray();
    }
    public long[] LongArray()
    {
        return StringArray().Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

class Magatro
{
    private long X, Y;
    private void Scan()
    {
        var cin = new Scanner(Console.OpenStandardInput());
        X = cin.NextLong();
        Y = cin.NextLong();
    }

    public void Solve()
    {
        Scan();
        Console.WriteLine(Math.Abs(X - Y) <= 1 ? "Brown" : "Alice");
    }

    private void swap()
    {
        X ^= Y;
        Y ^= X;
        X ^= Y;
    }
}



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

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd( T m, T n ){
    if ( ( 0 == m ) || ( 0 == n ) ) return 0;

    while( m != n ){
        if ( m > n ) m %= n;
        else         n %= m;

        if(m == 0) return n;
        if(n == 0) return m;
    }
    return m;
}

int main()
{
    ll N;
    cin >> N;
    ll Ai;
    vector<ll> A;
    cin >> Ai;
    ll res = Ai;
    for(int i=1;i<N;i++){
        cin >> Ai;
        res = gcd(res, Ai);
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
struct UnionFind {
	vector<int> parent; // parent[root] is the negative of the size.
	UnionFind(int n) : parent(n, -1) { };
	bool unite(int u, int v) { 
		u = root(u); v = root(v);
		if (u == v) return false;
		if (parent[u] > parent[v]) swap(u, v);
		parent[u] += parent[v]; parent[v] = u;
		return true;
	}
	bool find(int u, int v) { return root(u) == root(v); }
	int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
	int size(int u) { return -parent[root(u)]; }
};
using pi=pair<int,int>;
main(){
	int n,m,r,a,b,i;
	cin>>n>>m; r=n*(n-1)/2;
	UnionFind T(n);
	vector<pi> v(m);
	vector<int> res(m);
	for(i=m-1;i>=0;--i){
		cin>>v[i].first>>v[i].second;
		v[i].first--; v[i].second--;
	}
	for(i=0;i<m;++i){
		a=v[i].first,b=v[i].second;
		res[m-1-i]=r;
		if(!T.find(a,b)){
			r-=T.size(a)*T.size(b);
			T.unite(a,b);
		}
	}
	for(auto c:res)cout<<c<<"\n";
}

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

using namespace std;

int main()
{
	int n, t;
	double d1 = 0;
	double d2 = 0;
	double d3 = 0;
	double d4 = 0;
	vector<int> x;
	vector<int> y;

	cin >> n;

	for (int i = 0; i < n; i++) 
	{
		cin >> t;

		x.push_back(t);
	}
		
	for (int i = 0; i < n; i++)
	{
		cin >> t;

		y.push_back(t);
	}

	for (int i = 0; i < n; i++)
	{
		d1 += abs(x[i] - y[i]);
	}

	for (int i = 0; i < n; i++)
	{
		d2 += (abs(x[i] - y[i]) * abs(x[i] - y[i]));
	}

	d2 = sqrt(d2);

	for (int i = 0; i < n; i++)
	{
		d3 += abs(x[i] - y[i]) * abs(x[i] - y[i]) * abs(x[i] - y[i]);
	}

	d3 = pow(d3, 1.0 / 3);

	d4 = -1;
	double k;

	for (int i = 0; i < n; i++)
	{
		k = abs(x[i] - y[i]);
		
		if (k > d4) d4 = k;
	}

	cout.precision(6);

	cout << fixed << d1 << "\n";
	cout << fixed << d2 << "\n";
	cout << fixed << d3 << "\n";
	cout << fixed << d4 << "\n";

	return 0;
}


Measured memory_bytes: 3444
let n = int (stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.mapi (fun i x -> int64 x - int64 i - 1L) |> Array.sort
let b = if n % 2 = 0 then (a.[n / 2] + a.[n / 2 - 1]) / 2L else a.[n / 2]
printfn "%d" (Array.sumBy (fun x -> abs (x - b)) a)

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int K;
LL A[MC];

int main(){
	cin >> K;
	repp(i,0,K) cin >> A[i];
	if(A[K-1] != 2) return cout << -1 << endl , 0;
	LL mn = 2 , mx = 2;
	repm(i,K-1,-1){
		mn = ((mn-1)/A[i]+1)*A[i];
		if(mn>mx) return cout << -1 << endl , 0;
		mx = (mx/A[i]+1)*A[i]-1;
	}
	cout << mn << ' ' << mx << endl;
	return 0;
}


Measured memory_bytes: 1024
//
// Created by 10034 on 2020/7/28.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N=200010,mod=1e9+7;
int a[N];
vector<int> v0,v1;
vector<int> v2,v3;
typedef long long LL;
int calc(){
    int res=1;
    for(int i=0;i<v0.size();++i){
        res=((LL)res*v0[i]%mod+mod)%mod;
    }
    for(int i=0;i<v1.size();++i){
        res=((LL)res*v1[i]%mod+mod)%mod;
    }
    return res;
}
bool cmp(int a,int b){
    return abs(a)<abs(b);
}
int main(){

    int n,k;
    cin>>n>>k;
    int z=0,f=0,l=0;
    for(int i=1;i<=n;++i) {
        cin >> a[i];
        if(a[i]>0) z++;
        else if(a[i]<0) f++;
        else l++;
    }
    if(z>=k||((k-z)%2==0&&f/2*2>=k-z)||(z&&(k-z)%2==1&&f/2*2>=k-z+1)){
        sort(a+1,a+1+n,cmp);
        reverse(a+1,a+1+n);
        int zz=0,ff=0;
        for(int i=1,j=k;i<=n;++i){
            if(a[i]==0) continue;
            if(j) {
                if(a[i]>0)
                    v0.push_back(a[i]);
                else v1.push_back(a[i]);
                --j;
                if(a[i]>0) zz++;
                else ff++;
            }
            else if(a[i]>0) v2.push_back(a[i]);
            else v3.push_back(a[i]);
        }
        if(ff%2==0){
            cout<<calc()<<endl;
        }
        else {
            if(v0.size())
                sort(v0.begin(),v0.end());
            if(v1.size())
                sort(v1.begin(),v1.end(),cmp);
            if(v2.size())
                sort(v2.begin(),v2.end(),greater<int>());
            if(v3.size())
                sort(v3.begin(),v3.end());
            if(v0.size()==0){
                v1[0]=v2[0];
            }
            else {
                if(v2.size()==0){
                    v0[0]=v3[0];
                }
                else if(v3.size()==0) {
                    v1[0]=v2[0];
                }
                else {
                    if((LL)v0[0]*v2[0]>(LL)v1[0]*v3[0]){
                        v1[0]=v2[0];
                    }
                    else v0[0]=v3[0];
                }
            }
            cout<<calc()<<endl;
        }
    }
    else if(l){
        puts("0");
    }
    else {
        sort(a+1,a+1+n,cmp);
        for(int i=1;i<=k;++i){
            v0.push_back(a[i]);
        }
        cout<<calc()<<endl;
    }




    return 0;
}

Measured memory_bytes: 4696
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Objects;

public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();

        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0)break;
            for(int i=0;i<W;i++)System.out.print("#");
            System.out.println();
            for(int i=1;i<H-1;i++){
                System.out.print("#");
                for(int j=1;j<W-1;j++)System.out.print(".");
                System.out.println("#");
            }
            for(int i=0;i<W;i++)System.out.print("#");
            System.out.println();
            System.out.println();
        }

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}



Measured memory_bytes: 35632
#include <bits/stdc++.h>
#define up(i,a,b) for(int i=a;i<=b;i++)
#define down(i,a,b) for(int i=a;i>=b;i--)
#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 CL(x) (x<<1)
#define CR(x) (x<<1)+1
#define pb push_back
#define bit1(x) __builtin_popcount(x)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

template<typename T> inline void _read(T &x){
    char ch; x=0; bool neg=false;
    for(ch=getchar();ch<'0'||ch>'9';ch=getchar())
        if(ch=='-') neg=true;
    for(;ch>='0'&&ch<='9';ch=getchar()) x=10*x+ch-'0';
    if(neg) x=-x;
}
#define read(a) _read(a)
#define Read(a,b) _read(a),_read(b)
#define READ(a,b,c) _read(a),_read(b),_read(c)

const int maxn=50+7;
const int maxS=(1<<19);
const ll mod=1234567890;
const int inf=1e9+9;

int n,Max,Min;
int a[maxn];
bool pos,neg;
vector<pii> kq;

inline void Enter(){
    cin>>n;
    pos=neg=true;
    a[0]=-inf,a[n+1]=inf;
    Max=0,Min=n+1;
    up(i,1,n){
        cin>>a[i];
        if(a[i]<0) pos=false;
        if(a[i]>0) neg=false;
        if(a[i]>a[Max]) Max=i;
        if(a[i]<a[Min]) Min=i;
    }
}

inline void AllPos(){
    up(i,2,n) if(a[i]<a[i-1]) a[i]+=a[i-1],kq.pb(pii(i-1,i));
    cout<<kq.size()<<'\n';
    rep(i,0,kq.size()) cout<<kq[i].first<<' '<<kq[i].second<<'\n';
}

inline void AllNeg(){
    down(i,n-1,1) if(a[i]>a[i+1]) a[i]+=a[i+1],kq.pb(pii(i+1,i));
    cout<<kq.size()<<'\n';
    rep(i,0,kq.size()) cout<<kq[i].first<<' '<<kq[i].second<<'\n';
}

inline void PosNeg(){
    if(abs(a[Max])>abs(a[Min])){
        up(i,1,n) if(a[i]<0) a[i]+=a[Max],kq.pb(pii(Max,i));
        AllPos();
    } else{
        up(i,1,n) if(a[i]>0) a[i]+=a[Min],kq.pb(pii(Min,i));
        AllNeg();
    }
}

inline void Solve(){
    if(pos) AllPos();
    else if(neg) AllNeg();
    else PosNeg();
}

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


    Enter();
    Solve();

    return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

ll a[100000];
int main(){
    int n;
    cin >> n;
    REP(i,n){
        cin >> a[i];
    }
    sort(a, a+n);
    ll max = a[n-1];
    ll mid = max/2;
    //ll diff = LLONG_MAX;
    ll val;
    ll val2 = LLONG_MAX;
    int index = -1;
    REP(i,n-1){
        val = abs(mid - a[i]);
        if(val > val2) break;
        index = i;
        val2 = val;
    }
    printf("%lld %lld\n", max, a[index]);
    return 0;
}


Measured memory_bytes: 1024
from collections import deque

w = ["dream", "erase", "dreamer", "eraser"]
s = deque(list(input()))
c = 1
while s:
    u = deque()
    p = s.pop()
    u.append(p)
    if p == "r":
        for _ in range(5):
            u.appendleft(s.pop())
            if len(s) == 0:
                break
        if "".join(u) != w[3] and len(s) != 0:
            u.appendleft(s.pop())
            if "".join(u) != w[2]:
                c = 0
    else:
        for _ in range(4):
            u.appendleft(s.pop())
            if len(s) == 0:
                break
        if not "".join(u) in w:
            c = 0
    if c == 0:
        break
print("YES" if c == 1 else "NO")

Measured memory_bytes: 4900
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

using P = pair<ll, int>;
#define fi first
#define se second

#define amax(a, b) a = max(a, b)

int main() {
    int n;
    cin >> n;
    int i = 0;
    P babies[n]; 
    for (auto &bi:babies) {
        cin >> bi.fi;
        bi.se = i++;
    }
    sort(babies, babies+n, greater<P>());
    // for (auto &bi:babies) cerr << bi.fi << ' ' << bi.se << '\n';
    ll dp[n+1][n+1];
    fill(dp[0], dp[n+1], 0);
    for (int w=n; w>0; w--) {
        P baby = babies[n-w];
        // cerr << baby.fi << ' ' << baby.se << '\n';
        for (int j=0; j+w<=n; j++) {
            amax(dp[j][j+w-1], dp[j][j+w] + baby.fi * abs(j+w-1 - baby.se));
            amax(dp[j+1][j+w], dp[j][j+w] + baby.fi * abs(j - baby.se));
        }
    }
    ll ans = 0;
    for (int i=0; i<=n; i++) amax(ans, dp[i][i]);
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    string ans = "";
    rep (i, s.size()) {
        if (i % 2 == 0) {
            ans += s[i];
        }
    }

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


Measured memory_bytes: 592
#include <stdio.h>
 
int main(){
    long long int a;
    scanf("%lld",&a);
 
    char name[100];
    int i=0;
    
    while(a!=0)
    {
        a--;
        int b = a%26;
        name[i] ='a'+ b;
        a/=26;
        i++;
    }
 
    for(int j=i-1;j>=0;j--)
    {
        printf("%c",name[j]);
    }
    
    return 0;
}

Measured memory_bytes: 1644
#include<stdio.h>

int main(){
  int i,n,A[100001],q,key,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(binarySearch(n,A,key)!=0)sum++;
  }
  printf("%d\n",sum);
  return 0;
}

int binarySearch(int n,int A[],int key){
  int left = 0;
  int right = n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==key)return 1;
    else if(key<A[mid])right = mid;
    else left=mid+1;
  }
  return 0;
}

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

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

    static class BDigits {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int cnt = 0;
            while (n != 0) {
                n /= k;
                cnt++;
            }
            out.println(cnt);

        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

bool snuke[101];

int main(){
	int n, k, d;
	cin >> n >> k;

	for (int i = 0; i < k; i++){
		cin >> d;
		for (int j = 0; j < d; j++){
			int a;
			cin >> a;
			snuke[a] = true;
		}
	}
	int answer = 0;

	for (int i = 1; i <= n; i++){
		if (!snuke[i]) answer++;
	}
	cout << answer << endl;
	return 0;
}


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

int main() {
  int A, B;
  cin>>A>>B;
  if(A+B>A-B){
    if(A+B>A*B){
      cout<<A+B;
    }
    else{
      cout<<A*B;
    }
    
  }
  else{
    if(A-B>A*B){
      cout<<A-B;
    }
  
  else{
    cout<<A*B;
  }
}
}
  
  

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,M,c[100000];
bool b[100000];
int main(){
	cin>>N>>M;
	rep(i,N) c[i]=1;
	b[0]=1;
	rep(tt,M){
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		c[x]--;
		c[y]++;
		if(b[x]) b[y]=1;
		if(c[x]==0) b[x]=0;
	}
	int a=0;
	rep(i,N) if(b[i]) a++;
	cout<<a<<endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll N, M;
ll A[100100];

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

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

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

    ll x = 1;

    for(int i=0;i<N;++i){
        A[i] /= 2;

        x = x * (A[i] / gcd(x, A[i]));

        if(x >= 10'000'000'000){
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    for(int i=0;i<N;++i){
        if(x / A[i] % 2 == 0){
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    ll res = M / x - M / (2ll * x);

    std::cout << res << std::endl;
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


vector<vector<bool>> card(3, vector<bool>(3, false));
bool bingo() {
  bool flag = false, flag_v, flag_h, flag_d_1, flag_d_2;
  rep(i, 3) {
    flag_v = true, flag_h = true, flag_d_1 = true, flag_d_2 = true;
    rep(j, 3) {
      if (!card[j][i]) {
        flag_v = false;
      }
      
      if (!card[i][j]) {
        flag_h = false;
      }
      
      if (!card[j][2-j]) {
        flag_d_1 = false;
      }
      
      if (!card[j][j]) {
        flag_d_2 = false;
      }
    }
    if (flag_v || flag_h || flag_d_1 || flag_d_2) flag = true;
  }
  return flag;
}



int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i, 3)rep(j, 3) cin >> a[i][j];
  int n; cin >> n;
  
  rep(i, n){
    int x;
    cin >> x;
    rep(j, 3)rep(k, 3){
      if (x == a[j][k]) card[j][k] = true;
    }
  }
  
  if (bingo()) puts ("Yes");
  else puts ("No");
  return 0;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
#define MOD 1000000007

ll m[200010],p[200010];
int mcnt,pcnt;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	rep(i,0,n){
		int t;
		scanf("%d",&t);
		if(t>=0)p[pcnt++]=t;
		else m[mcnt++]=-t;
	}
	//正の数・負の数をそれぞれソート
	sortup(m,mcnt);
	sortup(p,pcnt);
	
	//K==Nのとき
	if(k==n){
		ll ans=1;
		rep(i,0,mcnt)ans=ans*(MOD-m[i])%MOD;
		rep(i,0,pcnt)ans=ans*p[i]%MOD;
		printf("%lld",ans);
		return 0;
	}
	
	//Kが奇数かつ負のみのとき
	if(k%2==1&&mcnt==n){
		ll ans=1;
		rep(i,0,k)ans=ans*(MOD-m[i])%MOD;		
		printf("%lld",ans);
		return 0;
	}
	
	ll ans=1;
	while(k){
		// 負の数を2個とる or 正の数を1個とる
		if(k>=2 && mcnt>=2 &&(pcnt<=1 || (pcnt>=2 && m[mcnt-1]*m[mcnt-2]>=p[pcnt-1]*p[pcnt-2]))){
			ans=ans*m[--mcnt]%MOD;
			ans=ans*m[--mcnt]%MOD;
			k-=2;
		}else{
			ans=ans*p[--pcnt]%MOD;
			k--;
		}
	}
	printf("%lld",ans);
}


Measured memory_bytes: 4124
#include<stdio.h>
int main(){
        int a,b,x;
        char op;
        
        scanf("%d %c %d",&a,&op,&b);
        
        while(1){//加算
                if(op == '+'){
                        x = a + b;
                }//減算
                else if(op == '-'){
                        x = a - b;
                }//乗算
                else if(op == '*'){
                        x = a * b;
                }//除算
                else if(op == '/'){
                        x = a / b;
                }//ループを抜ける
                else if(op == '?'){
                        break;
                }
                printf("%d\n",x);
                scanf("%d %c %d",&a,&op,&b);
        }
        return 0;
}



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

int main(){
    int n, k;
    cin >> n >> k;
    vector<double> P(n+1, 0);
    double ans = -1;
    for (int i = 0; i < n; i++){
        double p;
        cin >> p;
        P.at(i+1) = P.at(i) + (1 + p) / 2;
        if(i + 1 >= k)
            ans = max(ans, P.at(i+1) - P.at(i-k+1));
    }

    cout << setprecision(10) << fixed << ans << endl;
    
}


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

int main(){
    int n, d, x;
    cin >> n >> d >> x;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];

    for(int i = 0; i < n; i++){
        x++;
        if(d / a[i] >= 1){
            x += (d-1) / a[i];
        }
    }
    cout << x << endl;
    return 0;
}

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

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int a = abs(A-B) + abs(B-C); // ABC // CBA
  int b = abs(A-C) + abs(C-B);//ACB // BCA
  int c = abs(B-A) + abs(A-C); // BAC // CAB
  int mi = min(a, min(b, c));
  cout << mi << endl;
  
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(N):
	for j in range(N):
		for k in range(N):
			if a[i] + a[j] + a[k] - max(a[i], a[j],a[k]) > max(a[i], a[j],a[k]) and a[i] != a[j] and a[i] != a[k] and a[k] != a[j]:
				count += 1
count = count //6
print(count)

Measured memory_bytes: 9164
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin>>h.at(i);
    }
    
    int now=0;
    int ans=0;
    for(int i=0; i<n-1; i++){
        if(h.at(i)>=h.at(i+1)){
            now++;
        }else{
            now=0;
        }
        ans = max(ans, now);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 640
from collections import deque


K = int(input())
q = deque()
for i in range(1, 10):
    q.append(i)

while K > 0:
    p = q.popleft()
    K -= 1
    r = p % 10
    if r != 0:
        q.append(10 * p + r - 1)
    q.append(10 * p + r)
    if r != 9:
        q.append(10 * p + r + 1)

print(p)


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


int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;

    cout<<(n>k ? x*k+(n-k)*y : n*x) <<endl;


    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s.at(i);
	int cnt=0;
	vector<vector<bool>> check(h,vector<bool>(w,true));
	check[0][0]=false;
	queue<pair<pii,int>> q;
	q.push(mp(mp(0,0),1));
	while(!q.empty()){
		pii cur=q.front().first;int num=q.front().second;
		q.pop();
		if(cur.first==w-1 && cur.second==h-1){
			cnt=num;
			break;
		}
		if(cur.first-1>=0 && s[cur.second][cur.first-1]=='.' && check[cur.second][cur.first-1]){
			q.push(mp(mp(cur.first-1,cur.second),num+1));
			check[cur.second][cur.first-1]=false;
		}
		if(cur.first+1<w && s[cur.second][cur.first+1]=='.' && check[cur.second][cur.first+1]){
			q.push(mp(mp(cur.first+1,cur.second),num+1));
			check[cur.second][cur.first+1]=false;
		}
		if(cur.second-1>=0 && s[cur.second-1][cur.first]=='.' && check[cur.second-1][cur.first]){
			q.push(mp(mp(cur.first,cur.second-1),num+1));
			check[cur.second-1][cur.first]=false;
		}
		if(cur.second+1<h && s[cur.second+1][cur.first]=='.' && check[cur.second+1][cur.first]){
			q.push(mp(mp(cur.first,cur.second+1),num+1));
			check[cur.second+1][cur.first]=false;
		}
	}
	if(cnt==0) cout << -1 << endl;
	else{
		int sum=0;
		rep(i,h){
			rep(j,w){
				if(s[i][j]=='.') sum++;
			}
		}
		cout << sum-cnt << endl;
	}
}

Measured memory_bytes: 256
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)

Measured memory_bytes: 25708
#include<bits/stdc++.h>
#define int ll
#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 3005;
int ar[N][N];
int dp[N][N][6];
int R , C;
int fun(int i , int j ,int k){
    if(i == R || j == C)
        return 0;
    auto & res = dp[i][j][k];
    if(res != -1)
        return res;
    if(k == 3)
        return res = max(fun(i + 1 , j , 0) , fun(i , j + 1 , k));
    return res = max({fun(i + 1 , j , 0) + ar[i][j] , fun(i , j + 1 , k) , fun(i , j + 1 , k + 1) + ar[i][j]});
}
signed main(){

#ifndef ONLINE_JUDGE
	freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int K;
    cin >> R >> C >> K;
    fo(_ , K){
        int r , c , v;
        cin >> r >> c >> v;
        ar[r - 1][c - 1] = v;
    }

/*
    auto relax = [](int & a , int b){ a = max(a , b) ; };
   
    dp[0][0][0] = 0;
    fo(i , R)
        fo(j , C)
            fo(k , 4){
                if(k < 3){
                    relax(dp[i][j + 1][k + 1] , dp[i][j][k] + ar[i][j]);
                    relax(dp[i + 1][j][0] , dp[i][j][k] + ar[i][j]);
                }
                relax(dp[i][j + 1][k] , dp[i][j][k]);
                relax(dp[i + 1][j][0] , dp[i][j][k]);
            }
    
    auto ans = max(
                *max_element(dp[R][C - 1] , dp[R][C - 1] + 4) , 
                *max_element(dp[R - 1][C] , dp[R - 1][C] + 4)
    );
    
    cout << ans << '\n';
*/
    memset(dp , -1 , sizeof dp);
    cout << fun(0 , 0 , 0) << '\n';
    return 0;

}



Measured memory_bytes: 497660
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
# Pythonのpowは繰り返し二乗法で実装されている
ans = pow(2, n, MOD) - 1
product = 1
div = 1
for i in range(1, b + 1):
    product = product * (n - i + 1) % MOD
    div = div * i % MOD
    if i == a or i == b:
        # 逆元を求める
        ans -= product * pow(div, MOD - 2, MOD)
print(ans % MOD)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int K;string S;cin>>K>>S;
    if(S.size()<=K)cout<<S<<endl;
    else cout<<S.substr(0,K)<<"..."<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

 
int main(void){
    int n,m;
    cin>>n>>m;
    if(n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int heap[250];
int H;

int parent(int i)
{
    return i / 2;
}

int left(int i)
{
    return 2 * i;
}

int right(int i)
{
    return 2 * i + 1;
}
int main()
{
    cin >> H;
    for (int i = 1; i <= H; i++)
        cin >> heap[i];

    for (int i = 1; i <= H; i++)
    {
        printf("node %d: key = %d, ", i, heap[i]);
        if (parent(i) > 0)
            printf("parent key = %d, ", heap[parent(i)]);
        if (left(i) <= H)
            printf("left key = %d, ", heap[left(i)]);
        if (right(i) <= H)
            printf("right key = %d, ", heap[right(i)]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    int ans=0,ph=0,tmp=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int h;
        cin>>h;
        if(h>ph){
            ans=max(ans,tmp);
            tmp=0;
        }
        else tmp++;
        ph=h;
    }
    ans=max(ans,tmp);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>

using namespace std;

int a[200'009];

int main() {
  int n;
  scanf("%d", &n);
  long long tot = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    tot += a[i];
  }
  long long ans = 1'000'000'000'000'000'000;
  long long sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    sum += a[i];
    ans = min(ans, abs(tot - 2 * sum));
  }
  printf("%lld\n", ans);
}


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

int n,m,a,b,sum=0,ans=0;
vector<int> adj[51]={};
vector<pair<int,int>> graph;
bool visited[51];

void dfs(int start, int x, int y){
    visited[start]=true;
    for(int i=0;i<adj[start].size();i++){
        if((start == x && adj[start][i] == y) || (start == y && adj[start][i] == x)){
            continue;
        }
        if(!visited[adj[start][i]]){
            visited[adj[start][i]]=true;
            dfs(adj[start][i], x, y);
        }  

    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;   
        adj[a].push_back(b);
        adj[b].push_back(a);
        graph.push_back(make_pair(a,b));
    }
    
    for(int i=0;i<m;i++){
        memset(visited, false, sizeof(visited));
        sum=0;
        dfs(graph[i].first, graph[i].first, graph[i].second);
        for(int j=1;j<=n;j++){
            if(visited[j]){
                sum++;
            }
        }
        if(sum!=n)
            ans++;
    }
    cout<<ans;
    return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;
    for(int i = 0; i < S.length(); i++){
        if(S[i] != T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

const int maxn=1e4+5;

int pre[maxn],n;

void init()
{
    for(int i=0;i<=n;i++){
        pre[i]=i;
    }
}

int find(int u)//擒贼先擒王
{
	if(u==pre[u]){
		return u;
	}else{
		pre[u]=find(pre[u]);//路径压缩，使得第二次更快，直接找到老大
		return pre[u];
	}
}

void merge(int u,int v)
{
	int t1=find(u);
	int t2=find(v);
	if(t1!=t2){
		pre[t2]=t1;
	}
	return ;
}

int main()
{
    int q;
    scanf("%d%d",&n,&q);
    init();
    for(int i=0;i<q;i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(a==1){
            if(find(b)==find(c)){
                printf("1\n");
            }else{
                printf("0\n");
            }
        }else{
            merge(b,c);
        }
    }
    return 0;
}
/*
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
*/



Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
int aa[N+2],bb[N+2];
/*************** BIT *****************/
long Bit[N+2];
void Upd(int x,long vl)
{
  for( ;x<=N;x+=(x&-x))
    Bit[x]=max(Bit[x],vl);
}
long Sum(int x)
{
  long sum=0;
  for( ;x>0;x-=(x&-x))
    sum=max(sum,Bit[x]);
  return sum;
}
////////////////////////////////////////
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;long ans=0;
  for(int i=1;i<=n;i++)cin>>aa[i];
  for(int i=1;i<=n;i++)cin>>bb[i];
  for(int i=1;i<=n;i++)
  {
    long mx=Sum(aa[i]);
    Upd(aa[i],mx+bb[i]);
    ans=max(ans,mx+bb[i]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 14080
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main (void)
{
 int a,b,c,x,i,j,k,count = 0;

  cin >> a >> b >> c >> x;

  for(i = 0;i <= a;i++){
    for(j = 0;j <= b;j++){
      for(k = 0;k <= c;k++){
        if(i * 500 + j * 100 + k * 50 == x){
          count++;
        }
      }
    }
  } 

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
//Link : https://atcoder.jp/contests/arc083/tasks/arc083_b
#include <bits/stdc++.h>

using namespace std;
#define ll long long

#define N 305
long long dist[N][N];
long long R[N][N];
vector<int> adj[N];
void sp(int node) {
  R[node][node] = 0;
  priority_queue<pair<long long,int> ,vector<pair<long long,int> >, greater<pair<long long,int> > >pq;
  pq.push(make_pair(0,node));
  while(!pq.empty()) {
    long long d = pq.top().first;
    int cur = pq.top().second;
    pq.pop();
    if(d!=R[node][cur]) {
      continue;
    }
    for(int i=0;i<adj[cur].size();++i) {
      int nextNode = adj[cur][i];
      if(R[node][nextNode]==-1 || R[node][nextNode]> d + dist[nextNode][cur]) {
        R[node][nextNode] = d+ dist[nextNode][cur];
        pq.push(make_pair(R[node][nextNode],nextNode));
      }
    }
  }
}
pair<long long,pair<int,int> > in[N*N];
void solve() {
  int n;scanf("%d",&n);
  int pos = 0;
  for(int i=1;i<=n;++i) {
    for(int j=1;j<=n;++j) {
      scanf("%lld ", &dist[i][j]);
      if(i<j)
        in[pos++] = (make_pair(dist[i][j],make_pair(i,j)));
    }
  }
  sort(in,in+pos);
  memset(R,-1,sizeof(R));
  long long ret = 0;
  for(int i=0;i<pos;++i) {
    long long d = in[i].first;
    int x = in[i].second.first, y= in[i].second.second;
    bool needEdge = true;
    for(int node=1;node<=n;++node) {
      if(node==x || node==y) {
        continue;
      }
      if(d == dist[x][node] + dist[node][y]) {
        needEdge = false;
      }
    }
    if(needEdge) {
      ret += d;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
  }
  for(int i=1;i<=n;++i) {
    sp(i);
  }
  for(int i=1;i<=n;++i) {
    for(int j=1;j<=n;++j) {
      if(R[i][j]!=dist[i][j]) {
        printf("-1\n");
        return;
      }
    }
  }
  printf("%lld\n", ret);
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String args[]) throws Exception {
        String s = br.readLine();
        System.out.println(s.charAt(0)+""+s.charAt(1)+""+s.charAt(2));
    }

}

Measured memory_bytes: 25324
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {
void cout_str (int a, int b) {
  REP(i,b) cout << a; 
  cout << endl;
}

int main(void) {
  int a,b;cin>>a>>b;
  if(a>b) {
    cout_str(b,a);
  } else {
    cout_str(a,b);
  }
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
using namespace  std;

struct Node{    //リストのような扱い
    int key;
    Node* left;
    Node* right;
    Node* parent;
};

Node* root, *NIL;   //代表的なポインタを記録しておく

void insert(int k){
    Node* y = NIL;
    Node* x = root;
    Node* z;

    //kのキーを持つ節点を生成
    z = new Node;
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NIL){  //根から降りてくる
        y = x;  //ひとつ前の節点を保持
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y==NIL){
        root = z;
    }else{
        //場所が分かった構造体に情報を書き込む；
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inParse(Node* u){
    if(u==NIL) return;
    inParse(u->left);
    printf(" %d", u->key);
    inParse(u->right);
}

void preParse(Node* u){
    if(u==NIL) return;
    printf(" %d", u->key);
    preParse(u->left);
    preParse(u->right);
}

int main(){

    int n;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        string str;
        cin >> str;
        if(str == "insert"){
            int key;
            scanf("%d", &key);
            insert(key);
        }else if(str == "print"){
            inParse(root);
            printf("\n");
            preParse(root);
            printf("\n");
        }
    }


    return 0;
}


Measured memory_bytes: 26700
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);

int __inf_ignore(){
	int t = inf<int>;
	return t;
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int n;
Int s;

void solve(){
	for(Int b = 2;b*b <= n;b++){
		Int _n = n, s0 = 0;
		for(;_n!=0;){
			s0 += _n%b;
			_n /= b;
		}
		if(s==s0){
			cout<<b<<endl;
			return;
		}
	}
	if(s>n){
		cout<<-1<<endl;
		return;
	}
	Int d = n - s, ans = inf<Int>;
	for(Int t = 1;t * t <= d;t++){
		if(d%t==0){
			Int p = t, b = d/t + 1;
			if(p>=b)continue;
			Int q = s - p;
			if(q<0 or q>=b)continue;
			if(not (p*b + q == n and p + q == s))continue;
			ans = min(ans,b);
		}
	}
	if(n==s){
		ans = min(ans,s+1);
	}
	if(ans == inf<Int>){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
}
//{{{ main fucnction
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
    cin >> s;
	solve();
	return 0;
}
//}}}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin>>x;
    cout<<360/__gcd(360,x)<<endl;
    return 0;
}

Measured memory_bytes: 3628
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int n;
int a[M];
bitset<22>x;
int last[22];
 main()

{
    fast
    cin>>n;
    f(i,1,n)
    {
        cin>>a[i];
    }
    int ses=0,lft=0;
    f(i,1,n)
    {
        x=a[i];
        for(int j=0;j<20;j++)
        {
            if(x[j]==1)
            {
                lft=max(lft,last[j]);
            }
        }
       // cout<<i<<" "<<lft<<endl;
        ses+=(i-lft);
        for(int j=0;j<20;j++)
        {
            if(x[j]==1)
            {
                last[j]=i;
            }
        }
    }
    cout<<ses<<endl;
    return 0;
}































Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define gcd(a,b) __gcd(a,b)
#define IO() assert(freopen("in.in", "rt", stdin)), assert(freopen("out.out", "wt", stdout))
#define FastIO() ios::sync_with_stdio(false),cin.tie(0);
#define debug(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl
#warning do not forget to change size of N and M  and -01 to -02
typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 1e7 + 9, M = 1e5 + 9, OO = 0x3f3f3f3f;
const double EPS = 1e-10;
inline bool dCMP(const long double &a, const long double &b) { return fabsl(a - b) < EPS; }
ll arr[N];
int main()
{
  
  int n;
  ll a,b,ans=0;
  scanf("%d%lld%lld",&n,&a,&b);
  for(int i=0;i<n;++i) scanf("%lld",arr+i);
  for(int i=1;i<n;++i)
  {
    ll A=(arr[i]-arr[i-1])*a;
    if(A<=b) ans+=A;
    else ans+=b;
  }
  printf("%lld",ans);
  
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

bool isLeap(int y) {
	if(y % 400 == 0) return true;
	if(y % 100 == 0) return false;
	if(y % 4 == 0) return true;
	return false;
}

int main() {
	bool isFirst = true;
	for(int a, b; cin >> a >> b, a || b;) {
		if(isFirst == false) cout << endl;
		bool f = false;
		for(int i = a; i <= b; i++) {
			if(isLeap(i)) {
				cout << i << endl;
				f = true;
			}
		}
		if(f == false) {
			cout << "NA" << endl;
		}
		
		isFirst = false;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long double a,b,c;
    cin>>a>>b>>c;
 
 long long int d=c-a-b;
    if(d*d> 4*a*b&&d>0)
    cout<<"Yes";
    else
    cout<<"No";
    
    
}

Measured memory_bytes: 256