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

using namespace std;

const int N = 5e3 + 10;
const int M = 205;

struct segtree
{
  int n;
  vector<int> base;
  vector<int> c;
  void init(vector<int> sd)
  {
    n = 1;
    while(n < (int) sd.size()) n <<= 1;
    base = sd;
    c = vector<int> (n << 1, 0);
  }
  void update(int node, int l, int r, int ind)
  {
    if(l > ind || r < ind) return;
    if(l == r)
    {
      c[node] = ind;
      return;
    }
    update(node << 1, l, (l + r) / 2, ind);
    update((node << 1) + 1, (l + r) / 2 + 1, r, ind);
    c[node] = base[c[node << 1]] > base[c[(node << 1) + 1]] ? c[node << 1] : c[(node << 1) + 1];
  }
  void update(int ind)
  {
    update(1, 0, n - 1, ind);
  }
  int rmq(int node, int l, int r, int i, int j)
  {
    if(l > j || r < i) return -1;
    if(l >= i && r <= j) return c[node];
    int p1 = rmq(node << 1, l, (l + r) / 2, i, j), p2 = rmq((node << 1) + 1, (l + r) / 2 + 1, r, i, j);
    if(p1 == -1) return p2;
    if(p2 == -1) return p1;
    return base[p1] > base[p2] ? p1 : p2;
  }
  int rmq(int i, int j)
  {
    return rmq(1, 0, n - 1, i, j);
  }
  int getVal(int i)
  {
    return base[i];
  }
} st[M];

vector<vector<long long>> imos(N, vector<long long> (N, 0));

