akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<unistd.h>
#define PI 3.14159265359


using namespace std;

int main()
{

    int n;
    cin >> n;
    int i = 1;
    int x;

    while(1){
        x = i;
        if(x%3 == 0){
            cout << " " << i;
        }
        else{
            while(1){
                if(x%10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
                if(!x) break;
            }
        }   
        

        if(++i > n) break;

    }

    cout << endl;

    return 0;
}



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

using namespace std;

typedef long long int ll;

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

  int n, k;
  cin >> n >> k;
  vector < int > a (n + 1);
  vector < ll > p (n + 2), lt (n + 2), rt (n + 2);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = p[i - 1] + a[i];
  }

  for (int i = 1; i <= n; i++) {
    lt[i] = lt[i - 1] + (a[i] > 0 ? a[i] : 0);
  }
  for (int i = n; i >= 1; i--) {
    rt[i] = rt[i + 1] + (a[i] > 0 ? a[i] : 0);
  }

  ll ans = LLONG_MIN;
  for (int i = 1; i <= n - k + 1; i++) {
    ans = max ({ans, lt[i - 1] + rt[i + k] + (p[i + k - 1] - p[i - 1] > 0 ? p[i + k - 1] - p[i - 1] : 0)});
  }

  cout << ans << '\n';
}


Measured memory_bytes: 6108
H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)

