akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;
struct tree{
  int x;
  std::vector<tree*> child;
};
tree T[100001];
int num[100001];
int cou[1];
set<int> ok;
void bfs(tree *Ts){
  ok.insert(Ts->x);
  for(int i=0;i<Ts->child.size();i++){
    if(ok.find(Ts->child[i]->x)==ok.end()){
      cou[0]++;
      num[cou[0]] = Ts->child[i]->x;
    }
  }
  for(int i=0;i<Ts->child.size();i++){
    if(ok.find(Ts->child[i]->x)==ok.end()){
      bfs(Ts->child[i]);
    }
  }
}

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<pair<int , int>> ab;
  std::vector<int> c(N);
  int a, b;
  for(int i=0;i<N;i++) num[i] = 0;
  cou[0] = 0;
  for(int i=0;i<N-1;i++){
    std::cin >> a >> b;
    ab.push_back(make_pair(a, b));
  }
  ll su=0;
  int ma = 0;
  for(int i=0;i<N;i++) {
    std::cin >> c[i];
    su += c[i];
    ma = max(ma, c[i]);
  }
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  for(int i=1;i<=N;i++) T[i].x = i;
  for(int i=0;i<N-1;i++){
    T[ab[i].first].child.push_back(&T[ab[i].second]);
    T[ab[i].second].child.push_back(&T[ab[i].first]);
  }
  num[0] = T[ab[0].first].x;
  bfs(&T[ab[0].first]);
  //for(int i=0;i<N;i++) std::cout << num[i] << '\n';
  std::vector<int> ans(N);
  for(int i=0;i<N;i++){
    ans[num[i]-1] = c[i];
  }
  std::cout << su - ma<< '\n';
  for(int i=0;i<N;i++) std::cout << ans[i] <<(i==N-1?"":" ");
  std::cout << '\n';
  return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>

#define INF 100000000
#define MAX_N 1000000

typedef struct {
	int num;
	int max;
	int last;
} FIELD;

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 }, corner[ 1998 ] = { 2 }, coord[ 1000001 ], m;
FIELD field[ 1002 ][ 1001 ];
const int dx[ 7 ] = { 1, 0, -1 , 0, -1, 0, 1 }, dy[ 7 ] = { 0, -1, 0, 1, 1, 1, 1 };

void dfs( int, int );

int main( void ) {
	int i, j, add, x, y, d, cnt, n;

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	add = 1;
	for ( i = 1; i < 1998; i++ ) {
		corner[ i ] = corner[ i - 1 ] + add;
		add += i % 2 ? 1 : 0;
	}

	x = y = 500;
	d = cnt = 0;
	for ( i = 1; i <= 1000000; i++ ) {
		coord[ i ] = x * 1001 + y;
		field[ x ][ y ].num = i;

		if ( i == corner[ cnt ] ) {
			d = d + 1 & 3;
			cnt++;
		}

		x += dx[ d ];
		y += dy[ d ];
	}

	for ( x = 1002; x--; field[ x ][ 1000 ].num = INF ) ;
	for ( y = 1001; y--; field[ 0 ][ y ].num = field[ 1001 ][ y ].num = INF ) ;

	for ( ; scanf( "%d %d", &m, &n ), m; printf( "%d %d\n", field[ x ][ y ].max, field[ x ][ y ].last ) ) {
		for ( i = m + 1; --i; field[ x = coord[ i ] / 1001 ][ y = coord[ i ] % 1001 ].max = INF, field[ x ][ y ].last = 0 ) ;

		dfs( x = coord[ n ] / 1001, y = coord[ n ] % 1001 );
	}

	return 0;
}

void dfs( int x, int y ) {
	int i;

	field[ x ][ y ].max = 0;
	for ( i = 4; i < 7; i++ ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ].num <= m ) {
			if ( field[ nx ][ ny ].max == INF )
				dfs( nx, ny );

			if ( field[ x ][ y ].max < field[ nx ][ ny ].max ) {
				field[ x ][ y ].max = field[ nx ][ ny ].max;
				field[ x ][ y ].last = field[ nx ][ ny ].last;
			} else if ( field[ x ][ y ].max == field[ nx ][ ny ].max )
				if ( field[ x ][ y ].last < field[ nx ][ ny ].last )
					field[ x ][ y ].last = field[ nx ][ ny ].last;
		}
	}

	if ( isPrime[ field[ x ][ y ].num ] ) {
		if ( !field[ x ][ y ].max )
			field[ x ][ y ].last = field[ x ][ y ].num;

		field[ x ][ y ].max++;
	}
}

