akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int n,a[maxn],Q;
bool takai[maxn];

int tr[2][4*maxn];
int tr_cx(int ty,int k,int l,int r,int x)
{
	if (x>n) return 0;
	int re=0;
	while (l<r)
	{
		int t=k<<1, mid=(l+r)>>1;
		if (x<=mid) re=max(re,tr[ty][t+1]), k=t, r=mid;
			else k=t+1, l=mid+1;
	}
	return max(re,tr[ty][k]);
}
void tr_xg(int ty,int k,int l,int r,int x,int z)
{
	if (l==r)
	{
		tr[ty][k]=z;
		return;
	}
	int t=k<<1, mid=(l+r)>>1;
	if (x<=mid) tr_xg(ty,t,l,mid,x,z); else tr_xg(ty,t+1,mid+1,r,x,z);
	tr[ty][k]=max(tr[ty][t],tr[ty][t+1]);
}

bool check(int hx,int hy,int cx,int cy,int ai)
{
	if (ai>hx) hx=ai, cx++;
	int ned=cx-cy+Q;
	if (ned>=0 && (tr_cx(1,1,1,n,hy+1)>=ned || !(ned&1) && tr_cx(0,1,1,n,hy+1)>=ned)) return 1;
	ned=cy-cx+Q;
	if (ned>=0 && (tr_cx(1,1,1,n,hx+1)>=ned || !(ned&1) && tr_cx(0,1,1,n,hx+1)>=ned)) return 1;
	return 0;
}

char ans[maxn];
int main()
{
	scanf("%d",&n);
	int maxa=0;
	fo(i,1,n)
	{
		scanf("%d",&a[i]);
		if (a[i]>maxa)
		{
			takai[i]=1;
			maxa=a[i];
			Q++;
		}
	}
	
	fd(i,n,1)
	{
		int tr0=tr_cx(0,1,1,n,a[i]+1), tr1=tr_cx(1,1,1,n,a[i]+1), f0, f1;
		if (takai[i]) f0=tr0+2, f1=(tr1) ?tr1+2 :0 ;
			else f0=0, f1=max(tr0,tr1)+1;
		tr_xg(0,1,1,n,a[i],f0);
		tr_xg(1,1,1,n,a[i],f1);
	}
	
	int hx=0, hy=0, cx=0, cy=0;
	fo(i,1,n)
	{
		Q-=takai[i];
		tr_xg(0,1,1,n,a[i],0);
		tr_xg(1,1,1,n,a[i],0);
		if (check(hx,hy,cx,cy,a[i]))
		{
			ans[i]='0';
			if (a[i]>hx) hx=a[i], cx++;
		} else if (check(hy,hx,cy,cx,a[i]))
		{
			ans[i]='1';
			if (a[i]>hy) hy=a[i], cy++;
		} else
		{
			puts("-1");
			return 0;
		}
	}
	
	printf("%s\n",ans+1);
}

Measured memory_bytes: 7552
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){
    string s,t;
    cin>>s>>t;
    int n = s.size(),m=t.size();
    
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    REP(i,n+1){
        dp[i][0]=i;
    }
    REP(i,m+1){
        dp[0][i]=i;
    }

    FOR(i,1,n+1){
        FOR(j,1,m+1){
            dp[i][j] = min(dp[i-1][j-1]+(int)(!(s[i-1]==t[j-1])),min(dp[i - 1][j] + 1, dp[i][j - 1] + 1));
        }
    }

    cout << dp[n][m] << endl;



    return 0;
}



Measured memory_bytes: 6760
url = "https://atcoder.jp//contests/abc070/tasks/abc070_b"

def main():
    t = list(map(int, input().split()))
    start = max(t[0], t[2])
    end = min(t[1], t[3])
    if end >= start:
        print(end - start)
    else:
        print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

class Direct_Graph {
    public:
    struct Edge { 
        int to; long long cost;
    };
    std::vector<std::vector<Edge>> G;
    int node_num;
    Direct_Graph() {}
    Direct_Graph(const int node_num_in) {
        node_num = node_num_in;
        G.resize(node_num);
    }
    void add_edge(const int from, const int to, const long long cost) {
        Edge edge; edge.to = to; edge.cost = cost;
        G[from].push_back(edge);
    }
    void add_edge_both(const int node1, const int node2, const long long cost) {
        add_edge(node1, node2, cost);
        add_edge(node2, node1, cost);
    }
};

