akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <cstdio>
using namespace std;

int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n==0 && m==0) {
      break;
    }
    int a[n];
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    int ans = -INT_MAX;
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	if (i!=j && a[i]+a[j]<=m) {
	  ans = max(ans,a[i]+a[j]);
	}
      }
    }
    if (ans<0) {
      printf("NONE\n");
    } else {
      printf("%d\n", ans);
    }
  }
  return 0;
}

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

void fnInput(string& rsMaxNum)
{
  cin >> rsMaxNum;
}

int fnDgtDP(string sMaxNum)
{
  // dp[nPos][nSmall][nFlag] :=  nPos: 上位 nPos 桁目まで決定
  //                             nSmall: small(数字を自由に選べる)か
  //                             nFlag: {3,5,7} を選んだかのflag
  //                             の条件を満たす数値の数
  int dp[11][2][8] = {};
  dp[0][0][0] = 1;

  int nLen = sMaxNum.size();

  for (int nPos = 0; nPos < nLen; ++nPos)
    for (int nSmall = 0; nSmall < 2; ++nSmall)
      for (int nFlag = 0; nFlag < 8; ++nFlag)
      {
        if (!dp[nPos][nSmall][nFlag]) continue;

        if (nSmall == 1)               // small ([0, 9] から数字を選べる)か
        {
          if (!nFlag) dp[nPos + 1][1][0] += dp[nPos][1][0];                // nothing

          dp[nPos + 1][1][nFlag | 1] += dp[nPos][1][nFlag];                // +3
          dp[nPos + 1][1][nFlag | 2] += dp[nPos][1][nFlag];                // +5
          dp[nPos + 1][1][nFlag | 4] += dp[nPos][1][nFlag];                // +7
        }
        else                           // not small ([0, d] から数字を選べる)か
        {
          int nDgt = sMaxNum[nPos] - '0';

          if (!nFlag)        dp[nPos + 1][1][0]     += dp[nPos][0][0];     // nothing

          if (nDgt == 3) dp[nPos + 1][0][nFlag | 1] += dp[nPos][0][nFlag]; // +3
          if (3 < nDgt)  dp[nPos + 1][1][nFlag | 1] += dp[nPos][0][nFlag]; // +3
          if (nDgt == 5) dp[nPos + 1][0][nFlag | 2] += dp[nPos][0][nFlag]; // +5
          if (5 < nDgt)  dp[nPos + 1][1][nFlag | 2] += dp[nPos][0][nFlag]; // +5
          if (nDgt == 7) dp[nPos + 1][0][nFlag | 4] += dp[nPos][0][nFlag]; // +7
          if (7 < nDgt)  dp[nPos + 1][1][nFlag | 4] += dp[nPos][0][nFlag]; // +7
        }
      }
  return dp[nLen][0][7] + dp[nLen][1][7];
}

