akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

// 約数列挙
vector<long long> calc_divisor(long long n) {
   vector<long long> res;
   for (long long i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           long long j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll n;
    cin >> n;
    vector<ll> nu = calc_divisor(n);
    ll num;
    ll sa = LLINF;
    ll wa = 0;
    rep(i, nu.size()){
      num = n / nu[i];
      if(sa <= abs(nu[i] - num)){
        print(wa);
        return 0;
      }
      sa = abs(nu[i] - num);
      wa = num - 1 + nu[i] - 1;
    }
}


Measured memory_bytes: 384
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int main()
{
  double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
  while(cin>>xa1>>ya1>>xa2>>ya2>>xb1>>yb1>>xb2 >>yb2){
    if(xa1<=xb2&&xb1<=xa2&&ya1<=yb2&&yb1<=ya2)
      cout <<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

const int VSIZE=30000,ESIZE=100000;

int MF(vector<vector<int> > &e,int s,int t)
{
  int n=e.size();
  bool F[ESIZE]={0};
  int K=0;
  vector<vector<int> > fk(n),be(n),bfk(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<e[i].size();j++){
      int k=e[i][j];
      fk[i].push_back(K);
      be[k].push_back(i);
      bfk[k].push_back(K);
      K++;
    }
  }
  int fl=0ll;
  while(1){
    int dis[VSIZE]={0};
    queue<int> Q;
    Q.push(s);
    dis[s]=1;
    while(!Q.empty()){
      int i=Q.front();
      Q.pop();
      for(int j=0;j<e[i].size();j++){
	if(F[fk[i][j]]){
	  continue;
	}
	int k=e[i][j];
	if(!dis[k]){
	  Q.push(k);
	  dis[k]=dis[i]+1;
	}
      }
      for(int j=0;j<be[i].size();j++){
	if(!F[bfk[i][j]]){
	  continue;
	}
	int k=be[i][j];
	if(!dis[k]){
	  Q.push(k);
	  dis[k]=dis[i]+1;
	}
      }
    }
    if(!dis[t]){
      break;
    }
    while(1){
      int B[VSIZE],FF[VSIZE];
      for(int i=0;i<n;i++){
	B[i]=-1;
      }
      stack<int> Q;
      Q.push(s);
      while(!Q.empty()){
	int i=Q.top();
	Q.pop();
	if(i==t){
	  break;
	}
	for(int j=0;j<e[i].size();j++){
	  int k=e[i][j];
	  if(dis[k]!=dis[i]+1||F[fk[i][j]]){
	    continue;
	  }
	  if(B[k]==-1){
	    Q.push(k);
	    B[k]=i;
	    FF[k]=fk[i][j]+1;
	  }
	}
	for(int j=0;j<be[i].size();j++){
	  int k=be[i][j];
	  if(dis[k]!=dis[i]+1||!F[bfk[i][j]]){
	    continue;
	  }
	  if(B[k]==-1){
	    Q.push(k);
	    B[k]=i;
	    FF[k]=-bfk[i][j]-1;
	  }
	}
      }
      if(B[t]==-1){
	break;
      }
      fl+=1;
      for(int i=t;i!=s;i=B[i]){
	int J=FF[i];
	if(J>0){
	  int j=J-1;
	  F[j]=1;
	}
	else{
	  int j=-J-1;
	  F[j]=0;
	}
      }
    }
  }
  return fl;
}

int main()
{
  int h,w;
  scanf("%d%d",&h,&w);
  static char M[100][101];
  for(int i=0;i<h;i++){
    scanf("%s",M[i]);
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if((i==0||i==h-1||j==0||j==w-1)&&M[i][j]=='X'){
	puts("-1");
	return 0;
      }
    }
  }
  vector<vector<int> > e(2*h*w+2);
  int s=2*h*w,t=s+1;
  int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(M[i][j]=='X'){
	for(int v=0;v<4;v++){
	  int x=i+dx[v],y=j+dy[v];
	  e[s].push_back(x*w+y);
	}
      }
      else{
	int k=i*w+j,l=h*w+k;
	e[k].push_back(l);
	for(int v=0;v<4;v++){
	  int x=i+dx[v],y=j+dy[v];
	  if(0<=x&&x<h&&0<=y&&y<w){
	    e[l].push_back(x*w+y);
	  }
	  else{
	    e[l].push_back(t);
	  }
	}
      }
    }
  }
  printf("%d\n",MF(e,s,t));
  return 0;
}


