akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ls p<<1
#define rs p<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define mem(x,i) memset(x,i,sizeof(x)) 
#define eps 1e-8 
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
const int maxn=1e5+100;
ll a[maxn],n;
int check()
{
	FOR(i,1,n-1)
	{
		if(a[i]>a[i+1]) return 0;
	}
	return 1;
}
int main()
{
	cin>>n;
	FOR(i,1,n) cin>>a[i];
	if(check()) {cout<<"YES"<<endl;return 0;}
	FOR(i,1,n)
	FOR(j,i+1,n)
	{
		swap(a[i],a[j]);
		if(check()) {cout<<"YES"<<endl;return 0;}
		swap(a[i],a[j]); 
	}
	cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BHomework solver = new BHomework();
        solver.solve(1, in, out);
        out.close();
    }

    static class BHomework {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int days = in.nextInt();
            int m = in.nextInt();
            while (m-- > 0) {
                int x = in.nextInt();
                days -= x;
            }
            out.println(days < 0 ? "-1" : days);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 34012
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    data class Way(val to: Int, val t: Int)

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = mutableMapOf<String, Int>()
        repeat(N) {
            val S = sc.next()
            A[S] = (A[S] ?: 0) + 1
        }
        pw.printf(
            "AC x %d\n" +
                    "WA x %d\n" +
                    "TLE x %d\n" +
                    "RE x %d\n", A["AC"] ?: 0, A["WA"] ?: 0, A["TLE"] ?: 0, A["RE"] ?: 0
        )
    }
}


Measured memory_bytes: 59412
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin>>a[i];
	}
	sort(all(a));
	int mi=-1,ma=-1;
	int cnt = 0;
	for (int i = 1; i < n; i++){
		if(a[i-1]==a[i]){
			cnt++;
		}
	}

	if(cnt%2==0)cout<<n-cnt<<endl;
	else cout<<n-cnt-1<<endl;

	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;

int main(){
  int n, m, tl;
  while(scanf("%d%d", &n, &m) && (n || m)){
    vector<int> d;
    d.push_back(0);
    rep(i, n + m){ scanf("%d", &tl); d.push_back(tl);}
    sort(d.begin(), d.end());
    int res = 0;
    rep(i, n + m) res = max(res, d[i + 1] - d[i]);

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

Measured memory_bytes: 1180
import java.util.HashSet;
//import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String[] wordArray = stdIn.nextLine().split(" ");
		Set<String> wordSet = new HashSet<String>();
		for(String i:wordArray){
			wordSet.add(i);
		}
		String[] notOverlapWordArray = wordSet.toArray(new String[0]);
		int[] wordCount = new int[notOverlapWordArray.length];
		for(int i = 0;i < notOverlapWordArray.length;i++){
			for(int j = 0;j < wordArray.length; j++){
				if(notOverlapWordArray[i].equals(wordArray[j])){
					wordCount[i]++;
				}
			}
		}
		String mostFrequentWord = null;
		int mostFrequentCount = -1;
		for(int i = 0;i < wordCount.length ; i++){
			if(mostFrequentCount < wordCount[i]){
				mostFrequentCount = wordCount[i];
				mostFrequentWord = notOverlapWordArray[i];
			}
		}
		String mostLongWord = null;
		int mostLongWordLength = -1;
		for(String i:notOverlapWordArray){
			if(mostLongWordLength < i.length()){
				mostLongWordLength = i.length();
				mostLongWord = i;
			}
		}
		System.out.println(mostFrequentWord + " " + mostLongWord);
//		Iterator<String> it = wordSet.iterator();

//		int[] wordCount = new int[wordSet.size()];
//		int wordMaxLength = 0;
//		for(int i = 0;i < wordCount.length; i++){
//			String tempWord = (String)it.next();
//			for(int j = 0;j < wordArray.length; j++){
//				if(wordArray[j].equals(tempWord)){
//					wordCount[i]++;
//					wordMaxLength = Math.max(wordMaxLength, wordArray[j].length());
//				}
//			}
//		}
//		int wordMaxCount = 0;
//		int wordMaxCountIndex = 0;
//		for(int i = 0;i < wordCount.length ;i++){
//			if(wordCount[i] > wordMaxCount){
//				wordMaxCount = wordCount[i];
//				wordMaxCountIndex = i;
//			}
//		}
//		int wordMaxLengthIndex = 0;
//		for(int i = 0; i < wordArray.length; i++){
//			if(wordArray[i].length() == wordMaxLength){
//				wordMaxLengthIndex = i;
//				break;
//			}
//		}
//		System.out.println(wordArray[wordMaxCountIndex] + " " + wordArray[wordMaxLengthIndex]);
	}
}

