akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int a,h;

void solve(){
    cin >> h >> a;
    cout << (h-1)/a+1 << endl;
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
    int n,d;
    int i,j,k;
    int x[10][10];
    int count=0,sum,dif,sq;
    double sumd,sqd;
    
    scanf("%d %d",&n,&d);
    
    for(i=0;i<n;i++)
    {
        for(j=0;j<d;j++)
        {
            scanf("%d",&x[i][j]);
        }
    }
    
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            sum = 0;
            for(k=0;k<d;k++)
            {
                dif = x[i][k] - x[j][k];
                sum = sum + dif * dif;
            }
            sumd = sum;
            sqd = sqrt(sumd);
//            printf("n=%d,%d sum=%d sqd=%f\n",i,j,sum,sqd);
            sq = sqd;
            if(sum == sq * sq)
            {
                count = count + 1;
            }
        }
    }
    
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int MOD = (int)(1e9 + 7);
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = 1ll * ret * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return ret;
}

const int N = 110;
int dp[N][N], hei[N], n;
vector<int> tmp;
int main() {
  read(n);
  rep (i, 1, n)
    read(hei[i]), tmp.push_back(hei[i]);
  hei[0] = 1, tmp.push_back(1);
  sort(tmp.begin(), tmp.end());
  tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
  rep (i, 0, n)
    hei[i] = lower_bound(tmp.begin(), tmp.end(), hei[i]) - tmp.begin();
  dp[0][n] = 1;
  rep (i, 1, n) {
    rep (j, 0, min(hei[i-1], hei[i]))
      Add(dp[i][j], 1ll * dp[i-1][j] * power(2, max(0, tmp[hei[i]] - tmp[hei[i-1]])) % MOD);
    int sum = 0;
    rep (j, min(hei[i-1], hei[i])+1, n)
      Add(sum, dp[i-1][j]);
    sum = (sum * 2) % MOD;
    rep (j, min(hei[i-1], hei[i])+1, hei[i]) {
      int v = power(2, tmp[j] - tmp[j-1]) - 1;
      v = 1ll * v * power(2, tmp[hei[i]] - tmp[j]) % MOD;
      Add(dp[i][j], 1ll * v * sum % MOD);
    }
    Add(dp[i][n], sum);
  }
  int ans = 0;
  rep (i, 0, n) Add(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,s;

int count(int depth,int sum,int bef)
{
	int cnt=0,i;

	if(depth==n+1)	return sum==s;

	for(i=bef+1;i<=9;i++)
		cnt+=count(depth+1,sum+i,i);

	return cnt;
}

main(){
	while(scanf("%d%d",&n,&s),n||s)
		printf("%d\n",count(1,0,-1));
	exit(0);
}

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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	
	if (t.substr(0, t.length() - 1) == s) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	
	return 0;
}


Measured memory_bytes: 3624
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt(),m=sc.nextInt();
        Point[] p=new Point[n];
        for (int i = 0; i < n; i++) {
            int a=sc.nextInt(),b=sc.nextInt();
            p[i]=new Point(a,b);
        }
        Arrays.sort(p,(p1,p2)->p1.x-p2.x);
        int t=0;
        long ans=0;
        int i=0;
        while (t<m){
            if(p[i].y>0){
                t++;
                ans+=p[i].x;
                p[i].y--;
            }else {
                i++;
            }
        }
        out.println(ans);
    }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x, y;
  cin >> x >> y;
  
  int ans = 0;
  if(x == 1) ans += 300000;
  else if(x == 2) ans += 200000;
  else if(x == 3) ans += 100000;
  
  if(y == 1) ans += 300000;
  else if(y == 2) ans += 200000;
  else if(y == 3) ans += 100000;
  
  if(x == 1 && y == 1) ans += 400000;
  
  cout << ans << "\n";
}

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

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

  ll n, k;
  cin >> n >> k;

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

  vector<int> last(n,-1);
  vector<int> root;
  int gap = 0;
  root.push_back(0);
  last[0] = 0;
  int i = 0;
  int from = 0;
  int cnt = 1;
  while(true) {
    if(last[a[i]] != -1) {
      gap = cnt - last[a[i]];
      from = last[a[i]];
      break;
    }
    last[a[i]] = cnt;
    root.push_back(a[i]);
    i = a[i];
    cnt++;
  }


  vector<int> f;
  if(k < cnt) {
    cout << root[k] + 1 << '\n';
  } else {
    k -= (cnt - gap);
    for (int j = from; j < cnt; j++) {
      f.push_back(root[j]);
    }
    k %= gap;
    cout << f[k] + 1 << endl;
  }
}