int main()
{
  string sMaxNum;

  fnInput(sMaxNum);
  cout << fnDgtDP(sMaxNum) << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    int n; cin >> n;
    vector<ll> a(n);
    ll sunuke=0, araiguma=0;
    rep(i, n) {
        cin >> a[i];
        if(i==0) sunuke += a[i];
        else araiguma += a[i];
    }
    ll ans = abs(sunuke - araiguma);
    for(int i=1; i < n-1; i++) {
        sunuke += a[i];
        araiguma -= a[i];
        chmin(ans, abs(sunuke - araiguma));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

int main(){
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    rep(i,s.size()){
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}


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


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/




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

    int n;
    cin>>n;
    vector<ll> a(3*n);
    for (int i = 0; i<3*n; i++) cin>>a[i];

    vector<ll> pref(n+1);
    vector<ll> suf(n+1);

    multiset<ll> kek;
    ll sum = 0;
    for (int i = 0; i<n; i++)
    {
        kek.insert(a[i]); sum+=a[i];
    }
    pref[0] = sum;
    for (int i = n; i<2*n; i++)
    {
        if (a[i]>*kek.begin())
        {
            sum-=*kek.begin();
            kek.erase(kek.begin());
            sum+=a[i];
            kek.insert(a[i]);
        }
        pref[i-n+1] = sum;
    }

    reverse(a.begin(), a.end());
    kek.clear(); sum = 0;
    for (int i = 0; i<n; i++)
    {
        kek.insert(-a[i]); sum+=a[i];
    }
    suf[0] = sum;
    for (int i = n; i<2*n; i++)
    {
        if (-a[i]>*kek.begin())
        {
            sum-=(-*kek.begin());
            kek.erase(kek.begin());
            sum+=a[i];
            kek.insert(-a[i]);
        }
        suf[i-n+1] = sum;
    }

    /*for (auto it: pref) cout<<it<<' ';
    cout<<endl;

    for (auto it: suf) cout<<it<<' ';
    cout<<endl;*/


    ll maxx = -1e18;
    for (int i = 0; i<=n; i++) maxx = max(maxx, pref[i] - suf[n-i]);
    cout<<maxx;




}


Measured memory_bytes: 8960
import java.util.Scanner;
import java.io.*;

public class Main
{
	public static void main(String[] args)
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		try
		{
			while(true)
			{
				line = reader.readLine();
				if(line.equals("0"))
				{
					break;
				}
				int ans = 0;
				for (int i = 0; i < line.length(); i++)
				{
					ans += line.charAt(i) - '0';
				}
				System.out.println(ans);
			}
		}
		catch(IOException e)
		{
			System.out.println(e);
		}
	}
}


Measured memory_bytes: 24364
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


using mint = atcoder::modint998244353;

std::istream &operator>>(std::istream &in, mint &o) {
    long long a;
    in >> a;
    o = a;
    return in;
}

int main() {

    int n, m;
    cin >> n >> m;
    vector<mint> a(n), b(m);
    rep(i, n)cin >> a[i];
    rep(i, m)cin >> b[i];

    auto c = atcoder::convolution(a, b);
    rep(i, n + m - 1) {
        cout << c[i].val() << ' ';
    }
    cout << endl;

}


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

int main() {
    string S;
    cin >> S;
    if (S.at(5) == '0' && S.at(6) - '0' <= 4) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) cin >> vec[i];
  int smallest = 1000000000;
  rep(i, -100, 101){
    int sum = 0;
    rep(j, n) sum += (i-vec[j])*(i-vec[j]);
    smallest = min(smallest, sum);
  }
  cout << smallest << endl;
  return 0;
}

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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define ll long long
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5+10;
const int inf = 1e9+7;

int n, a[N], mx, b = inf, d, I;

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if(mx < a[i]) {
            mx = a[i];
            I = i;
        }
    }

    for(int i = 1; i <= n; i++) {
        if(i == I) continue;
        if(abs(mx / 2 - a[i]) < b) {
            b = abs(mx / 2 - a[i]);
            d = a[i];
        }
        else if(abs(mx / 2 - a[i]) == b) {
            d = max(d, a[i]);
        }
    }
    cout << mx << " " << d << endl;
}


