akhauriyash/Code-Regression huggingface dataset:
require "set"
n,k = gets.chomp.split(" ").map(&:to_i)
ab_arr = (n-1).times.map{gets.chomp.split(" ").map(&:to_i)}

if n == 1 then
  puts k
  exit 0
end

hash = {}
ab_arr.each do |(a, b)|
  hash[a] ||= []
  hash[a] << b
  hash[b] ||= []
  hash[b] << a
end

# cache
perm_hash = {}
perm = lambda {|i, j|
  return 1 if j == 0
  result = 1
  j.times do |t|
    result *= (i - t)
    result %= 1000000007
  end
  perm_hash[[i,j]] = result
  return result
}

count = k
set = Set.new

a,b = ab_arr[0]
set.add(a)
count *= perm.call(k-1, hash[a].length)

stack = hash[a]
while stack.length > 0 do
  c = stack.pop()
  set.add(c)
  children = hash[c].select{|cc|!set.include?(cc)}
  count *= perm_hash[[k-2, children.length]] || perm.call(k-2, children.length)
  count %= 1000000007
  children.each do |cc|
    stack.push(cc)
  end
end
puts count


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

int minWeight(std::vector<int> w, int k) {
    int sum = 0;
    for (const auto& elm : w) {
        sum += elm;
    }
    return sum / k;
}

int main() {
    int n, k, temp;
    std::vector<int> w;
    
    std::cin >> n >> k;
    for (int i=0; i<n; ++i) {
        std::cin >> temp;
        w.push_back(temp);
    }
    
    bool ans = false;
    for (int i=minWeight(w, k); ; ++i) {
        int weight = 0;
        int k_rem = k;
        int P = i;
        auto itr = w.begin();
        #ifdef msg
        std::cout << "P = " << P << std::endl;
        #endif
        while (k_rem > 0 && ans == false) {
            #ifdef msg
            std::cout << "  k_rem: " << k_rem << std::endl;
            #endif
            if ( (weight + (*itr)) <= P ) {
                weight += (*itr);
                std::advance(itr, 1);
                if (itr == w.end()) {
                    #ifdef msg
                    std::cout << "limit!!!!!" << std::endl;
                    #endif
                    std::cout << P << std::endl;
                    ans = true;
                    break;
                }
                #ifdef msg
                std::cout << "    weight:" << weight << ",*itr:" << *std::prev(itr) << "->" << (*itr) << std::endl;
                #endif
            } else {
                weight = 0;
                --k_rem;
            }
        }
        if (ans) break;
    }
    
    return 0;
}


Measured memory_bytes: 3592
main = do
    s <- getLine
    case s of
        "SSS" -> print $ 0
        "RRR" -> print $ 3
        "SSR" -> print $ 1
        "RRS" -> print $ 2
        "SRR" -> print $ 2
        "RSS" -> print $ 1
        "SRS" -> print $ 1
        "RSR" -> print $ 1

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

