akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static int[] dx = {1,0,-1,0};
    static int[] dy = {0,1,0,-1};
    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        char[][] a = new char[n][m];
        for(int i = 0; i<n; i++){
            String s = in.next();
            for(int j = 0; j<m; j++){
                a[i][j] = s.charAt(j);
            }
        }
        boolean print = true;
        for(int i = 0; i<n; i++){
            for(int j = 0; j<m; j++){
                if(a[i][j] == '#'){
                    if(!check(i,j,a)){
                        print = false;
                        break;
                    }
                }
            }
            if(!print) break;
        }
        if(print) out.println("Yes");
        else out.println("No");
        out.close();
    }
    static boolean check(int i, int j, char[][] a){
        for(int k = 0; k<4; k++){
            int t1 = i+dx[k];
            int t2 = j+dy[k];
            if(t1>=0 && t1<a.length && t2>=0 && t2<a[0].length && a[t1][t2] == '#') return true;
        }
        return false;
    }
    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());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> b(n + 1);
  while (k--) {
    for (int i = 0; i <= n; i++) b[i] = 0;
    for (int i = 0; i < n; i++) {
      int from = max(i - a[i], 0);
      int to = min(i + a[i], n - 1);
      b[from] += 1;
      b[to + 1] -= 1;
    }
    bool changed = false;
    for (int i = 0; i < n; i++) {
      changed |= (a[i] != b[i]);
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (!changed) break;
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << a[i];
  }
  cout << '\n';
  return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string S; cin >> S;
  vector<char> ans;
  char tmp = S[0];
  for(int i = 1; i < S.size(); ++i) {
    if(S[i] != tmp) ans.push_back(tmp);
    tmp = S[i];
  }
  cout << ans.size() << endl;
}


Measured memory_bytes: 640
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif


