akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
#include <map>
using namespace std;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

#define R ((int)pow(10,9)+7)

int main(){
	int n, m;
	cin >> n >> m;
	string ss;
	cin >> ss;
	vector<int> s;
	for (int i = 0; i < n; ++i) {
		if (isdigit(ss[i])) {
			s.push_back(ss[i] - '0');
		} else {
			s.push_back(ss[i] - 'a' + 10);
		}
	}
	vector<pair<int, int> > u; //id, maxu
	for (int i = 0; i < m; ++i) {
		char var;
		int unum;
		cin >> var >> unum;
		u.push_back(make_pair(var - 'a' + 10, unum));
	}
	map<int, int> to;
	for (int i = 0; i < m; ++i) to[u[i].first] = i;
	int res = 0;
	for (int ii = 0; ii < (int)pow(3, m); ++ii) {
		//cout << "ii: ";
		//for (int i = 0; i < m; ++i) {
		//	cout << ii / pow
		vector<int> cs;
		int flg = 0;
		int min[30], max[30];
		for (int i = 0; i < 30; ++i) {
			min[i] = 0; max[i] = 0;
		}
		for (int j = 0; j < s.size(); ++j) {
			if (s[j]/10 == 0) {
				cs.push_back(s[j]);
			} else {
				int maxu = u[to[s[j]]].second;
				int k = ii / (int)pow(3, to[s[j]]) % 3;
				if (k == 2) { //2-digit M
					if (maxu / 10 == 0) {++flg; break;}
					cs.push_back(s[j] + 10);
					min[s[j] + 10] = max[s[j] + 10] = maxu / 10;
					cs.push_back(s[j]);
					min[s[j]] = 0, max[s[j]] = maxu % 10;
				}else if (k == 1) { //2-digit [1, M)
					if (maxu / 10 <= 1) {++flg; break;}
					cs.push_back(s[j] + 10);
					min[s[j] + 10] = 1, max[s[j] + 10] = maxu / 10 - 1;
					cs.push_back(s[j]);
					min[s[j]] = 0, max[s[j]] = 9;
				} else {
					cs.push_back(s[j]);
					min[s[j]] = 0, max[s[j]] = maxu / 10 ? 9 : maxu % 10;
				}
			}
		}
		//for (int i = 0; i < cs.size(); ++i) {
		//	cout << cs[i];
		//	if (i == cs.size() - 1) cout << endl;
		//	else cout << ", ";
		//}
		if (flg) continue;
		int uni[30];
		for (int i = 10; i < 30; ++i) uni[i] = i;
		int l = cs.size();
		for (int i = 0; i < l / 2; ++i) {
			int a, b;
			a = cs[i];
			b = cs[l-1-i];
			if (a/10 == 0 && b/10 == 0) {
				if (a != b) {
					++flg;
					break;
				}
			} else if (a/10 != 0 && b/10 != 0) {
				while (uni[a] != a) a = uni[a];
				while (uni[b] != b) b = uni[b];
				uni[a] = b;
				max[b] = std::min(max[b], max[a]);
				min[b] = std::max(min[b], min[a]);
			} else {
				if (b/10 == 0 && a/10 != 0) {
					int swap;
					swap = a;
					a = b;
					b = swap;
				}
				while (uni[b] != b) b = uni[b];
				if (min[b] <= a && a <= max[b]) min[b] = max[b] = a;
				else {++flg; break;}
			}
		}
		if (flg) continue;
		int pro = 1;
		for (int i = 10; i < 30; ++i) {
			if (uni[i] != i) continue;
			if (max[i] < min[i]) {++flg; break;}
			pro *= max[i] - min[i] + 1;
			pro %= R;
		}
		if (flg) continue;
		//cout << "pro = " << pro << endl;
		res += pro % R;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1284
//程序名:新的C++程序
//作者: 

#include<iostream>
#include<fstream>
#include<algorithm>

using namespace std;
int main()
{
     int a,b,c;
	 cin>>a>>b>>c;
	 if(b-a==c-b) cout<<"YES";
	 else cout<<"NO";

    return 0;
}

Measured memory_bytes: 384
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;
    (A - B * 2) < 0 ? COUT(0) : COUT(A - B * 2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=3e5+50; 

int n,a[N],xs[N],prv[N];
ll sum[N],ans;

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin); 
#endif
	read(n); 
	rep(i,1,n){
		read(a[i]); 
		sum[i]=a[i]+sum[i-1];
		prv[i]=a[i]?i:prv[i-1];
		xs[i]=xs[i-1]^a[i];
	}
	rep(i,1,n){
		int p=prv[i];
		for(;p&&(sum[i]-sum[p-1])==(xs[i]^xs[p-1]);)p=prv[p-1]; 
		ans+=i-p; 
	}
	printf("%lld\n",ans); 
	return 0;
}


Measured memory_bytes: 4992
/* Author darklight13 -_- 
   IIT Patna 
*/
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey baitch!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;
ld dp[301][301][301];
int n; 
ld solve(int a, int b, int c) {
	if(a < 0 or b < 0 or c < 0)	return 0.0;
	if(a==0 && b == 0 && c==0)	return 0.0;
	if(dp[a][b][c] != -1)	return dp[a][b][c];
	ld res = 0.0;
	res += (ld)n/(ld)(a+b+c);
	if(a > 0) {
		res += (ld)((ld)a/(a+b+c))*(solve(a-1,b,c));
	}
	if(b > 0) {
		res += (ld)((ld)b/(a+b+c))*solve(a+1,b-1,c);
	}
	if(c > 0) {
		res += (ld)((ld)c/(a+b+c))*solve(a,b+1,c-1);
	}
	dp[a][b][c] = res;
	return dp[a][b][c];
}
int32_t main()
{
	SYNC
	rep(i,0,301){
		rep(j,0,301) {
			rep(k,0,301)	dp[i][j][k] = -1;
		}
	}
	cin >> n;
	vi cnt(3,0);
	rep(i,0,n) {
		int x; cin >> x;
		cnt[x-1]++;
	}
	cout << fixed << setprecision(12) << solve(cnt[0],cnt[1],cnt[2]);
    return 0;
}

Measured memory_bytes: 426496
#include <stdio.h>

int main() {
	int n, i, j, k, l, p[101], m[101][101];
	
	scanf("%d", &n);
	for ( i = 1; i <= n; i++) {
		scanf("%d", &p[i - 1]);
		scanf("%d", &p[i]);
	}
	
	for ( i = 1; i <= n; i++) {
		m[i][i] = 0;
	}
	for ( l = 2; l <= n; l++) {
		for ( i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = ( 1 << 21);
			for ( k = i; k <= j - 1; k++) {
				if ( m[i][j] < m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]) {
					m[i][j] = m[i][j];
				} else {
					m[i][j] = m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j];
				}
			}
		}
	}
	
	printf("%d\n", m[1][n]);
	
	return 0;
}