Measured memory_bytes: 6788
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int n,k;
int a[100005];
int cnt[44];
int dfs(int pos,int v){
	if(v>k)while(1);
	if(pos==0){
		if(v+1<=k){
			return max(cnt[0],n-cnt[0]);
		}else if(v<=k){
			return n-cnt[0];
		}
		while(1);
	}
	if(cnt[pos]*2ll<=n){
		return dfs(pos-1,v)+(1ll<<pos)*(n-cnt[pos]);
	}else{
		if((v+(1ll<<pos))>k)return dfs(pos-1,v)+(1ll<<pos)*(n-cnt[pos]);
		int ret=dfs(pos-1,v+(1ll<<pos));
		ret+=cnt[pos]*(1ll<<pos);
		int rret=(1ll<<pos)*(n-cnt[pos]);
		for(int j=pos-1;j>=0;j--){
			rret+=(1ll<<j)*(ll)max(cnt[j],(n-cnt[j]));
		}
		ret=max(ret,rret);
		return ret;
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=0;i<42;i++)for(int j=1;j<=n;j++)cnt[i]+=((a[j]&(1ll<<i))?1:0);
	for(int i=0;i<42;i++)cnt[i]=n-cnt[i];
	if(!k){
		int ret=0;
		for(int i=1;i<=n;i++)ret+=a[i];
		cout<<ret<<endl;
		return 0;
	}
	int high=0;
	while((1ll<<high)<=k)high++;
	high--;
	int mask=(1ll<<high+1)-1;
	int ans=0;
	for(int i=1;i<=n;i++)ans+=a[i]-(a[i]&mask);
	cout<<ans+dfs(high,0)<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (begin); idx < (end); ++idx)
#define DBG(x) cerr << #x << ": " << x << "\n"

using namespace std;
typedef long long lint;
const int MOD = 1000000007;

int main() {

	cin.tie(0);

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

	vector<bool> visited(N, false);
	vector<bool> tmp(N);

	vector<int> a(M), b(M);
	FOR(i, 0, M) cin >> a[i] >> b[i];

	vector<vector<bool>> path(N, vector<bool>(N, false));
	FOR(i, 0, M) {
		path[a[i] - 1][b[i] - 1] = true;
		path[b[i] - 1][a[i] - 1] = true;
	}

	int ans = 0;

	queue<pair<int, vector<bool>>> node;
	copy(visited.begin(), visited.end(), tmp.begin());
	tmp[0] = true;
	node.push({0, tmp});

	while (!node.empty()) {
		
		auto now = node.front();
		node.pop();

		FOR(i, 0, N) {
			if (now.second[i] == false && path[now.first][i] == true) {
				copy(now.second.begin(), now.second.end(), tmp.begin());
				tmp[i] = true;
				node.push({i, tmp});
			}
		}

		FOR(i, 0, N) {
			if (now.second[i] == false) break;
			if (i == N - 1) {
				ans++;
			}
		}
	
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod2 998244353
#define INT_MAX1 900000000
//////////////////////////////////////////////////////////////////////////////////////////////

int n;
bool arr[21][21];
int dp[22][1<<22];
bool v[22][1<<22];

int s1(int i, int s)
{
    if(i==n)
        return 1;
    if(v[i][s])
        return dp[i][s];
    v[i][s] = 1;
    rep(j,0,n-1)
    {

        if(arr[i][j] and (s&(1<<j))==0)
            dp[i][s] += s1(i+1,(s|(1<<j))), dp[i][s]%=mod;
    }
    return dp[i][s];
}

void solve()
{
    cin >> n;
    rep(i,0,n-1)
        rep(j,0,n-1)
            cin >> arr[i][j];
    cout << s1(0,0);
}

 
int32_t main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 387328
N, K = map(int, input().split())
a = list(map(int, input().split()))
max_bit = 40
ans = 0
 
for bit in range(max_bit, -1, -1):
    num = 2**bit
    bit_count = len([1 for n in a if n&num > 0])
    if bit_count < N - bit_count and num <= K:
        bit_count = N - bit_count
        K -= num
    ans += num * bit_count
 
print(ans)

Measured memory_bytes: 14248
N,M = map(int,input().split())
A,B = [],[]
for _ in range(M):
    a,b = map(int,input().split())
    A.append(a-1)
    B.append(b-1)

cur = N *(N-1)//2
ans = [0]*(M)

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

  def union(self, a, b):
    a = self.root(a)
    b = self.root(b)
    if(a == b):
      return
    if(self.size(a) < self.size(b)):
      a, b = b, a
    self.tree[a] += self.tree[b]
    self.tree[b] = a

  def root(self, a):
    if(self.tree[a] < 0):
      return a
    res = self.root(self.tree[a])
    self.tree[a] = res
    return res

  def size(self, a):
    return -self.tree[self.root(a)]
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
uf = UnionFind(N)
for i in range(M-1,-1,-1):
    ans[i] = cur
    if(uf.root(A[i]) != uf.root(B[i])):
        cur -= uf.size(A[i])*uf.size(B[i])
        uf.union(A[i],B[i])
for n in ans:
    print(n)

Measured memory_bytes: 104024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> m[i];
        sum += m[i];
    }
    sort(m.begin(),m.end());
    cout << n + (x-sum)/m[0] << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();


		if(Math.max(a, b) <= c) {
				System.out.println(c*10+a+b);
			}else {
				if(Math.max(a, c)<=b) {
					System.out.println(b*10+a+c);
				}else {
					System.out.println(a*10+b+c);
				}
			}




		sc.close();
	}

}


