akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long int
#define MOD 1000000007

int main() {
    long int n,k,x,y,ans=0;
    cin>>n>>k>>x>>y;
    long int t=(n-k)>0?(n-k):0;
    //long int tt=n>=k?n
    if(n>k)
    ans=k*x+t*y;
    else 
    ans=n*x;
    cout<<ans<<endl;
	// your code goes here
	return 0;
}


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

typedef long long ll;

int main()
{

    ll n,a,b,t,p,i;
    double cal,mn,diff;
    cin >> n >> t >> a;
    for(i=0; i<n; i++){
        cin >> b;
        cal=(double)(t*1.0)-b*0.006;
        diff=abs(cal-a);
        if(i==0)mn=diff,p=i+1;
        else{
            if(mn>diff)mn=diff,p=i+1;
        }
    }
    cout << p << "\n";



    return 0;
}


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

const int MAXN = 100005;
const int MOD = int(1e9) + 7;
const double PI = acos (-1.0);
const int INF = 0x3f3f3f3f;
const int dx[] = { -1, 0, 1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

template <class T> inline T min (T a, T b, T c) { return min (min (a, b), c); }
template <class T> inline T max (T a, T b, T c) { return max (max (a, b), c); }
template <class T> inline T min (T a, T b, T c, T d) { return min (min (a, b), min (c, d)); }
template <class T> inline T max (T a, T b, T c, T d) { return max (max (a, b), max (c, d)); }
template <class T> inline T min (T a, T b, T c, T d, T e) { return min (min (min (a, b), min (c, d)), e); }
template <class T> inline T max (T a, T b, T c, T d, T e) { return max (max (max (a, b), max (c, d)), e); }

string a;
stack<char> s;
int main ()
{
    cin >> a;
    int end = a.length();
    int ans = end;
    for(int i = 0; i < end; ++i)
    {
        if(!s.empty() && s.top() == 'S' && a[i] == 'T')
            ans -= 2, s.pop();
        else 
            s.push(a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

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

    int cnt = 1;

    int brk = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == cnt)
        {
            cnt++;
        }
        else
        {
            brk++;
        }
    }

    if (brk == n)
    {
        cout << -1 << endl;
    }

    else
    {
        cout << brk << endl;
    }

    return 0;
}

Measured memory_bytes: 4028
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)

typedef pair<int, int> pii;

const int inf = 1e9;

struct edge {
	int to, cost, time;
	edge(int to0,int cost0,int time0) {
		to = to0; cost = cost0; time = time0;
	};
};

int N, M;

vector<edge> G[100];
int d[100];