void solve()
{
    int mxans = 0,n ;
    cin >> n ;
    vector<int> c(n),v(n) ;
    rep(i,n) cin >> v[i] ;
    rep(i,n) cin >> c[i] ;
    rep(i,(1<<n)){
        int ans = 0 ;
        rep(j,n){
            if((i>>j)&1)
                ans += v[j] - c[j] ;
        }
        mxans = max(mxans, ans) ;
    }
    cout << mxans ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long int a,b;
    cin >> a >> b;
    if(a+b>=a-b && a+b>=a*b)
        cout << a+b << endl;
    else if(a-b>=a+b && a-b>=a*b)
        cout << a-b << endl;
    else if(a*b>=a+b && a*b>=a-b)
        cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3604
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    string s; 
    cin >> s;
    int n = s.size();
    rep(i, n){
        if(s[i] == '?'){
            s[i] = 'D';
        }
    }
    cout << s << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3776
#include<cstdio>
using namespace std;
int n,m;
int main()
{
  scanf("%d%d",&m,&n);
  for(int i=0;i<=m;i++)
    for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
       {
          if(i+j+k==m && i*1000+j*5000+k*10000==n)
            {printf("%d %d %d",k,j,i);return 0;}
       }
  printf("-1 -1 -1");
  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    auto vmax = *max_element(A.begin(), A.end());

    auto res = *min_element(A.begin(), A.end(),
        [&](int a, int b){
            auto a2 = a != vmax? abs(2 * a - vmax) : INT_MAX;
            auto b2 = b != vmax? abs(2 * b - vmax) : INT_MAX;
            return a2 < b2;
        });
    cout<<vmax<<" "<<res<<endl;

    return 0;
}

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

 
int main() {
   int n;
   cin>>n;
   vector<ll> A(n+1),B(n);
   rep(i,n+1)cin>>A[i];
   rep(i,n)cin>>B[i];
   ll ans=0;
   rep(i,n){
       if(A[i]>=B[i])ans+=B[i];
       else {
           ans+=A[i];
           ans+=min(B[i]-A[i],A[i+1]);
           A[i+1]=max(A[i+1]-(B[i]-A[i]),(ll)0);
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>
 
using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;
 
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();
 
#define rep(i,n) for(ll i=0;i<ll(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl
 
ll num(ll A, ll B){
	ll score = A * B - 1;
	ll i_max = sqrt((long double)(score));
 
	ll res = i_max * 2;
	if(i_max >= min(A,B))
		res--;
	if(i_max != 0 && i_max == score / i_max)
		res--;
 
	return res;
}
 
void solve(){
	int Q;
	cin >> Q;
	int A[105], B[105];
	rep(i, Q){
		cin >> A[i] >> B[i];
	}
 
	rep(i, Q){
		cout << num(A[i], B[i]) << endl;
	}
}
 
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        a1: [i64; n],
        a2: [i64; n],
    };
    println!(
        "{}",
        (0..n)
        .map(|i|{
            (0..i+1).map(|i| a1[i]).sum::<i64>() +
            (i..n).map(|i| a2[i]).sum::<i64>()
        })
        .max().unwrap()
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int N;
  cin >> N;
  vi V(N); 
  vi C(N);
  rep(i,N)cin >> V[i];
  rep(i,N) cin >> C[i];
  int ans =0;
  rep(i,N){
    V[i] -= C[i];
    if(V[i]>0) ans += V[i]; 
  }   
  cout << ans << endl;
  
}


Measured memory_bytes: 256
k,x = map(int, input().split())
s = ""
for i in range(k - 1):
    s += str(x - (k - 1) + i)  + " "
s += str(x) + " "
for i in range(k - 1):
    s += str(x + i + 1) + " "
print(s[:-1])


Measured memory_bytes: 2940
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
map<ll,int> mp;
typedef ll fuko[yuzu|10];
fuko sum;
int main(){
int i,n=read(),m=read();
for (i=1;i<=n;++i) sum[i]=(sum[i-1]+read())%m;
ll llx=0;
for (i=0;i<=n;++i) llx+=mp[sum[i]],mp[sum[i]]++; 
write(llx),pl;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main()
{
	int N;scanf("%d",&N);
	int r=0,p,v=0;
	for(int i=0;i<N;i++)
	{
		p=v;
		scanf("%d",&v);
		if(p==v)r=r+1,v=0;
	}
	printf("%d",r);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fi first
#define se second
#define mp make_pair
#define pb push_back
int32_t main(){
    
    
   unordered_map< string,int>cn;
   string s;
   cin>>s;
   for(int i = 0; i <s.size() ; i++){
       cout<<'x';
   }
   
    
}

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


int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll maxv = min(a, b);
    ll minv = max(a + b - n, 0LL);
    cout << maxv << ' ' << minv << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{   int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a+b>=c)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include <iomanip>
using namespace std;


int main()
{
    long long n,cnt=0,num=0;
    cin>>n;
    vector<string>s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
    
    string tmp=s[0];
    for(int i=1;i<n;i++){
        if(tmp==s[i]){
            num++;
        }else if(1<=num){
            cnt+=num*(num+1)/2;
            num=0;
            tmp=s[i];
        }else{
            tmp=s[i];
            num=0;
        }
        
        if(i==n-1 and 1<=num){
            cnt+=num*(num+1)/2;
        }

        
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){}
};
//using Graph = vector<vector<Edge>>;

int main(){
  int n; cin >> n;
  int ans;
  if(n%2==0) ans = n/2-1;
  else ans = n/2;

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if((x - r < 0 || x + r > W || y - r < 0 || y + r > H)){
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		sc.close();
	}
}


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

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 2000;
ll nck[N + 5][N + 5];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    nck[0][0] = nck[1][0] = nck[1][1] = 1;
    for (int i = 1; i <= N; i++) {
        nck[i][0] = 1;        
        for (int j = 1; j <= i; j++) {
            nck[i][j] = (nck[i - 1][j] + nck[i - 1][j - 1]) % MOD;
        }
    }

    int n, blue;
    cin >> n >> blue;
    int red = n - blue;
    for (int i = 1; i <= blue; i++) {
        if (i > red + 1) {
            cout << 0 << '\n';
            continue;
        }
        ll splitblue = nck[blue - 1][i - 1];
        ll splitred = nck[red + 1][i];
        ll ways = (splitblue*splitred) % MOD;
        cout << ways << '\n';
    }
    return 0;
}

Measured memory_bytes: 30208
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val i1 = sc.nextInt()
    val i2 = sc.nextInt()
    val rectange = i1 * i2
    val rectanglePerimeter = 2 * (i1 + i2)
    println("${rectange} ${rectanglePerimeter}")
}



Measured memory_bytes: 27512
#include <bits/stdc++.h>
#define ll long long
int main()
{
    std::string s;
    int k;
    std::cin >> s >> k;
    std::vector<std::string> Ans(k, "ああああ");
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 1; (i + j <= s.size() && j <= k); ++j) {
            for (int l = 0; l < k; ++l) {
                if (Ans.at(l).compare(s.substr(i, j)) == 0) {
                    break;
                } else if (Ans.at(l).compare(s.substr(i, j)) > 0) {
                    Ans.insert(Ans.begin() + l, s.substr(i, j));
                    break;
                }
            }
        }
    }
    std::cout << Ans[k - 1] << std::endl;
}

Measured memory_bytes: 3600
//A
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    int R;
    cin >> R;
    if(R < 1200) cout << "ABC" << endl;
    else if(R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))