Measured memory_bytes: 22228
n,k = map(int, input().split())
s = input()
list_s = [s[i] for i in range (len(s))]

if n==1:
  print(0)
else:#変わり目数を求める
  kaw = 0
  for i in range(n-1):
    if list_s[i+1]!=list_s[i]:
      kaw += 1
  ans = n-1-kaw+2*k
  print(min(ans,n-1))
  

Measured memory_bytes: 4084
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=998244353;
const int N=3e5+4;
int tree[N],n,k,r[11],l[11];
void add(int x,int val)
{
	while(x<=n)
	{
		tree[x]+=val;tree[x]%=mod;
		tree[x]+=mod;tree[x]%=mod;
		x+=(x&-x);
	}
}
int sum(int x)
{
	int ans=0;
	while(x>=1)
	{
		ans+=tree[x];
		ans%=mod;ans+=mod;ans%=mod;
		x-=(x&-x);
	}
	return ans;
}

int32_t main()
{
	n=in();k=in();
	for(int i=1;i<=k;i++)
	l[i]=in(),r[i]=in();
	add(1,1);add(2,-1);
	for(int i=1;i<=n;i++)
	{
		int val=sum(i);
		if(1)
		{
			for(int j=1;j<=k;j++)
			{add(i+l[j],val);
			add(i+r[j]+1,-val);}
		}
	}
	cout<<sum(n)%mod;
}