Measured memory_bytes: 11000
#include <iostream>

#include <math.h>
using namespace std;

int main()
{
	long int x,y;
	cin>>x;
	cin>>y;

	long int counter=0;
	for (long int i = x; i <= y; i=i*2)
	{
		counter++;
	}

	cout<<counter;
	
}


Measured memory_bytes: 256
s = input().rstrip()
n = len(s)
l = 0; r = n-1
ans = 0
while r - l > 0:
    if s[l] == s[r]:
        l+=1; r-=1
    elif s[l] == "x":
        ans += 1
        l += 1
    elif s[r] == "x":
        ans += 1
        r -= 1
    else:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 3316
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
inline bool chmax(T &a, T b) { return a < b && (a = b, true); }

int main() {

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

	int N;
	cin >> N;
	string s;
	cin >> s;

	auto check = [&](int len) {

		unordered_map<string, int> mp;
		for (int j = 0; j <= N - len; j++) {
			string tmp = s.substr(j, len);
			if (mp.find(tmp) == mp.end()) mp[tmp] = j;
			else if (j - mp[tmp] >= len) return true;
		}
		
		return false;
	};

	vector<int> len(N);
	iota(len.begin(), len.end(), 0);
	cout << *partition_point(len.begin(), len.end(), check) - 1 << endl;

	return 0;
}


Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a.at(i);
  bool b=true;
  rep(i,n){
    if(a.at(i)%2==0 && a.at(i)%3!=0 && a.at(i)%5!=0) b=false;
  }
  if(b) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; cin >> N;
  vector<float> v(N);
  rep(i, N) cin >> v[i];
  while(v.size() > 1){
    sort(v.begin(), v.end(), greater<float>());
    float tmp_a = v.back(); v.pop_back();
    float tmp_b = v.back(); v.pop_back();
    v.push_back((tmp_a+tmp_b)/2);
  }
  cout << v.front() << endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

N, M = map(int, input().split())

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
    else:
        print(10 ** (N - 1))
        sys.exit()

num = [-1] * (N + 1)
fin = 0
for _ in range(M):
    s, c = map(int, input().split())
    if num[s] == -1:
        num[s] = c
    elif num[s] != c:
        fin = 1
        print(-1)
        break

if fin == 0:
    for i in range(1, N + 1):
        if i == 1:
            if num[i] == -1:
                print(1, end="")
            elif num[i] == 0 and N == 1:
                print(0)
            elif num[i] == 0:
                print(-1)
                break
            else:
                print(num[i], end="")
        else:
            if num[i] == -1:
                print(0, end="")
            else:
                print(num[i], end="")

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


ll h, w;
string s[404];
bool used[400][400] = {0};

