akhauriyash/Code-Regression huggingface dataset:
/*  ex5_3
    hangan2020 */
 
#include <stdio.h>
#define IS 101
 
int main(void){
    int H, W;
    int i, j;
    char row[IS][IS];
 
 
    scanf("%d %d", &H, &W);
    //Input by loop
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            scanf(" %c", &row[i][j]);
        }
    }
 
    // Scanning for '.' only rows
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            if(row[i][j] != '.'){
                break;
            }
            else if((j == W -1)&&(row[i][j] == '.')){
                row[i][W] = 'n';// print none(n)
            }
        }
    }
    // Scanning for '.' only columns
    for (j = 0; j < W ; j++){
        for(i = 0; i < H ; i++){
            if(row[i][j] != '.'){
                break;
            }
            else if((i == H-1)&&(row[i][j] == '.')){
                row[H][j] = 'n';// print none(n)
            }
        }
    }
 
    /*for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            printf("%c", row[i][j]);
        }
        printf("\n");
    }*/
 
    //Printing out by loop ( except for rows or columns that starts with 'n')
    for (i = 0; i < H ; i++){
        if(row[i][W] != 'n'){
            for(j = 0; j < W ; j++){
                if(row[H][j] != 'n'){
                    printf("%c", row[i][j]);
                }
            }
        printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
import math
A,B,H,M = map(int, input().split())

h_rad = 360.0 / 60.0 / 12.0
m_rad = 360.0 / 60.0

h_theta = h_rad * ((H%12)*60 + M)
m_theta = m_rad * M

sa_theta = abs(h_theta-m_theta)

a = math.sqrt(A*A + B*B - 2*A*B*math.cos(math.radians(sa_theta)))
print(a)

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

int MAX = 100005;

int main() {
  int N, K; cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  
  vector<int> dp(N, 0);
  dp[0] = 0;
  
  for (int i = 1; i < N; i++) {
    int cur = dp[i-1] + abs(H[i]-H[i-1]);
    for (int j = 1; j <= K; j++) {
      if (i-j >= 0) {
        cur = min(dp[i-j] + abs(H[i]-H[i-j]), cur);
      }
    }
    dp[i] = cur;
  }
  
  cout << dp[N-1] << endl;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;

    int d = 1;
    vector<int> nums(n);
    vector<pair<double, double>> pos(n);
    rep(i, n){
        d *= (i+1);
        nums[i] = i;
        cin >> pos[i].first >> pos[i].second;
    }


    double ans = 0;
    do{
        double mans = 0;
        rep(i, n-1){
            int s = nums[i];
            int g = nums[i+1];
            mans += sqrt(pow((pos[s].first-pos[g].first), 2) + pow((pos[s].second-pos[g].second), 2));
        }
        ans += mans;
    }while(next_permutation(all(nums)));

    printf("%.10f\n", ans/d);;
}

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

vector<int> B;

int main() {
	int N, M, C;
	cin >> N >> M >> C;

	B.resize(M);
	for (int i = 0; i < M; i++)
		cin >> B[i];
	
	int count = 0;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j < M; j++) {
			int tmp;
			cin >> tmp;
			sum += tmp * B[j];
		}
		count += (sum + C > 0);
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#define llint long long
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, m;
string s;
llint a[505], u[505];
llint state[15];
llint ub[1005], lb[1005];
vector<char> comp;
UnionFind uf(1005);

int main(void)
{
	cin >> n >> m;
	cin >> s;
	
	for(int i = 0; i < s.size(); i++){
		if(s[i] >= 'a' && a[i] <= 'j') comp.push_back(s[i]);
	}
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	
	for(int i = 0; i < s.size(); i++){
		if(s[i] >= 'a' & s[i] <= 'j'){
			a[i] = 10 + lower_bound(comp.begin(), comp.end(), s[i]) - comp.begin();
		}
		else a[i] = s[i] - '0';
	}
	
	char var;
	for(int i = 0; i < m; i++){
		cin >> var;
		cin >> u[lower_bound(comp.begin(), comp.end(), var) - comp.begin()];
	}
	
	llint S = 1, ans = 0;
	for(int i = 0; i < m; i++) S *= 3;
	for(int i = 0; i < S; i++){
		llint t = i;
		for(int j = 0; j < m; j++) state[j] = t % 3, t /= 3;
		
		bool flag = true;
		for(int j = 0; j < m; j++){
			if(state[j] == 2 && u[j] < 10) flag = false;
			if(state[j] == 1 && u[j] < 20) flag = false;
		}
		if(!flag) continue;
		
		llint len = 0;
		vector<llint> vec[15];
		for(int j = 0; j < n; j++){
			if(a[j] <= 9) ub[len] = lb[len] = a[j], len++;
			else{
				llint c = a[j]-10;
				vec[c].push_back(len);
				if(state[c] == 0){
					lb[len] = 0, ub[len] = min(u[c], 9LL);
					len++;
				}
				if(state[c] == 1){
					lb[len] = 1, ub[len] = (u[c]-10)/10, len++;
					lb[len] = 0, ub[len] = 9, len++;
				}
				if(state[c] == 2){
					lb[len] = ub[len] = u[c]/10, len++;
					lb[len] = 0, ub[len] = u[c]%10, len++;
				}
			}
		}
		
		uf.init();
		for(int j = 0; j < len; j++) uf.unite(j, len-j-1);
		for(int j = 0; j < m; j++){
			for(int k = 0; k < (int)vec[j].size()-1; k++){
				uf.unite(vec[j][k], vec[j][k+1]);
				if(state[j] >= 1) uf.unite(vec[j][k]+1, vec[j][k+1]+1);
			}
		}
		
		map<llint, P> mp;
		for(int j = 0; j < len; j++){
			int r = uf.root(j);
			if(!mp.count(r)) mp[r] = make_pair(lb[j], ub[j]);
			else{
				mp[r].first = max(mp[r].first, lb[j]);
				mp[r].second = min(mp[r].second, ub[j]);
			}
		}
		
		llint tmp = 1;
		for(auto it = mp.begin(); it != mp.end(); it++){
			if(it->second.first > it->second.second) tmp *= 0;
			else tmp *= it->second.second - it->second.first + 1;
			tmp %= mod;
		}
		ans += tmp, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> g(n);
  struct Edge { int u, v; };
  V<Edge> es(m);
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    es[i] = {u, v};
  }
  if (m & 1) return cout << -1 << '\n', 0;
  UnionFind uf(n);
  set< pair<int, int> > se;
  V<> d(n);
  for (const auto& e : es) {
    if (uf.same(e.u, e.v)) continue;
    uf.unite(e.u, e.v);
    se.emplace(e.u, e.v);
    se.emplace(e.v, e.u);
    ++d[e.u], ++d[e.v];
  }
  V<> out(n);
  for (int v = 0; v < n; ++v) for (int w : g[v]) if (v < w) {
    if (se.count({v, w})) continue;
    cout << v + 1 << ' ' << w + 1 << '\n';
    ++out[v];
  }
  queue<int> que;
  for (int v = 0; v < n; ++v) if (d[v] == 1) {
    que.push(v);
  }
  V<bool> vis(n);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    vis[v] = true;
    for (int w : g[v]) if (se.count({v, w}) and !vis[w]) {
      if (out[v] & 1) {
        cout << v + 1 << ' ' << w + 1 << '\n';
        ++out[v];
      } else {
        cout << w + 1 << ' ' << v + 1 << '\n';
        ++out[w];
      }
      if (--d[w] == 1) que.push(w);
    }
  }
}

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

int main() {
  int n;
  cin >> n;
  unordered_map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  ll ans = 0;
  for (auto &p : mp) {
    int s = p.second;
    ans += (ll)s*(s-1)/2;
  }

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


Measured memory_bytes: 10660
N, X, M = map(int,input().split())
ans = 0
ls = [X%M] + [-1]*(M+1)
ls_app = [0]*(M+1)

for i in range(N):
    a = ls[i]
    ls_app[a] = i
    ls[i+1] = pow(a,2,M)
    if i+1 < N and ls_app[ls[i+1]] != 0:
        b = ls[i+1]
        L = ls_app[b]
        R = i
        len_roop = R - L + 1
        p = (N - L) // len_roop
        q = (N - L) % len_roop
        break
else:
    for i in range(N):
        ans += ls[i]
    print(ans)   
    exit()
    
sum_roop = 0        
for i in range(L, R+1):
    sum_roop += ls[i]
    
sum_edge = 0
for i in range(L, L+q):
    sum_edge += ls[i] 
    
for i in range(L):
    ans += ls[i]
else:
    ans += sum_roop * p + sum_edge        
    
print(ans) 

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(A * B, C * D);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

ABとCDで大小比較するだけ
*/

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
	int N, i,j;
	scanf("%d", &N);
 
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			if(i * 4 + j * 7 == N){
				printf("Yes\n");
				return 0;
			}
			
			
		}
		
		
	}
	printf("No\n");
	
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

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