def rui(A):
    R=[A[0]]*len(A)
    for i in range(len(A)-1):
        R[i+1]=R[i]+A[i+1]
    return R
R=rui(A)
S=sum(A)
ans=10**20
for i in range(n-1):
    a=R[i] ; b=S-a
    ans=min(ans, abs(a-b))
print(ans)

Measured memory_bytes: 30732
h, w = map(int, input().split())
c = []
for i in range(10):
    c.append(list(map(int, input().split())))
a = []
for i in range(h):
    a.append(list(map(int, input().split())))

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += c[a[i][j]][1]
        else:
            continue
print(ans)

Measured memory_bytes: 3444
p,q,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0]*m
y = [0]*m
c = [0]*m
z = [100000, 100000 ,200000]
for i in range(p):
    if(z[0] > A[i]):
        z[0] = A[i]
for i in range(q):
    if(z[1] > B[i]):
        z[1] = B[i]
for i in range(m):
    x[i],y[i],c[i] = map(int, input().split())
    if(A[x[i]-1] + B[y[i]-1] - c[i] < z[2]):
        z[2] = A[x[i]-1] + B[y[i]-1] - c[i]
print(min(z[0]+z[1], z[2]))

Measured memory_bytes: 23420
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
#[macro_use] extern crate text_io;
use proconio::marker::*;
use std::mem;