Measured memory_bytes: 5216
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0xff,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n,q;
vector<int> v[200005];
bool b[200005];
ll c[200005];
ll a[200005];
void dfs(int n){
	b[n]=1;
	c[n]+=a[n];
	for(int i=0;i<v[n].size();i++){
		if(!b[v[n][i]]){
			c[v[n][i]]+=c[n];
			dfs(v[n][i]);
		}
	}
}
int main(){
	cin>>n>>q;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	rep(i,q){
		int x,y;
		cin>>x>>y;
		a[x]+=y;
	}
	dfs(1);
	for(int i=1;i<=n;i++){
		cout<<c[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 25856
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,r; cin >> n >> r;
  if(n>=10)cout  << r << endl;
  else{
    cout << r + 100 * (10-n) << endl;
  }
  return 0;
}

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

int main(){
    while(1){
        int n, x, y, h, w;
        long p=0;

        cin >> n;
        if(n==0) break;

        for(int i=0; i<n; ++i){
            scanf(" %d %d %d %d", &x, &y, &h, &w);

            int s = x+y+h;

            if(s<=60 && w<=2) p+=600;
            else if(s<=80 && w<=5) p+=800;
            else if(s<=100 && w<=10) p+=1000;
            else if(s<=120 && w<=15) p+=1200;
            else if(s<=140 && w<=20) p+=1400;
            else if(s<=160 && w<=25) p+=1600;
            else ;
        }

        printf("%ld\n", p);
    }

    return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define maxP 100005
#define FOR(a,b,c) for(a=b;a<c;a++)
#define REMOVE_REDUNDANT
#define EPS 1e-9
#define PI acos(-1.0)
typedef struct {
    double x, y;
} Point;
Point P[maxP], CH[maxP],pivot;
int cmp(const void *i, const void *j) {
    Point *a, *b;
    a = (Point *)i, b = (Point *)j;
    if(a->y != b->y)
        return a->y - b->y > 0 ? 1 : -1;
    return a->x - b->x > 0 ? 1 : -1;
}
bool myComparison(const Point &a,const Point &b)
{
	if(a.y!=b.y)
       return a.y<b.y;
    else return a.x<b.x;
}
double cross(Point *o, Point *a, Point *b) {  		// cross product
    return (a->x - o->x)*(b->y - o->y) -
        (a->y - o->y)*(b->x - o->x);
}

double dist(Point p1, Point p2) {                // Euclidean distance
  return hypot(p1.x - p2.x, p1.y - p2.y); }           // return double

bool angleCmp(Point &a, Point &b) {                 // angle-sorting function
  if (fabs(cross(&pivot, &a, &b)) < EPS)                               // special case
    return dist(pivot, a) < dist(pivot, b);    // check which one is closer
  double d1x = a.x - pivot.x, d1y = a.y - pivot.y;
  double d2x = b.x - pivot.x, d2y = b.y - pivot.y;
  return (atan2(d1y, d1x) - atan2(d2y, d2x)) < 0; }   // compare two angles

void convexHull(int n) {
    int P0 = 0;
  for (int i = 1; i < n; i++)
  if (P[i].y < P[P0].y || (P[i].y == P[P0].y && P[i].x < P[P0].x)) //Diurutkan dari y terkecil, jika y sama maka diutamakan x yang paling kecil.
      {P0 = i;}
  Point temp; 
  temp = P[0]; 
  P[0] = P[P0]; 
  P[P0] = temp;  //swap pivot
  pivot=P[0];
  sort(P+1,P+n,angleCmp); // sort berdasarkan angle
  int i, m = 0, t;
    for(i = 0; i < n; i++) {
        while(m >= 2 && ((cross(&CH[m-2], &CH[m-1], &P[i]) < 0) || !(dist(CH[m-1],P[i])>0)))  // mengecek apakah belok ke kanan atau ke kiri. jika collinear tidak dimasukkan, ditambahkan = . Hati-hati dengan redundant karena tanpa =  akan menambahkan redundant
        		m--;
        CH[m++] = P[i];
    }
    for(i = n-2, t = m+1; i >= 0; i--) {		
        while(m >= t && ((cross(&CH[m-2], &CH[m-1], &P[i]) < 0) || !(dist(CH[m-1],P[i])>0))) //mengikuti aturan diatas. jika ingin memasukkan collinear, n-1 diubah menjadi n-2 (otomatis redundant masuk, sedang diperbaiki)
            m--;
        CH[m++] = P[i];
    }
    printf("%d\n",m-1);
    for(i = 0; i < m-1; i++) {
       
        printf("%.lf %.lf\n", CH[i].x, CH[i].y);
    }
}int main()
{	
	int t,tc,i,n;
	double x,y;
	int k;
	Point contoh;
	char dummy[5];
	tc=1;
	FOR(t,0,tc)
	{
		scanf("%d",&n);
		k=0;
		FOR(i,0,n)
		{
			scanf("%lf %lf",&contoh.x,&contoh.y);
			
				P[k]=contoh;
				k+=1;
			
		}
		convexHull(k);
	}
}

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

int main(void) {
  int a, b;
  cin >> a >> b;

  int c = b - a; 
  int d = 0; 

  for (int i = 1; i < c; i++) {
    d += i;
  }
  int ans = (d + c) - b;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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




int main(){
    int n; std::cin >> n;
    std::unordered_map<std::string, int> mp;
    {
        std::string s;
        for(int i(0); i < n; ++i){
            std::cin >> s;
            std::sort(s.begin(), s.end());
            ++mp[s];
        }
    }
    long long ans(0);
    for(auto itr(mp.begin()); itr != mp.end(); ++itr){
        long long cnt(itr->second);
        ans += cnt * (cnt-1) / 2;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 10660
open Num;;
Scanf.scanf "%d %d" (fun n m ->
    let a = Array.init m (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let v = [| 0; 2; 5; 5; 4; 5; 6; 3; 7; 6 |] in
    let dp = Array.make (n + 1) (Int (-1))  in
    dp.(0) <- Int 0;
    Array.sort (fun a b -> compare b a) a;
    Array.iter (fun d ->
        let c = v.(d) in
        for j = 0 to n - c do
            if dp.(j) <> Int (-1) then (
                let q = dp.(j) */ Int 10 +/ Int d in
                dp.(j + c) <- max_num dp.(j + c) q
            )
        done
    ) a;
    print_endline @@ string_of_num dp.(n)
)

Measured memory_bytes: 23168
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f >= 65:
        print("B")
    elif m+f >= 50:
        print("C")
    elif m+f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")



Measured memory_bytes: 5596
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll s;
    cin >> s;
    ll a = (s + (ll)1e9 - 1LL) / (ll)1e9;
    ll b = a * (ll)1e9 - s;
    cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << b << " " << a << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<string> S(N);
  vl A(4, 0);
  REP(i, N) cin >> S[i];
  REP(i, N) {
    if (S[i] == "AC")
      A[0]++;
    if (S[i] == "WA")
      A[1]++;
    if (S[i] == "TLE")
      A[2]++;
    if (S[i] == "RE")
      A[3]++;
  }
  REP(i, 4) {
    if (i == 0)
      cout << "AC x " << A[0] << endl;
    if (i == 1)
      cout << "WA x " << A[1] << endl;
    if (i == 2)
      cout << "TLE x " << A[2] << endl;
    if (i == 3)
      cout << "RE x " << A[3] << endl;
  }

  return 0;
}


Measured memory_bytes: 6364
#include<bits/stdc++.h>
#define faster_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mem(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 7, M = 1e5 + 7, mod = 1e9 + 7, inf = 1e18 + 7;
ll tc, n, m, q, a, b, c, d, i, j, k, l, sum, cnt;
ll ar[N];
string s;
vector < ll > vec;

int main()
{
    cin >> n;
    ll mx = inf;
    for(i = 1; i <= n; i++)
    {
        cin >> a;
        if(a <= mx)
            cnt++;
        mx = min(mx, a);
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import sys
#import cython
 
def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    #N: cython.longlong = 0
    n = int(read())
    a = list(map(int,read().split()))
    ans = 1
    flag = True
    iszero = any(num == 0 for num in a)
    if iszero: print(0)
    else:
        for num in a:
          ans *= num
          if ans > 10**18:
            flag = False
            break
        print(ans if flag else -1)
 
if __name__ == "__main__":
    main()

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

int main() {
    string s;
    int count = 0;
    cin >> s;

    for(int i = 0; i < 3; i++) {

        if (s.at(i) == '1') {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H,W,D;
pair<int,int>m[1111111];
int ABS(int a){return a>0?a:-a;}
int dist(pair<int,int>&a, pair<int,int>&b){
    return ABS(a.first-b.first)+ABS(a.second-b.second);
}
int ans[1111111];
int Q;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>H>>W>>D;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int x;
            cin>>x;
            m[--x]={i,j};
        }
    }
    for(int i=0;i<H*W;i++){
        ans[i+D] += dist(m[i],m[i+D])+ans[i];
    }
    cin>>Q;
    while(Q--){
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout<<ans[y]-ans[x]<<'\n';;
    }
    return 0;
}


Measured memory_bytes: 3584
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

nums = list(permutations(range(1,n+1), n))
a = 0
b = 0
c = 0
for i in nums:
  c += 1
  if i == p:
    a = c
  if i == q:
    b = c
print(abs(a-b))

Measured memory_bytes: 8052
#include<stdio.h>
int main(){
    int a, b, c;
    int count = 0;
    int i;
    scanf("%d %d %d", &a, &b, &c);
    for(i=a; i<=b; i++){
        if(c%i == 0){
            count += 1;
        }
    }
    printf("%d\n",count);
    return 0;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  //ll a;cin>>a;
  //ll a,b;cin>>a>>b;
  //ll a,b,c;cin>>a>>b>>c;
  //ll a,b,c,d;cin>>a>>b>>c>>d;
  //string s;cin>>s;
  //cout<<<<endl;
  ll a,b;char c;cin>>a>>c>>b;
  if(c=='+')cout<<a+b<<endl;
  else cout<<a-b<<endl;
  return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted
/****************************/
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
 
const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;
 
#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
	string s;cin >> s;
	vector<string> t;
	int i = 0;
	int n = s.size();
	int k = n;
	string c = ""; c += s[0];
	t.pb(c);
	i = 1;
	while(i < n){
		string c = "";
		c += s[i];
		if(c == t.back()){
			
			string q = ""; 
			if(i == n-1){k--; break;}
			q+= s[i]; q += s[i+1];
			t.pb(q);
			k--;
			i+=2;
		}else{
			string q = "";q+=s[i];
			t.pb(q);
			i++;
		}
	}
	cout << k << endl;
	return 0;
}

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


int main() {
	int a, b;
	cin >> a >> b;
	int diff = b - a;
	int towerb = 0;

	for(int i = 1;; i++) {
		towerb += i;
		if (i == diff)
			break;
	}
	cout << towerb - b << endl;
	return 0;
}

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  cout << max(a1, max(a2, a3)) - min(a1, min(a2, a3)) << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, m = map(int, input().split())
    ks = []
    for i in range(m):
        tks = [int(j) for j in input().split()]
        ks.append(tks[1:])
    ps = [int(i) for i in input().split()]
    ans = 0
    for i in range(2 ** n):
        t = []
        idx = 1
        while i > 0:
            if i & 1 == 1:
                t.append(idx)
            idx += 1
            i >>= 1
        for j in range(m):
            cnt = 0
            for k in ks[j]:
                if k in t:
                    cnt += 1
            if cnt % 2 != ps[j]:
                break
        else:
            ans += 1
    print(ans)

if __name__=="__main__":
    solve()


Measured memory_bytes: 42736
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 4e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

vector <vector <int>> g;
vector <int> p, h;
void dfs(int v)
{
    for (auto &to : g[v])
    {
        h[to] = h[v] + 1;
        dfs(to);
    }
}

signed main()
{
    Start();
    int n, k;
    cin >> n >> k;
    g.resize(n);
    p.resize(n);
    h.resize(n);
    cin >> p;
    for (auto &i : p)
        --i;
    int ans = 0;
    if (p[0] != 0)
        p[0] = 0, ++ans;
    for (int i = 1; i < n; ++i)
        g[p[i]].pb(i);
    dfs(0);
    set <pii> st;
    for (int i = 0; i < n; ++i)
        st.emplace(-h[i], i);
    function<void(int)> ers = [&] (int v)
    {
        st.erase(mp(-h[v], v));
        for (auto &to : g[v])
        {
            if (st.count(mp(-h[to], to)))
                ers(to);
        }
    };
    while (true)
    {
        if (st.empty())
            break;
        int dpth = st.begin()->first * -1;
        if (dpth <= k)
            break;
        int v = st.begin()->second;
        for (int i = 0; i < k - 1 && p[v] != 0; ++i, v = p[v]);
        ++ans;
        ers(v);
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 22912
# include <iostream>
using namespace std; 
int main(){
  long long int n,i,sum;
  cin>>n;
  sum=0;
  for(i=1;i<=n; i++){
    if(i%5==0 || i%3==0){
      
    }
    else{
      sum=sum+i;
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3648
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {

	while (1) {
		int N, M, r, q;
		int t, n, m, s;
		int ts, te;

		cin >> N >> M;
		if (N == 0) {
			break;
		}
		vector <vector <int> > dp(M + 1, vector<int>(723, 0));

		cin >> r;
		FOR(i, 1, r) {
			cin >> t >> n >> m >> s;
			if (s == 0) {
				dp[m][t - 538]--;
			}
			else {
				dp[m][t - 539]++;
			}
		}
		FOR(i, 1, M) {
			FOR(j, 1, 722) {
				dp[i][j] += dp[i][j - 1];
			}
		}
		cin >> q;
		FOR(i, 1, q) {
			int total = 0;
			int first = -1, end = -1;
			cin >> ts >> te >> m;
			FOR(j, ts - 539, te - 539) {
				if (first == -1 && dp[m][j] >= 1) {
					first = j;
				}
				if (first != -1 && dp[m][j] <= 0) {

					end = j;
					//cout << "a" << first + 539 << " " << end + 539 << endl;
					total += end - first - 1;
					first = -1;
					end = -1;
				}
				if (j == te - 539 && first != -1) {
					//cout << "b" << first + 539 << " " << j + 539 << endl;
					total += j - first;
				}
			}
			cout << total << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 30592
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    int n;
    cin >> n;
    int a = 0, out = 0;
    int base[4] = {0};
    string s;
    while (cin >> s) {
        if (s == "HIT") {
            for (int i = 2; i >= 0; i--) {
                if (base[i]) base[i+1] = 1, base[i] = 0;
            }
            base[0] = 1;
            if (base[3]) {
                a++;
                base[3] = 0;
            }
        }else if (s == "HOMERUN") {
            REP(i,3) a += base[i];
            a++;
            REP(i,3) base[i] = 0;
        }else {
            out++;
        }
        if (out == 3) {
            cout << a << endl;
            out = 0;
            a = 0;
            REP(i,4) base[i] = 0;
        }
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0;i<n;i++){
        int l,r;
        cin >> l >> r;
        ans += (r-l+1);
    }
    cout << ans << endl;
}


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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;
	int result;
	while( true )
	{
		n = in();
		if( n == 0 )break;
		
		result = 0;
		for(int i = 0; i < n / 4; i++)
		{
			result += in();
		}
		printf("%d\n", result);
	}
	return (0);
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    cout << 1;
    rep(i, n - 1) cout << 0;
    cout << endl;
    return 0;
  }
  vector<pair<int, int>> p(m);
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    p[i] = make_pair(s, c);
  }
  sort(ALL(p));
  int f = p[0].first;
  int ans[n] = {};
  ans[0] = -1;
  ans[f - 1] = p[0].second;
  repi(i, 1, m) {
    if (f == p[i].first) {
      if (ans[f - 1] != p[i].second) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      f = p[i].first;
      ans[f - 1] = p[i].second;
    }
  }
  if (ans[0] == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    cout << -1 << endl;
    return 0;
  }
  if (ans[0] == -1) ans[0] = 1;
  rep(i, n) cout << ans[i];
  cout << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    n %= 10;
    if(n == 3)cout << "bon" << endl;
    else if(n==0||n==1||n==6||n==8)cout << "pon" << endl;
    else cout << "hon" << endl;
    
}

Measured memory_bytes: 3584
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    PriorityQueue p=new PriorityQueue<>(n,Collections.reverseOrder());
    for(int i=0;i<n;i++){
      p.add(a[i]);
    }
    while(m>0){
        int k=(int)p.poll();
        k/=2;
        p.add(k);
        m--;
    }

    long ans=0;

    for(int i=0;i<n;i++){
      ans+=(int)p.poll();
    }

    System.out.println(ans);


    sc.close();
  }
}



Measured memory_bytes: 52360
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	cout << max({a + b, a - b, a * b}) << endl;	
}


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


void solve(long long A, long long B, long long C){
    cout << min(C, B/A) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = 1e9;
  for (int i = 0; i <= 1e6; i+=2) {
    ll cost = i * c;
    cost += (i / 2 < x ? (x - i / 2) * a : 0);
    cost += (i / 2 < y ? (y - i / 2) * b : 0);
    ans = min(cost, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

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

    string s; cin>>s;
    int N=s.size();
    int ans=0;
    for(int i=0;i<N;){
        int x=0,y=0;
        while(i<N and s[i]=='<') i++,x++;
        while(i<N and s[i]=='>') i++,y++;
        // cout<<x<<' '<<y<<endl;
        int mn=min(x,y),mx=max(x,y);
        ans+=mn*(mn-1)/2+mx*(mx+1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1172
// Ivan Carvalho
// Problem E - Educational Dynamic Programming Contest - AtCoder
// Link : https://atcoder.jp/contests/dp
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = sum(A) 
for i in range(N):
    if A[i] <= B[i]:
        B[i] -= A[i]
        A[i] = 0
        if A[i+1] <= B[i]:
            A[i+1] = 0
        else:
            A[i+1] -= B[i]
    else:
        A[i] -= B[i]
Y = sum(A)
print(X-Y)

Measured memory_bytes: 19156