void solve(int m, int l, int r)
{
  if(l > r) return;
  int pos = st[m].rmq(l, r);
  imos[l][pos] += (long long) st[m].getVal(pos);
  imos[pos + 1][pos] -= (long long) st[m].getVal(pos);
  imos[l][r + 1] -= (long long) st[m].getVal(pos);
  imos[pos + 1][r + 1] += (long long) st[m].getVal(pos);
  solve(m, l, pos - 1);
  solve(m, pos + 1, r);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n - 1);
  for(int i = 0; i < n - 1; i++)
  {
    cin >> a[i];
  }
  vector<vector<int>> B(m, vector<int> (n, 0));
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < m; j++)
    {
      cin >> B[j][i];
    }
  }
  for(int i = 0; i < m; i++) st[i].init(B[i]);
  for(int i = 0; i < m; i++)
  {
    for(int j = 0; j < n; j++)
    {
      st[i].update(j);
    }
  }
  for(int i = 0; i < m; i++)
  {
    solve(i, 0, n - 1);
  }
  for(int i = 0; i <= n; i++)
  {
    for(int j = 1; j <= n; j++)
    {
      imos[i][j] += imos[i][j - 1];
    }
  }
  for(int i = 1; i <= n; i++)
  {
    for(int j = 0; j <= n; j++)
    {
      imos[i][j] += imos[i - 1][j];
    }
  }
  long long ans = 0;
  for(int i = 0; i < n; i++)
  {
    long long cur = 0;
    ans = max(ans, imos[i][i]);
    for(int j = i + 1; j < n; j++)
    {
      cur += (long long) a[j - 1];
      imos[i][j] -= cur;
      ans = max(ans, imos[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 217344
#include<stdio.h>
int main(void){
	int N = 0;
	int A[100005] = { 0 };

	scanf("%d", &N);
	for (int i = 0; i < N; i++){
		int a = 0;
		scanf("%d", &a);
		if (a != 0)
			A[a - 1]++;
		A[a]++;
		A[a + 1]++;
	}
	int max = 0;
	for (int i = 0; i < 100000; i++){
		max = max < A[i] ? A[i] : max;
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;

    if(s.length() <= n) {
        cout << s << endl;
    } else {
        cout << s.substr(0, n) << "..." << endl;
    }
}


Measured memory_bytes: 3656
using System;

class Program
{
	static void Main()
	{
		string[] D = Console.ReadLine().Split(' ');
		int a = int.Parse(D[0]), b = int.Parse(D[1]);
		Console.WriteLine("{0} {1} {2}", a / b, a % b, ((double)a / b).ToString("F5"));
	}
}

Measured memory_bytes: 7728
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,K;
  cin >> n >> K;
  ll v[n+1]={};
  rep(i,n)cin >> v[i+1];
  ll l[n+1]={},r[n+1]={};
  rep(i,n){
    l[i+1]=l[i]+v[i+1];
  }
  rep(i,n+1){
    r[i]=l[n]-l[n-i];
  }
  ll ans=0;
  for(int i=0;i<=min(K,n);i++){
    for(int j=0;j<=i;j++){
      ll sum=0;
      vector<ll> vec;
      vec.clear();
      if(j>0){
        for(int k=1;k<=j;k++)vec.push_back(v[k]);
      }
      if(j<i){
        for(int k=n-i+j+1;k<=n;k++)vec.push_back(v[k]);
      }
      sort(vec.begin(),vec.end());
      int temp=0;
      while(temp<K-i && temp<vec.size() && vec[temp]<0){
        sum-=vec[temp];
        temp++;
      }
      ans=max(ans,sum+l[j]+r[i-j]);
    }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)

int main(){

	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt	
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif	

    FAST
//	PRECISE

ll n;
cin>>n;
ve <ll> v(100000+1);
ll sum=0;
FOR(i,0,n){
	ll x;
	cin>>x;
	sum+=x;
	v[x]++;
}
ll q;
cin>>q;
FOR(i,0,q){
	ll b,c;
	cin>>b>>c;
	sum-=b*v[b];
	sum+=c*v[b];
	v[c]+=v[b];
	v[b]=0;
	cout<<sum<<"\n";
}

return 0;
 }

Measured memory_bytes: 3984
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
set<string> S;
int main()
{
    string s;
    int k;
    cin>>s;
    scanf("%d",&k);
    char t='a';
    while(S.size()<k)
    {
        for (int i=0;i<s.size();i++)
        {
            if (s[i]==t)
            for (int j=1;j<=s.size()-i;j++)
            {
                string h=s.substr(i,j);
                set<string>::iterator iit=S.begin();
                S.insert(h);
                int flag=0;
                for (int o=0;o<k&&iit!=S.end();o++,iit++)
                    if (*iit==h) flag=1;
                if (flag==0&&S.size()>=k) break;
            }
        }
        t++;
    }
    set<string>::iterator it=S.begin();
    for (int i=1;i<k;i++,it++);
    cout<<*it<<endl;
    return 0;
}


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

using namespace std;
int n, b;
string s[105];
int main()
{
	cin >> n >> b;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s, s + n);
	for(int i = 0; i < n; i++){
		cout << s[i];
	}
    return 0;
}


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

const double PI = 4.0 * atan(1.0);

int
main()
{
	double r;
	scanf("%lf", &r);

	double area          = PI*r*r;
	double circumference = 2*PI*r;
	printf("%f %f\n", area, circumference);

	return 0;
}

Measured memory_bytes: 648
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(A);
            var max = A[N - 1] + 1;
            var answer = new bool[max];
            var tmp = new bool[max];
            foreach (var n in A)
            {
                if (answer[n]) answer[n] = false;
                if (tmp[n]) continue;
                answer[n] = true;
                for (var i = n; i < tmp.Length; i += n)
                {
                    tmp[i] = true;
                }
            }
            Console.WriteLine(answer.Count(x => x));
        }
    }
}


Measured memory_bytes: 45580
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int x=scan.nextInt();
        int outpint;
        
        while(!(n==0&&x==0)){
            outpint=0;
            for(int i=1; i<n-1; i++)
                for(int j=i+1; j<n; j++)
                    for(int k=j+1; k<n+1; k++){
                        if(i+j+k==x)
                            outpint++;
                    }
            
            n=scan.nextInt();
            x=scan.nextInt();
        System.out.println(outpint);
        }
    }
}


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

#define nl '\n'
#define op ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
   op;
   int n,i=1;
   cin>>n;
   while(i*2<=n)
   {
      i*=2;
   }
   cout<<i<<nl;
   return 0;
}


Measured memory_bytes: 3644
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;


int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i=i+2)
    cout<<s[i];

    return 0;
}    

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

using namespace std;
#define EB emplace_back
#define MP make_pair
typedef long long ll;
#define rep(i, a, b) for(ll i = a; i < b; ++i)