const int MAX_N = 200050;
const int MAX_M = 100050;

int N, M;
int A[MAX_M], B[MAX_M];

Direct_Graph dg = Direct_Graph(MAX_N);
std::set<int> used;

void dfs(int n, std::vector<int>& path) {
    path.push_back(n);
    used.insert(n);
    for (auto edge : dg.G[n]) {
        if (used.find(edge.to) == used.end()) {
            dfs(edge.to, path);
            break;
        }
    }
}

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> A[i] >> B[i];
    }

    for (int i = 1; i <= M; i++) {
        dg.add_edge_both(A[i], B[i], 1);
    }

    std::vector<int> path1, path2;
    used.insert(A[1]);
    used.insert(B[1]);

    dfs(A[1], path1);
    dfs(B[1], path2);

    std::cout << path1.size() + path2.size() << std::endl;

    for (int i = path1.size() - 1; 0 <= i; i--) {
        std::cout << path1[i] << " ";
    }
    for (int i = 0; i < path2.size(); i++) {
        std::cout << path2[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 20344
import numpy as np
import math as m

def main(**kwargs):
    if n >= 10:
        r = k

    else:
        r = k + 100 * (10 - n)

    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, k = cin

    cout = main(n=n, k=k)
    print(cout)

Measured memory_bytes: 12516
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long Q = sc.nextLong();
        long H = sc.nextLong();
        long S = sc.nextLong();
        long D = sc.nextLong();
        long n = sc.nextLong();
        long N = 4*n;
        long ans = 0;
        if(D<=2*S&&D<=4*H&&D<=8*Q&&8<=N){
            ans += D*(N/8);
            N=N%8;
        }
        if(S<=2*H&&S<=4*Q&&4<=N){
            ans += S*(N/4);
            N=N%4;
        }
        if(H<=2*Q&&2<=N){
            ans += H*(N/2);
            N=N%2;
        }
        ans += N*Q;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    if(a>x){
        cout << "NO" << endl;
    }
    else if(a+b<x){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    string s;
    cin>>s;
    int k; cin>>k;
    char x=s[k-1];
    for(int i=0;i<n;i++){
        if(s[i]!=x) cout<<'*';
        else cout<<s[i];
    }
}

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

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

void solve(int n, int m){
	vector<PP> v;
	for(int i=0; i<m; ++i){
		int t, s, d;
		cin >> t >> s >> d;
		v.push_back(PP(t, P(s, d)));
	}
	sort(v.begin(), v.end());
	bool a[20010] = {};
	a[1] = true;
	for(int i=0; i<m; ++i)
		a[v[i].second.second] |= a[v[i].second.first];
	int res = 0;
	for(int i=1; i<=n; ++i)
		if(a[i])
			++res;
	cout << res << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) return 0;
		solve(n, m);
	}
}


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

int main()
{
    string S;
    cin >> S;
    vector<int> hash(27, 0);

    for (int i = 0; i < S.size(); ++i){
        hash[S[i] - 'a'] += 1;
    }

    bool flag = true;
    for (int i = 0; i < 27;++i){
        if(hash[i]>=2){
            flag = false;
        }
    }

    if(flag){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
counter = s.count("E")
ans = counter
for i in range(1,n+1):
	if s[i-1] == "W":
		counter += 1
	elif s[i-1] == "E":
		counter -= 1
	if ans >= counter:
		ans = counter
print(ans)

Measured memory_bytes: 5920
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[62][2];
signed main(){
	int n;
	cin>>n;
	dp[61][0] = 1;
	for(int i=60;i>=0;i--){
		int cur = (n>>i)%2;
		if( cur == 0 ){
			dp[i][0] = dp[i+1][0] + dp[i+1][1];
			dp[i][1] = dp[i+1][1];
			dp[i][2] = dp[i+1][1] + 3 * dp[i+1][2];
		}
		if( cur == 1 ){
			dp[i][0] = dp[i+1][0];
			dp[i][1] = dp[i+1][0] + dp[i+1][1];
			dp[i][2] = 2 * dp[i+1][1] + 3 * dp[i+1][2];
		}
		dp[i][0] %= inf;
		dp[i][1] %= inf;
		dp[i][2] %= inf;
	}
	cout<<(dp[0][0]+dp[0][1]+dp[0][2])%inf<<endl;
	return 0;
}

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

int main(){
   int x, a, b;
   cin >> x >> a >> b;
   x -= a;
   x -= b * (x/b);
   cout << x << endl;
}


Measured memory_bytes: 384
<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d %d", $a, $b, $c);
$abc = array($a, $b, $c);
print(judge(0, 1, $abc, count($abc)));
# 出力

function judge($cmpA, $cmpB, $abc, $sum) {
  if($abc[$cmpA]==$abc[$cmpB]) $sum--;
  if($sum <= 0) $sum=1;
  
  if($cmpB+1 >= count($abc)) {
    if($cmpA+1 >= $cmpB){
      return $sum;
    }
    $cmpA++;
    $cmpB = $cmpA;
  }
  $cmpB++;
  return judge($cmpA, $cmpB, $abc, $sum);
}

?>


Measured memory_bytes: 3576
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		int result = 0;
		Stack<Integer> stack = new Stack<Integer>(); 
		Scanner in = new Scanner(System.in);
		String stringIn = in.nextLine();
		String[] lineString = stringIn.split(" ");
		for(int i = 0; i<lineString.length;i++) {
			if(lineString[i].equals("*")) {
				int n = stack.pop()*stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("+")) {
				int n = stack.pop()+stack.pop();
				stack.push(n);
			}
			else if(lineString[i].equals("-")) {
				int n1 = stack.pop();
				int n2 = stack.pop();
				int n = n2-n1;
				stack.push(n);
			}
			else {
			stack.push(Integer.parseInt(lineString[i]));	
			} 
			//System.out.println(stack.toString());
			
		}
		result = stack.pop();
		System.out.println(result);
	}

}