# 漸化式の実装はAtCoderで珍しい。パターンとして覚えよ！
def attack_num(x):
  if x == 1: return 1
  else: return 2*attack_num(x // 2) + 1
  
print(attack_num(H))

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

#define ll                                 long long
#define mp                                 make_pair
#define pb                                 push_back
#define pii                              pair<long long,long long>
#define vi                                 vector<long long>
#define setbits(x)                          __builtin_popcountll(x)
#define zrobits(x)                          __builtin_ctzll(x)
#define mod                              1000000007
#define inf                               1e18
#define make_array(array_name,array_size,type)   type array_name[array_size];
#define print_array(array_name,array_size)        for(int i=0;i<n;i++){cout<<array_name[i]<<" ";}cout<<endl;
#define input_array(array_name,array_size)       for(int i=0;i<n;i++){cin>>array_name[i];}

long long binexpo(long long a, long long b)
{
   long long res = 1;
   while (b > 0)
   {
      if (b & 1)
         res = res * a;
      a = a * a;
      b >>= 1;
   }
   return res;
}

void initialize()
{
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int main()
{
   initialize();

   ll n;
   cin >> n;
   make_array(arr, n, ll);
   input_array(arr, n);
   ll k;
   cin >> k;
   while (k--)
   {
      ll a, b;
      cin >> a >> b;
      ll sum = 0;
      for (int i = 0; i < n; i++)
         sum += arr[i];
      sum = sum - arr[a - 1] + b;
      cout << sum << endl;
   }

   return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string n;
  cin>>n;
  if(n[2]=='7') cout<<"Yes"<<endl;
  else if(n[1]=='7') cout<<"Yes"<<endl;
  else if(n[0]=='7') cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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


Measured memory_bytes: 3076
// spnauT
//
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int _b=(b),i=(a);i<_b;++i)
#define ROF(i,b,a) for(int _a=(a),i=(b);i>_a;--i)
#define REP(n) for(int _n=(n);_n--;)
#define _1 first
#define _2 second
#define PB(x) push_back(x)
#define SZ(x) int((x).size())
#define ALL(x) (x).begin(),(x).end()
#define MSET(m,v) memset(m,v,sizeof(m))
#define MAX_PQ(T) priority_queue<T>
#define MIN_PQ(T) priority_queue<T,vector<T>,greater<T>>
#define IO(){ios_base::sync_with_stdio(0);cin.tie(0);}
#define nl '\n'
#define cint1(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long LL;typedef pair<int,int> PII;
typedef vector<int>VI;typedef vector<LL>VL;typedef vector<PII>VP;
template<class A,class B>inline bool mina(A &x,const B &y){return(y<x)?(x=y,1):0;}
template<class A,class B>inline bool maxa(A &x,const B &y){return(x<y)?(x=y,1):0;}

template<class Int, Int mod>
class ModInt {
public:
	Int x;
	ModInt(): x(0) {}
	ModInt(int a, bool m=1) { if(m) {x=a%mod; if(x<0)x+=mod;} else x=a; }
	ModInt(LL  a, bool m=1) { if(m) {x=a%mod; if(x<0)x+=mod;} else x=a; }
	inline ModInt &operator+=(ModInt that) { if((x += that.x) >= mod) x -= mod; return *this; }
	inline ModInt &operator-=(ModInt that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
	inline ModInt &operator*=(ModInt that) { x = LL(x) * that.x % mod; return *this; }
	inline ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
	inline ModInt operator-() const { return ModInt(-this->x); }
	ModInt inverse() const {LL a=x,b=mod,u=1,v=0;while(b){LL t=a/b;a-=t*b;u-=t*v;swap(a,b);swap(u,v);} return ModInt(u);}
	inline friend ostream& operator << (ostream &out, ModInt m) {return out << m.x;}

#define op(o1,o2) ModInt operator o1(ModInt that) const { return ModInt(*this) o2 that; }
	op(+,+=) op(-,-=) op(*,*=) op(/,/=)
#undef op
#define op(o) bool operator o(ModInt that) const { return x o that.x; }
	op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

const int moder = 1e9+7;
typedef ModInt<int,moder> Mint;

#define MAXN (300005)

Mint F[MAXN];
Mint FI[MAXN];

Mint Cnr(int n, int r)
{
	if(r < 0 || r > n) return 0;
	return F[n] * FI[r] * FI[n-r];
}

int main()
{
	IO();
	F[0] = 1;
	FOR(i,1,MAXN) F[i] = F[i-1] * i;
	FI[MAXN-1] = F[MAXN-1].inverse();
	ROF(i,MAXN-2,-1) FI[i] = FI[i+1] * (i+1);

	cint2(H,W);
	cint2(A,B);

	Mint sol;
	FOR(i,B+1,W+1) sol += Cnr(i-1+H-A-1, i-1) * Cnr(A-1+W-i, A-1);

	cout << sol << nl;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;
int main()
{
  int N;
  cin >> N;
  int num;
  unordered_map<long, int> mp;
  string ans = "YES";
  
  for (int i = 0; i < N; i++) {
    cin >> num;
    if (mp[num] != 0) {
      ans = "NO";
      break; 
    }
    mp[num] = 1;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8520
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	n, m := scanInt(), scanInt()
	result := make(map[int]int, m)
	wa := make([]int, n)
	for i := 0; i < m; i++ {
		q := scanInt() - 1
		if scanText() == "AC" {
			if _, ok := result[q]; !ok {
				result[q] = wa[q]
			}
		} else {
			if _, ok := result[q]; !ok {
				wa[q]++
			}
		}
	}

	ok, ng := 0, 0
	for _, v := range result {
		ok++
		ng += v
	}

	fmt.Println(ok, ng)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {

	if a < b {
		a, b = b, a
	}

	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 10, NX = 1e9 + 7;
int n, dp[MXN], PS[MXN];
int main()
{
    scanf("%d", &n);
    dp[0] = 1; PS[0] = 1;
    dp[1] = n; PS[1] = n + 1;
    for (int i = 2; i <= n; i++)
    {
        dp[i] = (1ll * (n - 1) * (n - 1) + n - i + 1 + dp[i - 1]) % NX;
        if (i >= 3)
            dp[i] = (dp[i] + PS[i - 3]) % NX;
        PS[i] = (PS[i - 1] + dp[i]) % NX;
    }
    return !printf("%d", dp[n]);
}


Measured memory_bytes: 8064
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var zmin;
  var zmax;
  var wmin;
  var wmax;
  for(var i = 0; i < N; i++){
    var tmp = nextIntArray();
    if(i == 0){
      zmin = tmp[0] + tmp[1];
      zmax = tmp[0] + tmp[1];
      wmin = tmp[0] - tmp[1];
      wmax = tmp[0] - tmp[1];
    }else{
      zmin = Math.min(zmin, tmp[0] + tmp[1]);
      zmax = Math.max(zmax, tmp[0] + tmp[1]);
      wmin = Math.min(wmin, tmp[0] - tmp[1]);
      wmax = Math.max(wmax, tmp[0] - tmp[1]);
    }
  }
  myout(Math.max(Math.abs(zmax - zmin), Math.abs(wmax - wmin)));
}


Measured memory_bytes: 81872
import sys
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    for a in range(n-2):
        for b in range(a+1, n-1):
            ans += bisect.bisect_left(l, l[a]+l[b]) - b - 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
MOD = 10**9+7

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

primes = [0]
while M % 2 == 0:
    primes[0] += 1
    M //= 2

if M != 1:
    for i in range(3, int(M**0.5+1), 2):
        if M % i == 0:
            primes.append(0)
            while M % i == 0:
                primes[-1] += 1
                M //= i
            if M == 1:
                break
    else:
        primes.append(1)

#combinations[p] = p+N-1 C N-1
combinations = [1]

p_max = max(primes)
for p in range(1, p_max+1):
    combinations.append( combinations[-1] * (p+N-1) * pow(p, MOD-2, MOD) % MOD )

ans = 1
for p in primes:
    ans *= combinations[p]
    ans %= MOD

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;
int calc(int a,int b,int c){
    return a*10000+b*5000+c*1000;
}
int main(void){
    // Your code here!
    int n, y;
    cin >> n >> y;
    int a=-1,b=-1,c=-1;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if(calc(i,j,n-i-j) == y){
                a = i,b=j,c=n-i-j;
            }
        }
    }
    cout << a << " " << b << " " << c;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
vector<int> v[100010];
int n,m;
int a[100010];
int d[100010];
stack<int> s;
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		v[x].push_back(y);
		a[y]++;
	}
	for (int i=0;i<n;i++) if (!a[i]) s.push(i);
	while (!s.empty())
	{
		int x=s.top();
		s.pop();
		for (int i=0;i<v[x].size();i++)
		{
			int xi=v[x][i];
			d[xi]=max(d[xi],d[x]+1);
			a[xi]--;
			if (!a[xi]) s.push(xi);
		}
	}
	cout <<*max_element(d,d+n);
	return 0;
}

Measured memory_bytes: 6528
from scipy.sparse.csgraph import floyd_warshall as wf
h,w = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(h)]
C = wf(C)
cost = 0
for y in range(h):
    for x in range(w):
        if A[y][x] != -1:
            cost += C[A[y][x]][1]
print(int(cost))

Measured memory_bytes: 17636
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n = I()

if n % 1000 == 0:
    print(0)
else:
    print(1000 - n % 1000)


Measured memory_bytes: 9156
url = "https://atcoder.jp/contests/abc087/tasks/arc090_a"
import copy
def main():
    n = int(input())
    a1 = list(map(int, input().split()))
    a2 = list(map(int, input().split()))
    c = a1[0] + sum(a2)
    ans = c
    for i in range(1, n):
        c = c + a1[i] - a2[i - 1]
        ans = max(ans, c)
    print(ans)


if __name__ == '__main__':
    main()




Measured memory_bytes: 3444
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;

struct PCSZ {
  // assumption: every root node points itself.
  struct node_t {
    int parent;
    int size;
    int aux;
    node_t() : size(1), aux(0) {}
  };
  vector<node_t> nodes;

  PCSZ() { }
  PCSZ(int size) : nodes(size) {
    for (int i = 0; i < size; i++) {
      nodes[i].parent = i;
    }
  }

  // find root node
  int find(int index) {
    int root = index;
    while (root != nodes[root].parent) {
      root = nodes[root].parent;
    }
    while (root != nodes[index].parent) {
      int next = nodes[index].parent;
      nodes[index].parent = root;
      index = next;
    }
    return root;
  }

  // true if merge was successful
  bool merge(int first, int second) {
    int r1 = find(first);
    int r2 = find(second);
    if (r1 == r2) {
      return false;
    }
    if (nodes[r1].size < nodes[r2].size) {
      // careful, first and second not swapped
      swap(r1, r2);
    }
    nodes[r1].size += nodes[r2].size;
    nodes[r1].aux += nodes[r2].aux;
    nodes[r2].parent = r1;
    return true;
  }

  int group_size(int index) {
    return nodes[find(index)].size;
  }
  int aux(int index) {
    return nodes[find(index)].aux;
  }
};

int main() {
  int n, h, w;
  scanf("%d%d%d", &n, &h, &w);
  vector<char> used(n);
  vector<tuple<int, int, int>> dat(n);
  for (int i = 0; i < n; i++) {
    int r, c, w;
    scanf("%d%d%d", &r, &c, &w);
    r--, c--;
    dat[i] = make_tuple(w, r, c);
  }
  sort(dat.begin(), dat.end(), greater<tuple<int, int, int>>());
  PCSZ groups(h + w);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int w, r, c;
    tie(w, r, c) = dat[i];
    if (groups.aux(r) + 1 <= groups.group_size(r)) {
      ans += w;
      groups.nodes[groups.find(r)].aux++;
      groups.merge(r, h + c);
    } else if (groups.aux(h + c) + 1 <= groups.group_size(h + c)) {
      ans += w;
      groups.nodes[groups.find(h + c)].aux++;
      groups.merge(r, h + c);
    }
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 3840
main :: IO()
main = do
    str <- getLine
    print $ getsolve str 0
    
    
    
getsolve :: String -> Int -> Int
getsolve str num
    | str == []		  = num
    | head str == '+' = getsolve (tail str) (num + 1)
    | head str == '-' = getsolve (tail str) (num - 1)

Measured memory_bytes: 380
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int grid[4][4];
    for (int i=1;i<=3;i++){
        for (int j=1;j<=3;j++) {
            cin >> grid[i][j] ; 
        }
    }
    bool ok=true;
    if (grid[1][2]+grid[2][1] != grid[1][1]+grid[2][2]) ok = false ; 
    if (grid[3][2]+grid[2][3] != grid[2][2]+grid[3][3]) ok = false ; 
    if (grid[3][1]+grid[1][3] != grid[1][1]+grid[3][3]) ok = false ; 
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3576
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define mod 1000000007

using namespace std;

ll n,cnt=0,d,b,c;

ll coun(ll x)
{d=0,b=0,c=0;
    while(x>0){
        if(x%10==7)d=1;
        else if(x%10==5)b=1;
        else if(x%10==3)c=1;
        x/=10;
    }
    return (d&&b&&c);
}

void dfs(ll a)
{
    if(a>n)return;
    else if(coun(a))cnt++;
    dfs(a*10+3);
    dfs(a*10+5);
    dfs(a*10+7);
}

int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    cin>>n;dfs(0);
    cout<<cnt<<endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++){
    cin >> D.at(i);
  }
  
  int k = 0;
  vector<int> E(N*(N-1)/2);
   for (int i = 0; i < N-1; i++){
     for (int j = i+1; j < N ;j++){
       E.at(k) = D.at(i) * D.at(j);
       k++;
     }
   }
  
  int ans = 0;
  for (int i = 0; i < N*(N-1)/2; i++){
    ans += E.at(i);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

int N, M;

int s[10000], t[10000], c[10000];

typedef pair<int, i_i> iii;

bool f(int border) {
    UnionFind uni(N);
    vector<iii> v;
    //cerr << "--------" << border << "---------" << endl;
    for(int i = 0; i < M; i++) {
        v.push_back({0, {s[i], t[i]}});
        if(c[i] > border) v.back().first = 1;
    }
    sort(v.begin(), v.end());
    int cost = 0;
    for(auto tmp : v) {
        //cerr << tmp.first << " " << tmp.second.first << " " << tmp.second.second << endl;
        if(uni.merge(tmp.second.first, tmp.second.second)) {
            cost += tmp.first;
        }
    }
    return cost < N / 2;
}

void solve() {
    for(int i = 0; i < M; i++) cin >> s[i] >> t[i] >> c[i];
    int ok = 1e9;
    int ng = 0;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3508
import java.io.BufferedReader
import java.util.*
import kotlin.system.exitProcess

fun main() = agc031b()

@OptIn(ExperimentalStdlibApi::class)
fun agc031b() = SimpleFastIOWithToken_agc031b().exec {
    val n = readInt()
    val colors = IntArray(n) { readInt() - 1 }
    val mod = 1_000_000_007L

    val beforeAppearedIndexByColor = IntArray(200_000) { -1 }
    val patterns = LongArray(n).apply { this[0] = 1 }

    for ((i, c) in colors.withIndex()) {
        if (i != 0) {
            patterns[i] = patterns[i - 1]
            beforeAppearedIndexByColor[c]
                .takeIf { it != -1 && it != i - 1 }
                ?.let { patterns[i] += patterns[it] }
            patterns[i] %= mod
        }
        beforeAppearedIndexByColor[c] = i
    }

    val answer = patterns.last()

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_agc031b(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_agc031b.() -> Unit) = run {
        Thread(null, { action() }, "(^o^)", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) } }
            .apply { start() }.join()
    }.run { kotlin.io.print(sb) }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 58228
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, std::pair<int,int> > P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
using namespace std;
 
#define int long long
 
signed main(){
 
	int tmp;
 
	int n,m;
	cin>>n>>m;

	if(n==2||m==2){
		cout<<0<<endl;
		return 0;
	}
 
	if(n>2&&m>2){
		cout<<(n-2)*(m-2)<<endl;
	}else if(n>2&&m<=2){
		tmp=(n-2)*m;
		cout<<tmp<<endl;
	}else if(n<=2&&m>2){
		tmp=(m-2)*n;
		cout<<tmp<<endl;
	}else{
		cout<<1<<endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  int p,n;
  p=2019;
  n=s.size();
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4360
N = int(input())
dic = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
p = ["M", "M", "M", "M", "M", "M", "A", "A", "A", "R"]
q = ["A", "R", "C", "A", "R", "A", "R", "R", "C", "C"]
r = ["R", "C", "H", "C", "H", "H", "C", "H", "H", "H"]


for _ in range(N):
    s = input()
    if s[0] in "MARCH":
        dic[s[0]] += 1

res = 0
for i in range(10):
    res += dic[p[i]] * dic[q[i]] * dic[r[i]]

print(res)

Measured memory_bytes: 3064
#![allow(bare_trait_objects)]
#![allow(unused_imports)]
#![allow(dead_code)]

use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
use std::io::BufRead;
use std::io::Stdin;
use std::io::StdinLock;
use std::str::FromStr;

pub struct Scanner<'a> {
    // stdin: Stdin,
    buf_read: Box<BufRead + 'a>,
    tokens: Vec<String>,
}

impl<'a> Scanner<'a> {
    pub fn new(buf_read: StdinLock<'a>) -> Self {
        Scanner {
            buf_read: Box::new(buf_read),
            tokens: Vec::new(),
        }
    }

    // pub fn from_stdin() -> Self {
    //     let stdin = Box::leak(Box::new(std::io::stdin()));
    //     Self {
    //         buf_read: Box::new(stdin.lock()),
    //         tokens: Vec::new(),
    //     }
    // }

    pub fn next(&mut self) -> String {
        while self.tokens.is_empty() {
            let mut s = String::new();
            if self.buf_read.read_line(&mut s).is_err() {
                panic!()
            }
            self.tokens = s
                .split_whitespace()
                .filter(|s| !s.is_empty())
                .rev()
                .map(str::to_string)
                .collect();
        }
        self.tokens.pop().unwrap()
    }

    pub fn next_g<T: FromStr>(&mut self) -> T
    where
        T::Err: Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn usize(&mut self) -> usize {
        self.next_g()
    }

    pub fn i64(&mut self) -> i64 {
        self.next_g()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n = sc.usize();
    let m = sc.usize();

    let mut s = vec![0; n];
    for i in 0..m {
        let k = sc.usize();
        for _ in 0..k {
            s[sc.usize() - 1] |= 1 << i;
        }
    }

    let p = (0..m).map(|_| sc.usize()).collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..1 << n {
        let mut q = 0;
        for j in 0..n {
            if (i >> j & 1) == 1 {
                q ^= s[j];
            }
        }
        if (0..m).all(|b| (q >> b & 1) == p[b]) {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;

   if(n==2)
   {
       cout<<"1" ;
       exit(0) ;
   }
   ll ans=2 ;
   for(ll i=2;i*i<=n;i++){
    if(n%i==0){
        ll x=n/i ;
        while(x%i==0)
        {
            x/=i ;
        }

        if(x%i==1)
        {
            ans++ ;


        }
        if(i*i!=n)
        {
            x=i ;
            while(x%(n/i)==0)
            {
                x/=(n/i) ;
            }
            if(x%(n/i)==1)
            {

                ans++ ;

            }
        }
    }
   }

   ll k=n-1 ;
   for(ll i=2;i*i<=k;i++)
   {
       if(k%i==0)
       {

           ans++ ;


           if(i*i!=k)
           {

            ans++ ;

           }
       }
   }

   cout<<ans ;




}



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

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

int n, w, h, s, t, x, y, ans = 0;
int estate[105][105], dp[105][105];

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

    while (cin >> n, n) {
        cin >> w >> h;
        rep(i,n) {
            cin >> x >> y;
            estate[x-1][y-1] = 1;
        }
        cin >> s >> t;
        s--; t--;
        ans = 0;
        rep(i,w) {
            rep(j,h) {
                if (i == 0 && j == 0) {
                    dp[i][j] = estate[i][j];
                } else if (i == 0 && j != 0) {
                    dp[i][j] = dp[i][j-1] + estate[i][j];
                } else if (i != 0 && j == 0) {
                    dp[i][j] = dp[i-1][j] + estate[i][j];
                } else {
                    dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + estate[i][j];
                }
            }
        }

        for (int i = 0; i + s < w; ++i) {
            for (int j = 0; j + t < h; ++j) {
                if (i == 0 && j == 0) {
                    ans = dp[i+s][j+t];
                } else if (i == 0 && j != 0) {
                    ans = max(ans, dp[i+s][j+t] - dp[i+s][j-1]);
                } else if (i != 0 && j == 0) {
                    ans = max(ans, dp[i+s][j+t] - dp[i-1][j+t]);
                } else {
                    ans = max(ans, dp[i+s][j+t] - dp[i-1][j+t] - dp[i+s][j-1] + dp[i-1][j-1]);
                }
            }
        }
        cout << ans << endl;
        /*rep(i,w) {
            rep(j,h) {
                cout << estate[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;

        rep(i,w) {
            rep(j,h) {
                cout << dp[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        */
        memset(dp, 0, sizeof(dp));
        memset(estate, 0, sizeof(estate));
    }

    return 0;
}

Measured memory_bytes: 3172
def main():
    nvertices, nedges = map(int, input().split())
    INF = float('inf')
    D1 = [[INF for i in range(nvertices)] for i in range(nvertices)]
    for i in range(nedges):
        s, t, d = map(int, input().split())
        D1[s][t] = d

    for i in range(nvertices):
        D1[i][i] = 0

    for k in range(nvertices):
        D2 = [[INF for i in range(nvertices)] for i in range(nvertices)]
        for i in range(nvertices):
            for j in range(nvertices):
                D2[i][j] = min(D1[i][j], D1[i][k] + D1[k][j])
        D1 = D2

    for i in range(nvertices):
        if D1[i][i] < 0:
            print("NEGATIVE CYCLE")
            return

    for lst in D1:
        print(" ".join(map(lambda e: str(e) if e < INF else "INF", lst)))


main()

Measured memory_bytes: 8676
#include <stdio.h>
#include <string.h>
#define N 1000

int lcs(char x[], char y[])
{
	int m, n, i, j;
	int c[N + 1][N + 1];

	m = strlen(x);
	n = strlen(y);

	for (i = 0; i <= m; i++)
		c[i][0] = 0;
	for (j = 1; j <= n; j++)
		c[0][j] = 0;

	for (i = 1; i <= m; i++)
	{
		for (j = 1; j <= n; j++)
		{
			if (x[i - 1] == y[j - 1])
				c[i][j] = c[i - 1][j - 1] + 1;
			else if (c[i - 1][j] >= c[i][j - 1])
				c[i][j] = c[i - 1][j];
			else
				c[i][j] = c[i][j - 1];
		}
	}
	return c[m][n];
}

int main()
{
	int n, i;
	char a[N], b[N];

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%s", a);
		scanf("%s", b);
		printf("%d\n", lcs(a, b));
	}
	return 0;
}


Measured memory_bytes: 5616
function Main(input) {
    input = input.split("\n")
    const line = input[0]
    const items = line.split(" ")
    const n = parseInt(items[0])
    const k = parseInt(items[1])
    const ans = n.toString(k)
    console.log(ans.length)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main(){
  int n; cin >> n;
  vector<int> H(n);
  for(int i=0; i<n; i++){
    cin >> H[i];
  }
  int sum; sum = accumulate(H.begin(), H.end(), 0);
  int ans; ans = 0;
  int diff; diff = abs(sum - ans);
  for(int i=0; i<n; i++){
    sum -= H[i];
    ans += H[i];
    if(abs(sum - ans) <= diff){
      diff = abs(sum - ans);
    }else{
      ans = diff;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; --i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr int MAX = 2020;

int n;
vector<pair<ll, ll>> graph[100010];
int ans[100010];
void dfs(int v, int p, bool col) {
  for (auto nv : graph[v]) {
    if (nv.first != p) {
      if (nv.second & 1) {
        ans[nv.first] = col ^ 1;
        dfs(nv.first, v, col ^ 1);
      } else {
        ans[nv.first] = col;
        dfs(nv.first, v, col);
      }
    }
  }
}

int main()
{
  cin >> n;
  REP(i, n-1) {
    ll u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    graph[u].emplace_back(v, w);
    graph[v].emplace_back(u, w);
  }
  dfs(0, 0, 0);
  REP(i, n) cout << ans[i] << '\n';
  return 0;
}

Measured memory_bytes: 10624
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w, k = MAP()
s = [input() for i in range(h)]
n = h + w

ans = 0
for i in range(2**n):
    a = []
    for j in range(n):
        a.append(( i >> j ) & 1)
    reg = 0
    for j in range(h):
        for l in range(w):
            if s[j][l] == '#' and a[j]&a[h+l]==1:
                reg += 1
    if reg == k:
        ans += 1
print(ans)

Measured memory_bytes: 10128
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError:
        break
s = set(array)
count= list(map(lambda a: array.count(a), s))
mx = max(count)
modes = list(list(s)[i] for i, x in enumerate(count) if x == mx)
print(*modes, sep = '\n')

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << H*W - W*h - H*w + h*w << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <limits.h>

#define TEST_MODE 1

int main(void) {
#if TEST_MODE
	long long  a,b;
	while(scanf("%lld%lld",&a,&b)==2) {
		if(a+b>(long long)INT_MAX || a+b<(long long)INT_MIN)return 1;
		printf("%lld\n",a+b);
	}
#else
	int a,b;
	while(scanf("%d%d",&a,&b)==2) {
		printf("%d\n",a+b);
	}
#endif
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
long long gcd(long long a, long long b) {return b ? gcd(b, a % b) : a;}
long long lcm(long long m, long long n ){if((0 == m )||( 0 == n ))return 0;
    return ((m / gcd(m, n)) * n);
}
#define mp make_pair
signed main(){
    int a,b;cin>>a>>b;
    int hoge=gcd(a,b);
    if(hoge==b)return puts("-1")*0;
    else{
        cout<<a*(b-1)<<endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._700problems
{
    class CodeFestival2016B_D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = ReadLong();

            long res = array[0] - 1;
            int now = 2;
            for(int i = 1; i < n; i++)
            {
                if (now == array[i]) now++;
                else res += (array[i] - 1) / now;
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 15712
import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def update(self, i, x):
        """ 値の更新：添字i, 値x """
        self.add(i, x - self.get(i))

def bucket_sort(A, M, key):
    from itertools import accumulate

    N = len(A)
    C = [0] * (M+1)
    res = [()] * N
    for i in range(N):
        C[A[i][key]] += 1
    C = list(accumulate(C))

    for i in range(N-1, -1, -1):
        res[C[A[i][key]]-1] = A[i]
        C[A[i][key]] -= 1
    return res

N, Q = MAP()
A = [a-1 for a in LIST()]

prev = [-1] * N
events = []
bit = BIT(N)
for t, a in enumerate(A):
    s = prev[a]
    if s != -1:
        events.append((t, 0, s))
    prev[a] = t

for i in range(Q):
    l, r = MAP()
    l -= 1; r -= 1
    events.append((r, 1, l, i))

# events.sort(key=itemgetter(0))
events = bucket_sort(events, N, 0)
ans = [0] * Q
for event in events:
    # 色の区間が来たら、点を追加
    if event[1] == 0:
        t, _, s = event
        bit.add(s, 1)
    # クエリが来たら、点の数を数える
    else:
        r, _, l, i = event
        total = r - l + 1
        # 区間全体 - この時の領域内の点の数
        ans[i] = total - bit.get(l, N)

for a in ans:
    print(a)


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

int s;

int solve(int s) {
  int res = 1;
  while( s != 1 ) {
    if(s % 2 == 0)
      s /= 2;
    else
      s = 3 * s + 1;
    
    res++;
  }
  return (res + 1);
}

int main() {
  cin >> s;
  if(s == 1 || s == 2)
    cout << 4 << endl;
  else
    cout << solve(s) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j > i; j--) {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			}
		}

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	}

}

Measured memory_bytes: 26220
#include<stdio.h>
	int main(){
		int H,A;
		scanf("%d %d", &H, &A);
		if (H%A == 0){
			printf ("%d", H/A);
		}else if (H%A != 0){
			printf ("%d",H/A+1);
		}
		return 0;
	}

Measured memory_bytes: 2072
n = int(input())
a = list(map(int, input().split()))
ans = 0
while a[0] > 1:
        for i in range(n):
                if a[i] % 2 != 0:
                        break
                else:
                        a[i] /= 2
        else:
                ans += 1
                continue
        break;

print(ans)

Measured memory_bytes: 3060
n, m = map(int, input().split())
al = [0]*m; bl = [0]*m
for i in range(m):
    a,b = list(map(int, input().split()))
    al[i] = a
    bl[i] = b
res = [0] * n
for i in range(m):
    res[al[i]-1] += 1
    res[bl[i]-1] += 1

for i in range(n):
    print(res[i])

Measured memory_bytes: 3064
n = int(input())
al = list(map(int, input().split()))
res = 0
temp = 0
for j in range(n-1,-1,-1):
    if j ==al[j]-1:
        temp +=1
    else:
        break
if temp % 2 ==1:
    res +=1

for i in range(n-1):
    if al[i] ==i+1:
        res += 1
        al[i+1] = al[i]

print(res)

Measured memory_bytes: 14008
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<string>
#define Lens 105
#define Nil -1
using namespace std;

int N, sum;
stack<int> s;
int main()
{
	string c;
	while (cin >> c)
	{
		if (c[0] == '+')
		{
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(a + b);

		}
		else if (c[0] == '-')
		{
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(b-a);
		}
		else if (c[0] == '*')
		{
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(a * b);
		}
		else
		{
			int t = atoi(c.c_str());
			s.push(t);
		}
	}
	cout << s.top() << endl;
	return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int s=max(a,c);
  int e=min(b,d);
  cout<<max(0,e-s)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans=0;
  rep(i,n){
    ans+=i;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 384
N = gets.strip.to_i
S = gets.strip

hash = Hash.new(0)
S.chars do |s|
    hash[s]+=1
end
ans=1
hash.each do |k,v|
    ans*=(v+1)
    ans %= (1e9 + 7)
end

puts (ans-1).to_i


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

int main()
{

    string S;
    cin >> S;

    if (S == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (S == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else if (S == "Rainy")
    {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
#include <array>
#include <cmath>

using namespace std;

int PRIME = 1000000007;


int main(int argc, char* argv[]){
    int N, M;
    cin >> N >> M;

    int max_cand = M / 2;
    for(int i = N; i <= max_cand; ++i){
        if(M % i == 0){
            cout << M / i;
            return 0;
        }
    }

    cout << 1;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
 
  int i,j,k,x,n,a[10000];
  long long sum;
 
  scanf("%d",&n);
   
  for (i = 0; i < n; i++){
   
    scanf("%d",&a[i]);
 
  }
 
  for (j = 0; j < (n-1)*2; j++){
 
    for (i = 0; i < n-1; i++){
 
      if (a[i] >= a[i+1]){
 
        x=a[i];
        a[i]=a[i+1];
        a[i+1]=x;
 
      }
 
    }
 
  }
 
  sum=0;
 
  for (k = 0; k < n; k++){
 
    sum=a[k]+sum;
 
  } 
 
  printf("%d %d %lld\n",a[0],a[n-1],sum);
 
    return 0;
 
}


Measured memory_bytes: 2100
#include <stdio.h>

int main(void) {
	int a,b;
	scanf("%d%d",&a,&b);
	if(a-b<0){printf("a < b\n");}
	else if(a-b>0){printf("a > b\n");}
	else{printf("a == b\n");}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <climits>
using namespace std;
typedef long long int ll;

int t[100100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int d,n,m;
	while(cin >> d,d){
		cin >> n >> m;
		t[0]=0;
		for(int i=0;i<n-1;i++){
			cin >> t[i+1];
		}
		t[n]=d;
		sort(t,t+n+1);
		int ans=0;
		for(int i=0;i<m;i++){
			int x; cin >> x;
			int left=0,right=n;
			while(right-left>1){
				int mid=(left+right)/2;
				if(t[mid]>=x)right=mid;
				else left=mid;
			}
			ans+=min(abs(t[left]-x),abs(t[right]-x));
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3488