akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;

	cin >> n;

	vector <int> x(n), y(n);

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

	pair <int, int> a, b;
	int mx = 0;
	int mn = 1e9+5;
	int ans = 0;

	for (int i = 0; i < n; i++) {
		if (x[i] + y[i] < mn) {
			mn = x[i] + y[i];
			a.first = x[i];
			a.second = y[i];
		}

		if (x[i] + y[i] > mx) {
			mx = x[i] + y[i];
			b.first = x[i];
			b.second = y[i];
		}
	}

	ans = max(ans, abs(a.first - b.first) + abs(a.second - b.second));
	
	mn = 1e9+5;
	mx = 0;

	for (int i = 0; i < n; i++) {
		if (x[i] - y[i] < mn) {
			mn = x[i] - y[i];
			a.first = x[i];
			a.second = y[i];
		}

		if (x[i] - y[i] > mx) {
			mx = x[i] - y[i];
			b.first = x[i];
			b.second = y[i];
		}
	}

	ans = max(ans, abs(a.first - b.first) + abs(a.second - b.second));

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4772
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
bool pj(int n){
    if(n==1) return false;
    int d=2;
    while(d*d<=n){
        if(n%d==0)return false;
        d++;
    }
    return true;
}

int main(){
    int n; cin>>n;
    int i=0;
    while(n){
        if(pj(5*i+6)){
            cout<<5*i+6<<" ";
            n--;
        }
        i++;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
    FAST_IO();
    int N, K; cin >> N >> K;
    vector<int> A(N);
    int S = 0;
    rep(i, N) {
        cin >> A[i];
        S += A[i];   
    }
    vector<int> cand;
    for(int i = 1; i <= sqrt(S); ++i) {
        if(S % i == 0) {
            if(S / i == i) cand.push_back(i);
            else {
                cand.push_back(i);
                cand.push_back(S / i);
            }
        }
    }
    sort(all(cand));
    reverse(all(cand));
    for(auto &x : cand) {
        vector<int> B;
        rep(i, N) {
            if(A[i] % x != 0) B.push_back(A[i] % x);
        }
        sort(all(B));
        int left = 0, right = 0, mid = 0;;
        rep(i, sz(B)) right += x - B[i];
        rep(i, sz(B)) {
            left += B[i];
            right -= x - B[i];
            if(left == right) mid = left;
        }
        if(mid <= K) {
            cout << x << "\n";
            break;
        }
    }
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n, p; cin>>n>>p;
  string st; cin>>st;
  vi ar;
  rep(i,0,n) {
    ar.pb(st[i]-'0');
  } 
  if(p == 2 || p == 5) {
    lli ans = 0;
    rep(i,0,n) {
      if(ar[i]%p == 0) ans += (i+1);
    }
    cout<<ans<<endl;
    return 0;
  }
  lli p10 = 1;
  for(int i = n-1; i>=0; i--) {
    ar[i] = (ar[i]*p10)%p;
    p10 = (p10 * 10) %p;
  }
  debug(ar);
  debug(ar);
  for(int i = n-2; i>=0; i--) {
    ar[i] = (ar[i] + ar[i+1])%p;
  }
  debug(ar);
  map<int, int> mm;
  lli ans = 0;
  mm[0]++;
  for(int i = n-1; i>=0; i--) {
    ans += mm[ar[i]];
    mm[ar[i]]++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1680
#include <bits/stdc++.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++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll s = a[0];
    ll ans1 = 0, ans2 = 0;
    if (s <= 0) {
        ans1+=-s+1;
        s=1;
    }
    rep2(i, 1, n) {
        if (i%2 && s+a[i] >= 0) {
            ans1 += s+a[i]+1;
            s = -1;
        }
        else if (i%2==0 && s+a[i] <= 0) {
            ans1 += -(s+a[i]) + 1;
            s = 1;
        }
        else s += a[i];
    }
    s = a[0];
    if (s >= 0) {
        ans2+=s+1;
        s=-1;
    }
    rep2(i, 1, n) {
        if (i%2==0 && s+a[i] >= 0) {
            ans2 += s+a[i]+1;
            s = -1;
        }
        else if (i%2 && s+a[i] <= 0) {
            ans2 += -(s+a[i]) + 1;
            s = 1;
        }
        else s += a[i];
    }
    cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 3988
from collections import Counter

N = int(input())
s = []
t = []

for i in range(N):
    s.append(input())

M = int(input())

for i in range(M):
    t.append(input())

a = Counter(s)
b = Counter(t)

maxvalu = 0

for k,v in a.items():
    ans = a[k]
    if k in b:
        ans -= b[k]
    maxvalu = max(maxvalu,ans)

print(maxvalu)

Measured memory_bytes: 3316
// 8/22 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<map<int, int>>;

const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};

int H, W;
vector<string> field;

Graph G;

// int seen[1010][1010];
int color[1010][1010];
// int warp[1010][1010];

void dfs(int h, int w, int c = 0) {
    color[h][w] = c;

    // 移動A
    for (int dir = 0; dir < 4; dir++) {
        int nh = h + dh[dir];
        int nw = w + dw[dir];

        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (field[nh][nw] == '#') continue;

        if (color[nh][nw] != -1) continue;

        dfs(nh, nw, c);
    }

}

int main() {
    cin >> H >> W;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
    field.resize(H);
    rep(i, H) {
        cin >> field[i];
    }

    rep(h, H) rep(w, W) {
        // seen[h][w] = false;
        // warp[h][w] = -1;
        color[h][w] = -1;
    }

    int count = 0;
    rep(h, H) {
        rep(w, W) {
            if (field[h][w] == '#') continue;

            if (color[h][w] == -1) {
                dfs(h, w, count);
                count++;
            }
        }
    }

    // cout << "カラー" << endl;
    // rep(h, H) {
    //     rep(w, W) {
    //         cout << color[h][w];
    //     }
    //     cout << endl;
    // }

    G.resize(count);

    rep(h, H) {
        rep(w, W) {
            if (field[h][w] == '#') continue;

            int now = color[h][w];

            // 移動B
            for (int nh = h - 2; nh <= h + 2; nh++) {
                for (int nw = w - 2; nw <= w + 2; nw++) {
                    // printf("h, w, nh, nw = %d, %d, %d, %d\n", h, w, nh, nw);
                    if (nh == h && nw == w) continue;

                    if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
                    if (field[nh][nw] == '#') continue;

                    int next = color[nh][nw];

                    G[now][next]++;
                }
            }
        }
    }

    // 以下、bfs。
    int sc = color[ch][cw];  // スタート地点のカラー
    int gc = color[dh][dw];  // ゴール地点のカラー

    vector<int> dist(count, -1);
    queue<int> que;
    dist[sc] = 0;
    que.push(sc);

    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto p : G[v]) {
            int nv = p.first;
            if (dist[nv] == -1) {
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
    }

    if (dist[gc] != -1) cout << dist[gc] << endl;
    else cout << "-1" << endl;

    return 0;
}











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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define DI(v,i) distance((v).begin(),(auto(i)))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

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

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

    return 0;
}



Measured memory_bytes: 3644
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, t[20][20];
int dp[1 << 16];

signed main() {
    while(cin >> N, N) {
        rep(i,0,N) rep(j,0,N+1) cin >> t[i][j];
        rep(i,1,1<<N) dp[i] = INF;
        dp[0] = 0;

        rep(bit,0,1<<N) {
            vector<int> v; v.push_back(0);
            rep(i,0,N) if(bit >> i & 1) v.push_back(i+1);
            rep(i,0,N) {
                if(bit >> i & 1) continue;
                int mi = INF;
                for(auto x : v) {
                    if(x == i+1) continue;
                    chmin(mi, t[i][x]);
                }
                int nbit = bit | (1 << i);
                chmin(dp[nbit], dp[bit] + mi);
            }
        }
        cout << dp[(1<<N)-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define REP(i,n) for(long long i = 0;i < n;++i)
#define FOR(i,a,b) for(long long i = a;i < b;++i)
using namespace std;
using ll = long long;
using point = pair< int,int >;

int main(){
    int n;
    ll LCM, t;
    cin >> n;
    cin >> LCM;
    REP(i, n - 1) {
        cin >> t;
        LCM = (LCM / __gcd(LCM, t)) * t;
    }

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



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

using namespace std;
typedef long long int ll;



int main() {
   int n;
   cin>>n;
   int x;
   vector<pair<int, int>> d;
   for(int i =0; i<n; ++i){
       cin>>x;
       d.emplace_back(x, i+1);
   }
   sort(d.begin(), d.end());
   for(auto i:d){
       cout<<i.second<<" ";
   }
}




Measured memory_bytes: 1780
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int n,m,s,e,ans;
bool vis[303030];
vector<int>g[303030];/*
set<int>can[101010];
void dfs(int st,int now,int stp)
{
	if(stp==3)
	{
		can[st].insert(now);
		return;
	}
	for(int i=0;i<g[now].size();i++)
	{
		dfs(st,g[now][i],stp+1);
	}
}*/
void bfs()
{
	queue<int>q,b;
	q.push(s);
	b.push(0);
	vis[s]=true;
	while(!q.empty())
	{
		int x=q.front(),t=b.front();
		q.pop();
		b.pop();
		if(x==e)
		{
			cout<<t/3<<endl;
			exit(0);
		}
		for(int i=0;i<g[x].size();i++)
		{
			int it=g[x][i];
			if(!vis[it])
			{
				vis[it]=true;
				q.push(it);
				b.push(t+1);
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b+n);
		g[a+n].push_back(b+2*n);
		g[a+2*n].push_back(b);
	}
	cin>>s>>e;/*
	for(int i=1;i<=n;i++)
	{
		dfs(i,i,0);
	}*/
	bfs();
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 17024
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

bool ok(long long x, long long n){
  int sum = 0;
  long long x_orig = x;
  while(x>0){
    sum+=x%10;
    x /= 10;
  }
  return sum+x_orig==n;
}

int main(){
  int N;
  scanf("%d", &N);
  std::vector<long long > A(N), B(N);
  std::multimap<long long, int, std::greater<long long > > sum;
  for (int i=0; i<N; i++){
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    sum.insert(std::make_pair(A[i]+B[i], i));
  }
  long long Asum = 0;
  long long Bsum = 0;
  int counter = 0;
  for (auto &entry : sum){
    int index = entry.second;
    if(counter%2==0){
      Asum += A[index];
    } else {
      Bsum += B[index];
    }
    counter++;
  }
  std::cout << Asum-Bsum << std::endl;
  return 0;
}


Measured memory_bytes: 8064
function Main(input) {
  var inputArr = input.replace(/\n+$/, '').split(/\n/);
  var sum = 0;
  for(stay = 0; stay < inputArr[0]; stay++) {
    if (stay < inputArr[1]) {
      sum += Number(inputArr[2]);
    } else {  
      sum += Number(inputArr[3]);
    }    
  }
  console.log(sum);
}

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

Measured memory_bytes: 32356
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
    if(a < b) swap(a,b);
    if(a%b == 0) return b;
    else return (gcd(b,a%b));
}
int main() {
    int x,y;
    cin >> x >> y;
    cout << gcd(x,y) << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    map<int,int> m;
    int n; cin>>n;
    int a[n+1]; for(int i=1; i<=n; i++) cin>>a[i];
    for(int i=1; i<=n; i++){
        m[i-a[i]]++;
    }
    int ans=0;
    for(int i=1; i<=n; i++){
        m[i-a[i]]--;
        ans+=m[a[i]+i];
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 27912
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n, p / 2);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;
	N--;
	stack<char> st;
	while (N >= 26) {
		ll tmp = N % 26;
		/*
		if (tmp == 0) {
			tmp = 25;
		}
		else {
			tmp--;
		}
		*/
		st.push('a' + tmp);
		N /= 26;
		N--;
	}

	ll tmp = N % 26;
	/*
	if (tmp == 0) {
		tmp = 25;
	}
	else {
		tmp--;
	}
	*/
	st.push('a' + tmp);
	while (!st.empty()) {
		std::cout << st.top();
		st.pop();
	}
	std::cout << endl;
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll A,B,Query;
ll s[100005],t[100005];
//左0右1
ll dfs(bool LR,bool AB,ll now,ll n){
	ll ret=0;
	if(AB){
		ll to;
		ll in=lower_bound(s,s+A,now)-s; 
		if(!LR){
			if(now>s[A-1]){
				to=s[A-1];
			}else{
				to=s[in];
			}
		}else{
			if(now<=s[0]){
				to=s[0];
			}else{
				to=s[in-1];
			}
		}
		ret+=abs(to-now);
		if(n==1) return ret;
		ret+=min(dfs(0,0,to,n+1),dfs(1,0,to,n+1));
	}else{
		ll to;
		ll in=lower_bound(t,t+B,now)-t;
		if(!LR){
			if(now>t[B-1]){
				to=t[B-1];
			}else{
				to=t[in];
			}
		}else{
			if(now<=t[0]){
				to=t[0];
			}else{
				to=t[in-1];
			}
		}
		ret+=abs(to-now);
		if(n==1) return ret;
		ret+=min(dfs(0,1,to,n+1),dfs(1,1,to,n+1));
	}
	return ret;
}
int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>A>>B>>Query;
rep(i,A) cin>>s[i];
rep(i,B) cin>>t[i];
rep(i,Query){
ll x; cin>>x;
ll d1=0;
ll d2=0;
//神社firstならtrue
d1=min(dfs(0,1,x,0),dfs(1,1,x,0));
//寺firstならfalse
d2=min(dfs(0,0,x,0),dfs(1,0,x,0));
cout<<min(d1,d2)<<endl;

}

}
    


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

int main() {
  int N,i,sum=0;
  cin >> N;

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



Measured memory_bytes: 256
import java.util.*;
public class Main {
	//0040 start
	//0251 RE
	int INF = 1 << 24;
	int [] vx = {0,1,-1};
	int [] vy = {1,0,0};
	
	class State implements Comparable<State>{
		
		int cost, nowh, noww, cap;
		String state;
		public State(int cost, int nowh, int cap, String state, int noww) {
			this.cost = cost;
			this.nowh = nowh;
			this.cap = cap;
			this.state = state;
			this.noww = noww;
		}
		@Override
		public int compareTo(State o) {
			if(this.cost < o.cost) return -1;
			if(this.cost > o.cost)return 1;
			return 0;
		}
		@Override
		public String toString() {
			return "State [cost=" + cost + ", nowh=" + nowh + ", cap=" + cap
					+ ", state=" + state + "]";
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h) == 0) break;
			int f = sc.nextInt();
			int m = sc.nextInt();
			int o = sc.nextInt();
			int [][] data = new int[h][w];
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					data[i][j] = -1 * sc.nextInt();
				}
			}
			
			PriorityQueue<State> open = new PriorityQueue<Main.State>();
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < w; i++){
				sb.append('1');
			}
			StringBuilder none = new StringBuilder();
			for(int i = 0; i < w; i++){
				none.append('0');
			}
			for(int i = 0; i < w; i++){
				none.setCharAt(i, '1');
				open.add(new State(0, -1, o,none.toString(),i));
				none.setCharAt(i, '0');
				
			}
			int [][][][] close = new int[h][w][m + 1][1 << w];
			for(int i = 0; i < h; i++){
				for(int j = 0;j < w; j++){
					for(int k = 0; k <= m; k++){
						Arrays.fill(close[i][j][k], INF);
					}
				}
			}
			int ans = -1;
			while(! open.isEmpty()){
				State now = open.poll();
				if(now.nowh == h - 1){
					ans = now.cost;
					break;
				}
				
				for(int i = 0; i < 3; i++){
					int hh = now.nowh + vy[i];
					int ww = now.noww + vx[i];
					if(hh == -1) continue;
					if(ww < 0 || ww >= w) continue;
					
					int nextcost = now.cost;
					int nextcap = now.cap - 1;
					if(nextcap <= 0) continue;
					StringBuilder nextstate = new StringBuilder(now.state); 
					if(i == 0){
						nextstate = new StringBuilder(none.toString()); 
						if(data[hh][ww] > 0){
							nextcost += data[hh][ww];
						}
						else{
							nextcap = Math.min(m, nextcap - data[hh][ww]);
						}
						nextstate.setCharAt(ww, '1');
					}
					else if(now.state.charAt(ww) == '0'){
						if(data[hh][ww] > 0){
							nextcost += data[hh][ww];
						}
						else{
							nextcap = Math.min(m, nextcap - data[hh][ww]);
						}
						nextstate.setCharAt(ww, '1');
					}
					if(nextcost > f) continue;
					int nextstatenum = Integer.parseInt(nextstate.toString(), 2);
					if(close[hh][ww][nextcap][nextstatenum] <= nextcost) continue;
					open.add(new State(nextcost, hh, nextcap, nextstate.toString(), ww));
					close[hh][ww][nextcap][nextstatenum] = nextcost;
				}
			}//end while
			System.out.println(ans == -1 ? "NA" : ans );
		}
	}

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

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,M;
	cin>>N>>M;
    vector<ll> A(N);

    rep(i,N){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    typedef pair<ll,ll> P;
    vector<P> BC(M);
    ll b,c;
    rep(i,M){
        cin>>b>>c;
        BC[i] = P{b,c};
    }
    sort(BC.begin(),BC.end(),[](P p1,P p2){return p1.second>p2.second;});
    vector<ll> new_num(N);
    ll ind = 0;
    rep(i,M){
        b = BC[i].first;
        c = BC[i].second;
        rep(j,b){
            new_num[ind]=c;
            ++ind;
            if(ind==N) break;
        }
        if(ind==N) break;
    }

    // rep(i,N){
    //     cout<<new_num[i]<<" ";
    // }

    if(A[0]>=new_num[0]){
        ll ans= 0;
        rep(i,N){
            ans+= A[i];
        }
        cout<<ans<<"\n";
        return 0;
    }
    ll min_i = 0,max_i = N;
    ll tmp_i = (min_i+max_i)/2;

    while(min_i!=max_i-1){
        tmp_i = (min_i+max_i)/2;

        if(A[tmp_i]<new_num[tmp_i]){
            min_i = tmp_i;
        }else{
            max_i = tmp_i;
        }
    }
    ll ans = 0;
    rep(i,min_i+1){
        ans += new_num[i];
    }
    rep(i,N-(min_i+1)){
        ans += A[N-1-i];
    }
    cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
  #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
  #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct UnionFind {
  vector< int > data;
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main (void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<P> b(m); for (auto &e : b) cin >> e.first >> e.second;
  UnionFind uf(n);
  vector<ll> diff(m);
  eprintf("input ok\n");
  reprev (i, m) {
    // auto[x, y] = b[i]; x--; y--;
    int x, y; P p = b[i]; x = p.first - 1, y = p.second - 1;
    eprintf("%d %d\n", x, y);
    if (uf.find(x) != uf.find(y)) {
      diff[i] = (ll)uf.size(x) * uf.size(y);
      uf.unite(x, y);
    }
  }
  eprintf("uf ok\n");
  ll sum = 0;
  rep (i, m) {
    eprintf("%d: ", i);
    sum += diff[i];
    cout << sum << "\n";
  }
  return 0;
}

Measured memory_bytes: 3328
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    double[] x, y;
    double d1, d2, d3, di, a;
    int i;

    n = sc.nextInt();
    x = new double[n];
    y = new double[n];

    for(i = 0;i < n;i++){
      x[i] = sc.nextDouble();
    }
    for(i = 0;i < n;i++){
      y[i] = sc.nextDouble();
    }

    d1 = 0.0;
    d2 = 0.0;
    d3 = 0.0;
    di = 0.0;
    for(i = 0;i < n;i++){
      a = Math.abs(x[i] - y[i]);
      d1 += a;
      d2 += a * a;
      d3 += a * a * a;
      if(di < a)di = a;
    }

    System.out.println(d1);
    System.out.println(Math.sqrt(d2));
    System.out.println(Math.cbrt(d3));
    System.out.println(di);


    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}


Measured memory_bytes: 28948
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int n;
/*
int solve(int indx){
    if(indx == n)
        return 0;

    if(indx == n-1)
        return 0;

    if(dp[indx] != -1 )
        return dp[indx];
    if(indx == n-2)
       return dp[indx]= solve(indx+1) + abs(arr[indx] - arr[indx+1]);



   return dp[indx] = min(solve(indx+1)+abs(arr[indx] - arr[indx+1]), solve(indx+2)+abs(arr[indx] - arr[indx+2]));

}

*/





int main() {


    cin >> n;
    int arr[3];
    int dp[n][3];
    cin >> arr[0]>>arr[1] >> arr[2];
    dp[0][0] = arr[0];
    dp[0][1] = arr[1];
    dp[0][2] = arr[2];
    for(int i=1;i<n;i++){
        cin >> arr[0]>>arr[1] >> arr[2];

        dp[i][0] = arr[0] + max(dp[i-1][1] , dp[i-1][2]);
        dp[i][1] = arr[1] + max(dp[i-1][0] , dp[i-1][2]);
        dp[i][2] = arr[2] + max(dp[i-1][0] , dp[i-1][1]);

    }

   // memset(dp, -1 , sizeof(dp));
    cout << max(dp[n-1][0], max(dp[n-1][1] , dp[n-1][2]));
    return 0;
}


Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int m,w;
  while(cin>>m>>w,m||w){
    vector<Int> as(m),bs(w);
    for(Int i=0;i<m;i++) cin>>as[i];
    for(Int i=0;i<w;i++) cin>>bs[i];

    auto calc=[&](Int i,Int j)->Int{
      Int dif=abs(as[i]-bs[j]);
      return dif*(dif-30)*(dif-30);
    };

    Int s=1<<w;
    const Int INF = 1e15;    
    vector<Int> dp(s,-INF);
    dp[0]=0;
    for(Int i=0;i<m;i++){
      vector<Int> nx(s,-INF);
      for(Int b=0;b<s;b++){
	chmax(nx[b],dp[b]);
	for(Int j=0;j<w;j++){
	  if((b>>j)&1) continue;
	  chmax(nx[b|(1<<j)],dp[b]+calc(i,j));		   
	}
      }
      swap(dp,nx);
    }
    cout<<*max_element(dp.begin(),dp.end())<<endl;
  }  
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < N; i++) {
    cout << S.at(i);
    cout << T.at(i);
  }
  cout << "\n";
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main() {
	long long int  n, a, b, memo;
	char s[105][105];
	scanf("%lld%lld",&a,&b);
	printf("100 100\n");
	for (int i = 1; i <= 50; i++) {
		for (int j = 1; j <= 100; j++) {
			s[i][j] = '.';
		}
	}
	for (int i = 51; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			s[i][j] = '#';
		}
	}

	for (int i = 1; i <= 50; i++) {
		for (int j = 1; j <= 100; j++) {
			if (j % 2 == 0 && i % 2 == 1 && b != 1) { s[i][j] = '#'; b--; }
		}
	}
	for (int i = 51; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			if (j % 2 == 0 && i % 2 == 0 && a != 1) { s[i][j] = '.'; a--; }
		}
	}
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			printf("%c", s[i][j]);
		}
		printf("\n");
	}
}


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



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

    int count = 0;
    for(int i = 0; i < s.size() - 1; i++){
        if(s.at(i) != s.at(i + 1)) count++;
    }
    count += 2;  //文字列の最初と最後を値変化とみなす
    vector<int> sw(count); //値が変化した配列のインデックス（0->1 or 1->0）
    int s_n = 1;
    sw.at(0) = 0;
    for(int i = 0; i < s.size() - 1; i++){
        if(s.at(i) != s.at(i + 1)){
            sw.at(s_n) = i + 1;
            s_n++;
        }
    }
    sw.at(sw.size() - 1) = s.size();
    /*
    for(int i=0;i<sw.size();i++){
        cout << sw.at(i) << ' ' ;
    }
    cout << endl;
    */
    vector<int> length(sw.size());
    
    if(s.at(0) == '0' && 2 * k <= sw.size() - 1){
        length.at(0) = sw.at(2 * k);
    }else if(s.at(0) == '0' && 2 * k > sw.size() - 1){
        length.at(0) = sw.at(sw.size() - 1);
    }else if(s.at(0) == '1' && 2 * k + 1 <= sw.size() - 1){
        length.at(0) = sw.at(2 * k + 1);
    }else{
        length.at(0) = sw.at(sw.size() - 1);
    }
    
    for(int i = 1; i < sw.size() - 1; i++){
        if(s.at(sw.at(i)) =='1' && 2 * k + i + 1 <= sw.size() - 1){
            length.at(i) = sw.at(2 * k + i + 1) - sw.at(i);
        }else if(s.at(sw.at(i)) =='1' && 2 * k + i + 1 > sw.size() - 1){
            length.at(i) = sw.at(sw.size() - 1) - sw.at(i);
        }
    }
    int max_length = length.at(0);
    for(int i = 1; i < length.size(); i++){
        if(max_length <= length.at(i)) max_length = length.at(i);
    }
    cout << max_length << endl;  
}

Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int pay = 0;
    while(pay < N)
        pay += 1000;
    cout << pay - N << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    REP(i,N+1){
        if(int(i*1.08)==N){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int intersect(int l1, int r1, int l2, int r2){
	return max(0, min(r1,r2) - max(l1,l2));
}

int main(){
	int n;
	while (cin >> n && n){
		VVI in(1000), out(1000);
		while (n--){
			int M, D, h, m, p;
			char c;
			scanf("%d/%d %d:%d %c %d", &M, &D, &h, &m, &c, &p);
			int t = m + 60*h + 24*60*D + 31*24*60*M;
			if (c == 'I'){
				in[p].push_back(t);
			}else{
				out[p].push_back(t);
			}
		}
		VI s(1000);
		FOR(x,1,999){
			REP(i,in[x].size()){
				REP(j,in[0].size()){
					s[x] += intersect(in[x][i], out[x][i], in[0][j], out[0][j]);
				}
			}
		}
		sort(s.begin(), s.end());
		cout << s[999] << endl;
	}

    return 0;
}

Measured memory_bytes: 3244
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = a+b;
    if(c%2==0){
      System.out.println(c/2);
    }else{
      System.out.println("IMPOSSIBLE");
    }
    
  } 
}