LL cash(LL money, LL max, LL min){
      // 株価の端数で現金が余る
      LL mod = money%min;
      LL stock = (money/min);
      return stock*max + mod;
}
int N;
vector<LL> A;
int rec(int money, int stock, int day, int ops){
  if (day >= N) return money;
  // 購入
  if(ops == 1){
    stock += money/A[day];
    money = money%A[day];
  } else if (ops == 2){
    money += stock*A[day]; 
    stock = 0;
   
  }
  money = max(max(money, rec(money, stock, day+1, 0)),
          max(rec(money, stock, day+1, 1),rec(money, stock, day+1, 2)));
  return money;
}
int main() {
  scanf("%d", &N);
  A = vector<LL>(N+1, (LL)0);
  vector<LL> T = vector<LL>(N+1, (LL)0);
  vector<int> max_ind;
  rep(i, N) scanf("%d ", &A[i]);

  T[0] = 1000;
  rep(i,N){
  // kは買う日
    for (int k = 0; k < i+1; k++){
      // jは売る日
      for (int j = k; j < i+1; j++){      
          LL tmp =cash(T[k], A[j], A[k]);
          if(T[i+1] < tmp) T[i+1] = tmp;
      } 
    }

    
  }
  LL maxval = 0;
  rep(i, N+1){
    maxval = max(T[i],maxval);
  }
  cout << maxval <<endl;

  return 0;
}



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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, a;
  cin >> n >> a;
  int res = n * n - a;
  cout << res << endl;
  return 0;
}


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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int min_=inf;
    for(int i=-100;i<=100;i++){
        int b=0;
        rep(j,n){
            b+=pow((i-a[j]),2);
        }
        min_=min(min_,b);
    }
    cout << min_;
}

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