Measured memory_bytes: 4352
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int k;
    cin>>k;
	string str;
	cin>>str;
	if(sz(str)<=k)
		cout<<str;
	else
	{
		string ans = str.substr(0,k);
		ans+="...";
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r+100*(10-n) << endl;
    }

    return 0;
}


Measured memory_bytes: 3584
from itertools import accumulate


n = int(input())
arr = list(map(int, input().split()))

cum_sum = list(accumulate(arr))

min_diff = float("inf")

for i in range(n):
    diff = abs(cum_sum[-1] - cum_sum[i] * 2)
    min_diff = min(min_diff, diff)

print(min_diff)

Measured memory_bytes: 3064
def large_digits(A, B):
    return max(len(str(A)), len(str(B)))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def main():
    N = int(input())
    divs = make_divisors(N)
    # loop = len(divs) // 2 + 1
    ans = 10**10 + 1
    for d in divs:
        ans = min(ans, large_digits(d, N // d))
    # print(divs)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

int main() { char a;
  cin >> a;
if(isupper(a)){
  cout << "A" << endl;
}else
{
  cout << "a" << endl;
}

}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
const double PI  =3.141592653589793238463;
using namespace std;

int main()
{
    faster;
    ll a,b,c1,c2,r1,r2,d,e,f=0,ans=0,sum=0,m,h,n,p,q,r,t,w,x,y,z;
    string s;
    cin>>w>>h>>n;//w=x okhkho h=y okhkho
    r1=0;r2=w;c1=0;c2=h;
while(n--)
{
    cin>>x>>y>>a;
    if(a==1)
    {
        if(x>=r1)
        r1=x;
        r2=r2;
        c1=c1;
        c2=c2;
      //  cout<<"a =1 "<<"r1="<<r1<<"r2="<<r2<<"c1="<<c1<<"c2="<<c2<<endl;

    }

    else if(a==2)
    {
        r1=r1;
        if(x<=r2)
        r2=x;
        c1=c1;
        c2=c2;
      //  cout<<"a =2 "<<"r1="<<r1<<"r2="<<r2<<"c1="<<c1<<"c2="<<c2<<endl;
    }
   else if(a==3)
    {
        r1=r1;
        r2=r2;
        if(y>=c1)
        c1=y;
        c2=c2;
      //  cout<<"a =3 "<<"r1="<<r1<<"r2="<<r2<<"c1="<<c1<<"c2="<<c2<<endl;
    }
     else
    {
        r1=r1;
        r2=r2;
        c1=c1;
        if(y<=c2)
        c2=y;
      //  cout<<"a =4 "<<"r1="<<r1<<"r2="<<r2<<"c1="<<c1<<"c2="<<c2<<endl;
    }
}
if((r1>=r2)||(c1>=c2))
    cout<<"0"<<endl;
else{
        int ax=r2-r1;
int yk=c2-c1;

cout<<ax*yk<<endl;

}


    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            String S = in.next();
            char[] cs = S.toCharArray();

            int li = 0;
            int ri = cs.length - 1;
            int cnt = 0;
            while (true) {
                while (li < ri && cs[li] == cs[li + 1]) {
                    cnt++;
                    li++;
                }
                while (li < ri && cs[ri - 1] == cs[ri]) {
                    cnt++;
                    ri--;
                }
                if (li < ri) {
                    if (0 < K) {
                        if (li + 1 == ri) {
                            cnt++;
                            break;
                        }
                        cnt += 2;
                        K--;
                    }
                    li++;
                    ri--;
                } else {
                    break;
                }
            }
            out.println(cnt);
        }

    }
}



Measured memory_bytes: 26056
K , N = map(int,input().split())
A = list(int(i) for i in input().split())

maxL = (A[0]+K)-A[-1]
maxID =0