Measured memory_bytes: 26288
#include<bits/stdc++.h>
#define ll long long 
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main()
{
   fastio;
   string s;
   cin>>s;
   string ans="";
   for(int i=0;i<s.length();i++)
   {
       if(islower(s[i]))
       {
           ans+=s[i];
       }
       if(ans.size()==3)
       {
           break;
       }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3616
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]

for i in range(n):
  x[i], y[i] = map(int, input().split())

ans = 0

for i in range(n-1):
  for j in range(i+1, n):
    ans += ((x[i] - x[j]) ** 2 + (y[i] -y[j]) ** 2) ** 0.5

ans /= n / 2

print(ans)

Measured memory_bytes: 3188
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;


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

	cin >> N;
	int num = 0;
	for (int i = 0; i < N; i++) {
		cin >> M;
		if (M % 2) {
			num++;
		}
	}
	if (num % 2) {
		cout << "NO\n";
	}
	else {
		cout << "YES\n";
	}
	return 0;
}

Measured memory_bytes: 256
a=[str(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=input().strip()
x=b[0]
y=b[1]
if a[0]==c:
	b[0]=b[0]-1
elif a[1]==c:
	b[1]=b[1]-1

print(' '.join(map(str, b)))

Measured memory_bytes: 3064
n,m,c = map(int, input().split(' '))
B = list(map(int, input().split(' ')))
ans = 0
i = 0
while i < n:
    A = list(map(int, input().split(' ')))
    j = 0
    q = c
    while j < m:
        q += (B[j]*A[j])
        j += 1
    if q > 0:
        ans += 1
    i += 1
print(ans)

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




int main()
{
    ll n;
    cin>>n;
    map<ll,ll>m;
    ll ans = 0;


     while (n % 2 == 0)
    {
        if(!m.count(2))m[2]=1;
        else m[2]++;
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
          if(!m.count(i))m[i]=1;
        else m[i]++;
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        if(!m.count(n))m[n]=1;
        else m[n]++;
    for(auto c: m){

        ll k  =c.second;
        k = 8*k;
        k = k+1;
        ll p = sqrt(k)-1;
        p = p/2;

        ans+=p;

    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3724
n=int(input())
s=[]
t=[]
for i in range(n):
    a,b=map(str,input().split())
    s.append(a)
    t.append(int(b))
sum_t=sum(t)
x=input()
idx=0
awake=0
for i in range(n):
    if s[i]!=x:
        awake+=t[i]
    else:
        awake+=t[i]
        break
print(sum_t-awake)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

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

    int N, M, K;
    cin >> N >> M >> K;

    vector<ll> inv(N + 1), fac(N + 1), finv(N + 1);
    inv[1] = 1;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < N; ++i) {
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
        fac[i] = fac[i - 1] * i % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    auto binomial = [&](int n, int r) -> ll {
        return (fac[n] * finv[r] % MOD) * finv[n - r] % MOD;
    };

    ll ans = 0;
    for (int i = 0; i <= K; ++i) {
        ll tmp = M;
        (tmp *= modpow(M - 1, N - i - 1)) %= MOD;
        (tmp *= binomial(N - 1, i)) %= MOD;
        (ans += tmp) %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7920
/** author: __nishad__ **/

#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

bool bw(ll j){

    ll n, num=0, i=j;
    while(i != 0){
        n = i%10;
        i=i/10;
        num = num*10 + n;
    }

    if(j == num)
        return true;
    else
        return false;

}

int main()
{
    IOS;

    ll a, b, i, count=0;

    cin>>a>>b;

    for(i=a; i<=b; i++){
        if(bw(i))
            count++;

    }

    cout<<count;

}





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

int main(){
    int n,m;
    cin >> n >> m;
    int A[n][m];
    int b[m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++){
        cin >> b[i];
    }

    int result[n];
    int tmp;
    for (int i = 0; i < n; i++){
        tmp = 0;
        for (int j = 0; j < m; j++){
            tmp += A[i][j] * b[j];
        }
        result[i] = tmp;
    }
    for (int i = 0; i < n; i++){
        cout << result[i] << endl;
    }
}



Measured memory_bytes: 3112
s = int(input())
def func(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1
d = {}
i = 1
while True:
  if s in d:
    print(i)
    break
  else:
    d[s] = 1
  s = func(s)
  i += 1

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String[] s = new String[S.length()];
		for (int i = 0; i < S.length(); i++) {
			s[i] = String.valueOf(S.charAt(i));
		}
		String before = "";
		int district = 0;
		for (int i = 0; i < s.length; i++) {
			if (!before.equals(s[i])) {
				district++;
			}
			before = s[i];
		}
		System.out.println(district - 1);
	}
}

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

using namespace std;

const long long INF = (1ll<<31)-1;

template<typename T>
class lazy_segment_tree{
	int n;
	T fval;
	vector<T> dat, lazy;
	vector<bool> lazyFlag;
	
public:
	
	lazy_segment_tree(){
		
	}
	
	lazy_segment_tree(int n_, T val){
		init(n_, val);
	}
	
	~lazy_segment_tree(){
		
	}
	
	void init(int n_, T val){
		fval = val;
		
		n = 1;
		
		while(n < n_) n *= 2;
		
		dat.resize(2 * n - 1);
		lazy.resize(2 * n - 1, fval);
		lazyFlag.resize(2 * n - 1, false);
	
		for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval;
	}
	
	void eval(int k, int l, int r){
		
		if(lazyFlag[k]){
			dat[k] = lazy[k];
			
			if(r - l > 1) {
				lazy[2*k+1] = lazy[2*k+2] = lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = lazyFlag[k];
			}
			
			lazyFlag[k] = false;
		}
	}
	
	void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) {return ;}
		if(a <= l && r <= b){
			lazy[k] = x;
			lazyFlag[k] = true;
			eval(k, l, r);
		} else {
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			dat[k] = min(dat[2*k+1], dat[2*k+2]);
		}
	}
	
	T query(int a, int b, int k = 0, int l = 0, int r = -1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(r <= a || b <= l){
			return INF;
		}
		if(a <= l && r <= b){
			return dat[k];
		}else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2 );
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
};

signed main(){
	
	lazy_segment_tree<long long> lseg;
	
	int n, q;
	
	cin>>n>>q;
	
	lseg.init(n+10, INF);
	
	for(int i = 0; i < q; i++){
		int com, s, t, x;
		cin>>com;
		s++, t++;
		if(com){
			cin>>s;
			cout<<lseg.query(s,s+1)<<endl;
		} else {
			cin>>s>>t>>x;
			lseg.update(s, t+1, x);
		}
	}
	
	return 0;
}



Measured memory_bytes: 6992
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


// return sum of top K element (default: maximum)
template<typename T, T identity, typename V=vector<T>,
         typename C1=less<T>, typename C2=greater<T> >
struct PrioritySum{
  size_t num;
  T sum;
  priority_queue<T, V, C1> pq1;
  priority_queue<T, V, C2> pq2;
  PrioritySum():num(0),sum(identity){}
  PrioritySum(size_t num):num(num),sum(identity){}

  void resolve(){
    assert(size()>=num);
    while(pq2.size()<num){
      sum+=pq1.top();
      pq2.emplace(pq1.top());
      pq1.pop();
    }
    while(pq2.size()>num){
      sum-=pq2.top();
      pq1.emplace(pq2.top());
      pq2.pop();
    }
    if(pq1.empty()||pq2.empty()) return;
    while(C2()(pq1.top(),pq2.top())){
      T t1=pq1.top();pq1.pop();
      T t2=pq2.top();pq2.pop();
      sum+=t1;
      sum-=t2;
      pq1.emplace(t2);
      pq2.emplace(t1);
    }
  }

  T query(){resolve();return sum;}

  void push(const T &x){pq1.emplace(x);}
  void expand(){num++;}
  void shrink(){assert(num);num--;}

  size_t size()const{return pq1.size()+pq2.size();}
};
template<typename T>
using MaximumSum=PrioritySum<T, T(0), vector<T>, less<T>, greater<T> >;
template<typename T>
using MinimumSum=PrioritySum<T, T(0), vector<T>, greater<T>, less<T> >;


//INSERT ABOVE HERE
signed main(){
  int x,y,z;
  cin>>x>>y>>z;
  int n=x+y+z;
  vector<int> as(n),bs(n),cs(n);
  for(int i=0;i<n;i++) cin>>as[i]>>bs[i]>>cs[i];

  long long ans=0;
  for(int i=0;i<n;i++){
    ans+=as[i];
    bs[i]-=as[i];
    cs[i]-=as[i];
  }

  using P = pair<int, int>;
  vector<P> vp;
  for(int i=0;i<n;i++)
    vp.emplace_back(bs[i]-cs[i],bs[i]);

  sort(vp.rbegin(),vp.rend());

  vector<long long> dp(n,0);
  {
    MaximumSum<long long> ms(y);
    for(int i=0;i<y;i++)
      ms.push(vp[i].second);

    for(int i=y;i<n;i++){
      dp[i]+=ms.query();
      ms.push(vp[i].second);
    }
  }
  {
    MaximumSum<long long> ms(z);
    for(int i=n;i>n-z;i--)
      ms.push(vp[i-1].second-vp[i-1].first);

    for(int i=n-z;i>0;i--){
      dp[i]+=ms.query();
      ms.push(vp[i-1].second-vp[i-1].first);
    }
  }

  cout<<ans+*max_element(dp.begin()+y,dp.end()-z+1)<<endl;
  return 0;
}


Measured memory_bytes: 5236
n = gets.to_i
a = gets.split.map(&:to_i)
all = true
ans = true
min = a.min
max = a.max
for i in 0..n-2
    all = false if a[i] != a[i+1]
end
if !all
    cnt = a.count(min)
    ans = false if max-1 > min || max <= cnt || (n-cnt)/(max-cnt) < 2
else
    ans = false if n/min < 2 && min != n-1
end
puts ans ? "Yes" : "No"

Measured memory_bytes: 8076
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int,int> P;
int map[102][102];
int flg[102][102];
int main(){	
	int x,y,cnt=0;
	int dx[2][6]={{0,0,-1,1,-1,-1},{0,0,-1,1,1,1}},dy[2][6]={{1,-1,0,0,-1,1},{1,-1,0,0,1,-1}};
	cin>>x>>y;
	for(int i=1;i<=y;i++){for(int j=1;j<=x;j++){cin>>map[i][j];}}
	for(int i=0;i<=x+1;i++){map[0][i]=0;map[y+1][i]=0;}
	for(int i=0;i<=y+1;i++){map[i][0]=0;map[i][x+1]=0;}

	queue<P> q;
	q.push(make_pair(0,0));
	flg[0][0]=1;
	while(!q.empty()){
		P temp=q.front();
		q.pop();
		for(int i=0;i<6;i++){
			if(temp.first+dy[temp.first%2][i]>-1&&temp.first+dy[temp.first%2][i]<y+2&&temp.second+dx[temp.first%2][i]>-1&&temp.second+dx[temp.first%2][i]<x+2){
				if(map[temp.first+dy[temp.first%2][i]][temp.second+dx[temp.first%2][i]]!=1&&flg[temp.first+dy[temp.first%2][i]][temp.second+dx[temp.first%2][i]]!=1){
					q.push(make_pair(temp.first+dy[temp.first%2][i],temp.second+dx[temp.first%2][i]));
					flg[temp.first+dy[temp.first%2][i]][temp.second+dx[temp.first%2][i]]=1;
				}
				if(map[temp.first+dy[temp.first%2][i]][temp.second+dx[temp.first%2][i]]==1){
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1300
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin>>c;
    c++;
    cout<<c<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N;
    cin >> N;
    ll current = 101;
    ll count = 0;
    auto a = InputVec(N);
    for (int i = 1; i < N; ++i) {
        if(a[i-1] == a[i]){
            a[i] = current;
            current++;
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _1009
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == null)
                {
                    break;
                }
                int[] x = s.Split().Select(int.Parse).ToArray();
                Array.Sort(x);
                int n = x[0];
                while (true)
                {
                    if (x[0] % n == 0 && x[1] % n == 0)
                    {
                        break;
                    }
                    n--;
                }
                Console.WriteLine(n);
            }
        }
    }
}

Measured memory_bytes: 9628
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int, H: "List[int]"):
    H.sort(reverse=True)
    print(sum(H[K:]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29244
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int mo=1e6+3;
int fpow(int a,int b){
	int r=1;
	for(;b;b>>=1,a=1ll*a*a%mo)
		if(b&1)r=1ll*r*a%mo;
	return r;
}
int inv(int x){return fpow(x,mo-2);}
int jc[mo+2],jcv[mo+2];
int C(int a,int b){
	if(a<b)return 0;
	return 1ll*jc[a]*jcv[b]%mo*jcv[a-b]%mo;
}
int main(){
#ifdef flukehn
	freopen("a.in","r",stdin);
#endif
	ios::sync_with_stdio(0);
	jc[0]=1;
	rep(i,1,mo-1)jc[i]=1ll*jc[i-1]*i%mo;
	jcv[mo-1]=inv(jc[mo-1]);
//	debug("%d\n",jcv[mo-1]);
	per(i,1,mo-1)jcv[i-1]=1ll*jcv[i]*i%mo;
	int T;
	cin>>T;
	while(T--){
		int x,d,n;
		cin>>x>>d>>n;
		if(d==0){
			printf("%d\n",fpow(x,n));
			continue;
		}
		int p=inv(d);
		int l=1ll*x*p%mo,r=l+n-1;
		//debug("%d %d\n",l,r);
		if(r>=mo)puts("0");
		else{
		//	debug("%d %d %d\n",fpow(d,n),jc[r],jcv[l-1]);
			printf("%lld\n",1ll*fpow(d,n)*jc[r]%mo*jcv[l-1]%mo);
		}

	}
}

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

constexpr int MAX_H = 55;
constexpr int MAX_W = 55;

int H, W;
int grid[MAX_H][MAX_W];
bool reached[MAX_H][MAX_W];

int dh[8] = {-1, -1, -1,  0,  0,  1,  1,  1};
int dw[8] = {-1,  0,  1, -1,  1, -1,  0,  1};

void dfs(int h, int w) {
  reached[h][w] = true;
  for (int i{}; i < 8; ++i) {
    int nh = h + dh[i];
    int nw = w + dw[i];
    if (nh < 0 || nh >= H || nw < 0 || nw >= W ||
        reached[nh][nw] || grid[nh][nw] == 0)
      continue;
    dfs(nh, nw);
  }
}

int main() {
  while (true) {
    scanf("%d%d", &W, &H);
    if (W == 0 && H == 0) break;
    for (int h{}; h < H; ++h) {
      for (int w{}; w < W; ++w) {
        reached[h][w] = false;
        scanf("%d", &grid[h][w]);
      }
    }

    int island{};
    for (int h{}; h < H; ++h) {
      for (int w{}; w < W; ++w) {
        if (grid[h][w] == 0 || reached[h][w])
          continue;
        dfs(h, w);
        ++island;
      }
    }

    printf("%d\n", island);
  }

  return 0;
}



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

void call ( int n ) {
    int i = 1;
    while (i <= n) {
        int x = i;
        if ( x % 3 == 0 ){
            cout << " " << i;
            ++i;
        } else if ( x % 10 == 3 ){
            cout << " " << i;
            ++i;
        } else {
            while ( 1 ){
                x /= 10;
                if ( x != 0 ) {
                    if ( x % 10 == 3 ) {
                        cout << " " << i;
                        ++i;
                        break;
                    } 
                } else if (x == 0) {
                    ++i;
                    break;
                }
            }
        } 
    }
    cout << endl;
}


int main() {
    int n;
    cin >> n;
    call(n);

    return 0;
}


Measured memory_bytes: 3116
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

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

      //System.out.println( x^3 );   // ^???Java??§???????????§?????????XOR???????????????
      //System.out.println( x*x*x );            // <= ??£?§£
      //System.out.println( Math.pow(x,3) );
      System.out.println( (int)Math.pow(x,3) ); // <= ??£?§£

   }
}

Measured memory_bytes: 24400
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    all = A[0]
    for n in range(1, N):
        all ^= A[n]

    ret = []
    for n in range(N):
        ret.append(A[n] ^ all)
    print(*ret)


if __name__ == '__main__':
    main()


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

int main()
{
  int x;
  int i=1;
  while (true) {
    cin >> x;
    if (x == 0) break;

    printf("Case %d: %d\n", i, x);
    i++;
  }


  return 0;
}


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

int main() {
  int n,a,x;
  cin >> n >>a;
  x = n % 500;
  
  if (x == 0){
  cout << "Yes";
  }
  else {
    if (x <= a){
    cout << "Yes";
    }
    else {
    cout << "No";
    }
  }
}


Measured memory_bytes: 3600
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        sc.close();
        long s = 7;
        boolean ebishu = true;
        for(int i = 0 ; i < k + 1 && ebishu ; i++){
            if(i != 0){
                s = 10 * s + 7;
            }
            s = s % k;
            if(s == 0){
                System.out.println(i + 1);
                ebishu = false;
            }
        }
        if(ebishu){
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 35700
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D&lang=jp
#include<iostream>
using namespace std;
int main(void){
  int s,h,m;
  cin>>s;
  h=s/3600;
  s-=h*3600;
  m=s/60;
  s-=m*60;
  cout<<h<<":"<<m<<":"<<s<<endl;
  return 0;
}



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

int main() {

  long long int n;

  while( cin >> n ) {

    vector< string > id;

    for ( long long int i = 0; i < n; i++ ) {

      string in;
      cin >> in;
      id.push_back( in );

    }

    sort( id.begin(), id.end() );

    long long int m;
    cin >> m;

    long long int k = 0;

    for ( long long int i = 0; i < m; i++ ) {

      string in;
      cin >> in;

      if ( binary_search( id.begin(), id.end(), in ) ) {
	if ( k == 0 ) {
	  k = 1;
	  cout << "Opened by " << in << endl;
	}else {
	  k = 0;
	  cout << "Closed by " << in << endl;
	}
      }else {
	cout << "Unknown " << in << endl;
      }

    }

  }

  return 0;

}

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

using namespace std;

int main(){

	int n;
	vector<int> vec;

	cin >> n;
	for (int i = 0; i < n; ++i){
		int tmp;
		cin >> tmp;
		vec.emplace_back(tmp);
	}

	int count = 0;

	while (true){
		for (int i = 0; i < n; ++i){
			if (vec.at(i) % 2 == 0){
				vec.at(i) = vec.at(i) / 2;
			}
			else{
				goto exit;
			}
		}
		++count;
	}
exit:

	cout << count << endl;


	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#############################################

x,y,z=map(int,input().split())
x,y=y,x
x,z=z,x
print(x,y,z)










Measured memory_bytes: 7120
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define testcase int t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<long long int,long long int>
#define ub upper_bound // '>'
#define lb lower_bound // '>='
typedef long long int ll;
typedef unsigned long long int ull;
#define M 1000000007
using namespace std;
int main()
{
    fast
int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin>>k;
cout<<a[k-1];
return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
// library
struct w_union_find{
    // d_ws[a]はroot -> aの重み.
    vector<int> d_ws;
    vector<int> ps;
    w_union_find(int n = 1) : ps(n, -1), d_ws(n, 0){}

    int root(int a){
        if(ps[a] < 0){
            return a;
        }
        int r = root(ps[a]);
        // d_wsはrootからの重みなのでこれでok
        d_ws[a] += d_ws[ps[a]];
        return ps[a] = r;
    }

    bool same(int a, int b){
        return root(a) == root(b);
    }

    int weight(int a){
        root(a);
        return d_ws[a];
    }

    int diff_weight(int a, int b){
        return weight(b) - weight(a);
    }

    bool unite(int a, int b, int w){
        // weight[b] - weight[a] = wとなるようにweight[root(b)]を決定し,aに連結
        if(same(a, b)){
            // 無条件でfalseを返してしまうと元からa -> bがwになっている場合でもfalseになってしまうから下
            return diff_weight(a, b) == w;
        }

        w -= weight(b);
        w += weight(a);

        a = root(a);
        b = root(b);

        if(ps[a] > ps[b]){
            // 要素が多い方に連結.
            swap(a, b);
            w *= -1;
        }
        ps[a] += ps[b];
        ps[b] = a;
        d_ws[b] = w;

        return true;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    w_union_find uf(N);
    rep(i, M){
        int l, r, d;
        cin >> l >> r >> d;
        l --;
        r --;
        bool ans = uf.unite(l, r, d);
        if(! ans){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int a,b,c;

	public void solve() {
		a = nextInt();
		b = nextInt();
		c = nextInt();

		boolean[] used = new boolean[b];
		int now = a%b;
		while(!used[now]){
			used[now] = true;

			if(now == c){
				out.println("YES");
				return;
			}

			now = (now+a)%b;
		}

		out.println("NO");
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 22484
# まずはナイーブに書く
# スイッチは0から始まる

N, M = map(int, input().split())

light_s_dict = dict()
# 繋がっているスイッチ
for i in range(M):
    l = [int(j) for j in input().split()]
    connected_s = [0]*N
    for s in l[1:]:
        connected_s[s-1] = 1
    light_s_dict[i] = connected_s

# スイッチの全パターン
s_patterns = []
for i in range(2**N):
    p_str = bin(i)[2:].zfill(N)
    s_patterns.append([int(i) for i in list(p_str)])
    
# 点灯条件
light_conditions = [int(p) for p in input().split()]

# 全探索
ans = 0
for pattern in s_patterns:
    for light in range(M): # 全部のlightに対して
        cond = 0 # onをカウント
        for i, p in enumerate(pattern): # 各パターンの個々のスイッチに対して
            if p == 1:
                cond += light_s_dict[light][i] # 繋がっているスイッチ
        if cond % 2 != light_conditions[light]:
            break
    else: # 全てのlightに対して正常に終了すれば
        ans += 1
print(ans)

Measured memory_bytes: 3188
# include <stdio.h>

int main(){

	int a, b;
	scanf("%d %d", &a, &b);

	if (a > b){
		if (b != 1){
			printf("Alice\n");
		}else
			printf("Bob\n");
	}
	if (b > a){
		if (a != 1)
			printf("Bob\n");
		else
			printf("Alice\n");
	}

	if (a == b)
		printf("Draw\n");



	return 0;
}


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

int main(){
int n;
  cin >> n;
  cout << (1000-n%1000)%1000 << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b;
	while(scanf("%d %d",&a,&b) != EOF){
		int i = 0;
		a += b;
		while(a > 0){
			a /= 10;
            i++;
		}
		cout << i << endl;
	}
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 2e5 + 5;
const int mod = 1e7 + 7;
const int INF = 1e15;
const int LG = 21;

int arr[N];
int n, m, k;
vector<string> v1, v2;
int cnt[N];

void solve()
{
	int k, n;
	cin >> k >> n;
	int mx = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if(i)
		{
			mx = max(mx, arr[i] - arr[i - 1]);
		}
	}
	mx = max(mx, arr[0] + (k - arr[n - 1]));
	cout << k - mx << endl;
}

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

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 1792
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int COM(int n, int k) {
	int r = 1;
	for (int d = 1; d <= k; ++d) {
		r *= n--;
		r /= d;
	}
	return r;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, A, B;
	int V[100];
	map<int, int> vmap;

	cin >> N >> A >> B;
	rep(i, 0, N)
	{
		cin >> V[i];
		vmap[V[i]]++;
	}

	sort(V, V + N, greater<int>());

	double ansv = 0.0;
	int cnt = 0;
	int pv = -1;
	rep(i, 0, A)
	{
		ansv += (double)V[i];
		if (V[i] != pv)
		{
			cnt = 1;
		}
		else
		{
			cnt++;
		}
		pv = V[i];
	}
	ansv /= A;

	int ansc;
	if (cnt != A)
	{
		ansc = COM(vmap[pv], cnt);
	}
	else
	{
		ansc = 0;
		rep(i, A, min(B + 1, vmap[pv] + 1))
		{
			ansc += COM(vmap[pv], i);
		}
	}

	cout << fixed << setprecision(12) << ansv << endl << ansc << endl;

	return 0;
}

Measured memory_bytes: 256