#[fastout]
fn main() {
    input!{
        a:usize,
    }
    let mut ans:usize=1;
    for i in 2..a+1{
        let mut j=i*i;
        while j<=a{
            if 
            ans<j {
                ans=j;
            }
            j*=i;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 2156
import math

def resolve():
  n = int(input())
  k = int(input())
  x = list(map(int, input().split()))

  ans = 0
  for v in x:
    ans += min((v-0) * 2, (k - v) * 2)

  print(ans)
  return

if __name__ == "__main__":
  resolve()



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int n, num, mod;
    cin >> n;
    
    num = n / 111;
    mod = n % 111;

    if (mod) num ++;

    cout << num * 111 << endl;
    
    return 0;

}

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

int pref(string &s, string &sw, int n) {
  if ((int)s.size() - n < (int)sw.size()) {
    return 0;
  }
  
  for (int i = 0; i < sw.size(); i++) {
    if (s[i + n] != sw[i]) return 0;
  }
  return 1;
}

int main() {
  
  string tc[] = {"remaerd", "resare", "maerd", "esare"};
  
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  int p = 0;
  while (p < s.size()) {
    int found = 0;
    for (int i = 0; i < 4; i++) {
      if (pref(s, tc[i], p)) {
        p += tc[i].size();
        found = 1;
        break;
      }
    }
    if (!found) {
      cout << "NO\n";
      return 0;
    }
  }
  if (p == s.size())
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}


Measured memory_bytes: 3772
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<ctype.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[100];
	int sum=0;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			sum+=a[i]*a[j];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<iomanip>

using namespace std;


int main(void) {
	double l;
	cin >> l;
	cout <<fixed<<setprecision(7) << (l / (double)3.0)*(l / (double)3.0)*(l / (double)3.0);

	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
#define rep(i,n) for(int i = 0, i##_len=(n); i < i##_len; ++i)
typedef long long ll;

int main(){
	int a, b;
	cin >> a >> b;
	cout << ((a + b + 1) / 2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    int q;
    cin>>q;
    rep(i, q) {
        int b, e, t;
        cin>>b>>e>>t;
        swap_ranges(as.begin() + b, as.begin() + e, as.begin() + t);
    }
    rep(i, n) cout<<as[i]<<(i != n - 1 ? ' ' : '\n');
}


Measured memory_bytes: 3232
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  string input;
  cin>>input;
  if(input[0]==input.back()){
    if(input.size()%2==1){
      cout<<"Second"<<"\n";  
    }
    else{
       cout<<"First"<<"\n"; 
    }
  }
  else{
    if(input.size()%2==1){
      cout<<"First"<<"\n"; 
      
    }
    else{
       cout<<"Second"<<"\n";  
    }
  }
  return 0;
}

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

int main() {
  int n;
  string s, t, r;
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) {
    r += s.at(i);
    r += t.at(i);
  }
  cout << r << endl;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N;
    cin >> N;
    priority_queue<LL, vector<LL>, less<LL>> pq;
    REP(i, N) {
        LL a;
        cin >> a;
        pq.push(a);
    }

    LL W = 0;
    LL H = 0;
    for(;1 < pq.size();) {
        LL a = pq.top();
        pq.pop();
        LL b = pq.top();
        if(a == b) {
            pq.pop();
            if(W == 0) {
                W = a;
            }else if(H == 0) {
                H = a;
            }
        }
    }
    LL res = W*H;
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1528
#include<stdio.h>

int main(){
	const int CASH = 1000;
	int price;
	int hundred;
	int ten;
	int digit;
	int count;

	while( 1 ) {

		count = 0;

		scanf( "%d",&price );
		if( !price ) break;

		price = CASH - price;

		hundred = price / 100;
		ten = ( price - hundred * 100 ) / 10;
		digit = price - ( hundred * 100 ) - (ten * 10);

		while( hundred > 0 ){
			if( hundred >= 5 ){
				hundred -= 5;
				count++;
			}else{
				hundred--;
				count++;
			}
		}

		while( ten > 0 ){
			if( ten >= 5 ){
				ten -= 5;
				count++;
			}else{
				ten--;
				count++;
			}
		}

		while( digit > 0 ){
			if( digit >= 5 ){
				digit -= 5;
				count++;
			}else{
				digit--;
				count++;
			}
		}

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

	}
	return 0;
}

Measured memory_bytes: 1032
/*Program from Luvwgyx*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2e2+10;
const int mod=998244353;
int n,x[maxn],y[maxn],power[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void init(){power[0]=1;for(int i=1;i<=n;i++)power[i]=(power[i-1]<<1)%mod;}
bool check(int i,int j,int k){return (x[i]-x[j])*(y[i]-y[k])==(x[i]-x[k])*(y[i]-y[j]);}
int main(){
    n=read();init();int ans;
    for(int i=1;i<=n;i++)x[i]=read(),y[i]=read();
    ans=(power[n]-n-1+mod)%mod;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++){
            int ret=0;
            for(int k=j+1;k<=n;k++)
                if(check(i,j,k))ret++;
            ans=(ans-power[ret]+mod)%mod;
        }
    write(ans);
    return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll h,w,k; cin>>h>>w>>k;
    vector<vector<char>>a(h,vector<char>(w));
    rep(i,h){
        rep(j,w)cin>>a[i][j];
    }
    ll ans=0;
    for(ll tmp=0;tmp<(1<<(h+w));tmp++){
        bitset<12>b(tmp);
        ll cnt=0;
        rep(i,h){
            rep(j,w){
                if(b.test(i+w))continue;
                else if(b.test(j))continue;
                if(a[i][j]=='#')cnt++;
            }
        }
        if(cnt==k)ans++;
    }
    cout<<ans<<endl;
}





























































































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

using namespace std;

const int inf = 1e8;

int main(){
  int H, W;
  while(cin >> W >> H, H != 0){
    int sz = H* W;
    vector<vector<int>> g(sz, vector<int>(sz));
    rep(i, sz) g[i][i] = 0;

    rep(y, H) {

      rep(x, W - 1){
        int n; cin >> n;
        if (n == 0){
          g[y * W + x].push_back(y * W + (x + 1));
          g[y * W + x + 1].push_back(y * W + x); 
        }
      }
      if(y == H - 1) break;
      rep(x, W){
        int n; cin >> n;
          if (n == 0){
          g[y * W + x].push_back((y + 1) * W + x);
          g[(y + 1) * W + x].push_back(y * W + x);
          }
      }
    }
    
    deque<tuple<int, int>> q;
    vector<int> vis(sz, inf);
    vis[0] = 0;
    q.emplace_back(0, 0);
    while(q.size() > 0){
      int h, s; tie(h, s) = q.front(); q.pop_front();
      for(auto&& k : g[h]){
          if(vis[k] == inf){
              vis[k] = s + 1;
              q.emplace_back(k, s + 1);
          }
      }
    }
    int res = vis[sz - 1] + 1;
    cout << ((res >= inf) ? 0 : res) << endl;
  }
}

Measured memory_bytes: 9420
#include<stdio.h>
int main( ){
  int H,W;
  while( 1 ){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(i==0||i==H-1){
	  printf("#");
	}else{
	  if(j==0||j==W-1){
	    printf("#");
	  }else{
	    printf(".");
	  }
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;  
}

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

constexpr int MOD = 1000000007;

using namespace std;

int main() {

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

  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if (ans * 2 < ans + k) {
      ans *= 2;
    } else {
      ans += k;
    }
  }
  cout << ans << endl;
}



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

int main() {
    vector<string> divide = {"maerd", "remaerd", "esare", "resare"};

    string S;
    cin >> S;

    reverse(S.begin(), S.end());

    bool X = true;
    for (int i = 0; i < S.size();){
        bool Y = false;
        for (int j = 0; j < 4; j++){
            if (S.substr(i, divide.at(j).size()) == divide.at(j)){
                i += divide.at(j).size();
                Y = true;
                break;
            }
        }
        if (!Y) {
            X = false;
            break;
        }
    }
    if(X) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
typedef long long int ll;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = min(n*a, b);
    cout << ans << endl;
    return 0;
}

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

int main(){
    int mFlag[4][13];
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            mFlag[i][j]=0;
        }
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        char c;
        cin>>c;
        int rank;
        cin>>rank;
        int mark;
        if(c=='S')mark=0;
        if(c=='H')mark=1;
        if(c=='C')mark=2;
        if(c=='D')mark=3;
        mFlag[mark][rank-1]=1;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(mFlag[i][j]==0){
                if(i==0)cout<<"S"<<" ";
                if(i==1)cout<<"H"<<" ";
                if(i==2)cout<<"C"<<" ";
                if(i==3)cout<<"D"<<" ";
                cout<<j+1<<endl;
            }
        }
    }
    return 0;
}


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

int main() {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=a;
    ll res=k-a-b;
    if (k<=a) {
        cout<<k<<endl;
    } else if (k <= a+b) {
        cout<<a<<endl;
    } else {
        if (c<res) res=c;
        ans-=res;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3640
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())))
bc = sorted([list(map(int,input().split())) for _ in range(m)],key = lambda x:-x[1])
flag = 0
flag_2 = 0
#print(a,bc)
for i in range(n):
  if a[i] < bc[flag_2][1]:
    a[i] = bc[flag_2][1]
  else:
    break
  flag += 1
  if flag == bc[flag_2][0]:
    flag_2 += 1
    flag = 0
  if flag_2 == m:
    break
print(sum(a))

Measured memory_bytes: 83908
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a.size())
#define pll pair<ll,ll>
double a[10005];
double dp[3005][3005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll i,j,n,m;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	double p = 1;
	for(i=1;i<=n;i++)
	{
		p = p*(1-a[i-1]);
		dp[0][i] = p;
	}
	p = 1;
	for(i=1;i<=n;i++)
	{
		p = p * a[i-1];
		dp[i][i] = p;
	}
	for(i=1;i<=n;i++)
	{
		for(j=2;j<=n;j++)
		{
			if(i<j)
				dp[i][j] = a[j-1]*dp[i-1][j-1] + (1-a[j-1])*dp[i][j-1];
		}
	}


	double sum = 0;
	for(i=n/2+1;i<=n;i++)
		sum+=dp[i][n];

	cout<<setprecision(9)<<sum<<endl;
	return 0;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+5;
const ll MOD=1e9+7;
void solve()
{
	ll N,K;
	cin>>N>>K;
	ll sum=((N)*(N+1))/2;
	ll ans=0,c=0;
	for(ll i=N+1;i>=K;i--)
	{
		ll l=((i-1)*(i))/2;
		ll r=sum;
		ans=(ans+(r-l+1))%MOD;
		sum-=c;
		c++;
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main
{
	String s[] = new String[2];

	public Main()
	{
		Scanner scanner = new Scanner(System.in);
		for(int i = 0; i < 2; i++)
		{
			s[i] = scanner.next();
		}
		if(s[0].charAt(0) == s[1].charAt(2) && s[0].charAt(1) == s[1].charAt(1) && s[0].charAt(2) == s[1].charAt(0))
		{
			System.out.println("YES");
		}
		else
		{
			System.out.println("NO");
		}
	}

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


Measured memory_bytes: 22608
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(),x.rend()
#define mu(x) x.resize(unique(all(x))-x.begin());
#define srt(x) sort(all(x));
#define rev(x) reverse(all(x));
#define each(x,a) for(auto& x:a)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define debug_v(x) { cerr<<#x<<"\n";  each(y,x) cerr<<y<<" "; cerr<<'\n';}
#define debug_vp(x) { cerr<<#x<<"\n";  each(y,x) cerr<<y.ff<<" "<<y.ss<<'\n'; cerr<<'\n';}
#ifndef BTW
	#define cerr if(false)cerr
#endif
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

bool check(string s){
	rep(i,sz(s)){
		if(s[i]!=s[sz(s)-i-1]){
			return false;
		}
	}
	return true;
}

int main(){
	fastio;
	string s;
	cin>>s;
	int n=s.size();
	if(check(s) && check(s.substr(0,(n-1)/2)) && check(s.substr((n + 3)/2-1,n-(n + 3)/2+1))){
		cout<<"Yes";
	} else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));
	
	public static void main(String[] args) {
		int N=scan.nextInt();
		long K=scan.nextLong();
		int a[][]=new int[N][2];
		for(int i=0;i<N;i++) {
			a[i][0]=scan.nextInt();
			a[i][1]=scan.nextInt();
		}
		Arrays.sort(a,(x,y)->Integer.compare(x[0], y[0]));
		long cnt=0;
		for(int i=0;i<N;i++) {
			cnt+=a[i][1];
			if(cnt>=K) {
				System.out.println(a[i][0]);
				break;
			}
		}
	}
}

Measured memory_bytes: 94500
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

const int MAX = 510000;
const int MOD = 1000000007;


int a[200010],b[200010];

int main(void) {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + N);
	int first = b[N - 1], second = -1;
	int count = 1;
	for (int i = N - 2; i >= 0; i--) {
		if (b[i] < first) second = max(second, b[i]);
		else count++;
	}
	for (int i = 0; i < N; i++) {
		if (count > 1) cout << first << endl;
		else {
			if (a[i] < first) cout << first << endl;
			else cout << second << endl;
		}
	}
}


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

using namespace std;

vector <int> V[101010];
int L[101010], R[101010], D[101010];
int T[303030];
int P[101010][22];
int n,k,ans,cnt,sz;

int dfs(int p)
{
	int i,t;
	
	L[p] = R[p] = cnt++;
	
	for(i=0;i<V[p].size();i++){
		t = V[p][i];
		P[t][0] = p;
		D[t] = D[p] + 1;
		R[p] = max(R[p], dfs(t));
	}
	
	return R[p];
}

void update(int p, int s, int e, int l, int r)
{
	if(r < s || e < l) return;
	if(l <= s && e <= r){
		T[p] = 0;
		return;
	}
	
	update(p<<1, s, s+e>>1, l, r);
	update(p<<1|1, (s+e>>1)+1, e, l, r);
	
	if(D[T[p<<1]] > D[T[p<<1|1]]) T[p] = T[p<<1];
	else T[p] = T[p<<1|1];
}

int par(int p, int t)
{
	int i;
	
	for(i=0;i<=18;i++){
		if(t & (1<<i)) p = P[p][i];
	}
	
	return p;
}

int main()
{
	int i,j,a,p;
	
	scanf("%d%d", &n,&k);
	
	scanf("%d", &a);
	if(a != 1) ans ++;
	
	for(i=2;i<=n;i++){
		scanf("%d",&a);
		V[a].push_back(i);
	}
	
	dfs(1);
	D[0] = -1;
	
	for(i=1;i<=18;i++){
		for(j=1;j<=n;j++){
			P[j][i] = P[P[j][i-1]][i-1];
		}
	}
	
	for(sz=1;sz<n;sz<<=1);
	
	for(i=1;i<=n;i++){
		T[sz + L[i]] = i;
	}
	
	for(i=sz-1;i;i--){
		if(D[T[i<<1]] > D[T[i<<1|1]]) T[i] = T[i<<1];
		else T[i] = T[i<<1|1];
	}
	
	for(;;ans++){
		p = T[1];
		if(D[p] <= k) break;
		p = par(p, k-1);
		update(1, 0, sz-1, L[p], R[p]);
		
		//printf("%d %d\n",L[p],R[p]);
		//for(i=1;i<sz+sz;i++) printf("%d ",T[i]);
		//printf("\n");
	}
	
	printf("%d\n",ans);
	
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[3001];
ll dp[3001][3001];

ll dfs(ll l,ll r){
  if(dp[l][r]!=-INF)return dp[l][r];
  if(l==r)return 0;
  ll res=max(-dfs(l+1,r)+a[l],-dfs(l,r-1)+a[r-1]);
  return dp[l][r]=res;
}

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

  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,3001)rep(j,3001)dp[i][j]=-INF;
  cout<<dfs(0,n)<<endl;

  return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

bool check(string s){
    int N = s.size();
    bool res = true;
    REP(i,(N+1)/2){
        if(s[i] != s[N-1-i]){
            res = false;
            break;
        }
    }
    return res;
}
int main(void){
    string S; cin >> S;
    int N = S.size();
    string s1 = S.substr(0,(N-1)/2);
    string s2 = S.substr((N+3)/2-1);
    if(check(S) && check(s1) && check(s2)){
        cout << "Yes" << en;
    }
    else cout << "No" << en;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mp make_pair
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
void init() {
 int n,w;
 cin>>n>>w;
 vector<int>weight(n),val(n);
 for(int i=0;i<n;i++)   cin>>weight[i]>>val[i];
 /*vector<vector<int> > dp(n+1,vector<int>(w+1));
 dp[0][0]=0;
 for(int i=1;i<=n;i++){
     for(int j=0;j<=w;j++){
         dp[i][j]=dp[i-1][j];
         int left = j- weight[i-1];
         if(left>=0)    dp[i][j]= max(dp[i][j],dp[i-1][left]+val[i-1]);
     }
 } 
 cout<<dp[n][w]<<endl;*/
 vector<int>dp(w+1); //dp[i] max value that can be obtained with weight exactly i
 for(int i=0;i<n;i++){
   for(int j=w;j>=weight[i];j--) dp[j]=max(dp[j],val[i]+dp[j-weight[i]]);
 }
 cout<<dp[w]<<endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 1024
from sys import stdin
import sys
import math

n = int(input())
a = list(map(int, stdin.readline().rstrip().split()))

dict_count = {}
for i in a:
    dict_count[i] = 0

for j in a:
    dict_count[j] += 1

#print(dict_count)

max_count = 0

for key in dict_count.keys():
    max_count = max(max_count, dict_count.get(key - 1, 0) + dict_count.get(key, 0) + dict_count.get(key + 1, 0))

print(max_count)


Measured memory_bytes: 14180
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main(void){
    
    int N;
    int Min = INT_MAX;
    int ans = 0;
    cin >> N;
    vector<int>P(N+1);
    
    
    for(int i = 1; i <= N; i++){
        cin >> P[i];
        Min = min(Min, P[i]);
        if(Min == P[i]) ans++;
    }
    
    
    cout << ans << endl;
}
 

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

using namespace std;

const double EPS = 1e-7;
const int N = 4e5+5, M = 1e5+5, OO = 0x3f3f3f3f;
typedef long long ll;

int gcd(int a, int b){
    if(b)   return gcd(b, a%b);
    else return a;
}

int n,A[M],k;
int dp[M];
int main(){
//    freopen("araf_bara.txt", "wt", stdout);
    cin>>n>>k;
    for(int i=0; i<n; i++)cin>>A[i];

    memset(dp, OO, sizeof dp);
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i+j<n){
                int&ret= dp[i+j];
                ret = min(ret, dp[i]+abs(A[i]-A[i+j]));
            }
        }

    }
    cout<<dp[n-1]<<endl;



    }


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main()
{
    char A[20], B[20], C[20];
    scanf("%s %s %s", A, B, C);
    int l1, l2, l3;
    l1 = strlen(A);
    l2 = strlen(B);
    l3 = strlen(C);
    if(A[l1-1]==B[0] && B[l2-1]==C[0])
        printf("YES\n");
    else
        printf("NO\n");


    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		int ans = 0;
		if(N % 2 == 0){
			ans = N;
		}else{
			ans = 2 * N;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124