for x in range(1,N):
    dis = A[x]-A[x-1]
    if maxL <dis:
        maxL = dis
        maxID =x
print(K-maxL)

Measured memory_bytes: 26444
//#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<int,int>
const long long mod = 1000000007LL, inf = 1e9, linf = 1e18, base = 10;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 1002
using namespace std;


int main()
{
	i64 n;
	cin >> n;
	i64 tmp = 180 * n - 360;
	cout << tmp;
}

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

int main() {
  string s;
  cin >> s;
  int price = 700;
  
  if (s.at(0) == 'o') {
    price += 100;
  }
  if (s.at(1) == 'o') {
    price += 100;
  }
  if (s.at(2) == 'o') {
    price += 100;
  }
  
  cout << price << endl;
  
}


Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: chars
    }
    let mut c = 0;
    for i in 1..n {
        if v[i] == '1' {
            c += 1;
        } else {
            c = 0;
        }
        if c == m {
            println!("-1");
            return;
        }
    }
    let mut d = vec![n + 1; n + 1];
    d[n] = 0;
    let mut prev = n;
    loop {
        if prev < m {
            for i in 0..prev {
                if v[i] == '0' {
                    d[i] = d[prev] + 1;
                }
            }
            break;
        } else {
            let mut next = prev;
            for i in (prev - m..prev).rev() {
                if v[i] == '0' {
                    d[i] = d[prev] + 1;
                    next = i;
                }
            }
            prev = next;
        }
    }
    let mut p = 0;
    let mut prev = 0;
    let mut ans = vec![];
    while p < n {
        p += 1;
        if d[p] == d[prev] - 1 {
            ans.push(p - prev);
            prev = p;
        }
    }
    print!("{}", ans[0]);
    for i in 1..ans.len() {
        print!(" {}", ans[i]);
    }
    println!("");
}


Measured memory_bytes: 6524
# input
n = int(input())
a = input()
b = input()
c = input()

S = [0 for _ in range(n)]

for i in range(n):
    if a[i] == b[i] and a[i] == c[i]:
        S[i] = 0
    if a[i] == b[i] and b[i] != c[i] and c[i] != a[i]:
        S[i] = 1
    if a[i] != b[i] and b[i] == c[i] and c[i] != a[i]:
        S[i] = 1
    if a[i] != b[i] and b[i] != c[i] and c[i] == a[i]:
        S[i] = 1
    if a[i] == b[i] and b[i] == c[i] and c[i] != a[i]:
        S[i] = 1
    if a[i] != b[i] and b[i] == c[i] and c[i] == a[i]:
        S[i] = 1
    if a[i] == b[i] and b[i] != c[i] and c[i] == a[i]:
        S[i] = 1
    if a[i] != b[i] and b[i] != c[i] and c[i] != a[i]:
        S[i] = 2