int main(void){
    string s; 
    int k;
    cin >> k >> s;
    int n = (int)s.size();
    if(n<=k) cout << s << endl;
    else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
            cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
import sys
from itertools import product
input = sys.stdin.readline

def main():
    n, z, w = map(int, input().split())
    
    a = list(map(int, input().split()))
    
    ans = abs(w-a[-1])
    if n != 1:
        ans = max(ans, abs(a[-2]-a[-1]))
    
    print(ans)
        

    
if __name__ == "__main__":
    main()


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

#define PI acos(-1)
#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
#define mxx 1000000
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int tc;

void solve(){

    int n;
    string s;
    cin>>n>>s;
    if(s.size()<=n)cout<<s<<endl;
    else{
        string nw;
        for(int i=0; i<n; i++)nw.push_back(s[i]);
        nw+="...";
        cout<<nw<<endl;
    }
}

int main()
{

    _fastIO;

    //cin>>tc; while(tc--)
    solve();

    return 0;
}







Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int a, b, k;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  string s;
  cin >> s;

  reverse(s.begin(),s.end());
  mint cnt[13];
  cnt[0] = 1;
  int dig = 1;
  rep(si,s.size()){
    mint temp[13];
    if(s[si]=='?'){
      rep(d,10)rep(i,13){
        temp[(d*dig+i)%13] += cnt[i];
      }
    }else{
      int d = s[si]-'0';
      rep(i,13){
        temp[(d*dig+i)%13] += cnt[i];
      }
    }
    swap(cnt,temp);
    dig *= 10;
    dig %= 13;
  }
  cout << cnt[5] << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

int solve(vector<int>& vec, int N, int K) {
    int dp[N+1][K+1];
    for(int j=0; j<=K; j++) dp[1][j] = j > vec[1] ? 0 : 1;

    for(int i=2; i<=N; i++) {
        for(int j=0; j<=K; j++) {
            if(j == 0) dp[i][j] = dp[i-1][j];
            else dp[i][j] = (mod + dp[i][j-1] + dp[i-1][j] - (j - vec[i] - 1 >= 0 ? dp[i-1][j - vec[i] - 1] : 0))%mod;
        }
    }
    return dp[N][K];
}

int32_t main() {
    int N, K; cin>>N>>K;
    vector<int> vec(N+1);
    for(int i=1; i<=N; i++) cin>>vec[i];
    cout<<solve(vec, N, K)<<endl;
    return 0;
}


Measured memory_bytes: 81668
import java.io.*;
import java.lang.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		int w, n, i, tmp;
		int L,R;
		int list[];

		w = sc.nextInt();
		n = sc.nextInt();

		sc.useDelimiter(",| |\\n");

		list = new int[w + 1];
		for(i = 0; i < w; i++){
			list[i + 1] = i + 1;
		}

		for(i = 0; i < n; i++){
			L = sc.nextInt();
			sc.skip(",");
			R = sc.nextInt();
			//System.out.println(L + "," + R);
			tmp = list[L];
			list[L] = list[R];
			list[R] = tmp;
		}

		for(i = 0; i < w; i++){
			System.out.println(list[i + 1]);
		}
		
	}
}