Measured memory_bytes: 2736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
int main(){
  int i;
  int N,M;
  int c=0;
  cin >> N >> M;
  if(M <= N){
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> X(M);
  for(i=0;i<M;i++) cin >> X[i];
  sort(X.begin(),X.end());
  
  vector<int> d(M-1);
  for(i=0;i<M-1;i++){
    d[i] = X[i+1] - X[i];
  }
  sort(d.begin(),d.end());
  
  for(i=0;i<M-N;i++){
    c += d[i];
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 1024
S=input()
T=input()
check=[]
for i in range(len(S)-len(T)+1):
    check.append(0)
    for j,tt in enumerate(T):
        if tt==S[i+j]:
            check[i]+=1
# print(check)
check.append(0)
# print(check)
print(len(T)-max(check))

Measured memory_bytes: 9120
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int a,b,n,s;
	while(~scanf("%d%d%d",&a,&b,&n)){
		s=0;
		a=a%b;
		rep(i,n){
			a*=10;
			s+=a/b;
			a=a%b;
		}
		printf("%d\n",s);
	}
	return 0;
}

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

# 縦の累積ホワイトチョコ数
whites_col = [[0 for _ in range(W)] for _ in range(H)]
for w in range(W):
    for h in range(H):
        if h == 0:
            whites_col[h][w] = S[h][w]
        else:
            whites_col[h][w] = whites_col[h-1][w] + S[h][w]

"""
マス目で考えると、縦Hマスある場合はH+1本の横線がある。
その横線の番号を渡して、その間にある数をとってくる
"""
def calc(w, a,b):
    if a == 0:
        return whites_col[b-1][w]
    else:
        return whites_col[b-1][w] - whites_col[a-1][w]

ans = (H-1)*(W-1)
for bit in  range(1 << (H-1)):
    
    cnt_split = bin(bit).count("1")

    divs = [0]
    for i in range(H-1):
        if bit & (1 << i):
            divs.append(i+1)
    divs.append(H)

    curr = [0] * (len(divs)-1)
    prev = [0] * (len(divs)-1)
    over_K_in_curr = False
    for w in range(W):
        for i,(a,b) in enumerate(zip(divs, divs[1:])):
            curr[i] = calc(w, a, b)

        over_K_in_curr = False
        if max(curr) > K:
            over_K_in_curr = True
            break
        
        for i in range(len(divs)-1):
            prev[i] += curr[i]

        if max(prev) > K:
            cnt_split += 1
            prev = curr[:]

    if not over_K_in_curr:
        ans = min(ans, cnt_split)

print(ans)
            

        
        

Measured memory_bytes: 45660
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

void dijkstra(int n) {
	priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>que;
	fill(dij.begin(), dij.end(), INF);
	dij[n] = 0;
	que.push(pair<long long, long long>(0, n));

	while (!que.empty()) {
		pair<long long, long long>p = que.top();
		que.pop();
		long long mon = p.second;
		if (dij[mon] < p.first) continue;
		for (int i = 0; i < G[mon].size(); ++i) {
			edge e = G[mon][i];
			if (dij[e.to] > dij[mon] + e.cost) {
				dij[e.to] = dij[mon] + e.cost;
				que.push(pair<long long, long long>(dij[e.to], e.to));
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	dij.resize(n + 1);
	G.resize(n + 1);
	for (int i = 0; i < n - 1; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
	}

	int a, b;
	cin >> a >> b;
	dijkstra(b);

	for (int i = 0; i < a; ++i) {
		int aa, bb;
		cin >> aa >> bb;
		cout << dij[aa] + dij[bb] << endl;
	}
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
//#include<iostream>
using namespace std;
#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int k;
int a[100010];



signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>k;
    rep(i,0,k){
        cin>>a[i];
    }
    int maxcnt=2;
    int mincnt=2;
    //cout<<mincnt<<" "<<maxcnt<<endl;
    rrep(i,0,k){
         if(1){
            if(mincnt%a[i]!=0 && (mincnt+(a[i]-(mincnt%a[i])))>maxcnt){
                cout<<"-1"<<endl;
                return 0;
            }
        }
        mincnt=((mincnt+a[i]-1)/a[i])*a[i];
        maxcnt=(maxcnt/a[i]+1)*a[i]-1;
        //cout<<mincnt<<" "<<maxcnt<<endl;
    }
    cout<<mincnt<<" "<<maxcnt<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 1024
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;

int main()
{
    int n, m;
    int l, r;
    int judge[100005] ;
    
    cin >> n >> m;
    for (int i = 0; i <= n; i++) {
        judge[i] = 1;
    }

    for (int i = 0; i < m; i++) {
        cin >> l >> r;

        l = l - 1;
        while (judge[l]&& 0<l) {
            judge[l] = 0;
            l--;
        }
        r = r + 1;

        while (judge[r] && r <= n) {
            judge[r] = 0;
            r++;
        }


    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (judge[i] == 1)cnt++;
    }
    cout << cnt << endl;

    
}



Measured memory_bytes: 3920
N = int(input())
S = list(input())
s_r = []
s_g = []
s_b = []

for i in range(len(S)):
    if S[i] == 'R':
        s_r.append(i)
    elif S[i] == 'G':
        s_g.append(i)
    elif S[i] == 'B':
        s_b.append(i)

N = len(s_r)*len(s_g)*len(s_b)

s_b = set(s_b)
for i in range(len(s_r)):
    for j in range(len(s_g)):
        M = max(s_r[i],s_g[j])
        m = min(s_r[i],s_g[j])
        if M+(M-m) in s_b:
            N -= 1

        if (M-m) %2 == 0:
            if m + (M-m)//2 in s_b:
                N -= 1

        if m-(M-m) in s_b:
            N -= 1

print(N)



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

int main()
{
  int n;
  cin>>n;
  int sum =0 ;
  for (int i = 0; i < n; i++){
    int a,b;
    cin >> a >> b;
    sum += b -a + 1;
  }
  cout << sum <<endl;
}

Measured memory_bytes: 256
use std::io::*;
const MOD: i64 = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let x: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let y: Vec<i64> = (0..m)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut sx = x.iter().sum::<i64>();
    let mut sy = y.iter().sum::<i64>();
    let mut allx = 0i64;
    let mut ally = 0i64;
    for i in 0..n {
        sx -= x[i];
        allx += sx - x[i] * (n - 1 - i) as i64;
        allx %= MOD;
    }
    for i in 0..m {
        sy -= y[i];
        ally += sy - y[i] * (m - 1 - i) as i64;
        ally %= MOD;
    }
    println!("{}", allx * ally % MOD);
}


Measured memory_bytes: 5708
h, w = map(int, input().split())
a = [input() for _ in range(h)]
dp = [[0] * w for _ in range(h)]
 
for i in range(h):
    if a[i][0] == ".":
        dp[i][0] = 1
    else:
        break
 
for i in range(w):
    if a[0][i] == ".":
        dp[0][i] = 1
    else:
        break
 
for i in range(1, h):
    for j in range(1, w):
        if a[i][j] == "#":
            dp[i][j] = 0
        else:
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % (10 ** 9 + 7)
 
print(dp[h - 1][w - 1])

Measured memory_bytes: 43604
#include <bits/stdc++.h>
using namespace std;
int main() {
  string weather[3] = {"Sunny", "Cloudy", "Rainy"};
  string s;
  cin >> s;
  int index = -1;
  for(int i = 0; i < 3; i++) {
    if(weather[i] == s) index = i;
  }
  index = (index + 1) % 3;
  printf("%s\n", weather[index].c_str());
  
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
class UnionFind:
    def __init__(self, size):
        self.rank = [0] * size
        self.par = range(size)

    def find(self, x):
        if x == self.par[x]: return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return

        if (self.rank[x] > self.rank[y]):
            self.par[y] = x
        else:
            self.par[x] = y
            if (self.rank[x] == self.rank[y]): self.rank[y] += 1

N, K, L = map(int, raw_input().split())
pq = [map(int, raw_input().split()) for i in xrange(K)]
rs = [map(int, raw_input().split()) for i in xrange(L)]

road = UnionFind(N)
rail = UnionFind(N)
for p, q in pq:
    road.unite(p - 1, q - 1)
for r, s in rs:
    rail.unite(r - 1, s - 1)

for i in xrange(N):
    road.find(i)
    rail.find(i)

pair = defaultdict(int) 
for i, j in zip(road.par, rail.par):
    pair[i, j] += 1

print " ".join(map(str, [pair[road.par[i], rail.par[i]] for i in xrange(N)]))


Measured memory_bytes: 93100
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> flag(N + 1);
    vector<ll> Ai(N + 1);
    vector<ll> table(N + 1);
    REP(x, N + 1)
    {
        table.at(x) = (x * (x - 1)) / 2;
    }

    REP(i, N)
    {
        cin >> Ai.at(i);
        flag.at(Ai.at(i))++;
    }

    ll ans = 0;
    REP(j, N + 1)
    {
        ans += table.at(flag.at(j));
    }

    REP(k, N)
    {
        ll tmp = ans - (flag.at(Ai.at(k)) - 1);
        cout << tmp << "\n";
    }
}

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

using namespace std;

#define sz(v) (int)v.size()
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
struct Tree {
	typedef long long T;
	static constexpr T unit = 0;
	T f(T a, T b) { return max(a, b); } // (any associative fn)
	vector<T> s; int n;
	Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
	void update(int pos, T val) {
		for (s[pos += n] = val; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	T query(int b, int e) { // query [b, e)
		T ra = unit, rb = unit;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) ra = f(ra, s[b++]);
			if (e % 2) rb = f(s[--e], rb);
		}
		return f(ra, rb);
	}
};

int main() {
  // Q looks like an RMQ type DP, but it's funky...
  // like dp[i] = max sum of beauties using flowers 0 through i
  //   and including flower i
  // so then the update is: dp[i] = max over j<i with h[j] < h[i]
  //   of dp[j] right
  // when we calculate dp[i], insert dp[i] at h[i] into
  // our RMQ data structure
  // and then when we want to find the max, we just take RMQ.query
  //   (0, h[i]) and we should be fine
  // I keep forgetting that KACTL's RMQ isn't a mutable RMQ...
  // oof

  cin.tie(0);
  cin.sync_with_stdio(0);
  int n; cin >> n;
  int h[n];
  for(int i = 0; i<n; ++i) cin >> h[i];
  long long a[n];
  for(int i = 0; i<n; ++i) cin >> a[i];
  Tree rmq(n+1);

  long long ret = 0;
  for(int i = 0; i<n; ++i) {
    long long mx = rmq.query(0, h[i]);
    long long dp = mx + a[i];
    ret = max(ret, dp);
    rmq.update(h[i], dp);
  }
  cout << ret << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

ll N, A, B;
vector<ll> h(100005, 0);

bool check(int n){
    if(n == 0) return false;
    ll res = 0;

    for(int i=0; i<N; i++){
        ll tmp = h[i]-B*n;
        if(tmp <= 0) continue;

        res += (tmp-1)/(A-B) + 1;
    }

    if(res <= n) return true;
    else return false;
}

ll solve(){
    ll left = 0, right = 1e9;
    ll mid;

    while(left+1 < right){
        mid = (left + right)/2;
        if(check(mid)) right = mid;
        else left = mid;
    }

    return right;
}

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

    cout << solve() << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, k;

int main(){
	cin >> n >> k;
	
	cout << !(n%k == 0) << endl;
	
	return 0;
}

Measured memory_bytes: 768
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]): Unit = {
    var continue = true
    while (continue) {
      val Array(n, x) = readLine().split(" ").map(_.toInt)
      if (n == 0 && x == 0) {
        continue = false
      } else {
        println(countNoOfWays(n, x))
      }
    }
  }

  def countNoOfWays(n: Int, x: Int): Int = {
    var ans = 0
    for (i <- 1 to n; j <- i+1 to n; k <- j+1 to n) {
      if (i + j + k == x) {
        ans += 1
      }
    }
    ans
  }
}



Measured memory_bytes: 46348
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1];
   long long int sum=0;
     int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
   ans=a[1];
   for(int i=2;i<=n;i++)
   {
       if(ans>a[i])
       {
           sum+=(ans-a[i]);
       }
       else
       {
           ans=max(ans,a[i]);
       }
   }
   cout<<sum<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >>N;
  vector<double> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  vector<double> b(N);
  for(int i=0;i<N;i++){
    b[i] = 1/a[i];
  }
  double answer=0;
  for(int i=0;i<N;i++){
    answer+=b[i];
  }
  cout << fixed << setprecision(5);
  cout << 1/answer;
}

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

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
N = input()
S = input()
K = input()

targetalpha = S[int(K)-1]
S_list = list(S)

for i in range(0,int(N)):
  if(S_list[i] != targetalpha):
    S_list[i] = "*"
  
S = "".join(S_list)
print(S)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 x, n; cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int ans = INF;
    int ab = INF;
    for (int i = -100; i <= 200; i++) {
        bool ok = true;
        rep(j, n) {
            if (i == p[j]) ok = false;
        }

        if (ok) {
            if (abs(x - i) < ab) {
                ans  = i;
                ab = abs(x - i);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ll MAX=LLONG_MAX;
int n;
ll a[100100],cnt;
vector<ll> sum;
bool ok(ll x){
  ll fir=*lower_bound(ALL(sum),x);
  ll sec=*lower_bound(ALL(sum),fir+x);
  ll thi=*lower_bound(ALL(sum),sec+x);
  if(fir<=cnt&&sec<=cnt&&thi<=cnt){
		return true;
	}
  REP(i,n){
      fir=*lower_bound(ALL(sum),sum[i]+x);
			if(fir>sum[i+n])continue;
      sec=*lower_bound(ALL(sum),fir+x);
			if(sec>sum[i+n])continue;
      thi=*lower_bound(ALL(sum),sec+x);
			if(thi>sum[i+n])continue;
			return true;
  }
  return false;
}
int main(){
    scanf("%d",&n);
    REP(i,n){
        scanf("%lld",&a[i]);
        cnt+=a[i];
    }
    sum.resize(n*2);
    REP(i,n*2){
        if(i==0){
            sum[i]=a[i];
        }else{
            sum[i]=sum[i-1]+a[i%n];
        }
    }
    sum.PB(MAX);
    ll lb=0,rb=cnt;
    while(rb-lb>1){
        ll mid=(rb+lb)/2;
        if(ok(mid)){
            lb=mid;
        }else{
            rb=mid;
        }
    }
    printf("%lld\n",lb);
}

Measured memory_bytes: 6476
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
int n,a[N];
int main() {
    ios::sync_with_stdio(false);
    cin>>n;int s=0;
    for(int i=1;i<=n;i++)cin>>a[i],s+=a[i];
    LL x=0;
    for(int i=1;i<=n;i++){
        x+=1ll*a[i]*(s-a[i]);
    }
    cout<<x/2<<endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
  $str = trim(fgets(STDIN));
  $map[$i] = $str."#";
}
$map[$H] = str_repeat("#", $W);
for($i = 0; $i < $H; $i++){
  $h = 0;
  for($j = 0; $j < $W+1; $j++){
    if($map[$i][$j] === "#"){
      for($k = 0; $k < $h; $k++){
        $p[$i][$j - 1 - $k] = $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
for($i = 0; $i < $W; $i++){
  $h = 0;
  for($j = 0; $j < $H+1; $j++){
    if($map[$j][$i] === "#"){
      for($k = 0; $k < $h; $k++){
        $p[$j - 1 - $k][$i] += $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
$max = 0;
for($i = 0; $i < $H; $i++){
  $max = max($max, max($p[$i]));
}
echo $max - 1;

Measured memory_bytes: 154232
#include<stdio.h>

int main(void)
{
   int a, i=1;

   scanf("%d",&a);

   while((a!=1)&&(a!=2)&&(a!=4)){
      if(a%2==0)
         a=a/2;
      else
         a=3*a+1;
      i++;
   }

   printf("%d\n",i+3);
   return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String s = sc.nextLine();
			String p = sc.nextLine();

			String ss = s + s;

			if(ss.contains(p)){
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}



Measured memory_bytes: 26296
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


class Main {
    public static void main(String[] args) {
        int n, wt;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        wt = sc.nextInt();

        List<Long> wts = new ArrayList<>(), vals = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long wx, vx;
            wx = sc.nextLong();
            vx = sc.nextLong();
            wts.add(wx);
            vals.add(vx);
        }

        long[][] dp = new long[wt + 1][n + 1];
        for (int i = 1; i <= wt; i++) {
            for (int j = 1; j <= n; j++) {
                // get item
                long item_wt = wts.get(j - 1);
                long item_val = vals.get(j - 1);

                // case 1: item is not part of the knapsack
                dp[i][j] = dp[i][j - 1];

                // case 2: item is part of the knapsack
                if (item_wt <= i) {
                    dp[i][j] = Math.max(dp[i - (int)item_wt][j - 1] + item_val, dp[i][j]);
                }
            }
        }

//        for(int[] x: dp) {
//            System.out.println(Arrays.toString(x));
//        }

        System.out.println(dp[wt][n]);
    }
}

Measured memory_bytes: 127828
#include <bits/stdc++.h>
#define INF 9999999999999999
typedef long long ll;
using namespace std;
int n, m;
struct edge {
public:
	int to;
	ll cost;
	edge(ll c, int t) {
		to = t;
		cost = c;
	}
};
ll d[100000];
ll a[100000];
bool used[100000];
typedef pair<ll, int> P;
vector<vector<edge> > G;
vector<vector<edge> > G1;

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> >q;
	fill(d, d + n, INF);
	fill(used, used + n, false);
	d[s] = 0;
	q.push(P(0, s));
	while (!q.empty()) {
		P p = q.top();
		q.pop();
		int v = p.second;
		if (used[v]) {
			continue;
		}
		ll dist = p.first;
		used[v] = true;
		d[v] = dist;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (used[e.to]) {
				continue;
			}
			if (d[e.to] > dist + e.cost) {
				q.push(P(d[v] + e.cost, e.to));
			}
		}
	}
}


int main() {
	int from, to;
	int s, t;
	ll cost, cost1;
	cin >> n >> m >> s >> t;
	s--;
	t--;
	G = vector<vector<edge> >(n);
	G1 = vector<vector<edge> >(n);
	for (int i = 0; i < m; i++) {
		cin >> from >> to >> cost >> cost1;
		from--;
		to--;
		G[from].push_back(edge(cost, to));
		G[to].push_back(edge(cost, from));
		G1[to].push_back(edge(cost1, from));
		G1[from].push_back(edge(cost1, to));
	}
	dijkstra(s);
	swap(d, a);
	for (int i = 0; i < n; i++) {
		swap(G[i], G1[i]);
	}
	dijkstra(t);
	ll x[100000];
	for (int i = 0; i < n; i++) {
		x[i] = a[i] + d[i];
	}
	ll ans[100000];
	ans[n - 1] = x[n - 1];

	for (int i = n - 1; 0 < i; i--) {
		ans[i - 1] = min(x[i - 1], ans[i]);
	}
	for (int i = 0; i < n; i++) {
		cout << 1000000000000000 - ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

static const int MMAX = 20;
static const int NMAX = 500000;
static const int INFTY = (1 << 29);

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

    int n, m;
    // C[i]:i番目のコインの値
    // T[i]:i円に必要なコインの最小枚数
    int C[21];
    int T[NMAX + 1];

    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        cin >> C[i]; // C[i]:i番目のコイン
    }

    for (int i = 0; i  <= NMAX; i++) {
        T[i] = INFTY; // Tを初期化
    }
    T[0] = 0;
    for (int i= 0; i <= m; i++) {
        for (int j = 0; j + C[i] <= n ; j++) {
            T[j + C[i]] = min(T[j + C[i]], T[j] + 1); // j + C[i]のときに必要なコインの枚数:min(j + C[i]のときに必要なコインの枚数，jのときに必要なコインの枚数 + 1)
        }
    }

    cout << T[n] << endl;

    return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  string a,b,c;
  cin >> a>>b>>c;

 cout << "A" << b.at(0) << "C" << endl; 
      
}


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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<ll> x(N, 0);
    vector<ll> y(N, 0);
    vector<ll> h(N, 0);

    int px, py, ph;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if ( h[i] > 0 ) {
            px = x[i];
            py = y[i];
            ph = h[i];
        }
    }

    for (ll i = 0; i < 101; i++) {
        for (ll j = 0; j < 101; j++) {
            bool check = true;
            ll H = ph + abs(i-px) + abs(j-py);
            for (int k = 0; k < N; k++) {
                ll tempH = H - abs(x[k] - i) - abs(y[k] - j);
                if (tempH < 0) tempH = 0;
                if ( h[k] != tempH ) {
                    check = false;
                    break;
                }
            }
            if ( check ) {
                px = i;
                py = j;
                ph = H;
                break;
            }
        }
    }

    cout << px << " " << py << " " << ph << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

const long long MOD=1000000007;

long long fac[200000];
long long ifac[200000];
long long inv[200000];
int N, K;
std::vector<int> g[100000];

long long comb(int n, int k){
  return fac[n]*ifac[k]%MOD*ifac[n-k]%MOD;
}

long long perm(int n, int k){
  if(n<k) return 0;
  return fac[n]*ifac[n-k]%MOD;
}

// cur = fixed
// par = fixed
// cur!=par
// のときの通り数をreturn
long long dfs(int cur, int par){
  long long ret=1;
  int num=0;
  for(int to:g[cur]){
    if(to==par)continue;
    ret=ret*dfs(to, cur)%MOD;
    ++num;
  }
  if(par==-1){
    return K*perm(K-1, num)%MOD*ret%MOD;
  }else{
    return perm(K-2, num)*ret%MOD;
  }
}

int main(){
  fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
  for(int i=2;i<200000;++i){
    fac[i]=i*fac[i-1]%MOD;
  }
  for(int i=2;i<200000;++i){
    inv[i]=MOD-MOD/i*inv[MOD%i]%MOD;
  }
  for(int i=2;i<200000;++i){
    ifac[i]=inv[i]*ifac[i-1]%MOD;
  }

  std::cin>>N>>K;
  std::vector<int> a(N);
  std::vector<int> b(N);
  std::vector<int> deg(N);
  for(int i=0; i<N-1; ++i){
    std::cin>>a[i]>>b[i];
    --a[i];
    --b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
    ++deg[a[i]];
    ++deg[b[i]];
  }

  std::cout<<dfs(0, -1)%MOD<<std::endl;
  
  return 0;
}


Measured memory_bytes: 16256
(defvar *n* (read))
(defvar *m* (read))

(defvar *as*
  (loop repeat *n* collect (read)))

(defun modM-+ (a b)
  (mod (+ a b) *m*))

(defvar *sums*
  (loop for x fixnum in *as*
        with psum fixnum = 0
        collect (setf psum (modM-+ x psum))))

(defvar *mods* (make-hash-table))

(dolist (psum *sums*)
  (declare (fixnum psum)
           (optimize (debug 0) (speed 3)))
  (let ((prev (gethash psum *mods*)))
    (setf (gethash psum *mods*)
          (if prev (1+ prev) 1))))

(defun patterns (n)
  (/ (* n (1- n)) 2))

(format t "~a~%"
        (+ (loop for pnum being the hash-values in *mods*
                 sum (patterns pnum))
           (or (gethash 0 *mods*) 0)))


Measured memory_bytes: 59880
#include <iostream>
#include <cctype>
using namespace std; 
int main () {
    char c;
    int a[26] = {0};
    int k;
    while (cin >> c){
        c = tolower(c);
        if (isalpha(c)){
            a[c - 'a'] += 1;
        }
    }
     for (int i = 0; i < 26; i++){
        cout << char(i + 97) << ' ' << ':' << ' ' <<  a[i] << endl;
    }


   
        
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> X(N), Y(N);
    rep(i, N){cin >> X.at(i) >> Y.at(i);}

    // use std::next_permutation
    vector<ll> v; rep(i, N){v.push_back(i);}

    double total = 0.0;
    ll total_cnt = 0;

    do {
        double dist = 0.0;
        ll prev_x = INF, prev_y = INF;
        for (auto i: v){
            ll x = X.at(i); ll y = Y.at(i);
            if (prev_x != INF and prev_y != INF){
                dist += sqrt(pow(x - prev_x, 2) + pow(y - prev_y, 2));
            }
            prev_x = x; prev_y = y;
        }
        total += dist;
        total_cnt += 1;
    } while (next_permutation(v.begin(), v.end()));
    cout << total / total_cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)

int main() {
	int i;
	int t=0;
	int x[5];
	rep(i, 5) {
		cin >> x[i];
		if (x[i] == 0) {
			t = i + 1;
		}
	}
	cout << t;
	return 0;
}

Measured memory_bytes: 3624
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = [0]
for i in range(N):
    B.append(A[i]+B[i])
C = Counter(B[1:])
ans = 0
for c in C.items():
    if c[0] and c[1]>1:
        ans+=(c[1]-1)*c[1]//2
    elif c[0]==0:
        ans+=c[1]*(c[1]+1)//2
print(ans)

Measured memory_bytes: 114760
using System;

namespace a
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < S.Length; i++)
            {
                if(S[i]==T[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
<?php
while(1) {
    $c = trim(fgets(STDIN));
    if($c == 0){
        break;
    }
    
    $aa = 0;
    $r = 0;
    $wr = 0;
    for ($i = 0; $i < $c; $i++) {
        $n = 0;
        $w = 0;
        
         $ww = trim(fgets(STDIN));
         $www = explode(" ",trim($ww));
        //  print_r($www);
         if(count($www) == 4) {
         $n = $www[0] + $www[1] + $www[2]; 
         $w = $www[3];
         switch($n){
         case $n <= 60:
             $r = 600;
             break;
         case $n <= 80:
            //  echo "llllll";
             $r = 800;
             break;
         case $n <= 100:
            $r = 1000;
            break;
        case $n <= 120:
            $r = 1200;
            break;
        case $n <= 140:
            $r = 1400;
            break;
        case $n <= 160:
            $r = 1600;
            break;
        case $n > 160:
            $r = 666;
            // echo 'kkkkkkkkkk';
            break;
    }
    switch($w){
         case $w <= 2:
             $wr = 600;
             break;
         case $w <= 5:
             $wr = 800;
             break;
         case $w <= 10;
            $wr = 1000;
            break;
        case $w <= 15:
            $wr = 1200;
            break;
        case $w <= 20;
            $wr = 1400;
            break;
        case $w <= 25:
            $wr = 1600;
            // echo "ああああ";
            break;
        case $w > 25:
            $wr = 666;
            break;
    }
    // echo $r . "%%%" . PHP_EOL;
    // echo $wr . '+++' . PHP_EOL;
    if($r == 666 || $wr == 666) {
                    // echo 'mmm';

    } elseif($r < $wr) {
        $aa += $wr;
        // echo "aaaa";
    } else {
        $aa += $r;
    }
    // echo $aa . '::::';
    }
        //  echo $aa . PHP_EOL;
    }
    echo $aa . PHP_EOL;
    
}



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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<string> F;
int N, M, color[2][2000*2000], cnt[2][2000*2000];

int convert(int x, int y)
{
	return x*M+y;
}

int find_(int idx, int a)
{
	return color[idx][a]=color[idx][a]==a ? a:find_(idx,color[idx][a]);
}

void union_(int idx, int a, int b)
{
	a=find_(idx,a); b=find_(idx,b);
	if(a==b) return;
	if(a>b) swap(a,b);
	color[idx][b]=a;
	cnt[idx][a]+=cnt[idx][b];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int ans=0;
	cin>>N>>M;
	for(int i=0;i<N*M;i++) {
		color[0][i]=color[1][i]=i;
		cnt[0][i]=cnt[1][i]=1;
	}
	F.resize(N);
	for(int i=0;i<N;i++) {
		cin>>F[i];
		for(int j=0;j<M;j++) {
			if(i && F[i-1][j]=='.' && F[i][j]=='.') {
				union_(0,convert(i,j),convert(i-1,j));
			}
			if(j && F[i][j-1]=='.' && F[i][j]=='.') {
				union_(1,convert(i,j),convert(i,j-1));
			}
		}
	}
	for(int i=0;i<N;i++) for(int j=0;j<M;j++) if(F[i][j]=='.') ans=max(ans,cnt[0][find_(0,convert(i,j))]+cnt[1][find_(1,convert(i,j))]-1);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 67072
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

struct UF{
	int par[100000];
	int rank[100000];
	int si[100000];

	void init(int n){
		rep(i,n){
			par[i] = i;
			rank[i] = 0;
			si[i] = 1;
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]){
			par[x] = y;
			si[y] += si[x];
		} else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
			si[x] += si[y];
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int n, w, h;
int x[40000], y[40000];
map<int,vector<int> > xx, yy;
map<int,vector<int> >::iterator it;
bool edge;
UF uf;

int main(){
    cin >> n >> w >> h;
    uf.init(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        xx[x[i]].push_back(i);
        yy[y[i]].push_back(i);
        if(x[i] == 1 || x[i] == w || y[i] == 1 || y[i] == h) edge = true;
    }
    for(it = xx.begin(); it != xx.end(); it++){
        vector<int> hoge = (*it).second;
        for(int i = 1; i < hoge.size(); i++){
            uf.unite(hoge[0],hoge[i]);
        }
    }
    for(it = yy.begin(); it != yy.end(); it++){
        vector<int> hoge = (*it).second;
        for(int i = 1; i < hoge.size(); i++){
            uf.unite(hoge[0],hoge[i]);
        }
    }
    int ans = n-1;
    int cnt = 0;
    rep(i,n){
        if(i == uf.par[i]) cnt++;
    }
    if(cnt != 1){
        ans += cnt;
        if(edge) ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11060
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n,m;
    cin >> n >> m;
    cout << n*(n-1)/2+m*(m-1)/2;
    return 0;
}




Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    vector<int> vec(3);
    rep(i, 0, 3) cin >> vec[i];
    sort(all(vec));
    int x = vec[2] - vec[0];
    int y = vec[2] - vec[1];
    int ans = y;
    if ((x - y) % 2 == 0)
        ans += (x - y) / 2;
    else
        ans += (x - y) / 2 + 2;
    cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  set<int> values;
  int n = s.size();
  
  for (int i = 0; i < n; i++) values.insert(stoi(to_string(s.at(i))));

  int code = 97;
  for (auto x : values) if (x == code) code++;
  
  if (code == 123) cout << "None" << endl;
  else {
    char c = (char)code;
    printf("%c", c);
  }
}

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10**7)


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, m = LI()

root = [-1] * n


def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]


def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x


def size(x):
    x = r(x)
    return -root[x]


for _ in range(m):
    a, b = LI()
    a -= 1
    b -= 1
    unite(a, b)

ans = max(map(size, range(n)))
print(ans)


Measured memory_bytes: 36112
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int c[]={1,2,1,3,1,3,1,1,3,1,3,1};
int main(){
	int a,b;scanf("%d%d",&a,&b);a--;b--;
	if(c[a]==c[b])printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L
int main(){
    int a,b,h,m;
    long double c1;
    long double c2;
    cin>>a>>b>>h>>m;
    c2=(m-15)*6;
    if(c2<0){
        c2+=360;
        
    }
    c1=(h-3)*30;
    if(c1<0){
        c1+=360;
    }
    long double c3=c2+90;
    if(c3>=360){
        c3-=360;
    }
    c1+=c3/12;
    cout<<fixed<<setprecision(20);
    
    c1=c1*PI/180;
    c2=c2*PI/180;
    
    long double d=(a*cos(c1)-b*cos(c2))*(a*cos(c1)-b*cos(c2))+(a*sin(c1)-b*sin(c2))*(a*sin(c1)-b*sin(c2));
    long double e=sqrt(d);
    
    cout<<e<<endl;
}

Measured memory_bytes: 4164
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	while(getline(cin, s))
	{
		for(int j = 0; j < 26; j++)
		{
			for(int i = 0; i < s.size(); i++)
			{
				if(s[i] >= 'a' && s[i] <= 'z')
				{
					s[i] = (s[i] == 'z') ? 'a' : s[i] + 1;
				}
			}
			if(s.find("the") != string::npos || s.find("this") != string::npos || s.find("that") != string::npos)
			{		
				cout << s << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0