Measured memory_bytes: 640
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let w: i32 = iter.next().unwrap().parse().unwrap();
    let h: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let r: i32 = iter.next().unwrap().parse().unwrap();
    if 0<=x-r && x+r<=w && 0<=y-r && y+r<=h {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 5024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	long long a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	sort(a,a+n);
	long long cnt=0;
	for(int i=0;i<n-m;++i)
		cnt+=a[i];
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
vector<int> g[maxn];
int col[maxn];
int deg[maxn];

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    forn (i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> o;
    forn (i, n) {
        col[i] = -1;
        deg[i] = sz(g[i]);
        if (deg[i] <= 1)
            o.push_back(i);
    }
    forn (ii, sz(o)) {
        int u = o[ii];
        if (col[u] != -1)
            continue;
        int v = -1;
        for (int i: g[u]) {
            if (col[i] == -1)
                v = i;
        }
        //cerr << "cut " << u + 1 << ' ' << v + 1 << '\n';
        if (v == -1) {
            cout << "First\n";
            return 0;
        }
        col[v] = 1;
        col[u] = 0;
        for (int i: g[v]) {
            if (--deg[i] <= 1 && col[i] == -1)
                o.push_back(i);
        }
    }
    cout << "Second\n";
}


Measured memory_bytes: 6912
//Krzysztof Boryczka
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'

void solve(){
	int a, b, c;
	cin>>a>>b>>c;
	cout<<(a+b+c >= 22 ? "bust" : "win")<<ent;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// int tt; cin>>tt;
	// FOR(te, 1, tt)
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

char f(char a, char b, char c) {
	if (b == 'S') {
		if (c == 'o') return a;
		if (a == 'W') return 'S';
		return 'W';
	}
	if (c == 'x') return a;
	if (a == 'W') return 'S';
	return 'W';
}

int n;
string s;

bool ok(string ret) {
	char a = ret[n - 2];
	char b = ret[n - 1];
	char c = ret[0];
	char d = ret[1];
	if (f(a, b, s[n - 1]) != c) return false;
	if (f(b, c, s[0]) != d) return false;
	return true;
}

signed main() {
	cin >> n;
	cin >> s;

	string ret = "";
	ret += "SS";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	ret = "";
	ret += "SW";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	ret = "";
	ret += "WS";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	ret = "";
	ret += "WW";
	REP(i, 1, n - 2) {
		ret.push_back(f(ret[i - 1], ret[i], s[i]));
	}
	if (ok(ret)) {
		cout << ret << endl;;
		return 0;
	}

	cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define MAX_V 100000
#define INF 1000000000
typedef long long ll;
ll d[MAX_V][3];
ll n,m;
struct edge{ll to,cost;
  edge(ll a,ll b){
    to=a;
    cost=b;
  }
};
vector<edge> G[MAX_V];
typedef pair<ll,ll> P;
void dij(ll s){
  bool first=true;
  priority_queue<pair<ll,P>,vector<pair<ll,P>>,greater<pair<ll,P>>> que;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      d[i][j]=INF;
    }
  }
  d[s][2]=0;
  que.push(make_pair(0,P(2,s)));
  while(!que.empty()){
    pair<ll,P> p=que.top();
    que.pop();
    ll v=p.second.second,now=p.second.first;
    ll next=(now+1)%3;
    if(d[v][now]<p.first) continue;
    for(ll i=0;i<G[v].size();i++){
      edge e=G[v][i];
      if(d[e.to][next]>d[v][now]+e.cost){
        d[e.to][next]=d[v][now]+e.cost;  
        que.push(make_pair(d[e.to][next],P(next,e.to)));
      }
    }
    if(first){
      d[s][2]=INF;
      first=false;
    }
  }
}
int main(){
  cin >> n >> m;
  ll u,v,s,t;
  for(int i=0;i<m;i++){
    cin >> u >> v;
    u--;v--;
    G[u].push_back(edge(v,1));
  }
  cin >> s >> t;
  s--; t--;
  dij(s);
  if(d[t][2]==INF) cout <<"-1\n";
  else cout <<d[t][2]/3<<endl;
}


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

using namespace std;

const int N = 410;
const long long INF = (1LL << 50);

long long n, i, j, k, l, v[N], d[N][N], x[N][N];

int main() {
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (i = 0; i < n; ++i) {
        x[i][i] = v[i];
        for (j = 0; j < n; ++j) {
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    for (l = 1; l < n; ++l) {
        for (i = 0; i + l < n; ++i) {
            j = i + l;
            x[i][j] = x[i][j - 1] + v[j];
            for (k = i; k < j; ++k) {
                d[i][j] = min(d[i][j], d[i][k] + d[k + 1][j]);
            }
            d[i][j] += x[i][j];
        }
    }
    cout << d[0][n - 1] << "\n";
    return 0;
}


Measured memory_bytes: 2816
from bisect import bisect_right

N, A, B, *h = map(int, open(0).read().split())

h.sort()
d = A - B

ng = (h[-1] + (A - 1)) // A - 1
ok = (h[-1] + (B - 1)) // B
while ok - ng > 1:
    m = (ok + ng) // 2
    b = B * m
    if m >= sum((h[i] - b + (d - 1)) // d for i in range(bisect_right(h, b), N)):
        ok = m
    else:
        ng = m
print(ok)


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

int main(void) {
  int H, N;
  
  cin >> H >> N;
  int a;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    sum += a;
  }
  
  if (sum >= H) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}
  
  
  

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	HashSet<int>[] es;
	int[] par;
	void Solve()
	{
		var N = F;
		es = new HashSet<int>[N];
		par = new int[N];
		for (var i = 0; i < N; i++) es[i] = new HashSet<int>();
		for (var i = 0; i < (N - 1); i++)
		{
			var I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		DFS(0, -1);
		dp = new long[N, 2];
		done = new bool[N, 2];
		WriteLine((Calc(0, 0) + Calc(0, 1)) % MOD);
	}
	long[,] dp;
	bool[,] done;
	long Calc(int u, int c)
	{
		if (!done[u, c])
		{
			done[u, c] = true;
			dp[u, c] = 1;
			if (c == 0) foreach (var v in es[u]) dp[u, c] = dp[u, c] * (Calc(v, 0) + Calc(v, 1)) % MOD;
			else foreach (var v in es[u]) dp[u, c] = dp[u, c] * Calc(v, 0) % MOD;
		}
		return dp[u, c];
	}
	void DFS(int u, int p)
	{
		par[u] = p;
		es[u].Remove(p);
		foreach (var v in es[u]) DFS(v, u);
	}
}


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

int main() {

	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 3640
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	n=int(input())
	c=list(map(int,input().split()))
	c.sort()
	c=c[::-1]
	
	ans=0
	nn=[1]
	for i in range(n+1):
		nn.append(nn[-1]*2%mod)
		
	a=nn[n]
	
	for i in range(n):
		aa=c[i]%mod
		aaa=nn[n-1]+((i)*nn[n-2])%mod
		ans+=(a*aa*aaa)
		ans%=mod
		
	print(int(ans))
	
	
	


if __name__ == "__main__":
	main()


Measured memory_bytes: 74352
#include<stdio.h>

int main()

{

  char c[1000];

  int i,x;

  int sum;

  int co;

  while(1){

    co=0;

    sum=0;

    scanf("%s",&c);

    for(i=0;;i++){

      if(c[i]=='\0'){

    co=i;

    break;

      }

    }

    if(c[0]=='0')break;

    for(i=0;i<co;i++){

      x =c[i]-'0';

      sum+=x;

      }

    printf("%d\n",sum);

  }

      return 0;

}

Measured memory_bytes: 536
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n - 1];
		int[] b = new int[n - 1];
		int[] c = new int[n - 1];
		HLDecomposition hl = new HLDecomposition(n);
		for (int i = 0; i < n - 1; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			--a[i];
			--b[i];
			hl.ae(a[i], b[i], c[i]);
		}
		int Q = sc.nextInt();
		int K = sc.nextInt();
		--K;
		int[] x = new int[Q];
		int[] y = new int[Q];
		hl.root = K;
		hl.pre();
		for (int i = 0; i < Q; ++i) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			--x[i];
			--y[i];
			System.out.println(hl.depth2[x[i]] + hl.depth2[y[i]]);
		}
	}

	class HLDecomposition {
		int root = 0;
		int n;
		int[] depth;
		long[] depth2;
		int[] head;
		int[] heavy;
		int[] parent;
		int[] sz;
		ArrayList<Edge>[] g;
		int[] id;

		class Edge {
			int src, dst;
			long cost;

			public Edge(int src_, int dst_, int cost_) {
				src = src_;
				dst = dst_;
				cost = cost_;
			}
		}

		@SuppressWarnings("unchecked")
		public HLDecomposition(int n) {
			this.n = n;
			depth = new int[n];
			depth2 = new long[n];
			head = new int[n];
			heavy = new int[n];
			parent = new int[n];
			id = new int[n];
			sz = new int[n];
			g = new ArrayList[n];
			for (int i = 0; i < n; ++i) {
				g[i] = new ArrayList<>();
			}
			Arrays.fill(head, -1);
			Arrays.fill(id, -1);
			Arrays.fill(parent, -1);
		}

		void ae(int a, int b, int c) {
			g[a].add(new Edge(a, b, c));
			g[b].add(new Edge(b, a, c));
		}

		void pre() {
			dfs(root, -1);
			bfs();
		}

		void bfs() {
			ArrayDeque<Integer> pend = new ArrayDeque<>();
			int gen = 0;
			pend.add(0);
			while (!pend.isEmpty()) {
				int v = pend.pollFirst();
				int top = v;
				for (; v != -1; v = heavy[v]) {
					id[v] = gen++;
					head[v] = top;
					for (Edge e : g[v]) {
						int d = e.dst;
						if (d == parent[v] || d == heavy[v]) {
							continue;
						}
						pend.add(d);
					}
				}
			}
		}

		int lca(int u, int v) {
			if (head[u] != head[v]) {
				if (depth[head[u]] < depth[head[v]]) {
					int tmp = u;
					u = v;
					v = tmp;
				}
				return lca(parent[head[u]], v);
			} else {
				if (depth[u] > depth[v]) {
					int tmp = u;
					u = v;
					v = tmp;
				}
				return u;
			}
		}

		int dfs(int c, int p) {
			parent[c] = p;
			int s = 1;
			int to = -1;
			for (Edge e : g[c]) {
				int d = e.dst;
				if (d == p)
					continue;
				depth[d] = depth[c] + 1;
				depth2[d] = depth2[c] + e.cost;
				s += dfs(d, c);
				if (to == -1 || sz[d] > sz[to]) {
					to = d;
				}
			}
			sz[c] = s;
			heavy[c] = to;
			return s;
		}

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 210752
N, T = map(int, input().split())

t = list(map(int, input().split()))

diff = []

for i in range(N - 1):
    diff.append(t[i+1] - t[i])

# print(diff)

shower_time = list(map(lambda x: T if T < x else x, diff))
ans = sum(shower_time) + T

print(ans)


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

"""
input:
preorder & inorder

5
1 2 3 4 5
3 2 4 1 5

9
1 2 3 4 5 6 7 8 9
3 2 5 4 6 1 8 7 9

output:
postorder
3 4 2 5 1
"""

import sys


# recursively defines a binary tree
# node.left or node.right may also be a binary tree
class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left, self.right = None, None


def reconstruction(_pre_order, _in_order):
    # write your code here
    if not _pre_order:
        return None
    root = TreeNode(_pre_order[0])
    root_position = _in_order.index(_pre_order[0])
    root.left = reconstruction(_pre_order=_pre_order[1:1 + root_position], _in_order=_in_order[:root_position])
    root.right = reconstruction(_pre_order=_pre_order[root_position + 1:], _in_order=_in_order[root_position + 1:])
    post_order.append(root.val)
    return root.val


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    pre_order = list(map(int, _input[1].split()))
    in_order = list(map(int, _input[2].split()))
    # assert len(pre_order) == len(in_order) == array_length

    post_order = []
    reconstruction(_pre_order=pre_order, _in_order=in_order)
    print(*post_order)

Measured memory_bytes: 7788
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int P,Q,R, minVal;

void solve(){
    minVal = max(max(P, Q), R);

    cout << P + Q + R - minVal << endl;
}

int main(){
    cin >> P >> Q >> R;

    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int r,w,c,r2;
	while(cin >> r >> w >> c >> r2,r){
		cout << ((r/w > c) ? 0 : ((c*w-r) + r2 - 1)/r2) << endl;
	}
  return 0;
}

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

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

int T[M] = {0};

int h1(int key)
{
  return key % M;
}

int h2(int key)
{
  return 1 + (key % (M - 1));
}

int h(int key, int i)
{
  return (h1(key) + i * h2(key)) % M;
}

void insert(int key)
{
  int j, i = 0;
  while(1){
    j = h(key, i);
    if(T[j] == 0){
      T[j] = key;
      return;
    }else{
      i++;
    }
  }
}

bool search(int key)
{
  int j, i = 0;
  while(1){
    j = h(key, i);
    if(T[j] == key)
      return true;
    else if(T[j] == 0 || i >= M)
      return false;
    else 
      i++;
  }
}

int getChar(char ch)
{
  if(ch == 'A')
    return 1;
  else if(ch == 'C')
    return 2;
  else if(ch == 'G')
    return 3;
  else if(ch == 'T')
    return 4;
  else
    return 0;
}

int getKey(string str)
{
  int sum = 0, p = 1;
  REP(i, str.size()){
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}


int main()
{
  int n;
  cin >> n;
  string c, s;
  REP(i, n){
    cin >> c >> s;
    int key;
    key = getKey(s);
    if(c[0] == 'i')
      insert(key);
    else
      if(search(key))
	cout << "yes" << endl;
      else
	cout << "no" << endl;
  }
}

Measured memory_bytes: 5108
/// Solution No.: 01

/// Approach:

/// Comment:

/// Verdict:

/// Report:


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <string.h>
#include <climits>
#include <set>
#include <cassert>
#include <cfloat>
#include <stack>

///using namespace std;         /// Recommended not to use

#define p(x) std::cout<<#x<<" = "<<x<<"\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define absolute(x) (((x)<0)?(-(x)):(x))
/// #define _DEBUG

typedef long long int ll;
typedef unsigned long long llu;
typedef long double lld;

/// lld pi = 2 * acos(0.0);   /// precision error
lld pi = 2 * acosl(0.0);

int test_case_number, test_case=1;

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
/// Direction Array
/// int dx[]={0, 0, 1, -1, -1, 1, -1, 1};
/// int dy[]={-1, 1, 0, 0, 1, 1, -1, -1};

///place for problem specific functions


void function_name()
{
    int element_number, knapsack_capacity;
    scanf("%d %d", &element_number, &knapsack_capacity);
    ll dp[knapsack_capacity+1] = {0};
    /// dp[i] => maximum value for the total weight ( exactly ) i.
    for(int i=0;i<element_number;i++)
    {
        int value, weight;
        scanf("%d %d", &weight, &value);
        for(int j = knapsack_capacity-weight;j>=0;j--)
        {
            dp[j+weight] = std::max(dp[j+weight], dp[j]+value);
        }
    }
    ll ans=0;
    for(int i=1;i<=knapsack_capacity;i++)
    {
        ans = std::max(ans, dp[i]);
        //printf("%lld\n", dp[i]);
    }
    printf("%lld\n", ans);
}
void function_name(int v1, int v2, int v3)
{

}
void function_name(std::string line)
{

}
class initial_works
{
public:

    void with_test_case_number()
    {
        scanf("%d", &test_case_number);
        ///getchar();
        while(test_case <= test_case_number)
        {
            function_name();
            test_case++;
        }
    }

    void single_iteration()
    {
        function_name();
    }

    void without_test_case_number()
    {
        int v1, v2, v3;
        while(scanf("%d %d %d", &v1, &v2, &v3)==3 && v1!=0)
        {
            function_name(v1, v2, v3);
            test_case++;
        }
    }

    void eoof()
    {
        char dummy_char_array[100];
        while(scanf("%[^\n]", dummy_char_array)!=EOF)
        {
            ///it only takes the absence of one getchar to ruin your life. Don't understand remove the getchar below and then input the sample input
            getchar();
            ///if not given getchar. the dummu_char_array will not take new input as there is newline after the first input is taken. It will continue with the previous value.
            /// So, the function will run with same argument.
            std::string line = dummy_char_array;
            function_name(line);
            test_case++;
        }
    }
};


int main()
{
    //std::ios_base::sync_with_stdio(false);
    initial_works a;
    a.single_iteration();

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	int n, b[123], ans = 0; cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> b[i];
		if (i == 0)ans += b[i];
		else {
			ans += min(b[i], b[i - 1]);
		}
		if (i == n - 2)ans += b[i];
	}
	cout << ans << endl;
}

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

int main(){
        double x1,x2,y1,y2,x3,x4,y3,y4;
    
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4){
        double a = (x2-x1)*(x4-x3),b = (y2-y1)*(y4-y3);
        if((float)a+(float)b==0) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
    
    return 0;
}

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

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

    int a[100010];

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

    sort(a, a+n);

    if(a[n-1] == 0){
        cout << "Yes" << endl;
        return 0;
    }

    if(n % 3 != 0){
        cout << "No" << endl;
        return 0;
    }

    int tmp = n/3;
    for(int i = 1;i < tmp;i++){
        if(a[i-1] != a[i] || a[tmp + i-1] != a[tmp + i] || a[tmp*2 + i-1] != a[tmp*2+i]){
            cout << "No" << endl;
            return 0;
        }
    }

    if((a[0] ^ a[tmp]) == a[2*tmp]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		String taro,hana;
		int tp=0,hp=0;
		int n=sc.nextInt();
		for(int i=0;i<n;i++){
			taro=sc.next();
			hana=sc.next();
			if(taro.compareTo(hana)==0){
				tp+=1;
				hp+=1;
			}else if(taro.compareTo(hana)>0)tp+=3;
			else hp+=3;
		}
		System.out.println(tp+" "+hp);
	}
}

Measured memory_bytes: 29500
#include <bits/stdc++.h>
using namespace std;
 
int x,m,k,y,z,dp[10000000],ar[10000000];
 
int main() {
	scanf("%d",&x);
	for (int a = 1; a <= x; a++) {
		scanf("%d",&ar[a]);
	}
	dp[2] = abs(ar[2]-ar[1]);
	for (int a = 3; a <= x; a++) {
		dp[a] = min(dp[a-1]+abs(ar[a]-ar[a-1]),dp[a-2]+abs(ar[a]-ar[a-2]));
	}
	cout << dp[x] << "\n";
	return 0;
} 

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

int main(){
    ll N;
    cin >> N;
    
    FOR(mask, 0, 1LL<<N){
        cout << mask << ":";
        FOR(i, 0, 18){
            if(mask>>i&1){
                cout << ' ' << i;
            }
        }
        cout << endl;
    }

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s, t;
int ls, lt;

int main() {
	cin >> s >> t;
	ls = (int)s.length(), lt = (int)t.length();
	
	if (ls<lt) {
		cout << "UNRESTORABLE" << ln;
		return 0;
	}
	// 後ろから見ていかないと辞書順最小って条件を破るかもしれないから注意
	repr(i,ls-lt) {
		rep(j,lt) {
			// ?じゃなくて文字が違ったらだめ
			if (s[i+j]!='?' && s[i+j]!=t[j]) goto dame;
		}
		// 条件をクリアしたらsの[i, i+lt)をtに書き換えて、他の?を全部aに書き換えて出力
		rep(j,lt) s[i+j] = t[j];
		rep(i,ls) if (s[i]=='?') s[i] = 'a';
		cout << s << ln;
		return 0;
		dame:;
	}
	cout << "UNRESTORABLE" << ln;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String n = sc.next();

            if(n.charAt(2) == n.charAt(3) && n.charAt(4) == n.charAt(5)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }

        sc.close();
    }

}

Measured memory_bytes: 21844
#include <cstdio>
int main(){for(int m,n,i,j,k,a;a=1,scanf("%d",&m),m;puts(a?"OK":"NG")){int d[300]={0},g[300][300]={0};scanf("%d",&n);for(i=1;i<=n;)scanf("%d",d+i++);for(i=0;i<=n;i++)for(j=1;j<=m;j++)k=i+j+d[i+j],(k=k<0?0:n+1<k?n+1:k),g[i][k]=1;for(k=0;k<n+2;k++)for(i=0;i<n+2;i++)for(j=0;j<n+2;j++)if(g[i][k]&&g[k][j])g[i][j]=1;for(i=0;i<=n;i++)if(g[0][i]&&!g[i][n+1])a=0;}}

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

#define fi first
#define se second

const int N = 100100;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int k;
int d[N];
int f[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n >> k;
        for(int i = 0; i <= k; i++){
                d[i] = 1;
        }
        for(int i = 1; i <= n; i++){
                int x;
                cin >> x;
                for(int j = 0; j <= k; j++){
                        f[j] = d[j];
                        if(j - x - 1 >= 0){
                                f[j] -= d[j - x - 1];
                                if(f[j] < 0){
                                        f[j] += mod;
                                }
                        }
                }
                for(int j = 0; j <= k; j++){
                        d[j] = f[j];
                        if(j - 1 >= 0){
                                d[j] += d[j - 1];
                                if(d[j] >= mod){
                                        d[j] -= mod;
                                }
                        }
                }
        }
        cout << f[k] << "\n";
}



Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str1 = sc.next();
		String str2 = sc.next();
		String str3 = sc.next();

		System.out.print(str1.charAt(0));
		System.out.print(str2.charAt(1));
		System.out.print(str3.charAt(2));
	}

}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	int N = 3;
	VS s(N);
	FOR(i, 0, N) {
		cin >> s[i];
		cout << s[i][i];
	}
	cout << endl;

	return 0;
}


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