Measured memory_bytes: 21332
n=int(input())
a=[int(i) for i in input().split()]

shain=[None]


class Worker:
    def __init__(self):
        self.buka=[]



for i in range(n):
    zako=Worker()
    shain.append(zako)
    
    
for i in range(2,n+1):
    shain[a[i-2]].buka.append(i)

for i in range(1,n+1):
    print(len(shain[i].buka))

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

int main() {
  string S;
  cin >> S;
  
  int i=0;
  if(S.at(i)=='a' || S.at(i)=='i'||S.at(i)=='u'||S.at(i)=='e'||S.at(i)=='o'){
    cout << "vowel" << endl;
   }else{
  	cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3544
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	const int s = 1299710;
	vector<bool> prime(s, true);
	prime[0] = false; prime[1] = false;
	REP(i, s) {
		if (prime[i]) {
			for (int j =2; i*j < s; ++j)prime[i*j] = false;
		}
	}

	while (1) {
		int n;
		cin >> n;
		if (!n)break;
		int cnt1 = 0, cnt2 = 0;
		FOR(i, n, s) {
			if (!prime[i])cnt1++;
			else break;
		}
		RFOR(i, 0, n) {
			if (!prime[i])cnt2++;
			else break;
		}
		if (prime[n])cout << 0 << endl;
		else cout << cnt1 + cnt2 + 1 << endl;
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  
  for(int i = 1; i <= pow(N-1, 0.5); i++){
    ans += ((N-1)/i) * 2 - 1;
  }
  if(N >= 5){
    for(int i = 1; i <= pow(N - 1, 0.5) - 1; i++){
      ans -= i * 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4064
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}


// ----------------------------------------------------------------------------
int main(){
  string S;
  cin >> S;
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    string co;
    cin >> co;
    int a,b;
    cin >> a >> b;
    if(co[2] == 'i'){
      cout << S.substr(a,b-a+1) << endl;
    }else if(co[2] == 'p'){
      string T;
      cin >> T;
      S = S.substr(0,a) + T + S.substr(b+1,S.size()-a-1);
    }else if(co[2] == 'v'){
      string re;
      re = S.substr(a,b-a+1);
      reverse(re.begin(),re.end());
      S = S.substr(0,a) + re + S.substr(b+1,S.size()-a-1);
    }
  }
  return 0;
}



Measured memory_bytes: 3220
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<ll> A(N-1);
    rep(i,N-1) cin >> A[i];
    vector<vector<ll>> B(M, vector<ll>(N));
    rep(i,N) rep(j,M) cin >> B[j][i];

    vector<vector<ll>> C(N+1, vector<ll>(N+2));
    vector<int> idx(N);
    rep(i,M) {
        iota(all(idx),0);
        sort(all(idx),[&](int a, int b){return B[i][a] > B[i][b];});
        set<int> dic;
        dic.emplace(-1);
        dic.emplace(N);
        rep(j,N) {
            int u = idx[j];
            auto it = dic.lower_bound(u);
            int l = *prev(it)+1;
            int r = *it;
            C[l][u+1] += B[i][u];
            C[u+1][u+1] -= B[i][u];
            C[l][r+1] -= B[i][u];
            C[u+1][r+1] += B[i][u];
            dic.emplace(u);
        }
    }
    rep(i,N-1) {
        C[0][i+2] -= A[i];
        C[i+1][i+2] += A[i];
        C[0][N+1] += A[i];
        C[i+1][N+1] -= A[i];
    }
    rep(i,N+1) rep(j,N+1) C[i][j+1] += C[i][j];
    rep(j,N+2) rep(i,N) C[i+1][j] += C[i][j];
    ll ans = 0;
    rep(l,N) {
        for (int r = l+1; r <= N; r++) chmax(ans,C[l][r]);
    }

    cout << ans << ln;
}

Measured memory_bytes: 206080
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int nums[] = IntStream.rangeClosed(1,n).toArray();

    double oddSum = 0;
    for (int i=0; i < n; i++) {
      if (nums[i] % 2 != 0) {
        oddSum = oddSum + 1;
      }
    }
    System.out.println(oddSum / n);
  }
}


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