Measured memory_bytes: 25940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int main(){
    string S;
    cin >> S;
    char s = S[0];
    for(int i = 1; i < 3; i++){
        if(S[i] != s){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    char c;
    cin>>c;
    if(c>='A' && c<='Z'){
        cout<<"A"<<endl;
    }
    else{
        cout<<"a"<<endl;
    }

    return 0;
}




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

int main()
{
    int n; cin >> n;
    string s;
    vector<string> ans;
    while (n--) {
        cin >> s;
        ans.push_back(s);
    }
    int count = 1;
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size() - 1; i++) {
        if (ans[i] != ans[i+1]) count++;
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 11588
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		long n = saori.saorihayami();
		long a = saori.saorihayami();
		long b = saori.saorihayami();
		if((b-a)%2 == 0){
			System.out.println((long)(b-a)/2);
		} else {
			System.out.println(Math.min(a-1, n-b)+1+(long)(b-a-1)/2);
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    __;

    int n,red=0,blue=0;

    cin >> n;

    string s;
    
    cin >> s;
    
    for( int i=0 ; i<s.size() ; i++)
    {
        if(s[i] == 'R') red++;
        
        else blue++;
    }
    
    if(red> blue) cout<<"Yes";
    
    else cout<<"No";

    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)

int main(){
  int h,w,K,ans=1e9;cin>>h>>w>>K;
  vector<string> s(h);
  REP(i,h)cin>>s[i];
  REP(bit,1<<(h-1)){
    vector<int> v;
    REP(i,h-1)if((bit>>i)&1)v.push_back(i);
    int res=v.size(),n=v.size()+1;
    vector<int> cnt(n,0),tmp(n,0);
    REP(x,w){
      int now=0;
      REP(y,h){
        tmp[now]+=s[y][x]=='1';
        if(now<v.size()&&v[now]==y)now++;
      }
      REP(j,n)if(tmp[j]>K)x=res=1e9;
      bool f=true;
      REP(j,n)if(cnt[j]+tmp[j]>K)f=false;
      REP(j,n)cnt[j]=cnt[j]*f+tmp[j],tmp[j]=0;
      res+=!f;
    }
    if(ans>res)ans=res;
  }
  cout<<ans<<endl;
}


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

int a[200001];

bool check(int x,int n){
	stack<pair<int,int> > st;
	st.emplace(0,0);
	st.emplace(1,a[1]);
	for(int i=2;i<=n;i++){
		if(a[i]>st.top().second)
			st.emplace(1,a[i]);
		else{
			while(st.top().second > a[i]){
				auto tp = st.top();st.pop();
				if(st.top().second < a[i])
					st.emplace(tp.first,a[i]);
			}
			while(st.top().first == x)
				st.pop();
			if(st.size()==1)	return false;
			auto tp = st.top();st.pop();
			if(tp.second - 1 != st.top().second)
				st.emplace(tp.first,tp.second-1);
			st.emplace(tp.first+1, tp.second);
			if(st.top().second != a[i])
				st.emplace(1,a[i]);
		}
	}
	return true;
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int l=1,r=n;
	while(l<r){
		int mid = (l+r) >> 1;
		if(check(mid,n))
			r = mid;
		else
			l = mid+1;
	}
	cout<<l<<endl;
}


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

int a=0, b=0, c=0, k=0;
string s;

int main(void){
	cin >> s;

	if(s[0]=='A') a=1;
	for(int i=2; i<s.size()-1; i++){
		if(s[i]=='C'){
			c++;
			k=i;
		}
	}
	if(c==1){
		b=1;
		for(int i=1; i<s.size(); i++){
			if(i!=k){
				if('A'<=s[i]&&s[i]<='Z') b=0;
			}
		}
	}
	if(a*b*c==1) cout << "AC" << endl;
	else cout << "WA" << endl;
}

Measured memory_bytes: 256
/**
 * Doubly Linked List
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=ja
 */

#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <list>
using namespace std;

void trace(list <int>lst) {
  cout << lst.front();
  for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
    if (itr == lst.begin()) {
      continue;
    }
    cout << ' ';
    cout << *itr;
  }

  cout << endl;

  /*
  // 現在の並び替え状態を出力する
  int size = A.size();
  for (int i = 0; i < size; i++) {
    cout << A.at(i);
    if (i < size - 1) {
      cout << ' ';
    } else {
      cout << endl;
    }
  }
  */
}

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

  int N;
  cin >> N;

  // プロセスの格納
  string command;
  int number;
  list <int>lst;
  for (int i = 0; i < N; i++) {
    cin >> command;
    if (command == "insert") {
      cin >> number;
      lst.push_front(number);
    } else if (command == "delete") {
      cin >> number;
      for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
        if (*itr == number) {
          lst.erase(itr);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      lst.pop_front();
    } else if (command == "deleteLast") {
      lst.pop_back();
    }
  }

  trace(lst);

  return 0;
}



Measured memory_bytes: 34472
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

//関数宣言
//int func(int x, int y);

int main(void){

  //スカラー入力
  int r,D,A;

  scanf("%d %d %d", &r, &D, &A);

  int ans=A;
  for(int i=0; i<10; i++){
    ans = ans*r - D;
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int t = sc.nextInt();
            int r = sc.nextInt();
            
            	if(m == -1&& t == -1){
                    if(t == -1 && r == -1){
                        break;
                    }
                }
            if(m == -1 || t == -1){
                System.out.println("F");
            }else if(m + t >= 80){
                System.out.println("A");
            }else if(m + t >= 65){
                System.out.println("B");
            }else if(m + t >= 50){
                System.out.println("C");
            }else if(m + t >= 30 && r >= 50){
                System.out.println("C");
            }else if(m + t >= 30){
                System.out.println("D");
            }else{
                System.out.println("F");
            }
        }
    }
}


Measured memory_bytes: 26240
p = int(input())
a = [int(i) for i in input().split()]

ans = [0]*p

for i,j in enumerate(a):
    if j == 0:
        continue
    ans[0] -= p-1
    m = 1
    for k in range(p):
        ans[p-1-k] -= m
        ans[p-1-k] %= p
        m *= i
        m %= p

print(*ans)


Measured memory_bytes: 43996
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		ll N; input_returnner(ll N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
}

const ll MOD = 1e9 + 7;

void solve();

signed main() {
	SETUP;
	solve();
#ifdef _DEBUG
	system("pause");
#endif
	return 0;
}

#define int ll

void solve() {
	int N, M; cin >> N >> M;
	if (N == 1) N = 3;
	if (M == 1) M = 3;
	cout << (N - 2)*(M - 2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
void tuginodankai(char,char);

int main()
{
	std::string mojiretu;
	std::cin >> mojiretu;
	if ((mojiretu[0] == mojiretu[1]) && mojiretu[0] != mojiretu[2])
	{
		tuginodankai(mojiretu[2], mojiretu[3]);
	}
	else if ((mojiretu[0] == mojiretu[2]) && mojiretu[0] != mojiretu[1])
	{
		tuginodankai(mojiretu[1], mojiretu[3]);
	}
	else if ((mojiretu[0] == mojiretu[3]) && mojiretu[0] != mojiretu[1])
	{
		tuginodankai(mojiretu[1], mojiretu[2]);
	}
	else std::cout << "No" << std::endl;

}


void tuginodankai(char mojiiti,char mojini)
{
	if (mojiiti == mojini)
	{
		std::cout << "Yes" << std::endl;
	}
	else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
function main(input) {
  inputs = input.split(' ')
  num_of_coin = inputs[0]
  upper = inputs[1]
  
  if (500 * num_of_coin >= upper) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	set<int> s;
	int stk,N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> stk;
		s.insert(stk);
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>
 
#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
string s;
int main(){
    cin>>s;
    int n=s.length();
    int checker=0;
    rep(i,0,n){
        if(s[i]!=s[n-i-1])checker=1;
    }
    rep(i,0,(n-1)/2){
        if(s[i]!=s[(n-1)/2-i-1])checker=1;
        if(s[n-1-i]!=s[n-1-((n-1)/2-i-1)])checker=1;
    }
    if(checker==0){
        puts("Yes");
    }else{
        puts("No");
    }
}

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

#define DEBUG(x) cout << #x << " = " << x << endl
typedef long long ll;
const int N = 5e3 + 5;
int a[N];
int n, k;
ll sum;

int solve() {
    if (sum < k) return n;
    sort(a+1, a+n+1);
    sum = 0;
    int ret = n;
    for (int i=n; i>=1; --i) {
        sum += a[i];
        if (sum >= k) {
            sum -= a[i];
            ret = i;
        }
    }
    return ret-1;
}

int main() {
    cin >> n >> k;
    for (int i=1; i<=n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    cout << solve() << '\n';
    return 0;
}


Measured memory_bytes: 256
def main():
    h, n = map(int, input().split())
    ab = []
    for i in range(n):
        ab.append(tuple(map(int, input().split())))

    dp = []
    for i in range(h+1):
        dp.append(10**18)
    dp[h] = 0
    for i in range(h, 0, -1):
        for j in range(n):
            dp[max(0, i-ab[j][0])] = min(dp[max(0, i - ab[j][0])], dp[i] + ab[j][1])

    print(dp[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 41328
import numpy as np
N = int(input())
appearences = np.array([2501] * 26, dtype=np.int16)
for _ in range(N):
    temp = np.zeros((26,), dtype=np.int16)
    for c in input():
        i = ord(c) - ord("a")
        temp[i] += 1
    np.minimum(appearences, temp, out=appearences)
for i in range(26):
    if appearences[i] in [0, 2501]:
        continue
    print(chr(i + ord("a")) * appearences[i], end="")
print()


Measured memory_bytes: 12472
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int h, a; cin >> h >> a;
    cout << (h+a-1)/a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#if 1
    #define gc() getchar_unlocked()
#else
    #define gc() getchar()
#endif

int in() {
    int n = 0, c = gc();
    do n *= 10, n += (c & 0xf), c = gc(); while (c >= '0');
    return n;
}


int main(void){
  int a, b, c;
  a = in(); b = in(); c = in();
  if (a + b + 1 >= c) printf("%d\n", c + b);
  else printf("%d\n", a + b + 1 + b);
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int h,w;cin >> h >> w;
    vector<string> f(h);
    rep(i,h)cin >> f[i];
    vector<string> ans(2*h);
    rep(i,2*h){
        string ret;
        rep(j,w){
            ret += f[(i+2)/2-1][j];
        }
        ans[i] = ret;
    }
    rep(i,2*h)cout << ans[i] << endl;


    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define M 100005
#define N 102
using namespace std;
int ar[M];
int kar[M];

int fun(int n,int k){
	kar[0]=0;
	kar[1]=abs(ar[0]-ar[1]);
	
	
	for(int i=2;i<n;i++){
		kar[i]=INT_MAX;
		for(int j=1;j<=k;j++){
			if(i-j<0)break;
			kar[i]= min(kar[i],kar[i-j]+abs(ar[i-j]-ar[i]));
			
          
		}
		
	}
	return kar[n-1];
}




int main(int argc, char const *argv[])
{
  int n,k;
	cin>>n>>k;
  for(int i=0;i<n;i++)cin>>ar[i];
  cout << fun(n,k)<<"\n";
	return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int h,w;
    string s;
    cin >> h >> w;
    rep(i,w+2)cout << '#';
    cout << endl;
    rep(i,h){
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    rep(i,w+2)cout << '#';
	return 0;
}

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

int main()
{
    int n,i;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<int> b(3,0);
    for(i = 0;i < n;++i){
        if(a.at(i)%4 == 0){
            ++b.at(0);
        }else if(a.at(i)%2 == 0){
            ++b.at(1);
        }else{
            ++b.at(2);
        }
    }
    if(b.at(1) == 0){
        if(b.at(0) >= b.at(2)-1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
       if(b.at(0) >= b.at(2)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        } 
    }
    return 0;
}

Measured memory_bytes: 640
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N,K = LI()
dA = [[LI() for _ in range(2)] for _ in range(K)]
num = set()
for x in dA:
    d,A = x
    for y in A:
        num.add(y)
print(N-len(num))


Measured memory_bytes: 9184
/*
NOTE
*min_element(.begin(),.end())
*max_element(.begin(),.end())
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>

#define MAX 100
#define INFTY 10e12 // 1<<31 // 2^31
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(o) (o).begin(), (o).end()

using namespace std;
typedef long long ll;
//
typedef int Weight;
struct Edge
{
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f)
{
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!! ???????????????????????????
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
/*
????°???¨?????¨
const Graph &g
  ??°???????????£??\????????????
  vector<vector<Edge> >

int s
  Prim ???????§????????????????????????¨????????¨?????¨????±??????????
  ??¨?????¨?????\???????????????
?????????
  ????°???¨?????¨???????????¨????°???¨?????¨????????????????????¢???
*/
pair<Weight, Edges> minimumSpanningTree(const Graph &g, int r = 0)
{
  int n = g.size();
  Edges T;
  Weight total = 0;
  vector<bool> visited(n); // ?¨????????????? default false
  priority_queue<Edge> Q;
  Q.push( Edge(-1, r, 0) ); // ?§????
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    FOR(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}
//
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE

  int V, E; cin >> V >> E;
  Graph G(V);
  REP(i,E)
  {
    int s, t, w; cin >> s >> t >> w;
    Edge a(s,t,w), b(t,s,w);
    G[s].push_back(a);
    G[t].push_back(b);
  }
  cout << minimumSpanningTree(G).first << endl;
  return 0;
}

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

using namespace std;

#define ios         ios_base::sync_with_stdio(false);
#define ll          long long
#define ld          long double
#define db(x)       cout << "[" << #x << ": " << (x) << "]\n"
#define db2(x,y)    cout << "[" << #x << ": " << (x) << "]  [" << #y << ": " << (y) << "]\n"
#define db3(x,y,z)  cout << "[" << #x << ": " << (x) << "]  [" << #y << ": " << (y) << "]  [" << #z << ": " << (z) << "]\n"
#define cn          107
#define sn          1007
#define bn          200007
#define M           1000000007
#define inf         LLONG_MAX



int main()
{
        ios;
        ll a,b; cin >> a >> b;
        ll c = 0;
        for(ll i = a; i <= b; i++)
        {
                string s = to_string(i);
                if(s[0] == s[4] and s[1] == s[3]) c++;
        }
        cout << c;
}



Measured memory_bytes: 3764
#include<stdio.h>
int main(void){
	int in,time,min,sec;
	scanf("%d",&in);
	time=in/3600;
	min=(in-time*3600)/60;
	sec=in-time*3600-min*60;
	printf("%d:%d:%d\n",time,min,sec);
	return 0;
}


Measured memory_bytes: 1836
#include <stdio.h>
int main()
{
	int n,p=0;
  	char s[105];
  	scanf("%d %s",&n,s);
  	if(n%2==0)
    {
     	for(int i=0;i<(n/2);i++)
        {
          if(s[i] != s[(n/2)+i])
          {
           	p=1; 
            break;
          }
        }
      	if(p==0){printf("Yes\n");}
        else if(p==1){printf("No\n");}
    }
    else
    {
     	printf("No\n"); 
    }
     return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);
int n, M[N][N];
int d[N];
void bfs(int s) {
    queue<int>q;
    q.push(s);
    for (int i = 0; i < n; i++)d[i] = INFTY;
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front(); q.pop();
        for (int v = 0; v < n; v++) {
            if (M[u][v] == 0)continue;
            if (d[v] != INFTY)continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}
int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(long long N, std::vector<long long> A){
    int countE = 0;
    int count = 0;
    REP(i, A.size()) {
        if (A[i] % 2 == 0) {
            countE++;
            if (A[i] % 3 == 0 || A[i] % 5 == 0)
                count++;
        }
    }
    if (countE == count) print("APPROVED");
    else print("DENIED");
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main()
        {
            var a = int.Parse(Console.ReadLine());
            var b = a + (a * a) + (a * a * a);
            Console.WriteLine(b);

        }
    }
}


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

int N, M;
int A[1010], V[1010];

int main() {
  cin >> N >> M;
  for (int i=0; i<N; i++) cin >> A[i];

  for (int i=0; i<M; i++) {
    int b;
    cin >> b;
    for (int j=0; j<N; j++) {
      if (A[j] <= b) {
        V[j]++;
        break;
      }
    }
  }

  int m = -1, ans = -1;
  for (int i=0; i<N; i++) {
    if (V[i] > m) {
      m = V[i];
      ans = i + 1;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define mpp         make_pair
#define vll         vector<ll>
#define mll         unordered_map<ll,ll>
#define endl        "\n"
#define debug(x)    cout<< #x <<"="<<x<<"\n"
#define fo(i,a,x)   for(ll i=a;i<x;++i)
#define fastio      ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

ll n,m,k;

void solve()
{
     string a,b; cin>>a>>b;
     ll ans = INT_MAX;
     for(int i=0;i<a.length()-b.length()+1;i++)
     {
        ll cnt=0;
        for(int j=i,k=0;j<a.length() && k<b.length();j++,k++)
        {
            if(a[j]!=b[k]) cnt++;
        }
        // debug(cnt);
        ans = min(ans,cnt);
     }
     cout<<ans<<endl;
}

int main()
{
    fastio;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ll t=1; 
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdlib.h>
#include <functional>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <set>
#include <queue>
#include <map>
using namespace std;
int main(){
	int n;
	cin>>n;
	int t[n],a[n];
	for(int i=0;i<n;i++){
		cin>>t[i];
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	if(t[n-1]!=a[0]){
		cout<<0<<endl;
	}
	else{
		int h[n],now=0;
		long long s=1;
		for(int i=0;i<n;i++){
			if(now<t[i]){
				h[i]=1;
				now=t[i];
			}
			else{
				h[i]=0;
			}
		}
		now=0;
		for(int i=n-1;i>=0;i--){
			if(now<a[i]){
				h[i]=1;
				now=a[i];
				if(t[i]<a[i]){
					s=0;
				}
			}
			else{
				if(h[i]==1&&t[i]>a[i]){
					s=0;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(h[i]==0){
				s=(s*min(t[i],a[i]))%1000000007;
			}
		}
		cout<<s<<endl;
	}
    return 0;
}

Measured memory_bytes: 1408
/*
Author: Sanskar Agarwal
Nick: sanskarag
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second

int main()
{
    fast
    ll x;
    cin>>x;
    ll p=100;
    int count=0;
    while(p<x)
    {
        count++;
        p=p+floor(p*0.01);
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll s=0,t=0;
    if(a<c){
        if(c<b){
            s=c;
            if(b<d) t=b;
            else t=d;
        }
    }else{
        if(a<d){
            s=a;
            if(d<b) t=d;
            else t=b;
        }
    }

    cout << t-s << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N = 0;
    int D = 0;
    int p = 0, q = 0;

    scanf("%d %d", &N, &D);

    p = N/(2*D + 1);
    q = N%(2*D + 1);

    if(q == 0){
        printf("%d", p);
    }else{
        printf("%d", p+1);
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ll n, d;

    cin >> n;
    for (ll i = 1, d = 3; ; i++) {
        if (d >= n) {
            cout << i << endl;
            break;
        }

        d *= 3;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#include <functional>

template< typename T, typename S >
struct LazySegmentTree{
    int n;
    vector<T> data;
    vector<S> lazy;
    T te;
    S se;

    inline void merge_functions(S& lazy,S& val){
        //lazy+=val;
        lazy=val;
    }
    inline void operate(T& data,S& val,int len){
        //data+=val*len;
        data=val*len;
        //data+=val;
        //data=val;
    }
    inline T merge_values(T& x,T& y){
        return x+y;
        //return min(x,y);
        //return max(x,y);
    }

    LazySegmentTree(){}
    LazySegmentTree(int sz,T te,S se):te(te),se(se){
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1,te);
        lazy.resize(2*n-1,se);
    }

    void build(vector<T> &A){
        for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k];
        for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]);
    }

    void eval(int k,int l,int r){
        if(lazy[k]==se) return;
        operate(data[k],lazy[k],r-l);
        if(r-l>1){
            merge_functions(lazy[2*k+1],lazy[k]);
            merge_functions(lazy[2*k+2],lazy[k]);
        }
        lazy[k]=se;
    }

    void update(int a,int b,S val,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){
            merge_functions(lazy[k],val);
            eval(k,l,r);
        }else{
            update(a,b,val,2*k+1,l,(l+r)/2);
            update(a,b,val,2*k+2,(l+r)/2,r);
            data[k]=merge_values(data[2*k+1],data[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(b<=l||r<=a) return te;
        if(a<=l&&r<=b) return data[k];

        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return merge_values(vl,vr);
    }
};

const ll INF=1e18;

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

  int N,Q;
  cin>>N>>Q;

  LazySegmentTree<ll,ll> seg(N,0,-2*INF);

  vector<ll> init(N,0);
  seg.build(init);

  for(int q=0;q<Q;q++){
      int t;cin>>t;
      if(t==0){
          int a,b;
          ll x;
          cin>>a>>b>>x;
          seg.update(a,b+1,x);
      }else{
          int a,b;
          cin>>a>>b;
          cout<<seg.query(a,b+1)<<"\n";
      }
  }

  return 0;
}



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

void rec(string *field, int y, int x)
{
	field[y][x]='0';
	if (y>0 && field[y-1][x]=='1')rec(field,y-1,x);
	if (x>0 && field[y][x-1]=='1')rec(field,y,x-1);
	if (y<11 && field[y+1][x]=='1')rec(field,y+1,x);
	if (x<11 && field[y][x+1]=='1')rec(field,y,x+1);
}

int main() {
	string field[12];
	while (1)
	{
		int r=0;
		for (int i=0; i<12; i++)cin >> field[i];
		for (int i=0; i<12; i++)
		{
			for (int j=0; j<12; j++)
			{
				if (field[i][j]=='1')
				{
					rec(field,i,j);
					r++;
				}
			}
		}
		if (scanf("%*c") == EOF)break;
		cout << r << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N, M = gets.split.take(2).map(&:to_i)
h = []
g = []
$<.map{|s|
  a, b = s.split.take(2).map(&:to_i)
  h << b if a == 1
  g << a if b == N
}
puts (h & g).empty? ? :IMPOSSIBLE : :POSSIBLE

Measured memory_bytes: 13416
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(int argc,char** argv)
{
 
	float R, G, x;
 
	scanf("%f%f",&R, &G);
 
	x = 2 * G - R;
 
	printf("%g\n", x);
	return(0);
 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int N, L;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> N >> L;
  int ans = N + L - 1;
  int apple = 0;
  if (ans <= 0) apple = ans;
  else if (L >= 0) apple = L;
  cout << (ans + L) * (ans - L + 1) / 2 - apple << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
a, b, h, m = map(int, input().split())
short_hand = 30*h+0.5*m
long_hand = 6*m
angle = min(abs(short_hand-long_hand), 360-abs(short_hand-long_hand))

print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(angle))))


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int i=0; i<n; ++i) cin >> a.at(i);
    for (int i=0; i<m; ++i) cin >> b.at(i);

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    a.push_back(0), b.push_back(0);
    int curH = 0, curW = 0;
    ll res = 1;
    for (int i=0; i<n*m; ++i) {
        int cur = n*m - i;
        if (a.at(curH) == cur && b.at(curW) == cur) {
            ++curH, ++curW;
        } else if (a.at(curH) == cur) {
            res *= curW;
            res %= MOD;
            ++curH;
        } else if (b.at(curW) == cur) {
            res *= curH;
            res %= MOD;
            ++curW;
        } else {
            res *= curH * curW - i;
            res %= MOD;
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 256