int main(){
  int N, T, A, H, temp, ans;
  cin >> N >> T >> A;

  for(int i = 1; i <= N; i++){
    cin >> H;
    if(abs((T*1000-H*6)-A*1000) <= temp || i == 1){
      temp = abs((T*1000-H*6)-A*1000);
      ans = i;
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#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))

int main(void)
{
	//変数の宣言
	int n,m;
	int x,y;
	char c;
	static int map[2010][2010];
	static int ruiseki[2010][2010];
	static int ruisekitemp[2010][2010];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int sum=0;
	int temp,temp1,temp2;
	//int max,min;
	int len;
	//データの読み込み
	
	scanf("%d %d",&n,&m);
	
	for(i=0;i<=2000;i++){
		for(j=0;j<=2000;j++){
			map[i][j]=0;
		}
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d %c",&x,&y,&c);
		if(c=='W') x=x+m;
		x=x%(2*m);
		y=y%(2*m);
		map[x][y]=map[x][y]+1;
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	//二次元累積和の計算
	
	for(i=0;i<2*m;i++){
		for(j=0;j<2*m;j++){
			if(j==0){
			ruisekitemp[i][0]=map[i][0];
			}else{
				ruisekitemp[i][j]=ruisekitemp[i][j-1]+map[i][j];
			}
		}
	}
	
	for(j=0;j<2*m;j++){
		for(i=0;i<2*m;i++){
			if(i==0){
				ruiseki[0][j]=ruisekitemp[0][j];
			}else{
				ruiseki[i][j]=ruiseki[i-1][j]+ruisekitemp[i][j];
			}
		}
	}
	
	for(i=0;i<m;i++){
		for(j=0;j<m;j++){
			temp=0;
			temp=temp+ruiseki[i+m][j+m]-ruiseki[i+m][j]-ruiseki[i][j+m]+ruiseki[i][j];
			temp=temp+ruiseki[i][j];
			temp=temp+ruiseki[2*m-1][2*m-1]-ruiseki[i+m][2*m-1]-ruiseki[2*m-1][j+m]+ruiseki[i+m][j+m];
			temp=temp+ruiseki[2*m-1][j]-ruiseki[i+m][j];
			temp=temp+ruiseki[i][2*m-1]-ruiseki[i][j+m];
			if(temp<n-temp) temp=n-temp;
			if(temp>ans) ans=temp;
		}
	}
	
	
	
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

int main(){
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	rep(i, n) cin >> s.at(i);

	sort(s.begin(), s.end());

	rep(i, n) cout << s.at(i);
	cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);

  int turn = 1;
  while(true){
    if(turn == 1){
      if(a + 1 == b){
        if(a - 1 == 0){
          printf("Borys\n");
          break;
        }else{
          a--;
        }
      }else{
        a++;
      }
    }else{
      if(b - 1 == a){
        if(b == n){
          printf("Alice\n");
          break;
        }else{
          b++;
        }
      }else{
        b--;
      }
    }
    turn *= -1;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin>>N;
    int ans=0,idx=1;
    for (int i=1;i<=N;i++){
        int cnt=0,a=i;
        while (a%2==0){
            cnt++;
            a=a/2;
        }
        if(ans<cnt){
            ans=cnt;
            idx=i;
        }
    }
    cout<<idx<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    set<int> appear_once;
    vector<int> appear_twice;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (appear_once.find(x) == appear_once.end()) {
            appear_once.insert(x);
        }
        else {
            appear_twice.push_back(x);
            appear_once.erase(x);
        }
    }
    if (appear_twice.size() < 2) {
        cout << 0;
        return 0;
    }
    sort(appear_twice.begin(), appear_twice.end());
    //look at adj
    ll max_area = 0;
    for (int i = 0; i < appear_twice.size() - 1; i++) {
        max_area = max(max_area, (ll)appear_twice[i] * (ll)appear_twice[i + 1]);
    }
    cout << max_area;
}

Measured memory_bytes: 8300
#include<stdio.h>

int main()
{
int h,m,s,S;
scanf("%d",&s);
h = s / 3600;
m = s / 60 - 60 * h;
S = s - 3600 * h - 60 * m;
printf("%d:%d:%d\n",h,m,S);
return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
int main()
{
     int a,b,c[2000],s=0,i,j=0,d,e;
    scanf("%lld%lld",&a,&b);
    for(i=0;i<a;i++)
    {
        scanf("%d",&c[i]);
        s=s+c[i];
    }
    d=4*b;
    e=s/d;
    if(s%d!=0)
        e++;
    for(i=0;i<a;i++)
    {
        if(c[i]>=e)


            j++;

    }
    if(j>=b)
        printf("Yes");
    else
        printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  
  int r;
  cin >> r;
  cout << r*3.14159265359*2 << endl;

  return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;

int main()
{
	int K,N;
	while(cin>>N>>K && (K || N)){
		ll res = 0, ans = 0;
		queue<int> A;
		for(int i = 0; i < N; i++){
			int buf;
			cin>>buf;
			res += buf;
			A.push(buf);
			if(i >= K){
				res -= A.front();
				A.pop();
				ans = max(ans, res);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test lli t;cin>>t;while(t--)
#define vll vector<lli>
#define mll map<lli,lli>
#define vvll vector<vector<lli>>
#define vpll vector<pair<lli,lli>>
#define vvpll vector<vector<pair<lli,lli>>>
#define mpll map<pair<lli,lli>,lli>
#define pll pair<lli,lli>
#define sll stack<lli>
#define qll queqe<lli>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
int main()
{
  #ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
  fastio
  lli l,r,d,i,f=0;
  cin>>l>>r>>d;
  for(i=l;i<=r;i++)
  {
  	if(i%d==0)
  		f++;
  }
  cout<<f;
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	
	int ans[10001];
	fill(ans, ans+N+1, 0);
	for(ll x = 1; x*x <= N; x++){
		for(ll y = 1; y*x <= N; y++){
			for(ll z = 1; x*y + z*x <= N; z++){
				if(x*x + y*y + z*z + x*y + y*z + z*x <= N){
					ans[x*x + y*y + z*z + x*y + y*z + z*x]++;
				}
			}
		}
	}
	for(int i = 1; i <= N; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(){
    int n;
    string s;
    string t;
    string u;
    cin>>n;
    cin>>s>>t;
    for(int i=0;i<n;i++){
        cout<<s[i]<<t[i];
    }
}


Measured memory_bytes: 256