#define ll long long

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

    int n;
    cin >> n;
    if(n == 0)cout << 1 <<"\n";
    else if(n == 1) cout << 0 << "\n";

    return 0;
}


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

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

using namespace std;
using lint=long long;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size(){ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n; cin>>n;
	vector<int> x(n),y(n);
	rep(i,n) cin>>x[i]>>y[i];

	vector<pair<int,int>> X(n),Y(n);
	rep(i,n){
		X[i]={x[i],i};
		Y[i]={y[i],i};
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());

	vector<pair<int,pair<int,int>>> E;
	rep(i,n-1){
		E.emplace_back(X[i+1].first-X[i].first,make_pair(X[i].second,X[i+1].second));
		E.emplace_back(Y[i+1].first-Y[i].first,make_pair(Y[i].second,Y[i+1].second));
	}
	sort(E.begin(),E.end());

	lint ans=0;
	union_find U(n);
	for(auto e:E){
		int u=e.second.first,v=e.second.second;
		if(!U.is_same(u,v)){
			U.unite(u,v);
			ans+=e.first;
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 7156
#include <stdio.h>
int main(void){

    int H,W,h,w;
    int all=0;
    
    scanf("%d",&H);
    scanf("%d",&W);
    scanf("%d",&h);
    scanf("%d",&w);
    

    
    all=H*W-(w*H)-(h*(W-w));
    
    printf("%d",all);
}

Measured memory_bytes: 128
S = input()
L = len(S)
a = int((L - 1) / 2)
b = int((L+3)/2)
S_first = S[:a]
S_second = S[(b-1):]
if S_first == S_second[::-1]:
    L_2 = len(S_first)
    if L_2 % 2 == 1:  # 半分が奇数
        a_2 = int((L_2 - 1) / 2)
        b_2 = int((L_2 + 3) / 2)
        S_first_f = S_first[:a_2]
        S_first_s = S_first[(b_2 - 1):]
        if S_first_f == S_first_s[::-1]:
            print('Yes')
        else:
            print('No')
    else:  # 半分が偶数
        a_2 = int(L_2 / 2)
        b_2 = int((L_2 + 1) / 2)
        S_first_f = S_first[: a_2]
        S_first_s = S_first[(b_2):]
        if S_first_f == S_first_s[::-1]:
            print('Yes')
        else:
            print('No')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> H(N);
	rep(i,N)cin >> H[i];
	rep(i,N-1){
		if(H[i]==H[i+1])continue;
		else if(H[i]<H[i+1]){
			H[i+1]--;
		}else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>
using namespace std;
#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 rep_r(i,s,n)for(int i = n;i>s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

ll x[50];
ll y[50];
map<pair<ll,ll>, ll> m;


int main() {
	ll n; cin >> n;
	rep(i, 0, n)cin >> x[i] >> y[i];
	ll maxV = 0;
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (i != j) {
				maxV = max(maxV,++m[{x[j] - x[i],y[j] - y[i]}]);
			}
		}
	}
	cout << n- maxV << endl;

	//pair<ll,ll> pq;
	//ll maxV	 = 0;
	//for (map<pair<ll,ll>, ll>::iterator it = m.begin(); it != m.end(); it++) {
	//	maxV = max(maxV, it->second);
	//}
	//cout << n - maxV << endl;


	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1LL<<50);


void solve(long long N, std::string A, std::string B, std::string C){
    ll ans=0;
    REP(N){
        set<char> a;
        a.insert(A[i]);
        a.insert(B[i]);
        a.insert(C[i]);
        ans+=a.size()-1;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string A;
    std::cin >> A;
    std::string B;
    std::cin >> B;
    std::string C;
    std::cin >> C;
    solve(N, A, B, C);
    return 0;
}


Measured memory_bytes: 256
N, Y = map(int ,input().split())

for i in range(N+1):
    for j in range(N+1):
        c = N - i - j
        if 0<= c <= 2000 and (10000*i + 5000*j + c*1000) == Y:
            print(i,j,c)
            exit()

print('-1 -1 -1')

Measured memory_bytes: 9168
#include <queue>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { 1, 0, -1, 0 };
struct state { int x, y, over; };
const int inf = 1012345678;
int main() {
	int H, W;
	while (cin >> W >> H, H) {
		vector<string> S(H);
		for (int i = 0; i < H; ++i) {
			cin >> S[i];
		}
		bool stable = true;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (S[i][j] == '.') continue;
				vector<vector<bool> > vis(H, vector<bool>(W));
				vis[i][j] = true;
				deque<state> que;
				que.push_back(state{ i, j, 0 });
				int L = inf, R = -inf, sum = 0, cnt = 0;
				while (!que.empty()) {
					state u = que.front(); que.pop_front();
					sum += u.y;
					++cnt;
					for (int k = 0; k < 4; ++k) {
						int tx = u.x + dx[k], ty = u.y + dy[k];
						if (0 <= tx && tx < H && 0 <= ty && ty < W && !vis[tx][ty] && (S[tx][ty] == S[u.x][u.y] || (k == 3 && S[tx][ty] != '.'))) {
							vis[tx][ty] = true;
							if (S[tx][ty] == S[u.x][u.y]) {
								que.push_front(state{ tx, ty, u.over });
							}
							else {
								que.push_back(state{ tx, ty, u.over + 1 });
							}
						}
						if (u.over == 0 && k == 1 && (tx == H || (S[tx][ty] != '.' && S[tx][ty] != S[u.x][u.y]))) {
							L = min(L, u.y);
							R = max(R, u.y + 1);
						}
					}
				}
				sum = sum * 2 + cnt;
				cnt *= 2;
				if (!(L * cnt < sum && sum < R * cnt)) {
					stable = false;
				}
			}
		}
		cout << (stable ? "STABLE" : "UNSTABLE") << endl;
	}
	return 0;
}


Measured memory_bytes: 3172