Measured memory_bytes: 20264
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 ll N;
  cin >>N;
  vl vec(N);
  rep(i,N) {
    cin >>vec.at(i);
  }
  
  sort(all(vec));
  
  double mid=(double)(vec.at((N-1)/2)+vec.at(N/2))/(double)2;
  ll a=vec.at((N-1)/2);
  ll b=vec.at(N/2);
  if(a==b) {
    cout<<0<<endl;
  }
  
  else {
    ll count=0;
    while(b>a) {
      b=b-1;
      count++;
    }
    cout<<count<<endl;
    
    
  }
  
  
}
  
 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

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> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a,b;
	cin>>a>>b;
	a+=b;
	int x=stoi(a);
	for(int i=1;i*i<=x;i++){
		if(i*i==x){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
  int N;
  long long M;
  vector<long long> A;
  long long a_tmp;
  cin >> N >> M;
  for(int i = 0; i < N; ++i){
    cin >> a_tmp;
    A.push_back(a_tmp);
  }
  unordered_map<int, long long> mp; //key:n, value:A_1からA_nまでの和(mod M)
  long long sum_tmp, r;
  vector<int> SUM(N + 1);
  SUM[0] = 0;
  for(int i = 0; i < N; ++i){
    SUM[i+1] = (SUM[i] + A[i]) % M;
  }
  long long counter = 0;
  for(int i = 0; i < SUM.size(); ++i){
    counter += mp[SUM[i]];
    mp[SUM[i]]++;
  }
  cout << counter << endl;
}


Measured memory_bytes: 4852
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int m;
    cin >> m;
    ll d, c, sum=0, dcnt=0;
    for (int i=0; i<m; i++) {
        cin >> d >> c;
        sum += d*c;
        dcnt += c;
    }
    cout << (sum - 1) / 9 + dcnt - 1 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
int main() {
    int a;
    cin >> a ;
    if (a == 1) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int sum = 0;
            a %= b;
            while (c-- > 0) {
                sum += a * 10 / b;
                a = a * 10 % b;
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26308
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    string S;
    cin >> S;
    
    if (S[0] == 'A') {
        int c = 0;
        for (int i = 2; i <= int(S.length())-2; i++) {
            if(S[i] == 'C') c++;
        }
        if(c==1) {
            int d = 0;
            for (int i = 1; i < int(S.length()); i++) if (S[i] >= 'a' && S[i] <= 'z') d++;
            if(d == S.length()-2){
                cout << "AC" << endl;
                return 0;
                
            }
            
            
        }
    }
    
    
    cout << "WA" << endl;
    
    return 0;
}




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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll N;
    cin >> N;
    st stN = to_string(N);
    ll sumN;
    for(auto& i : stN) sumN += i -'0';
    cout << (N % sumN  ==0 ? "Yes" : "No") << endl;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

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

    int A,B;
    cin >> A >> B;
    int d[A+1][B+1], f[101][101], dmax = 100;
    reppp(i, 1, A+1) reppp(j, 1, B+1){
        cin >> d[i][j];
        // dmax = max(dmax, d[i][j]);
    }

    repp(a, dmax+1) repp(b, dmax+1){
        int m = 0;
        reppp(x, 1, A+1) reppp(y, 1, B+1){
            m = max(m, d[x][y] - x*a - y*b);
        }
        f[a][b] = max(0, m);
    }

    reppp(x, 1, A+1) reppp(y, 1, B+1){
        int shortest = INT_MAX;
        repp(a, dmax+1) repp(b, dmax+1){
            shortest = min(shortest, x*a + y*b + f[a][b]);
        }
        if(d[x][y] != shortest){
            cout << "Impossible" << endl;
            return 0;
        }
    }

    printf("Possible\n%d %d\n", (dmax+1)*2, (dmax+1)*(dmax+1) + 2*dmax);
    reppp(n, 1, dmax+1) printf("%d %d X\n", n, n+1);
    reppp(n, dmax+2, 2*dmax+2) printf("%d %d Y\n", n, n+1);
    repp(a, dmax+1) repp(b, dmax+1) printf("%d %d %d\n", a+1, 2*dmax+2-b, f[a][b]);
    printf("1 %d\n", 2*dmax+2);
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define P pair<int,int>
using namespace std;

P S[100000];
int p[100000];
int d[100000];
int W[100000];
int DFS(int a) {
	if (d[a] != -1)return d[a];
	return d[a] = DFS(p[a]) + 1;
}
signed main() {
	int n, k; scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
		p[i]--;
	}
	int ans = p[0] != 0;
	memset(d, -1, sizeof(d));
	d[0] = 0;
	S[0] = { 0,0 };
	for (int i = 1; i < n; i++) {
		DFS(i);
		S[i] = { d[i],i };
	}
	sort(S, S + n, greater<P>());
	for (int i = 0; i < n; i++) {
		if (S[i].second == 0)continue;
		int count = W[S[i].second];
		if (count == k - 1&&p[S[i].second]!=0) {
			ans++;
		}
		else {
			W[p[S[i].second]] = max(count + 1,W[p[S[i].second]]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3712
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)

typedef struct edge{ll s,g,c;}E;

ll n;
E e[200010];
ll vnow[100010];
ll epre[200010];

ll que[200010];
ll d[100010];
void bfs(int k){
	ll qcnt=1;
	que[0]=k;
	d[k]=1;
	rep(i,0,qcnt){
		ll v=que[i];
		for(ll t=vnow[v];t!=-1;t=epre[t])if(!d[e[t].g]){
			que[qcnt++]=e[t].g;
			d[e[t].g]=d[v]+1;
		}
	}
}

ll fennec[100010];
ll sunuke[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n)vnow[i]=-1;
	
	rep(i,0,n-1){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		a--;b--;
		e[2*i].s=a;
		e[2*i].g=b;
		epre[2*i]=vnow[a];
		vnow[a]=2*i;
		
		e[2*i+1].s=b;
		e[2*i+1].g=a;
		epre[2*i+1]=vnow[b];
		vnow[b]=2*i+1;
	}

	bfs(0);
	rep(i,0,n){
		fennec[i]=d[i];
		d[i]=0;
	}
	bfs(n-1);
	rep(i,0,n)sunuke[i]=d[i];

	ll ans=0;
	rep(i,0,n)if(fennec[i]<=sunuke[i])ans++;
	puts(ans>n-ans?"Fennec":"Snuke");
	return 0;
}

Measured memory_bytes: 11136
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    ll N,K,Q; cin>>N>>K>>Q;
    vector<int> A(N+1,K);
    for (int i = 1; i <= Q; ++i) {
        int temp; cin>>temp;
        A[temp]++;
    }

    for (int i = 1; i <= N; ++i) {
        if(A[i]-Q > 0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        int result = n-k;

        if(k <= 1) result = 0;

        System.out.println(result);
    }
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, m; cin >> n >> m;

    int ans = n * (n - 1) / 2 + m * (m - 1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

	struct data{
		char n[9];
		int m;
	}d[100];
int main(){
	int n,m;
	int N[100];
	int M[1000];
	int i,j,k;
	int b[1000];
	int ans=0;
	int flag = 0;
	int q,w,e,r,t,y;

	while(scanf("%d%d",&n,&k)!=EOF){
		for(i=0;i<100;i++)N[i]=0;
		ans=0;
		for(i=0;i<k;i++){
			scanf("%d",&m);
			for(j=0;j<m;j++){
				scanf("%d",&q);
				b[q] = i+1;
			}
		}
			scanf("%d",&m);
			for(j=0;j<m;j++){
				scanf("%d%d",&w,&e);
				if(b[w]==b[e]){
					N[w] = N[e] = 1;
				}
			}
			
			for(i=0;i<n;i++){
				ans+=N[i+1];
			}
			printf("%d\n",ans);
			
			
	}
	return 0;
}

Measured memory_bytes: 604
from functools import reduce

NNN = 10 ** 9 + 7


def main():
    N, M = [int(a) for a in input().split()]
    S = [int(a) for a in input().split()]
    T = [int(a) for a in input().split()]

    table = [0] * M

    for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

    s = 1
    for a in table:
        s = (s + a) % NNN
    print(s)


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    int n, k, ans = 0;
    cin >> n >> k;

    int a[n];
    for (int i=0;i<n;i++) a[i] = 0;
    for (int i=0;i<k;i++) {
        int d;
        cin >> d;
        for (int j =0;j<d;j++) {
            int man;
            cin >> man;
            a[man-1] += 1;
        }
    }

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

    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using vs = vector<string>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;

#define R(a,i) for(ll a=0; a < (i); (a)++)
#define FOR(a,i,j) for(ll a=(i); a < (j); (a)++)
#define RD(a,i) for(ll a=(i)-1; (a) >= 0; (a)--)
#define FORD(a,i,j) for(ll a=(j)-1; (a) >= (i); (a)--)

#define xx first
#define yy second
#define pb push_back

#define all(X) begin(X),end(X)
#define sz(X) (X).size()

#define DBG 0
#define TR(X) {if(DBG) cerr << (#X) << " = " << (X) << "\n";}
#define hline {if(DBG) cerr << "----------------------------------------------------------------------" << "\n";}
#define PK(X) {if(DBG) cerr << (X) << "\n";}

const ll mod = 1e9 + 7;

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

	ll N, K;
	cin >> N >> K;

	vvl a(N, vl(N));

	FOR(i,0,N) FOR(j,0,N)
		cin >> a[i][j];

	vvl res(N, vl(N,0));
	FOR(i,0,N)
		res[i][i] = 1;

	while(K > 1){
		hline;
		TR(K);

		vvl x(N, vl(N,0));
		vvl y(N, vl(N,0));

		if(K % 2) {
			TR("neq");
			FOR(i,0,N) FOR(j,0,N) {
				FOR(k,0,N) {
					y[i][j] += (res[i][k] * a[k][j]) % mod;
					x[i][j] += (a[i][k] * a[k][j]) % mod;
					y[i][j] %= mod;
					x[i][j] %= mod;
				}
			}
			K = (K-1) / 2;
			swap(res, y);
			swap(a,x);
		} else {
			TR("eq");
			FOR(i,0,N) FOR(j,0,N) {
				FOR(k,0,N) {
					x[i][j] += (a[i][k] * a[k][j]) % mod;
					x[i][j] %= mod;
				}
			}
			K = K / 2;
			swap(a,x);
		}
		TR(K);
	}

	vvl erg(N, vl(N));
	FOR(i,0,N) FOR(j,0,N) {
		FOR(k,0,N) {
			erg[i][j] += (a[i][k] * res[k][j]) % mod;
			erg[i][j] %= mod;
		}
	}

#if DBG
	TR("res");
	FOR(i,0,N) {
		FOR(j,0,N) {
			cerr << res[i][j] << ' ';
		}
		cerr << endl;
	}
	TR("a");
	FOR(i,0,N) {
		FOR(j,0,N) {
			cerr << a[i][j] << ' ';
		}
		cerr << endl;
	}
	TR("erg");
	FOR(i,0,N) {
		FOR(j,0,N) {
			cerr << erg[i][j] << ' ';
		}
		cerr << endl;
	}
#endif

	ll final_result = 0;
	FOR(i,0,N) {
		FOR(j,0,N) {
			final_result = (final_result + erg[i][j]) % mod;
		}
	}

	cout << final_result << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e9;
inline ll read(){
	ll X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
ll n,m;
ll c[105],w[105];
ll dp[105][100005];
int main()
{
	cin>>n>>m;
    ll maxn=-INF;
    for(ll i=0;i<n;i++)
    {
        cin>>w[i]>>c[i];
        maxn=max(c[i],maxn);
    }
    memset(dp,0x3f3f3f3f,sizeof(dp));
    dp[0][0]=0;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=n*maxn;j++)
        {
            if(j>=c[i])
            	dp[i+1][j]=min(dp[i][j],dp[i][j-c[i]]+w[i]);
            else
            {
            	dp[i+1][j]=dp[i][j];
            }
            if(dp[i+1][j]<=m and j>ans)
            {
            	ans=j;
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 82432
#include <iostream>
#include <cassert>
using namespace std;
int main() {
  char x;
  cin >> x;
  if('A'<=x && x<='Z') {
    cout << 'A' << endl;
  } else if('a'<=x && x<='z') {
    cout << 'a' << endl;
  } else {
    assert(false);
  }
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int main() {
	int d, l, r;
  cin >>l>>r>>d;
  int cnt = 0;
  for (int i=0 ; i<=r ; i+=d) {
    if (i>=l) cnt++;
  }
   cout <<cnt<<endl; 
	return 0;
}

Measured memory_bytes: 3592
N,K = map(int,input().split())
mod = 10**9+7
ans = 0

data = [0]*(K+1)
for x in range(K,0,-1):
    p = pow(K//x,N,mod)
    for k in range(2,K//x+1):
        p -= data[k*x]
        p %= mod
    data[x] = p
    ans += x*p
    ans %= mod

###
#print(data)
###
    
print(ans)

Measured memory_bytes: 11304
#include <bits/stdc++.h>
#define INT long long int
#define MOD (INT)(1e9)+7
using namespace std;

string s, op;
bool done;
void dfs(int x, int y)
{
    if(done) return;
    if( x == s.size() )
    {
        if( y == 7 )
        {
            done = 1;
            cout<<s[0];
            for(int i = 1 ; i < 4 ; i++ )
                cout<<op[i]<<s[i];
            cout<<"=7"<<endl;
        }
        return;
    }
    op[x] = '+';
    dfs(x+1, y+(s[x]-'0'));
    op[x] = '-';
    dfs(x+1, y-(s[x]-'0'));
}
int main()
{
     cin>>s; op = s;
     dfs(1, s[0]-'0');
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        // Your code here!
        Scanner sc = new Scanner(System.in);	
        int a = sc.nextInt();
        int b = sc.nextInt();
      if(a >= 13){
        System.out.println(b);
                 } else if(a >= 6){
        System.out.println(b/2);
                 }else{
       System.out.println(0);
      }
   }
}

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

int main() {
  long long int n,m,a,ans=0;
  cin>>n>>m;
  priority_queue<int> que;
  rep(i,n) cin>>a,que.push(a);
  rep(i,m){
    a=que.top();
    a=a/2;
    que.pop();
    que.push(a);
  }
  rep(i,n){
    ans+=que.top();
    que.pop();
  }
  cout<<ans<<endl;
}


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

long long A, B, C, X, Y, minx = (1LL << 60);

int main() {
	cin >> A >> B >> C >> X >> Y;
	for (long long i = 0; i <= 100000; i++) {
		long long x = max(0LL, X - i);
		long long y = max(0LL, Y - i);
		minx = min(minx, x*A + y*B + i*C * 2);
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        int sum = 0;
        for (int x = 0; x < n; ++x){
            int q; cin >> q;
            while (q % 2 == 0){
                q /= 2;
                sum++;
            }
        }
        cout << sum << endl;
    return 0;
}


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

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

    int first = N%10;

    if(first==2 || first==4 || first==5 || first==7 || first==9) {
        cout << "hon" << endl;
    } else if(first==0 || first==1 || first==6 || first==8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
using namespace std;
int n, m;
int s[100000];
int a[100000], b[100000], c[100000], l[100000];
int main()
{
	long long  ans = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> s[i]; s[i] = s[i] - 1;
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 0; i < m - 1; i++) {
		l[max(s[i], s[i + 1])]--;
		l[min(s[i], s[i + 1])]++;
	}
	for (int i = 0; i < n - 1; i++) {
		l[i + 1] += l[i];
	}
	for (int i = 0; i < n; i++) {
		long long  ti = (long long)a[i] * l[i];
		long long  ic = (long long)b[i] * l[i] + c[i];
		ans += min(ti, ic);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m,l;
  cin>>n>>m>>l;
  int mp[300][300];
  int mp2[300][300];
  rep(i,300) rep(j,300) mp[i][j]=mp2[i][j]=INF;
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    mp[a][b]=mp[b][a]=c;
  }
  rep(i,n){
    rep(j,n){
      rep(k,n){
	mp[j][k]=min(mp[j][i]+mp[i][k],mp[j][k]);
      }
    }
  }
  rep(i,n) rep(j,n) if(mp[i][j]<=l) mp2[i][j]=1;
  rep(i,n){
    rep(j,n){
      if(i!=j){
	rep(k,n){
	  if(j!=k) mp2[j][k]=min(mp2[j][i]+mp2[i][k],mp2[j][k]);
	}
      }
    }
  }
  int q;
  cin>>q;
  rep(i,q){
    int s,t;
    cin>>s>>t;
    s--;t--;
    if(mp2[s][t]!=INF) cout<<mp2[s][t]-1<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}


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

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

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

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

    // input
    string s, t;
    cin >> s >> t;

    ll L = s.size();
    ll M = t.size();

    if(M>L){
        return 0;
    }

    FOR(i, 0, L-M+1){
        if(s.substr(i, M)==t){
            p(i);
        }
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif

int main(void)
{
	double a, b;
	cin >> a >> b;

	double ans = (a + b) / 2;
	if (ceil(ans) == floor(ans))
		cout << (ll)ans;
	else
		cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
N,M,X = map(int,input().split())
A = list(map(int,input().split()))

ans0 = 0
ans1 = 0
for i in range(0,X):
    if i in A:
        ans0 += 1

for i in range(X,N+1):
    if i in A:
        ans1 += 1

print(min(ans0,ans1))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>

#define ft first
#define sd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x x__
#define y y__

using namespace std;

typedef long long int ll;
typedef long double ld;

const int MAXN = 200000;
const int INF = 1000000010;
const ll MOD = 1000000007LL;

int N;
int X;
int ans[MAXN] = {0};
char used[MAXN] = {0};

int main() {
    scanf("%d", &N);
    scanf("%d", &X);
    
    if (X == 1 || X == 2*N - 1) {
        puts("No");
        return 0;
    }

    if (N == 2) {
        printf("Yes\n1\n2\n3\n");
        return 0;
    }

    used[X] = used[X+1] = used[X-1] = 1;
    ans[N] = X;
    ans[N-1] = X-1;
    ans[N+1] = X+1;
    if (X + 2 <= 2*N - 1) {
        ans[N-2] = X+2;
        used[X+2] = 1;
    } else {
        ans[N+2] = X-2;
        used[X-2] = 1;
    }

    int ptr = 1;

    puts("Yes");
    for (int i = 1; i <= 2*N - 1; ++i) {
        if (ans[i]) {
            printf("%d\n", ans[i]);
            continue;
        }

        while (used[ptr]) {
            ++ptr;
        }
        used[ptr] = true;

        ans[i] = ptr;

        printf("%d\n", ans[i]);
    }

    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
using namespace std;
int main(){
        string S, a, b, c;
        a=("Sunny");
        b=("Cloudy");
        c=("Rainy");
        cin >> S;
        if (S==a){
                cout << b;
        }
        if (S==b){
                cout << c;
        }
        if (S==c){
                cout << a;
        }
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N = I()
    s = []

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

    ans = 0
    a = 0
    b = 0
    dup = 0

    for i in range(N):
        if s[i][0] == 'B':
            b += 1
        if s[i][-1] == 'A':
            a += 1
        if s[i][0] == 'B' and s[i][-1] == 'A':
            dup += 1
        for j in range(1, len(s[i])):
            if s[i][j-1] == 'A' and s[i][j] == 'B':
                # print(j, s[i])
                ans += 1

    # print(dup, a, b, ans)
    if dup > 0 and dup == max(a, b):
        # print(dup, a, b)
        print(ans + dup - 1)
    else:
        print(ans + min(a, b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
//#define MOD 1000000007
#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

signed main(void){
    int N,S,a;
    vector<int> A;
    cin >> N >> S;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    int dp[2][6000];
    REP(i,2){REP(j,6000){dp[i][j]=0;}}
    dp[0][0]=1;
    
    REP(j,N){
        REP(i,S+1){
            dp[1][i]+=2*dp[0][i];dp[1][i]%=MOD;
            if(i+A[j]<=S){
                dp[1][i+A[j]]+=dp[0][i];
                dp[1][i+A[j]]%=MOD;
            }
        }
        
        REP(i,S+1){
            dp[0][i]=dp[1][i];
            dp[1][i]=0;
        }
    }
    
    int Ans=dp[0][S];
    
    cout << Ans << endl;
    return 0;
}




Measured memory_bytes: 3780
a, b, c, d = list(map(int, input().split()))
pos1 = [a, b]
pos2 = [c, d]

ans = ''


def horizontal(xdiff, ydiff):
    ret = ''
    ret += 'R'*xdiff + 'U'*ydiff
    ret += 'L'*xdiff + 'D'*ydiff
    ret += 'D'+'R'*(1+xdiff)+'U'*(1+ydiff)+'L'
    ret += 'U'+'L'*(1+xdiff)+'D'*(1+ydiff)+'R'
    return ret


ans = horizontal(c-a, d-b)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  long long N,A[100000];
  cin>>N;
  FOR(i,0,N){
    cin>>A[i];
  }
  sort(A,A+N,greater<int>());
  int i=0;
  while(A[i]!=A[i+1]){
    i++;
    if(i==N-1){
      cout<<"0"<<endl;
      return 0;
    }
  }
  long long H=A[i];
  if(A[i]==A[i+1]&&A[i+1]==A[i+2]&&A[i+2]==A[i+3]){
    cout<<A[i]*A[i]<<endl;
    return 0;
  }
  while(A[i]==A[i+1]){
    i++;
  }
  while(A[i]!=A[i+1]){
    i++;
    if(i==N-1){
      cout<<"0"<<endl;
    }
  }
  long long W=A[i];
  cout<<W*H<<endl;
  return 0;
}


Measured memory_bytes: 1024
def resolve():
	a,b=map(str,input().split())
	s=int(a[:2])
	e=int(b[:2])
	ans=0
	for i in range(s,e+1):
		for j in range(10):
			kai=i*1000+j*100+int(str(i)[::-1])
			if int(a)<=kai<=int(b):
				ans+=1
	print(ans)
resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#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 pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, k;
vvi v, s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  int kk = k*2;
  v.resize(kk);
  each(itr, v) (*itr).resize(k*2);
  s.resize(kk);
  each(itr, s) (*itr).resize(k*2);
  int p = 0;
  FOR(i, 0, n){
    int x, y;
    char c;
    cin >> x >> y >> c;
    x %= kk;
    y %= kk;
    if(c == 'B'){
      v[x][y]++;
      if((x/k+y/k)%2 == 0) p++;
    }else{
      v[x][y]--;
      if((x/k+y/k)%2 == 1) p++;
    }
  }
  FOR(j, 0, kk){
    ll l = 0;
    FOR(i, 0, k) l += v[i][j];
    FOR(i, 0, kk){
      s[i][j] = l;
      l += v[(i+k)%kk][j] - v[i][j];
    }
  }
  int ans = 0;
  FOR(i, 0, kk){
    FOR(j, 0, kk){
      maxs(ans, p);
      p += s[i][(j+k)%kk] + s[(i+k)%kk][j] - s[i][j] - s[(i+k)%kk][(j+k)%kk];
    }
    FOR(j, 0, k) p += v[i][(j+k)%kk] + v[(i+k)%kk][j] - v[i][j] - v[(i+k)%kk][(j+k)%kk];
  }
  cout << ans << endl;
  return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
ll fact[N];

ll powmod(ll a, ll k) {
	if (k == 0) return 1;
	ll r = powmod(a, k/2);
	r = (r * r) % MOD;
	if (k % 2) r = (r * a) % MOD;
	return r;
}

ll comb(int n, int k) {
	assert(n >= k && k >= 0);
	ll x = (fact[k] * fact[n-k]) % MOD;
	x = powmod(x, MOD - 2);
	return (fact[n] * x) % MOD;
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n, k;
	scanf("%d%d", &n, &k);
	fact[0] = 1;
	for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % MOD;
	//for (int i = 1; i <= n; i++) {printf("%lld ", fact[i]);} puts("");

	vll a(n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	sort(all(a));

	if (k == 1) {
		puts("0");
		return 0;
	}

	ll min_sum = 0, max_sum = 0;
	for (int i = 0; i < n; i++) {
		if (i + k <= n) {
			ll tmp = (a[i] * comb(n-i-1, k-1)) % MOD;
			min_sum = (min_sum + tmp) % MOD;
		}
		if (i >= k-1) {
			ll tmp = (a[i] * comb(i, k-1)) % MOD;
			max_sum = (max_sum + tmp) % MOD;
		}
	}
	//printf("%lld %lld\n", min_sum, max_sum);
	ll ans = (MOD + max_sum - min_sum) % MOD;
	printf("%lld\n", ans);
}


Measured memory_bytes: 1792
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w=map(int,input().split())
    S=[input() for _ in range(h)]
    L=[[0]*w for _ in range(h)]
    R=[[0]*w for _ in range(h)]
    U=[[0]*w for _ in range(h)]
    D=[[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if S[i][j]=='#':
                L[i][j]=0
                U[i][j]=0
                continue
            if i==0:U[i][j]=1
            else:U[i][j]=U[i-1][j]+1
            if j==0:L[i][j]=1
            else:L[i][j]=L[i][j-1]+1
    for i in range(h-1,-1,-1):
        for j in range(w-1,-1,-1):
            if S[i][j]=='#':
                R[i][j]=0
                D[i][j]=0
                continue
            if i==h-1:D[i][j]=1
            else:D[i][j]=D[i+1][j]+1
            if j==w-1:R[i][j]=1
            else:R[i][j]=R[i][j+1]+1 
    X=[[l+r+u+d-3 for l,r,u,d in zip(ll,rr,uu,dd)] for ll,rr,uu,dd in zip(L,R,U,D)]
    print(max([max(x) for x in X]))


if __name__=='__main__':
    main()

Measured memory_bytes: 210824
#include <bits/stdc++.h>
/* Type alias */
using ll = long long;
using ld = long double;

using vec_i = std::vector<int>;
using vec_ll = std::vector<ll>;
using vec_ld = std::vector<ld>;

using set_i = std::set<int>;
using set_ll = std::set<ll>;
using set_ld = std::set<ld>;

using uset_i = std::unordered_set<int>;
using uset_ll = std::unordered_set<ll>;
using uset_ld = std::unordered_set<ld>;

/* IO macros */
#define in(i)            int i; std::cin >> i
#define in2(i, j)        int i, j; std::cin >> i >> j
#define in3(i, j, k)     int i, j, k; std::cin >> i >> j >> k
#define in_(i)           std::cin >> i
#define in2_(i, j)       std::cin >> i >> j
#define in3_(i, j, k)    std::cin >> i >> j >> k
#define in_ll(i)         ll i; std::cin >> i
#define in2_ll(i, j)     ll i, j; std::cin >> i >> j
#define in3_ll(i, j, k)  ll i, j, k; std::cin >> i >> j >> k
#define in_ll_(i)        std::cin >> i
#define in2_ll_(i, j)    std::cin >> i >> j
#define in3_ll_(i, j, k) std::cin >> i >> j >> k
#define in_ld(i)         ld i; std::cin >> i
#define in2_ld(i, j)     ld i, j; std::cin >> i >> j
#define in3_ld(i, j, k)  ld i, j, k; std::cin >> i >> j >> k
#define in_ld_(i)        std::cin >> i
#define in2_ld_(i, j)    std::cin >> i >> j
#define in3_ld_(i, j, k) std::cin >> i >> j >> k
#define in_c(i)          char i; std::cin >> i
#define in2_c(i, j)      char i, j; std::cin >> i >> j
#define in3_c(i, j, k)   char i, j, k; std::cin >> i >> j >> k
#define in_c_(i)         std::cin >> i
#define in2_c_(i, j)     std::cin >> i >> j
#define in3_c_(i, j, k)  std::cin >> i >> j >> k
#define in_str(s)        std::string s; std::cin >> s

#define vec_in(v, n)    auto v=vec_i(n); for(auto &x:v){std::cin>>x;}
#define vec_in_ll(v, n) auto v=vec_ll(n);for(auto &x:v){std::cin>>x;}
#define vec_in_ld(v, n) auto v=vec_ld(n);for(auto &x:v){std::cin>>x;}

#define print(x)   std::cout << x
#define println(x) std::cout << x << "\n"
#define print_vec(v) for (auto &x:v) { std::cout << x << " ";}
#define println_vec(v) for (auto &x:v) { std::cout << x << " ";} std::cout << "\n";
#define print_long_vec(v) for (auto &x:v) { std::cout << x << "\n";}
#define println_long_vec(v) for (auto &x:v) { std::cout << x << "\n";} std::cout << "\n";

/* Loops */
#define rep(i, n) for (auto i = 0; i < n; ++i)

/* Vector manipulation */
#define vec_sort(v) std::sort(v.begin(), v.end())

using namespace std;
/* Code Starts Here*/
int main () {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    rep(i, 5) {
        in(x);
        if (x == 0) { println(i + 1); return 0; }
    }

    return 0;
}


Measured memory_bytes: 3596
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private static int[] hills = new int[10];
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		for(int i = 0; i < hills.length; i++){
			hills[i] = sc.nextInt();
		}
		
		Arrays.sort(hills, 0, hills.length);
		
		for(int i = (hills.length - 1); i  > 6; i--){
			System.out.println(hills[i]);
		}
	}
}

Measured memory_bytes: 0
# ABC121 D - XOR World
from math import log2,ceil
a,b=map(int,input().split())
if a==0 and b==0:
    print(0)
    exit()
if a==0:
    pass
elif a>=2:
    na=int(ceil(log2(a)))
nb=int(ceil(log2(b)))
l=[0]*(nb+1)

if a>=2:
    a-=1
    for i in range(na+1):
        q=a//(2**(i+1))
        r=a%(2**(i+1))
        r-=2**i
        if r<0:
            r=0
        elif r>=0:
            r+=1
        l[i]-=q*2**i+r

for i in range(nb+1):
    q=b//(2**(i+1))
    r=b%(2**(i+1))
    r-=2**i
    if r<0:
        r=0
    elif r>=0:
        r+=1
    l[i]+=q*2**i+r

for i in range(len(l)):
    l[i]=l[i]%2

ans=0
for i in range(len(l)):
    ans+=l[i]*2**i
print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <queue>
using namespace std;

typedef long long LL;

int main(int argc, char** argv)
{
	int n;
	scanf("%d", &n);
	queue<LL> q;
	for(int i=1; i<10; i++) q.push(i);
	while(true)
	{
		LL x = q.front(); q.pop();
		if(--n == 0)
		{
			printf("%lld\n", x);
			return 0;
		}
		int r = x % 10LL;
		x *= 10LL;
		x += r;
		if(r > 0) q.push(x - 1);
		q.push(x);
		if(r < 9) q.push(x + 1);
	}
	return 0;
}

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

int main(){
  int A,B;
  cin>>A>>B;
  int sum=0;
  for(int i=A;i<=B;i++){
    if(i/10000==i%10&&i%10000/1000==i%100/10){
      sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

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

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) { cin >> a[j]; }
    for (int j = 0; j < N; ++j) { cin >> b[j]; }

    bool ok = true;
    int c[101010];
    fill(c, c+N+1, 0);
    for (int j = 0; j < N; ++j) {
        if (c[b[j]] == 0) {
            c[b[j]] ++;
        } else {
            ok = false;
        }
    }

    if (ok) { cout << "Yes" << endl; return 0; }

    cout << "No" << endl;

    for (int j = 0; j < N; ++j) {
        if (j > 0) cout << " ";
        cout << 1;
    }
    cout << endl;
    for (int j = 0; j < N; ++j) {
        if (j > 0) cout << " ";
        cout << (c[a[j]] > 0 ? 1 : 2);
    }
    cout << endl;
    return 0;
}



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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  998244353;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int main()
{
    double a,b,h,m; cin >> a >> b >> h >> m;
    double l = 0, s = 0;
    l += 360 * h / 12.0;
    l += 30 * (m / 60.0);
    s += 360 * m / 60.0;
    double dif = min(abs(l-s),abs(s-l));
    double ans = sqrt(a*a+b*b-2*a*b*cos(dif/180*PI));
    printf("%.14lf",ans);
}


Measured memory_bytes: 4160
#include<iostream>
using namespace std;
long long  a[100005];
int main()
{
	int n;
	cin>>n;
	int i,j;
	for(i=0;i<n;i++)
	cin>>a[i];
	int count=1;
	int flag;
	for(i=0;i<n;i=j)
		for(j=i+1;j<n;j++)
			{
				if(i==n-1)
				{
				i++;
				count++;
				break;	
				}
				if(a[i]==a[i+1])
				break;
				else if(a[i]<a[i+1])
				flag=1;
				else if(a[i]>a[i+1])
				flag=0;
				if(flag)
				{
					if(a[j]>=a[j-1])
					continue;
					else {
						count++;
						break;
					}
				}
				else {
					if(a[j]<=a[j-1])
					continue;
					else {
						count++;
						break;
					}
				}
			}
			cout<<count;
			return 0;
	
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n)cin>>c[0][i];R(i,n)cin>>c[1][i];fill(p[1],p[1<<n],1e9);;R(B,1<<n){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)p[B|1<<i][k]=min(p[B|1<<i][k],p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

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

#define rad M_PI/3

typedef struct{
  double x,y;
} Point;

void print(Point);
void rec(Point,Point,int);
Point rotate(Point,Point);

int main(){
  int n;
  Point p1 = {0,0},p2 = {100,0};
  scanf("%d",&n);
  print(p1);
  if(n > 0){  rec(p1,p2,n); }
  print(p2);
  return 0;
}

void print(Point p){
  printf("%.10f %.10f\n",p.x,p.y);
}

void rec(Point p1,Point p2,int depth){
  if(depth == 0){ return; }
  Point s = {p1.x+(p2.x-p1.x)/3.0,p1.y+(p2.y-p1.y)/3.0};
  Point t = {p1.x+(p2.x-p1.x)*2.0/3.0,p1.y+(p2.y-p1.y)*2.0/3.0};
  Point u = rotate(s,t);
  rec(p1,s,depth-1);
  print(s);
  rec(s,u,depth-1);
  print(u);
  rec(u,t,depth-1);
  print(t);
  rec(t,p2,depth-1);
}

Point rotate(Point p1,Point p2){
  double x = p2.x-p1.x,y = p2.y-p1.y;
  Point p = {x*cos(rad)-y*sin(rad)+p1.x,x*sin(rad)+y*cos(rad)+p1.y};
  return p;
}


Measured memory_bytes: 2092
#include <stdio.h>
//WA
struct lr {
  int r;
  int l;
};

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  char s[n+1];
  struct lr a[q];
  scanf("%s", s);
  for (size_t i = 0; i < q; i++) {
    scanf("%d%d", &a[i].l, &a[i].r);
  }
  int b[n+1], boo = 0;
  b[0] = 0;
  for (size_t i = 1; i <= n; i++) {
    if (s[i-1] == 'A') {
      boo = 1;
      b[i] = b[i-1];
    } else if (boo == 1 && s[i-1] == 'C') {
      boo = 0;
      b[i] = b[i-1] + 1;
    } else {
      boo = 0;
      b[i] = b[i-1];
    }
  }
  for (size_t i = 0; i < q; i++) {
    int ans = b[a[i].r] - b[a[i].l];
    printf("%d\n", ans);
  }
  /*TLE
  for (size_t i = 0; i < q; i++) {
    int count = 0, boo = 0;
    for (size_t j = (a[i].l)-1; j < a[i].r; j++) {
      if (s[j] == 'A') {
        boo = 1;
      } else if (boo == 1 && s[j] == 'C') {
        count++;
        boo = 0;
      } else {
        boo = 0;
      }
    }
    printf("%d\n", count);
  }*/
  return 0;
}


Measured memory_bytes: 2048