int main() {

   ll n , k ;
   cin >> n >> k;
   ll arr[n] ;
   rep(i, 0, n){
    cin >> arr[i];
   }
   sort(arr,arr + n);


    ll res = n - k;
    if(n - k <= 0)
        res = 0;
    ll sum = 0;
    rep(j, 0, res){
        sum += arr[j];
    }

    cout << sum ;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class MainClass
{
    static int[] dx = new int[4] { 1, 0, -1, 0 };
    static int[] dy = new int[4] { 0, 1, 0, -1 };
    static bool[,] frags;
    static void Main()
    {
        var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sx = r[0] + 1010, sy = r[1]+1010, tx = r[2]+1010, ty = r[3]+1010;
        string ans = "";
        frags = new bool[2020, 2020];

        for (int k = 0; k < 4; k++)
        {
            int[,] map = new int[2020, 2020];
            var que = new Queue<Tuple<int, int, int>>();
            que.Enqueue(Tuple.Create(sy, sx, 1));
            map[sy, sx] = 1;
            frags[ty, tx] = false;
            while (que.Count > 0)
            {
                var t = que.Dequeue();
                int y = t.Item1;
                int x = t.Item2;
                int c = t.Item3;
                for (int i = 0; i < 4; i++)
                {
                    int ny = y + dy[i];
                    int nx = x + dx[i];
                    if (0 <= ny && ny < 2020 && 0 <= nx && nx < 2020)
                    {
                        if (map[ny, nx] == 0 && !frags[ny, nx])
                        {
                            map[ny, nx] = c + 1;
                            que.Enqueue(Tuple.Create(ny, nx, c + 1));
                        }
                    }
                }
                if (map[ty, tx] != 0) break;
            }
            ans += Search(map, ty, tx);

            Swap(ref sy, ref ty);
            Swap(ref sx, ref tx);
        }
        Console.WriteLine(ans);
    }
    static string Search(int[,] map ,int y,int x)
    {
        char[] way = new char[4] { 'L', 'D', 'R', 'U' };
        int count = map[y, x];
        string res = "";
        while (count > 1)
        {
            frags[y, x] = true;
            for (int i = 0; i < 4; i++)
            {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (map[ny, nx] == count - 1)
                {
                    res += way[i];
                    frags[ny, nx] = true;
                    y = ny;
                    x = nx;
                    
                    break;
                }
            }
            count--;
        }
        return string.Join("",res.Reverse());
    }

    static void Swap(ref int a,ref int b)
    {
        int temp = a;
        a = b;
        b = temp;
    }
}

Measured memory_bytes: 111820
#include<iostream>

#include<stdio.h>

using namespace std;


int main(){

	int  d, r;

	double  a, b, f;

	cin >> a >> b;
	 
	int j = a;
	int k = b;

	d = a / b;
	r = j%k;
	f = a / b;

	cout << d <<" "<< r<<" ";
	printf("%.8lf\n", f);
	return 0;
}



Measured memory_bytes: 3236
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
d = 0
for i in range(n):
  if b[i] > a[i]:
    c += (b[i] - a[i]) // 2
  else:
    d += a[i] - b[i]
print(['Yes', 'No'][c < d])

Measured memory_bytes: 40560
# ABC158b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, a, b = map(int, input().split())
    loo = n // (a + b)
    wa = n - loo * (a + b)
    #print(loo, wa)

    print(loo*a+min(wa, a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i < (int)n; i++)
#define Loopr(i, n) for(int i= (int)n - 1; i >= 0; i--)
using namespace std;
typedef long long int ll;

struct node {
	int parent, left, right;
};

int n;
vector<node> nodes(100000, { -1,-1,-1 });

int depth(int id) {
	if (nodes[id].parent == -1) return 0;
	else return depth(nodes[id].parent) + 1; 
}

void print(int id) {
	int d;
	string t;
	d = depth(id);
	int buf = nodes[id].left;
	if (d == 0) t = "root";
	else if (buf == -1) t = "leaf";
	else t = "internal node";
	cout << "node " << id << ": parent = "<< nodes[id].parent
		<<", depth = " << d << ", " << t << ", [";
	if (buf != -1) {
		cout << buf;
		while (nodes[buf].right != -1) {
			cout << ", " << nodes[buf].right;
			buf = nodes[buf].right;
		}
	}
	cout << "]" << endl;
}

int main() {
	cin >> n;
	Loop(i, n) {
		int id, dim, buf, buf2;
		cin >> id >> dim;
		Loop(j, dim) {
			if (j == 0) {
				cin >> buf;
				nodes[id].left = buf;
			}
			else {
				cin >> buf2;
				nodes[buf].right = buf2;
				buf = buf2;
			}
			nodes[buf].parent = id;
		}
	}
	Loop(i, n) print(i);
	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

using weight = int;

struct edge {
    int to;
    weight cap;
    int rev;
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;

void add_edge(graph& g, int from, int to, weight cap) {
    g[from].push_back(edge{to, cap, static_cast<int>(g[to].size())});
    g[to].push_back(edge{from, 0, static_cast<int>(g[from].size()-1)});
}

void bfs(graph& g, std::vector<int>& level, int s) {
    for(int i=0; i<level.size(); ++i) {
        level[i] = -1;
    }
    level[s] = 0;
    std::queue<weight> que;
    que.push(s);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for(int i=0; i<g[v].size(); ++i) {
            edge& e = g[v][i];
            if(e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

weight dfs(graph& g, std::vector<int>& level, std::vector<int>& iter, int v, int t, weight f) {
    if(v == t) {
        return f;
    }
    for(int& i=iter[v]; i<g[v].size(); ++i) {
        edge& e = g[v][i];
        if(e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(g, level, iter, e.to, t, std::min(f, e.cap));
            if(d > 0) {
                e.cap -= d;
                g[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

weight max_flow(graph& g, int s, int t) {
    weight flow = 0;
    std::vector<int> level(g.size(), -1);
    std::vector<int> iter(g.size(), 0);
    int INF = 1e9;
    while(true) {
        bfs(g, level, s);
        if(level[t] < 0) {
            return flow;
        }
        for(int i=0; i<iter.size(); ++i) {
            iter[i] = 0;
        }
        weight f;
        while((f = dfs(g, level, iter, s, t, INF)) > 0) {
            flow += f;
        }
    }
}

int gcd(int m, int n) {
    if((m == 0 || n == 0)) {
        return 0;
    }
    while(m != n) {
        if(m > n) m = m-n;
        else      n = n - m;
    }
    return m;
}

int main() {
    int m, n;
    while(cin >> m >> n, m) {
        vector<int> b(m), r(n);
        graph g(m+n+2);
        for(int i=0; i<m; ++i) {
            cin >> b[i];
        }
        for(int i=0; i<n; ++i) {
            cin >> r[i];
        }
        for(int i=0; i<m; ++i) {
            add_edge(g, 0, i+1, 1);
        }
        for(int i=0; i<n; ++i) {
            add_edge(g, m+i+1, m+n+1, 1);
        }
        for(int i=0; i<m; ++i) {
            for(int j=0; j<n; ++j) {
                if(gcd(b[i], r[j]) != 1) {
                    add_edge(g, i+1, m+j+1, 1);
                }
            }
        }
        cout << max_flow(g, 0, m+n+1) << endl;
    }
}


Measured memory_bytes: 7360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 300100;

ll T,N,a,b,c,d,e,f,K,t,M;
ll A[MAXN];

int main(){
  cin>>N>>a;
  N%=a;
  ll opp = a-N;
  cout<<min(N,opp);
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

h, a = na()

if h % a == 0:
    print(h // a)
else:
    print(h // a + 1)

Measured memory_bytes: 38256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 10000000;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 100005;

int D[3][MX], T[3][MX];

int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D[1]+i);
	for(int i = 1; i <= N; i++) scanf("%d", D[2]+i);
	for(int i = 1; i <= 2; i++){
		for(int j = 1; j <= N; j++){
			T[i][j] = max(T[i-1][j], T[i][j-1]) + D[i][j];
		}
	}
	printf("%d\n", T[2][N]);
}


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

int main(void){
    int n;
    int i = 0;
    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;
    char str[3];
    scanf("%d", &n);
    while(i < n){
        scanf("%s", str);
        if(str[0] == 'A' && str[1] == 'C'){
            AC++;
        }else if(str[0] == 'W' && str[1] == 'A'){
            WA++;
        }else if(str[0] == 'T' && str[1] == 'L' && str[2] == 'E'){
            TLE++;
        }else if(str[0] == 'R' && str[1] == 'E'){
            RE++;
        }
        i++;
    }
    printf("AC x %d\n", AC);
    printf("WA x %d\n", WA);
    printf("TLE x %d\n", TLE);
    printf("RE x %d\n", RE);

}


Measured memory_bytes: 1704
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;

const int MAX_N = 205;

class Edge {
public:
  int nxt, to;
} e[MAX_N * MAX_N];

int head[MAX_N], cnt;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
}

bool isprime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}

int N, pos[MAX_N], tot, val[MAX_N], match[MAX_N];
map<int, bool> vis;
bool bad[MAX_N];

bool dfs(int x) {
  if (bad[x]) return false;
  bad[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt)
    if (!match[e[i].to] || dfs(match[e[i].to])) {
      match[e[i].to] = x;
      return true;
    }
  return false;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) 
    scanf("%d", &pos[i]);
  pos[0] = -1;
  for (int i = 1; i <= N; ++i) {
    if (pos[i - 1] != pos[i] - 1) val[++tot] = pos[i];
    if (pos[i + 1] != pos[i] + 1) val[++tot] = pos[i] + 1;
  }
  
  int odd = 0, even = 0;
  
  for (int i = 1; i <= tot; ++i)
    if (val[i] & 1) {
      odd++;
      for (int j = 1; j <= tot; ++j)
	if (!(val[j] & 1) && abs(val[i] - val[j]) > 1 && isprime(abs(val[i] - val[j])))
	  addedge(i, j);
    } else {
      even++;
    }

  int num = 0;
  for (int i = 1; i <= tot; ++i) 
    if (val[i] & 1) {
      memset(bad, 0, sizeof bad);
      num += dfs(i);
    }

  printf("%d\n", num + ((odd - num) / 2 + (even - num) / 2) * 2 + (odd - num) % 2 * 3);
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
ans = -float('inf')
for bit in list(product([0, 1], repeat=10))[1:]:
    v = 0
    for ff, pp in zip(f, p):
        cnt = 0
        for i, check in enumerate(ff):
            if bit[i] == check == 1:
                cnt += 1
        v += pp[cnt]
    if ans < v:
        ans = v
print(ans)


Measured memory_bytes: 3188
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 720720
#define yes cout << "Yes\n"
#define no cout << "No\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 100005;

int c = 1;

void solve() {
    int x;
    cin >> x;
    auto ok = [&]() -> bool {
        for(int i = 2; i * i <= x; i++) {
            if(x % i == 0) return 0;
        }
        return 1;
    };
    for(int i = x; ; i++) {
        if(ok()) {
            printf("%d\n", i); return;
        }
        x++;
    }
    return;
}

int main() {
    /*int tc;
    scanf("%d", &tc);
    while(tc-- > 0)*/
    solve();
    return 0;
}


Measured memory_bytes: 3752
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
using namespace std;
int a[100050];
map<int,int>b;
map<int,int>c;
int main(){
	int n,sum;
	sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(c[a[i]]==0){
			if(b[a[i]]>a[i]) sum=sum+abs(b[a[i]]-a[i]);
			else if(b[a[i]]<a[i]) sum=sum+b[a[i]];
		}
		c[a[i]]=1;
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define this-> tt
#define long long ll
using namespace std;
int main ()
{
int g;
cin>>g;
if (g%10==2||g%10==4||g%10==5||g%10==7||g%10==9)cout<<"hon"<<endl;
else if (g%10==0||g%10==1||g%10==6||g%10==8)cout<<"pon"<<endl;
else cout<<"bon"<<endl;






    return 0;
}

/*
▀█████████▄     ▄████████    ▄████████    ▄████████
  ███    ███   ███    ███   ███    ███   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
 ▄███▄▄▄██▀    ███    ███  ▄███▄▄▄▄██▀   ███    ███
▀▀███▀▀▀██▄  ▀███████████ ▀▀███▀▀▀▀▀   ▀███████████
  ███    ██▄   ███    ███ ▀███████████   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
▄█████████▀    ███    █▀    ███    ███   ███    █▀
                            ███    ███

*/


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

int main(){
	int n;
	string s, t; cin >> n >> s >> t;
	for(int i = 0; i < s.size(); ++i){
		if(s.substr(i, s.size() - i) == t.substr(0, s.size() - i)){
			cout << s.size() + i << endl;
			return 0;
		}
	}
	cout << 2 * n << endl;
	return 0;
}

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

using namespace std;

int main() {
  long long n, m, x;
  cin >> n >> m >> x;
  long long a[n], b[m];
  for(long long i = 0; i < n; i++) cin >> a[i];
  for(long long i = 0; i < m; i++) cin >> b[i];

  long long ans = 0, sum = 0, i = 0, j = 0;
  while(i < n && sum + a[i] <= x) {
    sum += a[i];
    i++;
  }
  ans = i;

  while(j < m && i >= 0) {
    sum += b[j];
    j++;
    while(sum > x && i > 0) {
      i--;
      sum -= a[i];
    }
    if(sum <= x && i + j > ans) ans = i + j;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class AFiftyFifty
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray().Select(x => x.ToString()).ToList();

            var sDic = new Dictionary<string, int>();
            for (int i = 0; i < s.Count; i++)
            {
                if (sDic.ContainsKey(s[i]))
                {
                    sDic[s[i]]++;
                    if (2 < sDic[s[i]])
                    {
                        Console.WriteLine("No");
                        Console.ReadLine();
                        return;
                    }
                }
                else
                {
                    sDic.Add(s[i], 0);
                    if (2 < sDic.Count)
                    {
                        Console.WriteLine("No");
                        Console.ReadLine();
                        return;
                    }
                }
            }

            Console.WriteLine("Yes");
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int n;
string s;
map<string,int> m={{"AC",0},{"WA",0},{"TLE",0},{"RE",0}};
string a[4]={"AC","WA","TLE","RE"};
void test() {
    cin>>n;
    for (int i=0; i<n; ++i) {
        cin>>s;
        ++m[s];
    }
    for (int i=0; i<4; ++i) {
        cout<<a[i]<<" x "<<m[a[i]]<<endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int t; cin>>t;
    // while (t--) {
    //     test();
    // }
    test();
    // for (int i=1; i<=t; ++i) {
    //     cout<<"Case #"<<i<<": ";
    //     test();
    // }
    return 0;
}

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

string s, t = "CODEFESTIVAL2016";

int main() {
  cin >> s;
  int res = 0;
  for (int i = 0; i < s.size(); ++i) res += s[i] != t[i];
  cout << res << endl;
  return 0;
}


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

//#define int long long

using namespace std;

const int maxn = 1005;
vector<int> adj[maxn];

int color[maxn]; // 0 = white, 1 = gray, 2 = black
int par[maxn];
int dist[maxn];

vector<vector<int>> cycles;

void dfs(int u) {
    color[u] = 1;

    //cout << "dfs " << u << '\n';

    for (int v : adj[u]) {
        //cout << v<< " has color " << color[v] << '\n';
        if (color[v] == 1) {
            vector<int> s;
            s.push_back(v);
            for (int p = u; p != v; p = par[p]) {
                s.push_back(p);
            }
            cycles.push_back(s);
        }
    }

    for (int v : adj[u]) {
        if (color[v] != 0) continue;
        par[v] = u;
        dist[v] = dist[u] + 1;
        dfs(v);
    }

    color[u] = 2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;


    for (int i = 0; i <= n; i++) {
        color[i] = 0;
        par[i] = 0;
    }

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    for (int i = 1; i <= n; i++) {
        if (color[i] == 0) {
            dfs(i);
        }
    }

    for (vector<int> cyc : cycles) {
        bool vis[maxn];
        int indeg[maxn];
        int outdeg[maxn];
        for (int i = 0; i <= maxn; i++) {
            vis[i] = false;
            indeg[i] = 0;
            outdeg[i] = 0;
        }
        for (int i : cyc) vis[i] = true;
        for (int u : cyc) for (int v : adj[u]) if (vis[v]) {
            indeg[v]++;
            outdeg[u]++;
        }
        bool flag = false;
        for (int i : cyc) {
            if (indeg[i] != 1 || outdeg[i] != 1) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            cout << cyc.size() << '\n';
            for (int i : cyc) cout << i << '\n';
            exit(0);
        }
    }
    cout << "-1\n";
}
/*

 */

Measured memory_bytes: 3712
#!/usr/bin/env python3
import sys


def solve(S: str, T: str):
    ans = 0
    for i in range(len(S)):
        if S[i]!=T[i]:
            ans+=1
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


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

int main(){
	string s;
	cin>>s;
	string t=s;
	int cnt=0,i;
	
	reverse(t.begin(),t.end());
	for(i=0;i<s.size();i++)
		if(s[i]!=t[i])
			cnt++;
			
	cout<<cnt/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int S[1000000],n;

int search(int);

int main(){
  int k,q,i,j,C = 0;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(j = 0; j < q; j++){
    scanf("%d",&k);
    if(search(k)) C++;
  }

  printf("%d\n",C);
  return 0;
}

int search (int k){
  int right = n,left = 0,mid;
  
  while(left < right){
      mid = (left + right) / 2;
      if(k == S[mid]) return 1;
      else if(k > S[mid]) left = mid + 1;
      else right = mid;
  }
  return 0;
}



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

int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> tree(n, vector<int> (0));
  for(int i = 0; i < n-1; i++){
    int a, b;
    cin >> a >> b;
    tree.at(a-1).push_back(b-1);
    tree.at(b-1).push_back(a-1);
  }
  vector<pair<long long, long long>> que(q);
  for(int i = 0; i < q; i++){
    long long p, x;
    cin >> p >> x;
    que.at(i) = {p-1, x};
  }
  
  vector<long long> ans(n);
  for(int i = 0; i < q; i++){
    long long np = que.at(i).first, nx = que.at(i).second;
    ans.at(np) += nx;
  }
  queue<int> bfs;
  vector<int> check(n);
  bfs.push(0);
  check.at(0) = 1;
  while(bfs.size() > 0){
    int now = bfs.front();
    bfs.pop();
    
    for(auto x : tree.at(now)){
      if(check.at(x)) continue;
      check.at(x) = 1;
      ans.at(x) += ans.at(now);
      bfs.push(x);
    }
  }
  
  for(int i = 0; i < n; i++) cout << ans.at(i) << " ";
  cout << endl;
}

Measured memory_bytes: 21392
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    int n; cin >> n;
    vector<vector<int>> da(n, vector<int>(0));
    rip(i,n-1,0) {
        int u,v; cin >> u >> v;
        if(u < v) swap(u, v);
        --u;--v;
        da[u].push_back(v);
    }
    ll ans = 1;
    vector<ll> dp(n,1);
    rip(i,n,1) {
        // sort(all(da[i]));
        // reverse(all(da[i]));
        dp[i] = dp[i-1] + i + 1;
        rip(j, da[i].size(), 0) {
            dp[i] -= da[i][j]+1;
        }
        ans += dp[i];
    }
    // vdeb(dp);
    cout << ans << endl;
}

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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; }}

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;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    int n; cin >> n;
    set<string> st;
    rep(i,n) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19284
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int x,y;
signed main(){
	cin>>x>>y;
	if(abs(x-y)<=1)puts("Brown");
	else puts("Alice");
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector <int> a(n), b(n), c(n);
    rep (i, n) cin >> a[i]; sort(a.begin(), a.end());
    rep (i, n) cin >> b[i]; sort(b.begin(), b.end());
    rep (i, n) cin >> c[i]; sort(c.begin(), c.end());

    vector <long long> bc(n + 1, 0);
    rep (i, n) bc[i + 1] = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    rep (i, n) bc[i + 1] += bc[i];

    long long ans = 0;
    rep (i, n) {
        auto lb = upper_bound(b.begin(), b.end(), a[i]);
        ans += bc[n] - bc[lb - b.begin()];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2304
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_085_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(10).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    INSPECT INP REPLACING FIRST "17" BY "18" BEFORE "/".

    DISPLAY INP.
    STOP RUN.


Measured memory_bytes: 764
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC126_1
{
    class A
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = a[0];
            var K = a[1];
            var s = Console.ReadLine();

            for (int i = 0; i < N; i++)
            {
                if (i == K - 1) Console.Write(s[i].ToString().ToLower());
                else Console.Write(s[i]);
            }
            Console.WriteLine();

        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	swap(a,b);
	swap(a,c);
	printf("%d %d %d",a,b,c);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;

signed main() {
  int n,m,l;
  cin>>n>>m>>l;
  int d[n][n];
  int a,b,c;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)d[i][j]=MOD*MOD;
  for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    d[a-1][b-1]=c;
    d[b-1][a-1]=c;
  }
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  vector<int> hen[n];
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(i!=j&&d[i][j]<=l)hen[i].push_back(j);
  int q,s,t,bi=0;
  queue<int> que;
  int used[n]={};
  cin>>q;
  for(int i=0;i<q;i++){
    for(int j=0;j<n;j++)used[j]=-1;
    cin>>s>>t;
    s--;t--;
    used[s]=0;bi=0;
    que.push(s);
    while(!que.empty()){
      s=que.front();
      for(int j=0;j<hen[s].size();j++){
        if(used[hen[s][j]]==-1){
          used[hen[s][j]]=used[s]+1;
          que.push(hen[s][j]);
          if(hen[s][j]==t){
            cout<<used[t]-1<<endl;
            bi=1;
            break;
          }

        }

      }
      que.pop();
      if(bi==1)break;
    }
    while(!que.empty())que.pop();
    if(bi!=1)cout<<-1<<endl;

  }
  



  return 0;
}


Measured memory_bytes: 2304
# -*- coding: utf-8 -*-


def main():
    """Function."""
    x, y = map(int, input().split())
    g1 = [1, 3, 5, 7, 8, 10, 12]
    g2 = [4, 6, 9, 11]
    g3 = [2]

    if x in g1 and y in g1:
        print("Yes")
    elif x in g2 and y in g2:
        print("Yes")
    elif x in g3 and y in g3:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int d[1010][1010];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
vector<pair<int,pair<int,int>>> G[1010][1010];//cost,x,y;
char mp[1010][1010];//2d-heimen
queue<pair<int,pair<int,int>>> que0,que1;
void bfs(int s,int t){
    que0.push({0,{s,t}});
    while(que0.size() || que1.size()){
        while(que0.size()){
            auto p = que0.front();
            que0.pop();
            int x = p.second.first,y = p.second.second,dist = p.first;
            if(d[x][y]!=-1) continue;
            d[x][y] = dist;
            for(auto p:G[x][y]){
                int nx = p.second.first,ny = p.second.second;
                if(p.first==0) que0.push({dist,{nx,ny}});
                else que1.push({dist + 1,{nx,ny}});
            }
        }
        if(que1.size()){
            auto p = que1.front();
            que1.pop();
            int dist = p.first,x = p.second.first,y = p.second.second;
            if(d[x][y]!=-1) continue;
            d[x][y] = dist;
            for(auto p:G[x][y]){
                int nx = p.second.first,ny = p.second.second;
                if(p.first==0) que0.push({dist,{nx,ny}});
                else que1.push({dist + 1,{nx,ny}});
            }
        }
    }
}

int main(){
    int i,j,k,l,h,w,cx,cy,gx,gy; cin >> h >> w >> cx >> cy >> gx >> gy; cx--; cy--; gx--; gy--;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++) cin >> mp[i][j];
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            d[i][j] = -1;
            for(k=0;k<4;k++){
                int nx = i + dx[k],ny = j + dy[k];
                if(nx<0 || nx>=h || ny<0 || ny>=w || mp[nx][ny]!='.') continue;
                G[i][j].push_back({0,{nx,ny}});
            }
            for(k=i - 2;k<=i + 2;k++){
                for(l=j - 2;l<=j + 2;l++){
                    if(k<0 || k>=h || l<0 || l>=w || mp[k][l]!='.') continue;
                    G[i][j].push_back({1,{k,l}});
                }
            }
        }
    }
    bfs(cx,cy);
    cout << d[gx][gy] << endl;
}

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

double check_dist(int *x, int *y, int d) {
    int root;
    double v = 0;
    rep(i, d) v += (x[i] - y[i]) * (x[i] - y[i]);
    root = int(sqrt(v));
    // cout << "result:" << (root * root) == v << endl;
    return root * root == v;
}

int main() {
    int n, d, ans = 0;
    cin >> n >> d;
    int x[n][d];

    rep(i, n) rep(j, d) cin >> x[i][j];
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            if(check_dist(x[i], x[j], d)) {
                // cout << "i:" << i << ",j:" << j << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
int main(void) {
    char tmp;
    int n = 0, max = 0;
    while ((tmp = getchar()) != EOF) {
        if (tmp == 'R')
            n += 1;
        else {
        	if (max < n)
                max = n;
            n = 0;
        }
    }
    printf("%d", max);
    return 0;
}

Measured memory_bytes: 1596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str = br.readLine();
	List<String> days = Arrays.asList("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT");
	System.out.println(7 - days.indexOf(str));
    }
}

Measured memory_bytes: 19412
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    vector<lint> p(n);
    for(auto& elem : p)  cin >> elem;

    vector<lint> q(n);
    for(auto& elem : q)  cin >> elem;

    vector<lint> a(n);
    for(lint i=0; i<n; i++)  a[i] = i+1;

    auto eq = [&](vector<lint> x, vector<lint> y) {
        for(lint i=0; i<n; i++) {
            if(x[i] != y[i])  return false;
        }
        return true;
    };

    lint i = 0, ai, bi;
    do {
        if(eq(a, p)) ai = i;
        if(eq(a, q)) bi = i;
        i++;
    } while(next_permutation(begin(a), end(a)));

    cout << abs(ai - bi) << endl;
}

Measured memory_bytes: 256