void dijkstra(int s, int mode)
{
	priority_queue<pii, vector<pii>, greater<pii> > q;

	fill(d, d + M, inf);
	d[s] = 0;

	q.push(MP(0, s));

	while (q.size()) {
		pii p = q.top(); q.pop();
		int v = p.scd;
		rep(u, G[v].size()) {
			edge e = G[v][u];
			int a = mode == 0 ? e.cost : e.time;
			if (d[e.to] > d[v] + a) {
				d[e.to] = d[v] + a;
				q.push(MP(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	while (scanf("%d %d", &N, &M), N || M) {
		rep(i, M) G[i].clear();

		rep(i, N) {
			int a, b, cost, time; scanf("%d %d %d %d", &a, &b, &cost, &time); a--; b--;
			G[a].PB(edge(b, cost, time));
			G[b].PB(edge(a, cost, time));
		}

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

		rep(i, K) {
			int p, q, r; scanf("%d %d %d", &p, &q, &r); p--; q--;
			dijkstra(p, r);
			printf("%d\n", d[q]);
		}
	}
}

Measured memory_bytes: 1124
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
int main() {
	int n; cin >> n;
	int d; cin >> d;

	int ans = n / (d * 2 + 1);
	if (n % (d * 2 + 1) == 0) cout << ans;
	else cout << ans + 1;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize "Ofast,omit-frame-pointer,inline"
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 998244353;



int main() {
	int n;
	cin >> n;
	VLL a(n);
	
	ll b = 0;

	REP(i, n) {
		cin >> a[i];
		b ^= a[i];
	}

	REP(i, n) {
		cout << (b ^ a[i]) << ' ';
	}



}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

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


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
ll dp[N];

ll powmod(ll a, int b) {
	ll r = 1;
	while (b > 0) {
		if (b&1) r = (r * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return r;
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int g = k; g > 0; g--) {
		dp[g] = powmod(k/g, n);
		for (int x = g + g; x <= k; x += g)
			dp[g] = (dp[g] + MOD - dp[x]) % MOD;
		ans = (ans + (dp[g] * g) % MOD) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4412
fn main() {
    use std::io;
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("cannot read input");

    let input_nums = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect::<Vec<_>>();

    let first = input_nums[0];
    let second = input_nums[1];

    if first % second == 0 {
        println!("0");
    } else {
        println!("1");
    }
}

Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CReplacingInteger {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            long n = s.nextLong(), k = s.nextLong();
            w.println(Math.min(n % k, k - n % k));
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public long nextLong() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }

            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21332
#include<iostream>
using namespace std;
int main()
{
  int n,p=0;
  cin>>n;
  for(int i=1;i<=9;i++)
  {
    for(int j=1;j<=9;j++)
    {
      if(i*j==n)
      {
        cout<<"Yes";
        p=1;
        break;
      }}
     if(p==1)
       break;
    }
    if(p==0)
      cout<<"No";
    return 0;
  }

Measured memory_bytes: 256
//In the name of ALLAH the most merciful the most beneficial

#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 1e5+7;
static const int INF = 0x3f3f3f3f;
static const int MOD = 1e9+7;

bool arr[11];

bool check(int n){

    while(n){

        if(arr[n%10] == 1){
            return false;
        }
        n /= 10;
    }
    return true;
}

int main(){
    /*
    clock_t start,end;
    start = clock();*/

    memset(arr,0,sizeof arr);
    int val;cin >> val;
    int n,x;cin >> n;
    FOR(i,0,n) {
        cin >> x;
        arr[x] = true; //1 stands for dislike
    }

    for(int i=val;;i++){

        if(check(i)){
            cout << i;
            return 0;
        }
    }


    /*end = clock();
    double time = double(end-start)/(double)CLOCKS_PER_SEC;
    cout <<fixed<< time/1000 << "sec";*/
}

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

int main(){
    string S;
    cin >> S;
    bool ans = 1;
    if(S[2] != S[3]){
        ans = 0;
    }
    if(S[4] != S[5]){
        ans = 0;
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No"<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int n; cin >> n;
  vector<int> a(n); rep(i,n){cin>>a[i];}
  double t=0;
  rep(i,n){
    t+=1.0/a[i];
  }

  cout << 1/t;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, M;
  cin >> N >> M;
  VEC<int> imos(N +2, 0);
  REP(i, 0, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    imos[a]++;
    imos[b + 1]--;
  }
  REP(i, 1, N+1) { imos[i] += imos[i - 1]; }
  int ma = *max_element(ALL(imos));
  // DUMP(imos);
  int cnt=0;
  if(ma!=M){
    cout<<0<<endl;
    return 0;

  }
  REP(i,0,N+1){
    if(ma==imos[i]){
      cnt++;
    }
  }
  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
void insertionSort(int A[], int n){
    for(int i=1; i<n;i++){
        int v = A[i];
        int j = i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
    }
    for(int i=0; i<n;i++){
        if(i>0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

int main(){
    int A[3];
    for(int i=0; i<3;i++) scanf("%d", &A[i]);
    insertionSort(A, 3);
    return 0;
}


Measured memory_bytes: 2720
#include<cstdio>
#define r register
inline bool isd(r char ch) {
	return ch<='9'&&ch>='0';
}
template<class temp>
inline temp F() {
	r temp x=0;
	r bool bo=0;
	r char ch=getchar();
	while(ch!='-'&&!isd(ch))
		ch=getchar();
	(ch=='-')&&(bo=1,ch=getchar());
	x=ch^'0',ch=getchar();
	while(isd(ch))
		x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	bo&&(x=-x);
	return x;
}
const int mod=1000000007;
#define inf 2147483647
class Graph {
	public:
		struct Edge {
			int to;
			Edge* nxt;
		};
		typedef Edge* Node;
		Node Nul,*Head;
		void Resize(r int siz) {
			Head=new Node[siz+1];
			for(r int i=0;i<=siz;++i)
				Head[i]=Nul;
		}
		void Add(r int f,r int t) {
			Node x=new Edge();
			x->to=t;
			x->nxt=Head[f],Head[f]=x;
		}
}P;
int c[200001],pos[200001],cnt[200001],tot;
long long w[200001],fac[200001],rfac[200001],mn[200001];
bool v[200001];
long long qpow(r long long a,r long long b) {
    r long long ans=1;
    while(b) {
        if(b&1)
			ans=(ans*a)%mod;
        a=(a*a)%mod,b>>=1;
    }
    return ans;
}
long long C(r long long n,r long long k){
    return fac[n]*rfac[n-k]%mod*rfac[k]%mod;
}
void dfs(r int x){
    v[x]=1;
    for(r Graph::Node j=P.Head[x];j!=P.Nul;j=j->nxt)
		if(!v[j->to])
        	dfs(j->to);
}
int main() {
    r int n=F<int>();
    P.Resize(n);
    r long long X=F<long long>(),Y=F<long long>(),min1,min2;
    fac[0]=1;
    for(r int i=1;i<=n;++i) {
    	c[i]=F<int>(),w[i]=F<long long>();
        fac[i]=(i*fac[i-1])%mod,mn[i]=inf;
    }
    rfac[n]=qpow(fac[n],mod-2);
    for(r int i=n;i;--i)
		rfac[i-1]=(i*rfac[i])%mod;
    for(r int i=1;i<=n;++i)
        if(w[i]<mn[c[i]])
            mn[c[i]]=w[i],pos[c[i]]=i;
    for(r int i=1;i<=n;++i)
        if(i!=pos[c[i]]&&w[i]+mn[c[i]]<=X)
            P.Add(i,pos[c[i]]),P.Add(pos[c[i]],i);
    min1=min2=inf;
    r int f,t;
    for(r int i=1;i<=n;++i)
        if(w[i]<min1)
            min1=w[i],f=i;
    for(r int i=1;i<=n;++i)
        if(w[i]<=min2&&c[i]!=c[f])
            min2=w[i],t=i;
    for(r int i=1;i<=n;++i) {
        if(i==f)
			continue;
        if(c[i]!=c[f]&&w[i]+w[f]<=Y)
            P.Add(i,f),P.Add(f,i);
        if(t&&c[i]!=c[t]&&w[i]+w[t]<=Y)
            P.Add(i,t),P.Add(t,i);
    }
    dfs(f);
	r long long tot=0;
    for(r int i=1;i<=n;++i)
        if(v[i])
            ++tot,++cnt[c[i]];
    r long long ans=1;
    for(r int i=1;i<=n;++i)
        if(cnt[i])
            ans=(ans*C(tot,cnt[i]))%mod,tot-=cnt[i];
    printf("%lld\n",ans);
}

Measured memory_bytes: 35968
#include "bits/stdc++.h"
#define rep(i, j) for (long long i = j; i > 0; i--)
using namespace std;


int main() {
	double w, h, x, y;
	cin >> w >> h >> x >> y;

	double ans;

	if (x == w / 2 && y == h / 2) {
		double menseki = w * h / 2;
		printf("%lf 1", menseki);
		return 0;
	}

	ans = w * h / 2;
	printf("%lf 0", ans);

	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
a=[-1]*(n+1)
st=set()
for i in range(m):
    x,y=map(int,input().split())
    chk=(min(x,y),max(x,y))
    if chk in st: 
        continue
    st.add(chk)
    while a[x]>=0:
        x=a[x]
    while a[y]>=0:
        y=a[y]
    if x==y:
        continue
    if a[x]<a[y]:
        a[x]+=a[y]
        a[y]=x
    else:
        a[y]+=a[x]
        a[x]=y
cnt=0
for i in a[1:]:
    if i<0:
        cnt=max(cnt,-i)
print(cnt)
    
    
    
    
    

Measured memory_bytes: 105480
n = int(input())
blue_list = [ input() for i in range(n)]
m = int(input())
red_list = [ input() for i in range(m)]

card_list = list(set(blue_list+red_list))

point = 0

for i in card_list:
	point = max(point,blue_list.count(i)-red_list.count(i))

print(point)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int dp[3000][3000];
void helper(string &s,string &t,int len)
{
    string LCS;
    int i=0,j=0;
    while(len)
    {
        if(s[i] == t[j])
        {
            LCS.push_back(s[i]);
            i++;
            j++;
            len--;
        }
        else if(dp[i][j+1]> dp[i+1][j])
            j++;
        else
            i++;
    }
    cout<<LCS;

}

int maxlensubseqence(int i,int j,string &s,string &t)
{
    if(i>= s.length() or j>= t.length())
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    if(s[i] == t[j])
        return dp[i][j] = 1 + maxlensubseqence(i+1,j+1,s,t);
    else
        return dp[i][j] = max(maxlensubseqence(i,j+1,s,t), maxlensubseqence(i+1,j,s,t));
}


void printmaxlensubsequence(string s,string t)
{
    memset(dp,-1,sizeof dp);
   int len =  maxlensubseqence(0,0,s,t);

    helper(s,t,len);
    // for(int i=0;i<s.length();i++)
    // {
    //     for(int j=0;j<t.length();j++)
    //         cout<<dp[i][j]<<"\t";
    //     cout<<endl;
    // }

}

int main()
{
    string s,t;
    cin>>s>>t;
    printmaxlensubsequence(s,t);
    return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 998244353;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}
void YES(bool condition){
	if(condition){
		p("YES");
	}else{
		p("NO");
	}
	return;
}
void Yes(bool condition){
	if(condition){
		p("Yes");
	}else{
		p("No");
	}
	return;
}

ll i,j,k,ii,jj,n,m,a,b,c,d,e,f,g,h,r,w,l,num,sum,ans,ok,ng,mid;
ll x[500005],y[500005],z[500005];
char s[500005],t[500005],u[500005];
bool dame,flag;
//string s;
int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	ans = x[0];
	for(i=1;i<n;i++){
		ans = gcd(ans,x[i]);
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 26624
from itertools import combinations
import numpy as np
n=int(input())
array=[]
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
for xi, yi in x:
  for xj, yj in x:
    cnt+=((xi-xj)**2+(yi-yj)**2)**0.5
print(cnt/n)
    


Measured memory_bytes: 12508
function rot (n, c) {
  const alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  return alpha.charAt((alpha.indexOf(c) + n) % 26)
}

function main (input) {
  const line = input.split('\n')
  const n = parseInt(line[0], 10)
  const s = line[1]
  const ss = s.split('')

  console.log(ss.map((x) => rot(n, x)).join(''))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7752
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int cnt[200020];
int main(void){
    cin.tie(0);ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    int n;cin >> n;
    for(int i = 2;i <= n;i++){
        int x;cin >> x;
        cnt[x]++;
    }

    for(int i = 1;i <= n;i++){
        cout << cnt[i] << '\n';
    }
}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MAX_N = 100005;
int P[MAX_N];
 
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> P[i];
		P[i]--;
	}
 
	set<int> s;
	int index[MAX_N];
	ll ans = 0;
 
	for (int i = 0; i < N; ++i)
	{
		index[P[i]] = i;
	}
 
	for (int x = N-1; x >= 0; --x)
	{
		int i = index[x];
		ll c;
		//calc c
		s.insert(i);
		int l[2] = {-1,-1};
		int r[2] = {N,N};
 
		//calc l
		auto it = s.find(i);
		for (int j = 0; j < 2; ++j)
		{
			if (it == s.begin()) break;
			it--;
			l[j] = *it;
		}
 
		//calc r
		it = s.find(i);
		for (int j = 0; j < 2; ++j)
		{
			it++;
			if (it == s.end()) break;
			r[j] = *it;
		}
 
		int ls[2],rs[2];
		ls[0] = i-l[0];
		ls[1] = l[0]-l[1];
		rs[0] = r[0]-i;
		rs[1] = r[1]-r[0];
		c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
 
		ans += c * (x+1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
use std::io;


/// https://beta.atcoder.jp/contests/abc083/tasks/abc083_b
fn main() {
    let (n, a, b) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };

    let ans = (1..(n + 1))
        .filter(|&i| a <= digit_sum(i) && digit_sum(i) <= b)
        .sum::<usize>();
    println!("{}", ans);
}

fn digit_sum(n: usize) -> usize {
    let mut x = n;
    let mut sum = 0;
    while x > 0 {
        sum += x % 10;
        x = x / 10;
    }
    sum
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;




int solve( ){

int n,k;
cin>>n>>k;
vi a(n);
rep(i,0,n)cin>>a[i];

int dp[n]={0};
//rep(i,0,n)dp[i]=1e9+5;

if(k>=n-1)
{
  cout<<abs(a[n-1]-a[0]);
  return 0;
}

rep(i,1,k)
{
  dp[i]=abs(a[i]-a[0]);
}

rep(i,k,n)
{  
    int mn=hell;

    rep(j,i-k,i)mn=min(mn,dp[j]+abs(a[i]-a[j]));
    dp[i]=mn;
}
cout<<dp[n-1];



return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);


  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
 //cout << "Processor time taken is "
   // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main()
{
    int i,j,n,Eng[50][26]={},D[26]={};
    char S[51];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",S);
        for(j=0;j<strlen(S);j++) Eng[i][S[j]-97]++;
    }
    for(i=0;i<26;i++) D[i]=Eng[0][i];
    for(i=1;i<n;i++) for(j=0;j<26;j++) if(D[j]>Eng[i][j]) D[j]=Eng[i][j];
    for(i=0;i<26;i++) for(j=0;j<D[i];j++) printf("%c",97+i);
    puts("");
    return 0;
}

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

bool usednumber[1000005];
bool ng[1000005];

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    sort(a.begin(), a.end());
    a.emplace_back(a.back() + 1);
    
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(usednumber[a[i]] || ng[a[i]])    continue;
        usednumber[a[i]] = true;
        if(a[i] != a[i + 1])    ++ans;
        for(int j = a[i] * 2; j < a[n]; j += a[i]){
            if(*lower_bound(a.begin() + i + 1, a.end(), j) == j)    ng[j] = true;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5872
#include <iostream>
#include<string>

using namespace std;

int main(){

	string s,p,S;
	int count, count_yes=0;
	cin >> s >> p;
	S = s + s;
	
	//??????????????°???????????????
	for (int i = 0; i<s.length(); i++){
 
		count = 0;
		//??????????????°????????????????????´??????????????????
		for (int j = 0; S[i+j] == p[j]; j++){

			count++;

		}
		//count?????°??§Yes,No??????
		if (count == p.length()){
			cout << "Yes" << endl;
			count_yes++;
		}
		if (count_yes != 0) break;
		

	}

	if (count_yes == 0){
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    long long three = n/3;
    long long five = n/5;
    long long fifteen = n/15;
    long long sumThree = 3*(0.5*three*(three+1));
    long long sumFive = 5*(0.5*five*(five+1));
    long long sumFifteen = 15*(0.5*fifteen*(fifteen+1));
    long long total = n*(n+1)*0.5;
    cout << total - sumThree - sumFive + sumFifteen << endl;
    return 0;
}

Measured memory_bytes: 3168
#include<stdio.h>
#include<math.h>
int main(void){
	int H,W,i,j;
	for(;;){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  if(A.back() == B.at(0) && B.back() == C.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define abs(n) ( (n) < 0 ) ? -(n) : (n)

int main(void){

  //入力
  int N;
  cin >> N;
  
  //処理
  bool can = false;	//できるならtrue
  for(int i = 0; i * 4 <= N; i++){
    if( (N - i*4)%4 == 0 || (N - i*4)%7 == 0){
      can = true;
      break;
    }
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

def main():
    
    input = sys.stdin.readline
    a,b,k = map(int, input().split())
    if a + b <= k:
        print(0,0)
        sys.exit()
    else:    
        if a < k:
            b = b-(k-a)
            a = 0
        else:
            a = a-k
        print(a,b)
            

if __name__ == "__main__":
    main()


Measured memory_bytes: 9076
#include<stdio.h>
int main(void){
    int i,j,n,m;          
    scanf("%d%d",&n,&m);
    int a[101][101],b[101],c[101]={0};
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0; j<m; j++){
        scanf("%d",&b[j]);
    }
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            c[i]+=a[i][j]*b[j];
        }
    }
    for(i=0; i<n; i++){
        printf("%d\n",c[i]);
    }
    return 0;
}


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

int main() {
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << ((a < b) ? a : b) + ((c < d) ? c : d) << endl;
	
	return 0;
}

Measured memory_bytes: 256
# coding:utf-8
import math

a,b,C=list(map(float,input().split()))

h=b*math.sin(math.radians(C))
S=a*h/2

c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
L=a+b+c

print('%.6f'%S)
print('%.6f'%L)
print('%.6f'%h)

Measured memory_bytes: 7664
#include<iostream>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<algorithm>
typedef long long ll;
using namespace std;

int main()
{
	int n;
	int a[150];
    ll sum = 0;
    int flag = 0;
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		cin >> a[i];
		sum += a[i];
		if(a[i]%10 != 0)
			flag = 1;
	}
	sort(a,a+n);
	if(flag == 0)//全部是10的倍数 
	{
		cout << 0 << endl;
	}
	
	if(sum%10 != 0)//没法取模 
	{
		cout << sum << endl;
	}
	else
	{
		for(int i = 0;i < n;i++)
		{
			if((sum-a[i])%10 != 0)
			{
				cout << sum-a[i] << endl;
				break;
			}	
		}
	}

	return 0;
} 

Measured memory_bytes: 256
//
//  AAAAAB.cpp
//  my_programs
//
//  Created by Jiatuo Zou on 7/22/20.
//  Copyright © 2020 Jiatuo Zou. All rights reserved.
//

#include <iostream>

int sum = 0;

void switchState(int n, int m, int d, int s[10][10], int k[10], int p[10], int states[10], int number){
    if(d == n){
        for(int i = 0; i < m; i++){
            number = 0;
            for(int j = 0; j < k[i]; j++){
                if(states[s[i][j] - 1] == 1){
                    number++;
                }
            }
            if(number % 2 != p[i]){
                return;
            }
        }
        sum++;
        return;
    }
    for(int i = 0; i <= 1; i++){
        states[d] = i;
        switchState(n, m, d + 1, s, k, p, states, number);
    }
    return;
}

int main()
{
    using namespace std;
    
    int n, m, k[10], s[10][10], p[10], states[10] = {0};
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }
    switchState(n, m, 0, s, k, p, states, 0);
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3528
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=1;i<=n;i++){
      cin>>a[i];
   }
   int b[n];
   for(int i=1;i<=n;i++){
      cin>>b[i];
   }
   int c[n-1];
   for(int i=1;i<=n-1;i++){
      cin>>c[i];
   }
   int sum=0;
   for(int i=1;i<=n;i++){
      sum+=b[i];
      if(i!=n){
	 if(a[i]+1==a[i+1]){
	    sum+=c[a[i]];
	 }
      }
   }
   cout<<sum<<endl;
}



Measured memory_bytes: 256
import sys


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


n, m = map(int, input().split())
uft = UnionFind(n)
for line in sys.stdin:
    x, y, z = map(int, line.split())
    x -= 1
    y -= 1
    uft.union(x, y)

ans = 0
for v in uft.table:
    if v < 0:
        ans += 1
print(ans)


Measured memory_bytes: 5304
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <atcoder/scc>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;

lli fact(lli n)
{
    if (n == 1 || n == 0)
    {
        return 1;
    }
    lli ans = 1;
    for (lli i = 2; i <= n; i++)
    {
        ans *= i;
        ans %= m;
    }
    ans %= m;
    return ans;
}

int main(void)
{
    /*
    all 10*10
    n0n9 8*8 = 64;
    all - n0n9 = 36;
    n0y9 = 8*2 +1 =17
    n9y0 =8*2 + 1=17
    ^^ = 34
    36 - ^^
    res = 2;
    */
    lli N;
    cin >> N;

    lli ans = 1;
    lli t = 10;
    for (int i = 0; i < N; i++)
    {
        ans *= t;
        ans %= m;
    }
    lli tmp = 1;
    t = 9;
    for (int i = 0; i < N; i++)
    {
        tmp *= t;
        tmp %= m;
    }
    tmp *= 2;
    tmp %= m;
    ans += m;
    ans -= tmp;
    ans %= m;
    lli ans2 = 1;
    t = 8;
    for (int i = 0; i < N; i++)
    {
        ans2 *= t;
        ans2 %= m;
    }
    ans += ans2;
    ans += m;
    ans %= m;
    if (N > 1)
    {
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}


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

int main(){
   long int n;
   cin >>n;
   long int b;
   int min=10000;
   int s=0;
   int t=0;
   long int ax;
   long int bx;
   for(long int a=1;a<=sqrt(n);a++){
      b=n/a;
      if(a*b==n){
            ax=a;
            bx=b;
            s=0;
            t=0;
            while(ax>=1){
               ax/=10;
               s++;
            }
            while(bx>=1){
               bx/=10;
               t++;
            }
            if(min>max(s,t))min=max(s,t);
         }
   }
   cout <<min <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = 1000000007;

LL N,M;
LL a[100010],b,c,d;
string s;

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int state=0;
    int cnt=1;
    for(int i=0;i<N-1;i++){
        switch(state){
        case 0:
            if(a[i]<a[i+1]){
                state=1;
            }else if(a[i]>a[i+1]){
                state=2;
            }
            break;
        case 1:
            if(a[i]>a[i+1]){
                state=0;
                cnt++;
            }
            break;
        case 2:
            if(a[i]<a[i+1]){
                state=0;
                cnt++;
            }
            break;
        }
    }
    cout<<cnt<<endl;
    

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val s = sc.next.toCharArray

    s(3) = '8'
    s.mkString("")
  }
}


Measured memory_bytes: 25416
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
        int h,n;
        cin>>n>>h;
        vector<ll>a(n);
        ll sum=0;
        for(int i=0;i<n;i++) 
        {
            cin>>a[i];
            // sum+=a[i];
        }
        sort(a.begin(),a.end());
        // int sum=0;
        for(int i=0;i<min(n,n-h);i++)
        sum+=a[i];
        cout<<sum;
    }
	return 0;
}

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

int main (){
  int n,a[1000];
  
  cin>>n;
  for(int i=0;i<n*2;i++) cin>>a[i];
  sort(a,a+n*2);
  int ans=0;
  for(int i=0;i<n;i++) ans+=a[i*2];
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
/*input
3
1 2 2
2 3 1






*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<int, int>
#define mp make_pair
#define N 1000005
#define rep(i, n) for(int i=0; i < n; i++)
#define Rep(i, k, n) for(int i=k; i < n; i++)
#define pb push_back
#define vi vector<int>
#define vii vector< vector<int> >
#define vl vector<ll>
#define F first
#define S second
#define all(v) v.begin(),v.end()
// const  ll mod =1000000000+7; 
const ll mod = 998244353;
ll gd(ll a, ll b)
{
	if ( b==0)
		return a;
	return gd(b, a%b);
}
ll absl(ll a )
{
	return  a>= 0 ?a:-a;
}
ll maxl(ll a, ll b)
{
	return a >= b? a:b;
}
ll p(ll a, ll n)
{
	if ( n==0)
		return 1;
	if ( n==1 )
		return a;
	if ( n & 1)
		return a* p(a*a, n/2);
	else
		return p(a*a, n/2);
}
ll lm( ll a, ll b)
{
	return( a*b/ gd(a,b));
}
vector<ii> edges[N];
int dist[N];
int vis[N];
void dfs( int child , int par)
{
	for ( ii u : edges[child])
	{

		int vertex = u.F;
		int weight = u.S;
		if ( !vis[vertex])
		{
			vis[vertex]=1;
		
		dist[vertex] = dist[child] + weight;
		if ( vertex != par)
			dfs(vertex, child);
	}
		
	}
}
int main()
{
	int n;
	cin >> n;
	for ( int i=0; i < n-1; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		edges[u].pb(mp(v,w));
		edges[v].pb(mp(u,w));
	}
	
	vis[1]=1;
	dfs(1, -1);
	for ( int i=1; i <=n; i++)
	if ( dist[i] & 1)
		cout << 1<<"\n";
	else
		cout << "0\n";
	

}

Measured memory_bytes: 35200
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
ll a[maxn], bit_tree[2 * maxn];
ll lowbit(ll x) {return x & (-x);}
void update(ll pos, ll x) {
    while (pos <= 400000) {
        bit_tree[pos] += x;
        pos += lowbit(pos);
    }
}
ll query(ll pos) {
    ll res = 0;
    while (pos > 0) {
        res += bit_tree[pos];
        pos -= lowbit(pos);
    }
    return res;
}
ll prefix[maxn];
ll num[2 * maxn];
unordered_map<ll, int> mp;
int main() {
    //freopen(".in", "r", stdin);
    int n;
    ll k;
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + a[i];
    for (int i = 1; i <= n; i++) prefix[i] -= 1LL * k * i;
    int cnt = 1;
    num[1] = 0;
    for (int i = 1; i <= n; i++) {
        num[++cnt] = prefix[i];
    }
    sort(num + 1, num + 1 + cnt);
    cnt = unique(num + 1, num + 1 + cnt) - num - 1;
    for (int i = 1; i <= cnt; i++) mp[num[i]] = i;
    update(mp[0], 1);
    ll ans = 0;
    for (int r = 1; r <= n; r++) {
        ans += query(mp[prefix[r]]);
        update(mp[prefix[r]], 1);
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 17352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N; cin >> N;
    int Mel = 0;
    int ans = 1;
    for (int i = 1; i <= N; i++) {
        int x = i;
        int cnt = 0;
        while (x % 2 == 0) {
            cnt++;
            x /= 2;
        }

        if (chmax(Mel, cnt)) ans = i; 
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
using ll = long long;
using pii = pair<int, int>;
const long long INF = 2e18;

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

void dprint(string s) {cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w = s.find(','); cout << "[" << s.substr(0, w) << ": " << t << "] "; dprint(s.substr(w+2, (int)s.size()-w-1), u...);} 

#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X, X)
#else
#define dbg(X...) "KEEP CALM" 
#endif

const int N=1e6+5; // CHANGE this value ACC. TO Q.

int32_t main()
{
    IOS;
    int n, x, t; cin>>n>>x>>t;
    int mult=(n+x-1)/x;
    cout<<mult*t;
    return 0;
}

Measured memory_bytes: 3648
<?php

fscanf(STDIN, "%d", $a);
$line = fgets(STDIN);

$arr = array_map('intval', explode(" ", $line));
$count = 1;
$length = count($arr);
$first = intval($arr[0]);
$ex = [];

for ($i = 1; $i < $a; $i++) {
    $prev = $i - 1;
    $num = $arr[$i];
    array_push($ex, $arr[$prev]);
    $max = max($ex);
    if ($arr[$i] >= $max && $arr[$i] >= $arr[$prev]) {
        $count++;
    }
}

echo $count;

?>


Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
int a[1000005],b[1000005],n,m,st,ed;
int main(void){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        scanf("%d",&st);
        cin>>ed;
        if(st==1)a[ed]=1;
        if(ed==n)b[st]=1;
    }
    for(int i=1;i<=m;i++)
        if(a[i]==1&&b[i]==1){
            puts("POSSIBLE");
            exit(0);
        }
    puts("IMPOSSIBLE");
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int pow4(int n){
    int ans = 1;
    for(int i=0;i<n;i++)ans*=4;
    return ans;
}

int main(){
    int n;
    int nagasa[3];
    cin >> n >> nagasa[0]>>nagasa[1]>>nagasa[2];
    int l[n];
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    int minMp = 1<<30;
    for(int bit = 0;bit<(1<<(2*n));bit++){
        vector<vector<int> >take(3);
        for(int i=0;i<n;i++){
            int num = (bit / pow4(i))%4;
            if(num != 3){
                take[num].push_back(l[i]);
            }
        }
        bool chkk = false;
        for(int i=0;i<3;i++){
            if(take[i].size() == 0)chkk = true;
        }
        if(chkk)continue;

        int mp = 0;
        
        for(int i=0;i<3;i++){
            mp += 10*(take[i].size()-1);
            int summ = 0;
            for(int j=0;j<take[i].size();j++){
                summ += take[i][j];
            }
            mp += abs(summ - nagasa[i]);
            
        }
        minMp = min(minMp,mp);

        
    }
    cout << minMp<<endl;
}

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

int main() {
  string s;cin >> s;
  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }else if(s == "Cloudy"){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

int main(){
	int x,y;
	cin>>x>>y;
	if(y>=x) puts("unsafe");
	else puts("safe");
	return 0;
}


Measured memory_bytes: 3132