int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	ll ans = 0;
	for(int i = 0; i < h; i++)for(int j = 0; j < w; j++){
		if(!used[i][j]){
			ll x = 0, y = 0;
			queue<P> que;
			que.push(P(i,j));
			used[i][j] = 1;
			while(!que.empty()){
				P q = que.front();
				que.pop();
				if(s[q.first][q.second] == '#') x++;
				else y++;
				int dx[4] = {0,-1,0,1}, dy[4] = {-1,0,1,0};
				for(int j = 0; j < 4; j++){
					int nx = dx[j]+q.first, ny = dy[j]+q.second;
					if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
					if(used[nx][ny]) continue;
					if(s[q.first][q.second] != s[nx][ny]){
						que.push(P(nx,ny));
						used[nx][ny] = 1;
					}
				}
			}
			ans += x * y;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
int N;cin>>N;
set <int> s;

for(int i=0;i<N;i++){
  int a;cin>>a;
  s.insert(a);
}
cout<<s.size()<<endl;


  return 0;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn, dt;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int H = getint(), W = getint(), D = getint();
	pair<int, int> A[90001];
	A[0] = mp(0, 0);
	rep(i, H) rep(j, W) {
		A[getint()] = mp(i, j);
	}
	int B[90001];
	rep(i, D) {
		int j = i;
		auto a = mp(0, 0);
		int mae = 0;
		while (j <= H * W) {
			B[j] = (mae += (abs(A[j].first - a.first) + abs(A[j].second - a.second)));
			a = A[j];
			j += D;
		}
	}
	int Q = getint();
	rep(i, Q) {
		int l = getint(), r = getint();
		putint(B[r] - B[l]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

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

public class Hello{
    public static bool[] Primes;
    public static bool[] Checked;
    
    public static void Main(){
        // Make Primes
        Primes = Enumerable.Repeat(true, Consts.MAXBADGET + 1).ToArray();
        for(int i = 0; i < Primes.Length; i++){
            if(i == 0){ // 0 is not prime
                Primes[i] = false;
                continue;
            }
            else if(i == 1 || Primes[i] == false){
                continue; // iclude 1 when this problem.
            }
            else{
                for(int n = i * 2; n < Primes.Length; n += i){
                    Primes[n] = false;
                }
            }
        }
        

        while(true){
            // Input MenuNum and Badget
            string[] n_x = System.Console.ReadLine().Split(' ');
            int MenuNum = int.Parse(n_x[0]);
            int Badget = int.Parse(n_x[1]);
            if(MenuNum == 0 && Badget == 0) break;
          
            // Input MenuPrices
            int[] MenuPrices = new int[MenuNum];
            bool ContainsOdd = false;
            for(int i = 0; i < MenuNum; i++){
                MenuPrices[i] = int.Parse(System.Console.ReadLine());
                ContainsOdd = MenuPrices[i] % 2 != 0 ? true : ContainsOdd;
            }
            /*
            // Cant make Prime Number when all given numbers are Even.
            if(ContainsOdd == false){ 
                System.Console.WriteLine("NA");
            }
            // when given single number
            else if(MenuPrices.Length == 1){
                if(Primes[MenuPrices[0]]) System.Console.WriteLine(MenuPrices[0]);
                else System.Console.WriteLine("NA");
            }            
            else{
            */
                Checked = Enumerable.Repeat(false, Primes.Length).ToArray();
                Checked[0] = true;
                int MaxPrime = 0;
                for(int i = 0; i < MenuPrices.Length; i++){
                    for(int n = 0; n < Checked.Length; n++){
                        if(Checked[n]){
                            int Nextn = n + MenuPrices[i];
                            if(Badget < Nextn) break;
                            try{
                                Checked[Nextn] = true;
                            }
                            catch(IndexOutOfRangeException){
                                break;
                            }
                            if(Primes[Nextn]){
                                MaxPrime = MaxPrime < Nextn ? Nextn : MaxPrime;
                            }
                        }
                    }
                }
                System.Console.WriteLine((MaxPrime <= 0 ? "NA" : MaxPrime.ToString()));
            /*
            }
            */
        }
    }
}

public static class Consts{
    public static int MAXBADGET = 1000000;
}

Measured memory_bytes: 15184
N = int(input().rstrip())
As = [int(x) for x in input().rstrip().split()]
fail_flg = False
for a in As:
    if a % 2 == 1:
        continue
    elif not (a % 2 == 0 and (a % 3 == 0 or a % 5 == 0)):
        fail_flg = True
        break
if fail_flg:
    print('DENIED')
else:
    print('APPROVED')



Measured memory_bytes: 3060
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
    tmp = input()
    if tmp == "AC":
        ac+=1
    elif tmp == "WA":
        wa+=1
    elif tmp == "TLE":
        tle+=1
    else:
        re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 9188
#include <stdio.h>
#define AMAX 10000

int i,j;
int A[20000000],B[20000000],C[AMAX];

void CountingSort(int n)
{
  for(i=1;i<AMAX;i++)
  {
    C[i] = 0;
  }
  for(j=0;j<n;j++)
  {
    C[A[j+1]]++;
  }
  for(i=1;i<AMAX;i++)
  {
    C[i] = C[i] + C[i-1];
  }
  for(j=1;j<=n;j++)
  {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

int main()
{
  int n,data;
  scanf("%d",&n);

  for(i=1;i<=n;i++)
  {
    scanf("%d",&A[i]);
  }
  CountingSort(n);
  for(i=1;i<=n;i++)
  {
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 17416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	string s;
	cin >> s;

	ll ans = 0, cnt = 0;
	for (char c : s) {
		if (c == 'A' || c == 'C' || c == 'G' || c == 'T') cnt++;
		else
			cnt = 0;
		chmax(ans, cnt);
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  cin >> n;

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

  ll A = 1, B = 1;
  for (int i = 0; i < n; i++) {
    int x = a[i];
    int y = t[i];

    ll num = max((A + x - 1) / x, (B + y - 1) / y);

    A = num * x;
    B = num * y;
  }

  ll ans = A + B;

  cout << ans << endl;

  return 0;
}

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

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


def expected_value(n):
    return (1 + n) / 2


ex_list = []
for i in range(N):
    ex_list += [expected_value(P[i])]

sum_list = []
for i in range(N+1-K):
    if i == 0:
        sum_list += [sum(ex_list[i:i+K])]
    if i >= 1:
        sum_list += [sum_list[i-1] + ex_list[i+K-1] - ex_list[i-1]]

print(max(sum_list))


Measured memory_bytes: 24548
#include <iostream>
using namespace std;
 
int main() {
 
  while(1) {
 
    int n;
    cin >> n;
    if(n == 0) break;
 
    int min = 1000000;
    int fee;
    for(int i=0;i<=n/200+1;i++) {
      for(int j=0;j<=n/300+1;j++) {
    for(int k=0;k<=n/500+1;k++) {
      if(i*200+j*300+k*500 == n) {
        fee = i*380 + j*550 + k*850;
        if(i>=5) fee += ((i/5)*5*380)*0.8 -(i/5*5*380);
        if(j >=4)fee += ((j/4)*4*550)*0.85 -(j/4*4 * 550);
        if(k>=3) fee += ((k/3)*3*850)*0.88 -(k/3*3 * 850);
        //cout <<i<<"*"<<j<<"*"<<k<<"="<< fee << endl;
        if(min > fee) min = fee;
      }
    }
      }
    }
 
    cout << min << endl;
  }
 
  return 0;
 
}


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

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n, m = [int (i) for i in raw_input ().split ()]
s = raw_input ()
t = raw_input ()
L = n * m / g (n, m)
d = defaultdict (str)
cnt = 0
ok = True
for i in range (n):
    d [i * L / n] = s [i]
for i in range (m):
    ok &= (d [i * L / m] == '' or d [i * L / m] == t [i])
    d [i * L / m] = t [i]
if not ok: L = -1
print L


Measured memory_bytes: 18420
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		int ans=0;
		for (i = 0; i < s.length; i++) {
			switch(s[i]) {
			case '+':
				ans++;
				break;
			case '-':
				ans--;
				break;
			}
			
		}
		out.println(ans);
	}
}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <algorithm>
constexpr long long INF = 1'000'000'000'000'000'000;
int n;
std::vector<std::vector<int>> a;
std::vector<std::vector<long long>> dp, sum, rsum;
long long query(std::vector<std::vector<long long>> &v, int l, int r, int d, int u) {
    return v[r][u] - v[r][d] - v[l][u] + v[l][d];
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    a.assign(n, std::vector<int>(n));
    dp.assign(n, std::vector<long long>(n, INF));
    sum.assign(n + 1, std::vector<long long>(n + 1));
    rsum.assign(n + 1, std::vector<long long>(n + 1));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (i != j)
                std::cin >> a[i][j];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            rsum[i + 1][j + 1] = rsum[i + 1][j] + rsum[i][j + 1] - rsum[i][j] + (i < j ? a[i][j] : 0);
    long long ans = INF;
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            ans = std::min(ans, dp[i][j] + query(rsum, j, n, j, n));
            for (int k = j + 1; k < n; ++k)
                dp[j][k] = std::min(dp[j][k], dp[i][j] + query(rsum, j, k, j, k) + query(sum, k, n, i, j));
        }
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9216
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
  for j in range(N):
    if i<j:
      dist = 0
      for k in range(D):
        dist += (X[i][k] - X[j][k])**2
      dist = math.sqrt(dist)
      if dist.is_integer():
        ans+=1

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

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

		String ans = "APPROVED";
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a % 2 == 0) {
				if (a % 3 != 0 && a % 5 != 0) {
					ans = "DENIED";
					break;
				}
			}
		}

		System.out.println(ans);

	}


}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 ab, bc, ca; cin >> ab >> bc >> ca;
    cout << (ab * bc) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
S = str(input())
N = int(len(S))
B = S[:(N-1)//2]
C = S[(((N+3)//2)-1):]

if S == S[::-1]:
    if B == B[::-1]:
        if C[::-1] == C:
            print("Yes")
        else:
            print("No")
    else:
            print("No")
else:
            print("No")

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        while self.parents[x] != root:
            parent = self.parents[x]
            self.parents[x] = root
            x = parent
        return root

    def unite(self, x, y):
        xroot = self.find(x)
        yroot = self.find(y)
        if xroot == yroot:
            return
        xrank = self.rank[xroot]
        yrank = self.rank[yroot]
        if xrank < yrank:
            self.parents[xroot] = yroot
            self.size[yroot] += self.size[xroot]
        elif xrank == yrank:
            self.parents[yroot] = xroot
            self.rank[yroot] += 1
            self.size[xroot] += self.size[yroot]
        else:
            self.parents[yroot] = xroot
            self.size[xroot] += self.size[yroot]

    def len(self, x):
        return self.size[self.find(x)]


import sys
input = sys.stdin.readline

N, M = map(int, input().split())
bridge = [tuple(map(int, input().split())) for _ in range(M)]

uf = UnionFind(N)
inc = N * (N - 1) // 2
ans = [inc]

for a, b in reversed(bridge):
    if uf.find(a - 1) != uf.find(b - 1):
        la = uf.len(a - 1)
        lb = uf.len(b - 1)
        uf.unite(a - 1, b - 1)
        lab = uf.len(a - 1)
        inc += la * (la - 1) // 2 + lb * (lb - 1) // 2 - lab * (lab - 1) // 2
    ans.append(inc)

print('\n'.join(map(str, ans[:-1][::-1])))

Measured memory_bytes: 35936
import java.util.Scanner;
 
public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
 
 
		    String str1 = scanner.next();
		    int N = Integer.parseInt(str1);
		    int[] array = new int[N];
		    String str2 = scanner.next();
                    int  M =Integer.parseInt(str2);
                    array[0] = M;
		    int maximum = array[0];
		    int minimum = array[0];
		    
		    for(int i = 1; i<array.length; i++)
		    {
		    	array[i] = scanner.nextInt();
		    	int v = array[i];
		    	if(v > maximum)
		    	{
		    		maximum = v;
		    	}
		    	if(v < minimum)
		    	{
		    		minimum = v;
		    	}
		    }
		    
		    int Delta = maximum - minimum ;
		    System.out.println(Delta);
		    
        	scanner.close();}
		  }

Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#define	BCD_SIZE	96

int checkOverFlow(char *numStr) {
	return strlen(numStr) > 80;
}

template <typename T> void mySwap(T &a, T &b) {
	T t = a; a = b; b = t;
}

template <typename T> void reverseArray(T a[], int n) {
	for (int i = n / 2 - 1; i >= 0; --i) { mySwap(a[i], a[n - i - 1]); }
}

void str2bcd(char *str, int n) {
	int len = (int)strlen(str), i;
	reverseArray(str, len);
	for (i = 0; i < len; ++i) { str[i] &= 0xf; }
	for (; i < n; ++i) { str[i] = 0; }
}

void bcd2str(char *bcd, int n) {
	int len;
	for (int i = n - 1; i >= 0 && bcd[i] == 0; --i) { len = i; }
	if (len <= 0) { len = 1; }
	reverseArray(bcd, len);
	for (int i = 0; i < len; ++i) { bcd[i] |= 0x30; }
}

void calcLargeIntSum(char sumStr[], char numStr[][BCD_SIZE], int numNum) {
	char carry = 0;
	for (int i = 0; i < numNum; ++i) { str2bcd(numStr[i], BCD_SIZE); }
	for (int i = 0; i < BCD_SIZE; ++i) {
		sumStr[i] = carry;
		for (int j = 0; j < numNum; ++j) { sumStr[i] += numStr[j][i]; }
		carry = sumStr[i] / 10;
		sumStr[i] %= 10;
	}
	bcd2str(sumStr, BCD_SIZE);
	for (int i = 0; i < numNum; ++i) { bcd2str(numStr[i], BCD_SIZE); }
}

int main() {
	char numStr[2][BCD_SIZE], sumStr[BCD_SIZE];
	int dataSet;
	for (scanf("%d", &dataSet); dataSet > 0; --dataSet) {
		scanf("%82s\n%82s", numStr[0], numStr[1]);
		if (checkOverFlow(numStr[0]) || checkOverFlow(numStr[1])) {
			puts("overflow");
			continue;
		}
		calcLargeIntSum(sumStr, numStr, 2);
		if (checkOverFlow(sumStr)) {
			puts("overflow");
			continue;
		}
		printf("%s\n", sumStr);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n;
    string s,t;
    cin  >> n >> s >> t;

    rep(i,n) cout << s[i] << t[i];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n,k;
    Scd2(n,k);
    ll ans = 0;

    int tmp = 0;
    for (int div = k+1; div <= n; div++){
        tmp = n / div * (div-k);
        if( k != 0 ){
            tmp += max(0, n - n / div * div + 1 - k);
        }else{
            tmp += n - n / div * div;
        }
        ans += tmp;
    }

    printf ("%llu\n", ans);

    return 0;
}



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

long long num[MAXM];
int main(){
	int x;
	int i,j;
	scanf("%d",&x);
	for(i = 0; i <= 320; i++ ){
		num[i] = (long long)pow(i-160,5);
	}
	
	for(i = 320; i >= 0; i--){
		for(j = 320; j >= 0; j--){
			if(num[i]-num[j] == x){
				printf("%d %d\n",i-160,j-160);
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000


int main() {
	long long a[N];
	long long l[N];
	long long r[N];
	long long b[N];
	f(i, N)a[i] = 0;
	long long n, k;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%lld", &n);
	f(i, n+1) {
		scanf("%lld", &a[i]);
	}
	ans = 0;
	x = 1;
	y = 1;
	f(i, n+1) {
		if (a[i] > y) {
			v = false;
			break;
		}
		l[i] = x;
		r[i] = y;
		x -= a[i];
		y -= a[i];
		if (y < 1000000000000000)y = 2 * y;
	}
	x = 0;
	y = 0;
	for (int i = n; i >= 0; i--) {
		x += a[i];
		y += a[i];
		if (r[i] < y) {
			v = false;
			break;
		}
		b[i] = min(x, r[i]);
		ans += b[i];
		x = b[i];
		y = (x + 1) / 2;
	}
	if(v)printf("%lld\n", ans);
	else printf("-1\n");

	return 0;
}

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

using namespace std;
#define repeat(i, n) for(int i=0;i<(n);i++)
int N;
const int inf=1e9;
vector<int> g[100005];
int dep[100005];
int sz[100005]; // subtree
int par[100005];

void dfs(int j, int i=-1){
   par[j]=i;
   sz[j]=1;
   for(int k: g[j])if(i!=k){
      dep[k]=dep[j]+1;
      dfs(k, j);
      sz[j]+=sz[k];
   }
}

int main(){

   cin>> N;
   repeat(i, N-1){
      int a, b;
      cin>> a>> b;
      g[a-1].push_back(b-1);
      g[b-1].push_back(a-1);
   }

   dfs(0);
   int d=dep[N-1];
   int n=N-1;
   repeat(i, (d-1)/2) n=par[n];
   int snu=sz[n];
   int fen=N-sz[n];

   cout<< (fen>snu? "Fennec": "Snuke")<< endl;

   return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N; cin>>N;
  for(int i=0; i<3; i++){
    if(N%10==7){
      cout<<"Yes"<<endl;
      return 0;
    }
    N/=10;
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3636
import sys


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


INF = float('inf')


n, m, c = LI()
b = LI()
a = LIR(n)
cnt = 0
for i in range(n):
    sahen = 0
    sahen += c
    for j in range(m):
        sahen += a[i][j] * b[j]
    if sahen > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 9160
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

//解説
//二次元累積和
int N,M,Q;
int L[200005],R[200005];
int dp[505][505];
signed main(){
    scanf("%lld %lld %lld",&N,&M,&Q);
    rep(l,N+1)rep(r,N+1)dp[l][r]=0;
    rep(i,M){
        int l,r;
        scanf("%lld %lld",&l,&r);r--;l--;
        dp[l][r]+=1;
    }
    rep(i,N)rep(j,N)if(i!=0)dp[i][j]+=dp[i-1][j];
    rep(j,N)rep(i,N)if(j!=0)dp[i][j]+=dp[i][j-1];
    rep(i,Q){
        int p,q;
        scanf("%lld %lld",&p,&q);p--;q--;
        int ans=dp[q][q];
        if(p>0)ans-=dp[p-1][q]+dp[q][p-1]-dp[p-1][p-1];
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  int x,n;
  cin>>x>>n;
  vi p(101,0);
  rep(i,n){
    int k;
    cin>>k;
    p[k]=1;
  }
  vi ch;
  FOR(i,0,101){
    if(i<1||i>100||p[i]==0){
      ch.pb(i);
    }
  }

  sort(all(ch));

  int ans=ch[ch.size()-1];
  int tmp=500;
  rep(i,ch.size()){
    if(abs(ch[ch.size()-1-i]-x)<=tmp){
      tmp=abs(ch[ch.size()-1-i]-x);
      ans=ch[ch.size()-1-i];
    }
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define tc(t)  int t; cin>>t; while(t--) 
#define f(n)    for(int i=0;i<n;i++)
#define unordered_map   u_m
#define endl   "\n" 


void i_o_f()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
       freopen("give_input.txt", "r", stdin);
    freopen("give_output.txt", "w", stdout);
#endif
}







int32_t main()
{
	//i_o_f();
  
   int n,l;
   cin>>n>>l;
   vector<string> v;
   for(int i=0;i<n;i++)
   {
   	  string user;
   	  cin>>user;
   	  v.push_back(user);

   } 

   sort(v.begin(),v.end());
   string answer;
   for(int i=0;i<n;i++)
   {

   	answer+=v[i];
   }
   cout<<answer<<endl;






}

Measured memory_bytes: 256
def main():
  from collections import deque
  H, W = map(int, input().split())
  graph = [['#'] * (W+2) for _ in range(H+2)]
  for i in range(H):
    S = input()
    for j in range(W):
      graph[i+1][j+1] = S[j]

  def dfs(sx, sy):
    q = deque([(sx, sy)])
    dist = [[-1] * (W+2) for _ in range(H+2)]
    dist[sx][sy] = 0
    s = 0
    while q:
      x, y = q.popleft()
      dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
      for dx, dy in dxy:
        nextx = x+dx
        nexty = y+dy
        if(dist[nextx][nexty] >= 0):
          continue
        if(graph[nextx][nexty] == '#'):
          continue
        dist[nextx][nexty] = dist[x][y] + 1
        q.append((nextx, nexty))
    for i in range(H+2):
      for j in range(W+2):
        if(dist[i][j] >= 0):
          s = max(s, dist[i][j])
    return s

  ans = 0  
  for sx in range(1, H+1):
    for sy in range(1, W+1):
      if(graph[sx][sy] == '.'):
          tmp = dfs(sx, sy)
          ans = max(ans, tmp)
          
  print(ans)
  
main()

Measured memory_bytes: 43484
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = stdin.readline().rstrip().split()
n = int(t[0])
m = int(t[1])
tour = [int(s) for s in stdin.readline().rstrip().split()]
data = []
for el in range(m):
    data.append([int(s) for s in stdin.readline().rstrip().split()])
para = []
for el in range(n):
    tmp = {'index': el, 'height': tour[el], 'rel': []}
    para.append(tmp)
for el in data:
    para[el[0] - 1]['rel'].append(el[1] - 1)
    para[el[1]-1]['rel'].append(el[0]-1)

count = 0
for el in para:
    check = True
    for el2 in el['rel']:
        if el['height'] <= para[el2]['height']:
            check = False
    if check:
        count += 1
print(count)


Measured memory_bytes: 142700
#include <iostream>

using namespace std;

int main() {

    int K,X;

    cin >> K >> X;

    for(int i=X-(K-1); i < K+X; i++)
        if(i < K+X-1)
            std::cout << i << " ";
        else
            std::cout << i;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int search(int);
int **line;
int N, M;
int main() {
	cin >> N >> M;
	line = new int*[N + 1];
	line[0] = new int[M + 1]{ 0 };
	int dummy;
	for (int i = 1; i <= N; ++i) {
		cin >> dummy;
		line[i] = new int[M + 1];
		for (int j = 1; j <= M; ++j) {
			line[i][j] = line[i - 1][j];
		}
		++line[i][dummy];
	}
	int *dp;
	dp = new int[1 << M];
	dp[0] = 0;
	for (int i = 1; i < (1 << M); ++i) {
		dp[i] = N + 1;
	}
	for (int i = 0; i < (1 << M) - 1; ++i) {
		for (int j = 0; j < M; ++j) {
			if (!(i&(1 << j))) {
				int nlong = search(i);
				dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + line[N][j + 1] - (line[nlong + line[N][j + 1]][j + 1] - line[nlong][j + 1]));
			}
		}
	}
	cout << dp[(1 << M) - 1] << endl;
	return 0;
}
int search(int use) {
	int res = 0;
	for (int i = 0; i < M; ++i) {
		if (use&(1 << i)) {
			res += line[N][i + 1];
		}
	}
	return res;
}

Measured memory_bytes: 17348
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }
    sc.close();

    int ans = 0; 
    int c = 1;
    for (int i = 0; i < N; i++) {
      if (a[i] == c) {
        c++;
      } else {
        ans++;
      }
    }
    if (c == 1) ans = -1;
    System.out.println(ans);
  }
}

Measured memory_bytes: 85684
N = int(input())
A = [int(i) for i in input().split()]
val = [0]*(10**5)
for a in A:
    val[a-1] += 1

t = 0
for i,n in enumerate(val):
    t += (i + 1)*n

ans = []
Q = int(input())
for _ in range(Q):
    B,C = [int(i) for i in input().split()]
    t += (C - B)*val[B-1]
    val[C-1] += val[B-1]
    val[B-1] = 0
    ans.append(str(t))
print("\n".join(map(str, ans)))

Measured memory_bytes: 24228
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int dr[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int n, m;

bool ins(int x, int y) {
	return x < n && y < m && x >= 0 && y >= 0;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int ch, cw;
	int dh, dw;
	cin >> n >> m;
	cin >> ch >> cw;
	ch--, cw--;
	cin >> dh >> dw;
	dh--, dw--;
	vector<string> mat(n);
	for(auto& el: mat) cin >> el;
	vector<vector<int>> dp(n, vector<int>(m, -1));
	queue<ii> q;
	q.push(ii(ch, cw));
	int u = 0;
	for(; q.size(); u++) {
		queue<ii> nxt;
		while(q.size()) {
			ii cr = q.front(); q.pop();
			if(dp[cr.fi][cr.se] != -1) continue;
			dp[cr.fi][cr.se] = u;
			if(cr.fi == dh && cr.se == dw) {
				cout << u << '\n'; exit(0);
			}
			for(int i = 0; i < 4; i++) {
				int x = cr.fi + dr[i][0], y = cr.se + dr[i][1];
				if(ins(x, y) && mat[x][y] == '.' && dp[x][y] == -1) {
					q.push(ii(x, y));
				}
			}
			for(int i = cr.fi - 2; i <= cr.fi + 2; i++)
				for(int j = cr.se - 2; j <= cr.se + 2; j++)
					if(ins(i, j) && mat[i][j] == '.' && dp[i][j] == -1) 
						nxt.push(ii(i, j));
		}
		swap(q, nxt);
	}
	cout << "-1\n";
}



Measured memory_bytes: 9704
#include<stdio.h>
#include<stdlib.h>

int calcdep(int);
int tjudge(int);
int calcdeg(int);
int calchei(int);
int greater(int, int);

typedef struct {
  int parent;
  int sibling;
  int left, right;
} Tree;

Tree *t;

int main()
{
  int i, j;
  int id;
  int n;
  char type[3][15] = {{"root"},{"internal node"},{"leaf"}};
  
  scanf("%d", &n);
  
  t = malloc(sizeof(Tree) * n);
  
  for(i = 0; i < n; i++)
    {
      t[i].parent = -1;
      t[i].sibling = -1;
    }
  
  for(i = 0; i < n; i++)
    {    
      scanf("%d", &id);
    
      scanf("%d %d", &t[id].left, &t[id].right);
      t[t[id].left].parent = id;
      t[t[id].left].sibling = t[id].right;
      t[t[id].right].parent = id;
      t[t[id].right].sibling = t[id].left;
    }
  
  for(i = 0; i < n; i++)
    {
      printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
	     i, t[i].parent, t[i].sibling, calcdeg(i), calcdep(i), calchei(i)-1, type[tjudge(i)]);
    }
  
  return 0;
}

int calcdep(int key)
{
  int count = 0;
  
  while(t[key].parent != -1)
    {
      key = t[key].parent;
      count++;
    }
  
  return count;
}

int tjudge(int key)
{
  if(t[key].parent == -1)return 0;
  if(t[key].right == -1 && t[key].left == -1)return 2;
  return 1;
}

int calcdeg(int key)
{
  int count = 0;
  
  if(t[key].left != -1)count++;
  if(t[key].right != -1)count++;
  
  return count;
}

int calchei(int key)
{
  if(key == -1)return 0;
  else return greater(calchei(t[key].left), calchei(t[key].right)) + 1;
}

int greater(int x, int y)
{
  if(x > y) return x;
  return y;
}
  
/*  int count;

  if(t[key].left == -1)
    {
      if(t[key].right == -1)
	{
	  return calchei(t[t[key].parent].right);
	}
      count++;
      return calchei(t[key].right);
    }
  count++;
      return calchei(t[key].left);
*/



Measured memory_bytes: 2132