ans = sum(S)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	vector<int> B(M);
	vector<int> rec(N,0);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
	}
	for (int i = 0; i < M; i++) {
		rec[A[i] - 1]++;
		rec[B[i] - 1]++;
	}
	for (int i = 0; i < N; i++) {
		cout << rec[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint h,w,K;std::cin>>h>>w>>K;
    std::vector<std::vector<lint>>a(h+1,std::vector<lint>(w+1));
    for(lint i=1;i<=h;i++){
        for(lint j=1;j<=w;j++){
            char c;std::cin>>c;
            a.at(i).at(j)=(c=='1')+a.at(i-1).at(j)+a.at(i).at(j-1)-a.at(i-1).at(j-1);
        }
    }
    lint H=1ll<<h,ans=h*w;
    for(lint bs=H/2;bs<H;bs++){
        lint now=__builtin_popcountll(bs)-2;
        for(lint i=0,j=0;j<=w;j++){
            for(lint k=0,l=1;l<=h;l++){
                if(bs>>l-1&1){
                    if(j==w||K<a.at(l).at(j+1)-a.at(l).at(i)-a.at(k).at(j+1)+a.at(k).at(i)){
                        now++;
                        if(i==j)goto Impossible;
                        else {i=j;break;};
                    }
                    k=l;
                }
            }
        }
        if(now<ans)ans=now;
        Impossible:{};
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	int cnt=0;
	for(int i=0;i<n;i++){
		int cp=a[i];
		int c=0;
		while(i<n&&a[i]==cp){
			i++;
			c++;
		}
		cnt+=(c-1);
		i--;
	}
	cout << n-cnt-(cnt%2==0?0:1) << endl;
}

Measured memory_bytes: 640
def main():
    n, m = map(int, input().split())
    ans = [0] * n
    count = [0] * n
    for i in range(m):
        s, c = map(int, input().split())
        if s == 1 and c == 0 and n != 1:
            print(-1)
            exit()
        if count[s - 1] == 0 or ans[s - 1] == c:
            ans[s - 1] = c
            count[s - 1] += 1
        else:
            print(-1)
            exit()
    if ans[0] == 0 and n != 1:
        ans[0] = 1
    print(''.join(map(str, ans)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	string s;
	cin >> s;
	cin >> s;
//ßcout << s << endl;
	cout << "A" << s[0] << "C" << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	int tmp = 0;
	vint a(n);
	rep(i, n)cin >> a[i];
	rep(i, n) {
		tmp += a[i];
	}
	int w;
	cin >> w;
	rep(i, w) {
		int x, y;
		cin >> x >> y;
		x--;
		cout << tmp - (a[x] - y) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def main():
  import bisect
  
  n = int(input())
  s = list(input())
  q = int(input())
  
  d = {}
  for i in range(26):
    d[chr(ord('a')+i)] = []
  for i in range(n):
    d[s[i]].append(i)
  #print(d)
  
  for i in range(q):
    t,a,b = input().split()
    if t == '1':
      a = int(a)-1
      if s[a] == b:
        continue
      idx = bisect.bisect_left(d[s[a]],a)
      d[s[a]].pop(idx)
      bisect.insort_left(d[b],a)
      s[a] = b
    else:
      a = int(a)-1
      b = int(b)-1
      c = 0
      for i in range(26):
        idx = bisect.bisect_left(d[chr(ord('a')+i)],a)
        if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b:
          c += 1
      print(c)
  
main()

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


int main(){
  int n;
  cin >> n;
  int cal=n%1000;
  if(cal==0){
    cout << "0" << endl;
    return 0;
  }
  int ans=1000-cal;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))[::-1]

a1 = sorted(a[i] + b[j] for i in range(x) for j in range(y))[::-1]
a2 = sorted(a1[i] + c[j] for i in range(min(len(a1), k))
            for j in range(z))[::-1]
for i in range(k):
    print(a2[i])


Measured memory_bytes: 207228
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int N, K,ans=1;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		if (ans >= K)ans += K;
		else ans *= 2;
	}
	cout << ans;
}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCD = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var THP = ABCD[0]; var TAT = ABCD[1]; var AHP = ABCD[2]; var AAT = ABCD[3];
            var Tcount = (AHP + TAT - 1) / TAT;
            var Acount = (THP + AAT - 1) / AAT;
            Console.WriteLine(Tcount <= Acount ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 27500
#include<bits/stdc++.h>
using namespace std;
int main(void){
  vector<int> v(4);
  for(int i = 0;i<4;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  if(v[0]==1&&v[1]==4&&v[2]==7&&v[3]==9)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

Measured memory_bytes: 256
n = int(input())
yaku = [0]*101
from collections import Counter

def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in range(2,n+1):
    c = pf(i)
    for j in c:
        yaku[j] += 1
        
b = Counter(yaku)
ans = 0
aa = 0
for i in range(4,101):
    aa += b[i]
    
ans += (b[2]+b[3]) * aa * (aa-1) // 2
ans += aa * (aa-1) * (aa-2) // 2

aa = 0
for i in range(74,101):
    aa += b[i]
ans += aa

aa = 0
for i in range(24,101):
    aa += b[i]
bb = 0
for i in range(2,101):
    bb += b[i]
ans += (bb-1) * aa

aa = 0
for i in range(14,101):
    aa += b[i]
bb = 0
for i in range(4,101):
    bb += b[i]
ans += (bb-1) * aa

print(ans)

Measured memory_bytes: 65340
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void printArray(List<Integer> array) {
		StringBuilder sb = new StringBuilder();
		sb.append(array.get(0));
		for (int j = 1; j < array.size(); j++) {
			sb.append(" ").append(array.get(j));
		}
		System.out.println(sb.toString());
	}

	static public List<Integer> acceptArray (InputStream ins) {
		Scanner sc = new Scanner(ins);
		int num = sc.nextInt();
		List<Integer> array = new ArrayList<Integer>();
		for (int i = 0; i < num; i++) {
			array.add(sc.nextInt());
		}
		return array;
	}

	static public List<Integer> bubbleSort (List<Integer> array) {
		// 1, 2,4,5,3
		//
		int swapCount = 0;
		for (int i = 0; i < array.size()-1; i++){
			for (int j = array.size()-1; j > i; j--) {
				if (array.get(j-1) > array.get(j)) {
					//swap
					int c = array.get(j);
					array.set(j, array.get(j-1));
					array.set(j-1, c);
					swapCount++;
				}
			}

		}
		printArray(array);
		System.out.println(swapCount);
		return array;
	}

	static public void main(String[] args) {
		List<Integer> array = acceptArray(System.in);
		List<Integer> sorted = bubbleSort(array);

	}
}

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

int main(){
  int n,ans=0;cin>>n;
  vector<int> sx(n,0),y(n,0),sy(n,0);
  REP(i,n){
    cin>>sx.at(i);
    if(i>0) sx.at(i)+=sx.at(i-1);
  }
  REP(i,n) cin>>y.at(i);
  for(int i=n-1;i>=0;i--){
    sy.at(i)=y.at(i);
    if(i<n-1) sy.at(i)+=sy.at(i+1);
  }
  REP(i,n) ans=max(ans,sx.at(i)+sy.at(i));
  
  cout<<ans;
}

Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2019-12-11 22:07:00
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    vector<string> day = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", ""};
    reverse(all(day));

    string S;
    cin >> S;

    int ans = 0;
    for (; ans < 7; ans++) {
        if (S == day[ans]) break;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split(' '))
rst_ls = [ '' for i in range(N) ]
rst = ''
if M == 0:
    if N == 1:
        print(0)
    else:
        rst = '1' + '0' * (N - 1)
        print(rst)
else:
    is_end = False
    for i in range(M):
        ls = list(input().split(' '))
        idx = int(ls[0]) - 1
        if idx == 0 and ls[1] == '0' and N > 1:
            is_end = True
            print(-1)
            break
        elif rst_ls[idx] == '':
            rst_ls[idx] = ls[1]
        elif rst_ls[idx] != ls[1]:
            is_end = True
            print(-1)
            break
    if not is_end:
        if rst_ls[0] == '' and N > 1:
            rst_ls[0] = 1
        for i in rst_ls:
            if i == '':
                i = 0
            print(i, end='')

Measured memory_bytes: 9076
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	m := make(map[int]int, 0)
	for i := 0; i < n; i++ {
		m[nextInt(sc)]++
	}
	// fmt.Println("m", m)
	ans := make([]int, 0)
	for k := range m {
		ans = append(ans, k)
	}
	sort.Ints(ans)
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(ans); i++ {
		if i > 0 {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, ans[i])
	}
	fmt.Fprintln(wtr)
	wtr.Flush()

}



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

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

    double cup = a * a * b;
    double ans; 
    if (x > cup / 2){
        ans = atan2((cup - x),(a * a * a / 2));
    } else {
        ans = atan2((a * b * b / 2),x);
    }
    ans *= 180 / PI;
    printf("%3.10f\n", ans);

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int x = 0;
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    x += r - l + 1;
  }
  cout << x;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	long long int cnt=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;++i)
		cin>>arr[i];
	int max=arr[0];
	for(int i=0;i<n;++i)
	{
		if(arr[i]>max)
			max=arr[i];
		if(arr[i]<max)
		{
				cnt=cnt+max-arr[i];
		}
		
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 4344
import java.math.BigDecimal

fun main(args: Array<String>) {
    readLine()!!
    val al = readLine()!!.split(" ").map { BigDecimal(it) }

    val mo: BigDecimal = al.reduce { a, b -> a.multiply(b) }
    val ch = al.map { mo.divide(it) }.reduce { a, b -> a.add(b) }

    print(mo.divide(ch, 6, BigDecimal.ROUND_HALF_UP))
}


Measured memory_bytes: 36008
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>
#include <boost/dynamic_bitset.hpp>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int words[50][26];

int main(int argc, char *argv[]) {
	// INFILE();
	int n;
	cin >> n;
	vector<string> strs(n);
	scan(strs);

	for (int i = 0; i < n; i++) {
		const string &str = strs[i];
		for (const char &c : str) {
			words[i][c - 'a']++;
		}
	}

	for (int i = 0; i < 26; i++) {
		int minCount = 9999;
		for (int j = 0; j < n; j++) {
			minCount = min(minCount, words[j][i]);
		}
		cout << string(minCount, 'a' + i);
	}
	cout << endl;
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  map<type_index, const char *const> m = {{typeid(int), "%d"},
                                          {typeid(ll), "%lld"},
                                          {typeid(double), "%lf"},
                                          {typeid(char), "%c"}};

  auto tFormat = m[typeid(T)];

  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
	if (isWord) {
		for (auto &n : v) {
			cin >> n;
		}
		return;
	}

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
	string s;
	getline(cin, s);

	if (s.size() == 0) {
		getline(cin, s);
	}

	for_each(begin(s), end(s), [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
	return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 888
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

xs = A[::]
last = 0
for i in range(N):
    if 0 < last:
        xs[i] = max(xs[i] - last, 0)
    if B[i] <= xs[i]:
        xs[i] -= B[i]
        last = 0
    else:
        last = B[i] - xs[i]
        xs[i] = 0
xs[N] = max(xs[N] - last, 0)
print(sum(A) - sum(xs))


Measured memory_bytes: 82020
#include<bits/stdc++.h>
using namespace std;
int A[5],B[5];
string S;
int main()
{
	S="ABCDE";
	while(true){
		scanf("%d%d",&A[0],&B[0]);
		if(A[0]==0&&B[0]==0)return 0;
		for(int i=1;i<5;i++){
			scanf("%d%d",&A[i],&B[i]);
		}
		int ma=-1;int maxi=-1;
		for(int i=0;i<5;i++){
			if(ma<A[i]+B[i]){
				ma=A[i]+B[i];
				maxi=i;
			}
		}
		cout << S[maxi] << " " << ma << "\n";
	}
}

Measured memory_bytes: 1216
H, W = map(int, input().split())
T = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if T[i][j] == '#':
            continue
        cnt = 0
        
        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                if not(0<=i+dy<H) or not(0<=j+dx<W):
                    continue
                if T[i+dy][j+dx] == '#':
                    cnt += 1
        T[i][j] = str(cnt)

for t in T:
    print(''.join(t))

Measured memory_bytes: 3316
Option Infer On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim W As Integer = NextInt()
        Dim a As Integer = NextInt()
        Dim b As Integer = NextInt()
        Dim ans As Integer

        If b + W < a Then
            ans = Diff(b + W, a)
        ElseIf a + W < b Then
            ans = Diff(a + W, b)
        Else
            ans = 0
        End If

        WriteLine(ans)
    End Sub

    Function Diff(a As Integer, b As Integer) As Integer
        Return Math.Abs(a - b)
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20432
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <boost/multiprecision/cpp_dec_float.hpp>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;

int main()
{
	Real N;
	cin >> N;
	if (ceil(N / 1.08) > floor((N + 1) / 1.08))
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << ceil(N / 1.08) << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  vector<P> times;

  int N, M;
  cin >> N;
  rep(i, N) {
    int h, m;
    cin >> h >> m;
    times.pb(make_pair(h, m));
  }
  cin >> M;
  rep(i, M) {
    int h, m;
    cin >> h >> m;
    times.pb(make_pair(h, m));
  }
  sort(all(times));
  uniq(times);

  rep(i, times.size()) {
    if(i > 0) {
      cout << " ";
    }
    cout << times[i]._1 << ":";
    cout << setfill('0') << setw(2) << right << times[i]._2;
  }
  cout << endl;
}



Measured memory_bytes: 3184
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String line1 = sc.nextLine();
        String[] array = line1.split(" ");
        
        int k = Integer.parseInt(array[0]);
        int x = Integer.parseInt(array[1]);
        
        String result = "No";
        int sum = 500 * k;
        
        if(sum >= x)
        {
            result = "Yes";
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
S = input()
N = len(S)

def is_palindrome(s):
  return s == s[::-1]

if is_palindrome(S) \
and is_palindrome(S[:int((N-1)/2)]) \
and S[int((N+3)/2-1):] == S[:int((N-1)/2)]:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(e, i) for (auto e: i)
#define all(x) x.begin(), x.end()


using namespace std;
const int maxn = 105;
const int inf = 0x3f3f3f3f;
typedef long long ll;


int main() {
#ifdef AZUKI_LOCAL
    freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
#endif
    int n, m;
    ll k;
    while (cin >> n >> m >> k) {
        vector<ll> a(n), b(m), sum_a, sum_b;
        rep(i, n) {
            cin >> a[i];
        }
        rep(i, m) {
            cin >> b[i];
        }
        int ans = 0;
        sum_a.push_back(0);
        sum_b.push_back(0);
        rep(i, n) {
            if (sum_a[i] > k) break;
            sum_a.push_back(sum_a[i] + a[i]);
        }
        rep(i, m) {
            if (sum_b[i] > k) break;
            sum_b.push_back(sum_b[i] + b[i]);
        }
        int j = (int) sum_b.size() - 1;
        rep(i, sum_a.size()){
            if (sum_a[i] > k) break;
            while (sum_b[j] + sum_a[i] > k) {
                --j;
            }
            ans = max(ans, i + j);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 11100
H,W=map(int,input().split())
S=[]
for _ in range(H):
    S.append(list(input()))

from collections import deque

que=deque()
maxx=0

for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            continue
        ans=[[500]*W for _ in range(H)]
        ans[i][j]=0
        que.append((i,j))
        while que:
            h,w=que.popleft()
            if h!=0 and S[h-1][w]==".":
                if ans[h-1][w]==500:
                    ans[h-1][w]=ans[h][w]+1
                    que.append((h-1,w))
            if h!=H-1 and S[h+1][w]==".":
                if ans[h+1][w]==500:
                    ans[h+1][w]=ans[h][w]+1
                    que.append((h+1,w))
            if w!=0 and S[h][w-1]==".":
                if ans[h][w-1]==500:
                    ans[h][w-1]=ans[h][w]+1
                    que.append((h,w-1))
            if w!=W-1 and S[h][w+1]==".":
                if ans[h][w+1]==500:
                    ans[h][w+1]=ans[h][w]+1
                    que.append((h,w+1))
            maxx=max(maxx,ans[h][w])
print(maxx)  


Measured memory_bytes: 74732
def genP(W):
    P = []
    D = [0]*(W-1)
    P.append(D[:])
    for i in range(2**(W-1)-1):
        d = 0
        while D[d] == 1:
            D[d] = 0
            d+=1
        D[d] = 1
        if any(D[i] == 1 and D[i+1] == 1 for i in range(W-2)):
            continue
        P.append(D[:])
    return P 

def make_swap(p, W):
    base = [x for x in range(0,W)]
    b = base[:] 
    for w in range(len(p)):
        if p[w] == 1:
            b[w], b[w+1] = b[w+1], b[w]
    return b

if 0==1:
    W = 4
    base = [x-1 for x in range(1,W+1)]
    for p in genP(W):
        print(*base)
        print("", *p)
        print(*make_swap(p, W))
        print()

def solve(H, W, K):
    swaps = []
    for p in genP(W):
        s = make_swap(p, W)
        swaps.append(s)

    count = [[0]*W for i in range(H+1)]
    count[0][0] = 1

    for h in range(0,H):
        for w in range(0, W):
            for swap in swaps:
                count[h+1][w] += count[h][swap[w]]
                count[h+1][w] %= 1000000007
    #print(count[H])
    print(count[H][K-1])

def main():
    H, W, K = map(int, input().split())
    solve(H, W, K)
main()


Measured memory_bytes: 3064
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let mut v: Vec<i32> = (0..n).map(|_| input()).collect();
    v.sort();

    let mut ans = v[0] as f64;
    for i in 1..n {
        ans += v[i] as f64;
        ans *= 0.5;
    }
    println!("{}", ans);
}


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

const int N = 121;
char c[N][N];
int ans[N][N];

int main() {
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		scanf("%s", c[i] + 1);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			ans[i][j] = -1;
			if(c[i][j] == 'c')
				ans[i][j] = 0;
			else if(j > 1 && ~ans[i][j - 1])
				ans[i][j] = ans[i][j - 1] + 1;
		}
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
			printf("%d%c", ans[i][j], j == m ? '\n' : ' ');
}

Measured memory_bytes: 3252
r=range
h,*s=open(0)
h,w,k,*m=map(int,h.split())
for i in r(512):
 t=[j+1for j in r(h)if i>>j&1]+[h];l=len(t);v=1;c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v-=f
  if f:c=u
 if g<1:m+=l-v,
print(min(m))

Measured memory_bytes: 51672
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back

using namespace std;

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

int a[110];

int main(){
     
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
        
	int n , m , ind = 0 , o = 0;
	cin >> n >> m;

	for(int i = 0 ; i < m ; i++){
	   cin >> a[i];
	   if(a[i] % 2){		  
		  if(!o)
			 swap(a[i] , a[0]);
		  else
			 ind = i;
			 
		  o++;	
		}  
	}

	if(o > 2){
	  cout << "Impossible" << endl;
	  return 0;
	}
	
	swap(a[ind] , a[m-1]);

	for(int i = 0 ; i < m ; i++)
	   cout << a[i] << " ";
	
	cout << endl;

	int t = (a[0] == 1 ? m-1 : m);

	if(m == 1){

		if(n == 1)
		   cout << "1\n1" << endl;
		else  
		   cout << "2\n1 " << a[0] - 1 << endl;

	}
	else{
	   
	   cout << t << endl;
	   if(t == m)
		  cout << a[0] - 1 << " ";

	   for(int i = 1 ; i < m-1 ; i++)
		  cout << a[i] << " ";

		cout <<  a[m-1] + 1 << endl;
	}



	return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = 0
for L in range(1,N+1):
  ans += (N-L+1)*(N-L+2)//2
for _ in range(N-1):
  u,v = [int(i) for i in input().split()]
  if v>u:
    u,v = v,u
  ans -= (N-u+1)*v
print(ans)

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

const int sz = 500;
const int dy[4] = {-1,0,1,0};
const int dx[4] = {0,-1,0,1};
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> x(N*N),y(N*N);
    rep(i,N*N) {
        int a; cin >> a;
        a--;
        y[i] = a/N;
        x[i] = a%N;
    }

    array<array<int, sz>, sz> A;
    array<array<int, sz>, sz> check;
    rep(i,N) {
        rep(j,N) {
            A[i][j] = min({i,N-1-i,j,N-1-j});
            if (A[i][j]) check[i][j] = 1;
        }
    }
    auto func=[&](auto&& self, int y, int x)->void {
        rep(i,4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 or ny >= N or nx < 0 or nx >= N) continue;
            if (chmin(A[ny][nx],A[y][x] + check[y][x])) {
                self(self,ny,nx);
            }
        }
    };
    int ans = 0;
    rep(i,N*N) {
        ans += A[y[i]][x[i]];
        check[y[i]][x[i]] = 0;
        func(func,y[i],x[i]);
    }

    cout << ans << ln;
}


Measured memory_bytes: 26108
D, *I = map(int, open(0).read().split())
C, S, T = I[:26], list(zip(*[iter(I[26:-D])] * 26)), I[-D:]

last = [0] * 26
ans = 0
for d, i in enumerate(T, 1):
    ans += S[d - 1][i - 1]
    last[i - 1] = d
    ans -= sum(c * (d - l) for c, l in zip(C, last))
    print(ans)

Measured memory_bytes: 9944