int main() {
  LL n;
  cin>>n;
  map<LL, LL> m;
  REP(i, 0, n) { LL a;
    cin >> a;
    if(m[a]==0)
      ++m[a];
      else
        m[a] = 0;
  }
  LL sum = 0;
  for(auto v:m){
    if(v.second>0)
      ++sum;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int gcd(int a, int b) { return b?gcd(b, a%b):a; }

int main()
{
  int N, X, x, ans=0;
  cin >> N >> X;
  for(int n=0; n<N; ++n)
  {
    cin >> x;
    x = X-x;
    ans = gcd(ans, x);
  }
  cout << abs(ans) << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace abc105_b
{
    class Program
    {
        static void Main(string[] args)
        {
            bool[] dp = new bool[200];
            dp[4] = true; dp[7] = true;
            for (int i = 8; i < 200; i++)
            {
                if (dp[i - 4] || dp[i - 7]) dp[i] = true;
            }
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(dp[n] ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
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; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<pii,int>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
template <class T>
class CumulativeSum{
public:
    vector<T>sum;
    T e;
    
    CumulativeSum(vector<T>v,T e) : sum(v.size()),e(e){
        copy(v.begin(),v.end(),sum.begin());
        T past = 0;
        for(auto && itr : sum){
            itr += past;
            past = itr;
        }
    }
    //[l,r)
    auto query(int l, int r){
        if(r > 0) return (sum[r - 1] - (l == 0 ? 0 : sum[l - 1]));
        else return e;
        
    }
};
signed main(){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    vector<piii>res;
    for(int i = 0; i < s.size(); ++i){
        auto key = s[i];
        bool in = true;
        for(int j = i;j < s.size();++j){
            if(key == s[j])continue;
            else {
                res.push_back(make_pair(pii(i,j),key == '1'));
                in = false;
                i = j-1; break;
            }
        }
        if(in){
            res.push_back(make_pair(pii(i,(int)s.size()),key == '1'));
            break;
        }
    }
    vector<int>cnt(res.size(),0LL);
    vector<int>u(res.size());
    rep(i,res.size()){
        if(i)cnt[i] += cnt[i-1];
        if(!res[i].second)cnt[i] += 1;
        u[i] = res[i].first.second - res[i].first.first;
    }
    auto usum = CumulativeSum<int>(u,0LL);
    int ans = -1;
    rep(i,res.size()){
        int range = (int)(upper_bound(all(cnt),k + cnt[i] - (res[i].second == false) ) - cnt.begin());
        cmax(ans,usum.query(i,range));
    }
    cout << ans << endl;
}




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

using namespace std;

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

    //cout<<s.length()<<endl;

    if(k>=s.length()){
        cout<<s<<endl;
    }else{
        for(int i=0;i<k;i++){
        cout<<s.at(i);
        }
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3600
import itertools
 
N = int(input())
 
evidence_dit = {}
 
for i in range(N):
    A = int(input())
    x_y = []
    if A == 0:
        evidence_dit[i] = []
    for j in range(A):
        x_y.append(list(map(int,input().split())))
        
        evidence_dit[i] = x_y 

attribute = [0,1]
ans = 0
 
for i in itertools.product(attribute,repeat=N):
    flag = False
    
    for j in range(N):
       
        if i[j] == 1:
            for k in evidence_dit[j]:
                
                
                if i[k[0]-1] != k[1]:
                    flag = True
                    break
            if flag:
                break
 
    if flag == False:
        
        ans = max(ans,sum(i))
             
 
print(ans)
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod(1e9 + 7);
ll qmi(ll a,ll k){//快速幂 算a的k次方 
	ll res=1;
	while(k){
		if(k&1/*判断是否为奇数 */) res=(ll)res*a%mod;
		a=(ll)a*a%mod;
		k>>=1/*实际上将K除以2*/;
	}
	return res;
}
ll C(ll n,ll m){//运算C(n,m) n>=m 要用到快速幂 
    ll res=1;
    for(ll i=1,j=n;i<=m;i++,j--){
    	res=(ll)res*j%mod;
    	res=(ll)res*qmi(i,mod-2)%mod;
    }
    return res;
}
ll lucas(ll a, ll b){//lucas给组合数取模 
    if(a<mod&&b<mod) return C(a,b);
    return (ll)C(a%mod,b%mod)*lucas(a/mod, b/mod)%mod;
}
int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<(qmi(2,n)-(lucas(n,a)%mod+lucas(n,b)%mod)%mod-1+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace _0046
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] mountain = new double[50];
            int i = 0;
            while (true)
            {
                string input = Console.ReadLine();
                if (input == null)
                {
                    break;
                }
                mountain[i] = double.Parse(input);
                i++;
            }
            Array.Sort(mountain);
            Array.Reverse(mountain);
            Console.WriteLine(mountain[0] - mountain[i-1]);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9192
main :: IO ()
main = do
  w:a:b:_ <- fmap (\x -> read x :: Int) <$> words <$> getLine
  print $ solve w a b
    where
      solve w a b
        | w + x >= y = 0
        | True = y - x - w
          where
            x = min a b
            y = max a b

Measured memory_bytes: 508
s=input()
n=len(s)
def dfs(i,f):
    if i==n-1:#iがn-1になったら，全数字を区切って+を加えてint型に変換して合計する
        return sum(list(map(int,f.split("+"))))
    return dfs(i+1,f+s[i+1])+dfs(i+1,f+ "+"+s[i+1]) # 文字列で次の数字をそのまま連結するパターンと、+で区切るパターン
# 初期値でsの一文字目を入れておく
print(dfs(0,s[0]))

Measured memory_bytes: 9032
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#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)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

const ll INF = LONG_MAX;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in(argv[1]);
    std::cin.rdbuf(in.rdbuf());
#endif

    int r, d, x2000;
    cin >> r >> d >> x2000;

    int x = x2000;
    rep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



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

using namespace std;
using ll = long long;

int main() {
    string s = "";
    cin >> s;
    for(int i = 0;i < s.size();i++){
        if(s[i] == '?'){
            s[i] = 'D';
        }
    }
    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 3720
# https://atcoder.jp/contests/abc094/tasks/abc094_b
n, m, x = map(int, input().split())

boxes = [0] * (n + 1)
nums = [int(i) for i in input().split()]
for num in nums:
    boxes[num] = 1

left = sum(boxes[:x])
right = sum(boxes[x:])
ans = min(left, right)
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
  std::cin >> x;
  std::vector<int> v(x,0);
  rep(i,x-1){
    std::cin >> z;
    v[z-1]++;
  }
  rep(i,x){
    std::cout << v[i] << '\n';
  }
}


Measured memory_bytes: 4844
# E
import numpy as np

N = int(input())

X = [0]*N
Y = [0]*N

for i in range(N):
    x, y = map(int, input().split())
    X[i] = min(x, y)
    Y[i] = max(x, y)


# CASE1
res1 = (max(Y) - min(Y)) * (max(X) - min(X))

# CASE2
x_arg = np.argsort(X)
max_a = max(X)
min_a = min(X)
min_b = 1000000001
max_b = 0
res2 = max_a - min_a

for i in range(N-1):
    min_b = min(min_b, Y[x_arg[i]])
    max_a = max(max_a, Y[x_arg[i]])
    if min_b <= X[x_arg[i]]:
        break
    else:
        min_a = min(X[x_arg[i+1]], min_b)
        res2 = min(res2, max_a - min_a)
print(min(res1, res2*(max(Y)-min(X))))


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int x,y;cin>>x>>y;

    int ans=0;
    while(x<=y){
        ans++;
        x*=2;
    }
    cout<<ans<<endl;
}


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

int main()
{
    ll N;

    cin >> N;
    N %= 10;

    if (N==2 || N==4 || N==5 || N==7 || N==9) {
        cout << "hon";
    } else if (N==3) {
        cout << "bon";
    } else {
        cout << "pon";
    }
    cout << endl;
}


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

using namespace std;


void inseritonSort(int A[], int n, int g, int* cnt) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j=i-g;
    while(j>=0 && A[j] > v) {
      A[j+g] = A[j];
      j -= g;
      (*cnt)++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int N) {
  int cnt = 0;
  int m = 0;
  int h = 1;
  vector<int> G;
  while (true) {
    m++;
    G.push_back(h);
    h = 3*h + 1;
    if (h > N) break;
  }
  cout << m << endl;
  for (int i = 0; i < m; i++) {
    if (i) {
      cout << " ";
    }
    cout << G[m-i-1];
  }
  cout << endl;

  for (int i = 0; i < m; i++) {
    inseritonSort(A, N, G[m-i-1], &cnt);
  }
  cout << cnt << endl;
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
}

int main() {
  int A[1000000], N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  shellSort(A, N);
  return 0;
}



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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12



int main(void)
{
	//変数の宣言
	int n;
	char s[200010];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	llong int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	//データの読み込み
	scanf("%s",&s);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	len=strlen(s);
	for(i=0;i<len;i++){
//		printf("%d %d\n",s[i],'W');
		if(s[i]=='W'){
//			printf("%d ok\n",i);
			ans=ans+i;
			count++;
		}
	}
	
	ans=ans-count*(count-1)/2;
	
	
//	printf("計算部分終了\n");
	//出力
	printf("%lld",ans);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string S, T;
	cin >> S >> T;
	int ans = LINF;
	N = S.size();
	M = T.size();
	rep(i, N - M + 1) {
		int tmp = 0;
		rep(j, M) {
			if (S[i + j] != T[j])
				tmp++;
		}
		chmin(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

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

int count(vector<char> &cs, int cnt){
    if(cs.size() == 1) return cnt > 1 ? 3 : 1;
    else if(cnt > 1){
        return cs.size() * 2 - 1 + 2 + (int)log10(cnt) + 1 + 1;
    } else {
        return cs.size() * 2 - 1;
    }
}

int main(){
    int N; cin >> N;
    string s; cin >> s;
    vector<int> c_cnt('z'-'a' + 1, 0);
    for(char c : s) if('a' <= c and c <= 'z') c_cnt[c-'a']++;
    map<int, vector<char>> i_cnt;
    rep(i, c_cnt.size()){
        if(c_cnt[i] > 0) i_cnt[c_cnt[i]].push_back(i + 'a');
    }
    int ans  = -1;
    for(auto& p : i_cnt){
        int cnt = p.first;
        vector<char> cs = p.second;
        ans += count(cs, cnt) + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3472
//广度优先搜索，队列实现 
#include <iostream>
#include <queue>

using namespace std;

const int N = 100;

const int NIL = -1;

int n;
bool graph[N+1][N+1] = {false}; //关系矩阵图 
char *color;//标记点的状态 B代表访问结束，W代表未访问

int *d; //点0到点u距离

//广度优先搜索 
void bfs(int u) {
	//初始化距离 
	for (int i = 1;i<=n;i++) {
		if (i == u) {
			d[i] = 0;
		} else {
		    d[i] = -1;
	    }
	}
	queue<int> q;
	color[u] = 'B';
	q.push(u);
	
	while (!q.empty()) {
		u = q.front();q.pop();
		for (int v = 1;v<=n;v++) {
		  if (graph[u][v] && color[v] == 'W') {
			  d[v] = d[u] + 1;
			  color[v] = 'B';
			  q.push(v);
		  }
	   }
	}
}

int main() {
	cin >> n;
	color = new char[n+1]; 
	d = new int[n+1]; 
	//初始化 
	for (int i = 1;i<=n;i++) {
		color[i] = 'W';
	}
	
	for (int i=0;i<n;i++) {
		int x,k;
		cin >> x >> k;
		for (int j = 0;j<k;j++) {
			int y;
			cin >> y;
			graph[x][y] = true; 
		}
	}
	
	bfs(1); //从1点开始搜索 
	
	for (int i = 1;i<=n;i++) {
		cout << i << " " << d[i] << endl;
	}
	delete[] color;
	delete[] d;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ll x, y;
    cin >> x >> y;
    ll ans;
    if(abs(x) <= abs(y)){
        ans = abs(y) - abs(x) + ((x < 0) ? 1 : 0) + ((y < 0) ? 1 : 0);
    }else{
        ans = abs(x) - abs(y) + ((x > 0)? 1 : 0) + ((y > 0) ? 1 : 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 600
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rs(a, b) ((a) >> (b))
#define ls(a, b) ((a) << (b))
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

const int N = 2e5 + 1;
vi G[N];
bool vis[N];
ll lazy[N];

void dfs(int x)
{
    vis[x] = 1;
    for (auto i : G[x]) {
        if (!vis[i]) {
            lazy[i] += lazy[x];
            dfs(i);
        }
    }
}

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    int n, q;
    cin >> n >> q;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adde(G, u, v);
    }

    while (q--) {
        int p, q;
        cin >> p >> q;
        lazy[p] += q;
    }

    dfs(1);

    for (int i = 1; i <= n; i++)
        cout << lazy[i] << " ";
    return 0;
}


Measured memory_bytes: 21376
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	char A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	if (A == F && B == E && C == D) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  ll X, Y; cin >> X >> Y;
  int ans = 0;
  while (X <= Y) {
    X *= 2;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

const int mod = 1e9 + 7;
const int inf = 9e18;
const int N = 4005;

int a[N],b[N],c[N];

void solve(){
    int i,j,n;
    string s;
    cin>>n>>s;
    if(s[0]=='R')
        a[0]=1;
    else if(s[0]=='G')
        b[0]=1;
    else
        c[0]=1;
    for(i=1;i<n;++i){
        a[i]=a[i-1];
        b[i]=b[i-1];
        c[i]=c[i-1];
        if(s[i]=='R')
            a[i]++;
        else if(s[i]=='G')
            b[i]++;
        else
            c[i]++;
    }
    int ans=0;
    for(i=1;i<n;++i){
        for(j=0;j<i;++j){
            if(s[i]!=s[j]){
                char ch='R'+'B'+'G'-s[i]-s[j];
                if(ch=='R'){
                    ans+=a[n-1]-a[i];
                    if(s[i-j+i]=='R'){
                        --ans;
                    }
                }
                else if(ch=='G'){
                    ans+=b[n-1]-b[i];
                    if(s[i-j+i]=='G'){
                        --ans;
                    }
                }
                else{
                    ans+=c[n-1]-c[i];
                    if(s[i-j+i]=='B'){
                        --ans;
                    }
                }
            }
        }
    }
    cout<<ans;
}

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

Measured memory_bytes: 3724
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX = 1261;

int main() {
	int N, M;
	while(cin >> N >> M, N) {
		vector<vector<int>>	log(M+1, vector<int>(MAX, 0));	
		int R;
		cin >> R;
		int t, n, m, s;	
		rep(i, R) {
			cin >> t >> n >> m >> s;	
			log[m][t] += (s == 1) ? 1 : -1;
		}

		REP(i, 1, M+1) {
			REP(j, 540, MAX) {
				log[i][j] += log[i][j-1];
			}
		}

		int Q;
		cin >> Q;
		int ts, te;	
		rep(i, Q) {
			cin >> ts >> te >> m;	
			int ans = 0;	
			for(int i = ts; i < te; ++i) {
				if(log[m][i] > 0) ++ans;	
			}
			cout << ans << endl;
		}
	}
	return 0;
}

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

int main () {
	int N, N_cp;
	int temp = 0;
	cin >> N;
	
	N_cp = N;
	while (N_cp > 0) {
		temp += N_cp % 10;
		N_cp /= 10;
	}
	if ((N % temp) == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
bool prime(int x) { //xが素数かどうかを判定
    bool judge = true;
    if(x == 0 ||x == 1) {judge = false;}
    for (int i = 2; i < x; i++) {
        if (x % i == 0) {judge= false; break;}
    }
    return judge;
}
int main() {
    int X; cin >> X;
    while (prime(X) == false) {
        X++;
    }
    cout << X << endl;
}

Measured memory_bytes: 256
H, W = list(map(int, input().split()))
S = [list(input()) for _ in range(H)]

flag = True
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            # 上下左右
            if (i-1 >= 0 and S[i-1][j] == '#') or (i+1 < H and S[i+1][j] == '#') or (j-1 >= 0 and S[i][j-1] == '#') or (j+1 < W and S[i][j+1] == '#'):
                continue
            else:
                flag = False

if flag:
    print('Yes')
else:
    print('No')

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

int K, R, L;
double P, E, T;

inline bool inner(double t) { return fabs(t-T)<E; }

double calc(double r, double l, int k) {
    const double h = (r+l)/2;
    if(k==0) return inner(h) ? 1 : 0;
    if(inner(l) && inner(r)) return 1;
    else if(!inner(l) && !inner(r) && (l-T)*(r-T)>0) return 0;
    if(h<T) return calc(h, l, k-1)*(1-P)+calc(r, h, k-1)*P;
    else return calc(h, l, k-1)*P+calc(r, h, k-1)*(1-P);
}

int main() {
    scanf("%d%d%d%lf%lf%lf", &K, &R, &L, &P, &E, &T);
    printf("%.9f\n", calc(R, L, K));
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n,m;
	cin >> n >> m;

	vector< vector<pair<ll,ll>>> v(n);

	rep(i,0,m){
		ll p,y;
		cin >> p >> y;
		v[p-1].push_back(make_pair(y,i));
	}

	rep(i,0,n) vsort(v[i]);

	vector<string> sv(m);

	rep(i,0,n){
		string s1;
		s1 = to_string(i+1);
		if( s1.size() < 6 ){
			string tmp = "";
			while( tmp.size() < 6 - s1.size()) tmp +='0';
			s1 = tmp + s1;
		}
		rep(j,0,v[i].size()){
			string s2;
			s2 = to_string(j+1);
			if( s2.size() < 6 ){
				string tmp = "";
				while( tmp.size() < 6 - s2.size()) tmp +='0';
				s2 = tmp + s2;
			}
			sv[v[i][j].sec] = s1+s2;
		}
	}

	rep(i,0,m) cout << sv[i] << endl;

	ret 0;
}

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

typedef long long ll;

const int MAXN = 16;
const int MAXL = (1 << 16) + 10;
const ll NEG = -1e18;

vector<int> grafo[MAXL];
ll valor[MAXL],dp[MAXL],mat[MAXN][MAXN];
int vis[MAXL],N;

void brute(int pos,int bitmask,int submask){

	if(pos == N){
		if(__builtin_popcount(submask) == 0) return;
		grafo[bitmask].push_back(submask);
		return;
	}

	brute(pos+1,bitmask,submask);
	brute(pos+1, bitmask | (1 << pos), submask );
	brute(pos+1, bitmask | (1 << pos), submask | (1 << pos) );

}

void calcula(){

	for(int bitmask = 1;bitmask < (1 << N);bitmask++){
		for(int i = 0;i<N;i++){
			if(!(bitmask & (1 << i))) continue;
			for(int j = i+1;j<N;j++){
				if(!(bitmask & (1 << j))) continue;
				valor[bitmask] += mat[i][j];
			}
		}
	}

}

ll solve(int bitmask){

	if(bitmask == 0) return 0;
	if(vis[bitmask]) return dp[bitmask];

	vis[bitmask] = 1;

	ll best = NEG;

	for(int submask : grafo[bitmask]){
		best = max(best, solve(bitmask ^ submask) + valor[submask] );
	}

	return dp[bitmask] = best;

}

int main(){

	cin >> N;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			cin >> mat[i][j];
		}
	}

	brute(0,0,0);
	calcula();

	cout << solve((1 << N) - 1) << endl;

	return 0;

}

Measured memory_bytes: 178448
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("F:/cpp/input.txt", "r", stdin);
    // freopen("F:/cpp/output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll a[n][3], i, j;
    for (i=0;i<n;i++)
    {
        for (j=0;j<3;j++)
        {
            cin >> a[i][j];
        }
    }
    for (i=n-2;i>=0;i--)
    {
        a[i][0] += max(a[i+1][1], a[i+1][2]);
        a[i][1] += max(a[i+1][2], a[i+1][0]);
        a[i][2] += max(a[i+1][0], a[i+1][1]);
    }
    cout << max(a[0][0], max(a[0][1], a[0][2]));
    return 0;
}

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

int main(){
        ll h, w; scanf("%lld %lld", &h, &w);
        vector<vector<ll>> fig(h+2, vector<ll>(w+2, 0));
        for(ll j=0; j<w+2; j++){
                fig[0][j] = 1;
                fig[h+1][j] = 1;
        }
        for(ll i=0; i<h+2; i++){
                fig[i][0] = 1;
                fig[i][w+1] = 1;
        }
        for(ll i=1; i<h+1; i++){
                string s; cin >> s;
                for(ll j=1; j<w+1; j++) fig[i][j] = (s[j-1]=='#');
        }

        ll ans = 0;
        ll dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
        for(ll i=1; i<=h; i++){
                for(ll j=1; j<=w; j++){
                        vector<vector<ll>> used(fig);
                        vector<vector<ll>> dist(h+2, vector<ll>(w+2, 1e11));

                        queue<PP> que;
                        que.push({{i, j}, 0});
                        while(!que.empty()){
                                PP pp = que.front(); que.pop();
                                ll ti = pp.first.first, tj = pp.first.second, dis = pp.second;
                                if(used[ti][tj]) continue;
                                used[ti][tj] = 1;
                                ans = max(ans, dis);
                                for(ll d=0; d<4; d++){
                                        ll ni = ti + dx[d], nj = tj + dy[d];
                                        if(fig[ni][nj]!='#' and !used[ni][nj]){
                                                que.push({{ni, nj}, dis+1});
                                        }
                                }
                        }

                }
        }
        printf("%lld\n", ans);
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;
bool flag;
unsigned long long a1,a2,a3,m1,m2,m3;
unsigned long long x,y,z,ans,calc,cnt1,cnt2,cnt3;
 
unsigned long long  gcd(unsigned long long a,unsigned long long b){
    unsigned long long result =a;
    unsigned long long k=0;
    unsigned long long n=b;
    do{
        k=result %n;
        result=n;
        n=k;
    }while(k!=0);
    return result;
}
int main(){
  while(scanf("%lld %lld %lld %lld %lld %lld", &a1,&m1,&a2,&m2,&a3,&m3),
	a1||a2||a3||m1||m2||m3){
        x=y=z=1;
        cnt1=cnt2=cnt3=0;
        while(1){
            cnt1++;
            x=(a1%m1)*(x%m1)%m1;
            if(x==1)break;
        }
        while(1){
            cnt2++;
            y=(a2%m2)*(y%m2)%m2;
            if(y==1)break;
        }
        while(1){
            cnt3++;
            z=(a3%m3)*(z%m3)%m3;
            if(z==1)break;
        }
        calc=cnt1/gcd(cnt1,cnt2)*cnt2;
        ans=cnt3/gcd(calc,cnt3)*calc;
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3084