akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,2647){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3176
s = int(input())
def f(n):
    if n % 2 == 0:
        return int(n/2)
    else:
        return 3*n + 1

def a(i):
    if i == 1:
        return s
    else:
        return f(a(i-1))

list = []
for i in range(1,1000000):
    list.append(a(i))
    if len(list) != len(set(list)):
        print(i)
        break

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

const int INFTY=1000000007;
int cnt=0;

void merge(int A[], int left, int mid, int right) {
  int n1=mid-left;
  int n2=right-mid;
  vector<int> L(n1+1), R(n2+1);
  for (int i=0;i<n1;i++) L[i]=A[left+i];
  for (int i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=R[n2]=INFTY;
  for (int i=0, j=0, k=left; k<right; k++) {
    cnt++;
    if (L[i] <= R[j]) A[k]=L[i++];
    else A[k]=R[j++];
  }
}

void mergeSort(int A[], int left, int right) {
  if (left+1<right) {
    int mid=(left+right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n; cin>>n;
  int a[500002];
  for (int i=0;i<n;i++) cin>>a[i];

  mergeSort(a, 0, n);
  for (int i=0;i<n;i++) {
    if (i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 6796
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MODD 1000000007
#define ll long long
using namespace std;


int dp[111][2];

int GetMaxSum(int pos, bool isless, const vector<int>& digs) {
    
    if (pos == digs.size()) {
        return 0;
    }
    
    if (dp[pos][isless]!=-1)
        return dp[pos][isless];
    
    int ans = 0;
    for(int d=0;d<=9;d++) {
        
        if (!isless && d > digs[pos])
            continue;
        
        ans = max(ans, d+GetMaxSum(pos+1,isless||(d < digs[pos]), digs));
        
    }
    
    return dp[pos][isless]=ans;
    
    
    
}

int main() {
    ll x;
    cin>>x;
    
    for(int i=0;i<111;i++)
        for(int j=0;j<2;j++)
            dp[i][j]=-1;
    
    vector<int> digs;
    while(x) {
        digs.push_back(x%10);
        x/=10;
    }
    
    std::reverse(digs.begin(),digs.end());
    
    cout << GetMaxSum(0, false, digs) << endl;
    
    
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let h1: i64 = read();
    let m1: i64 = read();
    let h2: i64 = read();
    let m2: i64 = read();
    let k: i64 = read();

    let s = h1 * 60 + m1;
    let e = h2 * 60 + m2;

    println!("{}", e - s - k);
}


Measured memory_bytes: 2104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<vector>
#define ll long long
#define maxn 1000005
#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
using namespace std;
int gi()
{
	char c;int x,sign=1;
	while((c=getchar())>'9'||c<'0')if(c=='-')sign=-1;
	x=c-'0';while((c=getchar())>='0'&&c<='9')x=(x<<1)+(x<<3)+c-'0';
	return x*sign;
}
int seq[maxn],n;
struct node {int x,id;}f[maxn],h[maxn];
bool operator<(node x,node y){return x.x>y.x;}
int main()
{
	//FILE("name");
	cin>>n;int x=0,y=0;
	for(int i=1;i<=n;i++)scanf("%d",&seq[i]);
	for(int i=1;i<=100000;i++)h[i].id=i;
	for(int i=1;i<=n;i+=2)
	{
		h[seq[i]].x++;
	}
	for(int i=1;i<=100000;i++)f[i].id=i;
	for(int i=2;i<=n;i+=2)
		f[seq[i]].x++;
	sort(f+1,f+1+100000);sort(h+1,h+1+100000);
	if(f[1].id!=h[1].id)cout<<n-f[1].x-h[1].x;
	else cout<<min(n-f[1].x-h[2].x,n-f[2].x-h[1].x);
	return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//    freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);

    string s,t;
    cin>>s>>t;
    int count[26] = {0};
    map<int,int> m,mm;
    for(int i=0;i<t.size();i++)
    {
		if(m.find(s[i]-'a') !=m.end() || mm.find(t[i]-'a')!=mm.end())
		{
			if(m[s[i]-'a']!=(t[i]-'a') || mm[t[i]-'a']!=(s[i]-'a'))
			{
				// cout<<s[i]<<" "<<m[s[i]]<<endl;
				// cout<<t[i]<<" "<<mm[t[i]]<<endl;
				cout<<"No";
				return 0;
			}
		}
		mm[t[i]-'a'] = (s[i]-'a');
		m[s[i]-'a'] = (t[i]-'a');
	}
    cout<<"Yes";
} 

Measured memory_bytes: 916
#include<stdio.h>
int main(){
  int A[3][3], b[100];
  int N, i, j, k;
       for (j=0;3>j;++j){
        scanf("%d",&A[0][j]);
    }
          for (j=0;3>j;++j){
        scanf("%d",&A[1][j]);
    }
          for (j=0;3>j;++j){
        scanf("%d",&A[2][j]);
       
    }
    

  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%d", &b[i]);
    for(j=0; j<3; j++){
      for(k=0; k<3; k++){
        if(b[i] == A[j][k]) A[j][k] = 0;
      }
    }
  }

  if(A[0][0] + A[0][1] + A[0][2] == 0) printf("Yes");
  else if(A[1][0] + A[1][1] + A[1][2] == 0) printf("Yes");
  else if(A[2][0] + A[2][1] + A[2][2] == 0) printf("Yes");
  else if(A[0][0] + A[1][0] + A[2][0] == 0) printf("Yes");
  else if(A[0][1] + A[1][1] + A[2][1] == 0) printf("Yes");
  else if(A[0][2] + A[1][2] + A[2][2] == 0) printf("Yes");
  else if(A[0][0] + A[1][1] + A[2][2] == 0) printf("Yes");
  else if(A[0][2] + A[1][1] + A[2][0] == 0) printf("Yes");
  else printf("No");

  return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int ans[222222];
vint vs[222222];

signed main(){
    int N,K,L;
    scanf("%lld%lld%lld",&N,&K,&L);
    UF X,Y;
    X.init(N);Y.init(N);
    rep(i,K){
        int a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        X.unite(a,b);
    }

    rep(i,L){
        int a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        Y.unite(a,b);
    }

    rep(i,N)vs[X.find(i)].pb(i);
    rep(i,N){
        map<int,int>cnt;
        for(auto u:vs[i])cnt[Y.find(u)]++;
        for(auto u:vs[i])ans[u]=cnt[Y.find(u)];
    }

    rep(i,N){
        if(i)printf(" ");
        printf("%lld",ans[i]);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 20980
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

//????????¨?????????
class Node {
public:
	int location;
	int p, l, r;
	Node(){}
};

//????¬?????????????
class Point {
public:
	int id, x, y;
	Point(){}
	Point(int id,int x,int y):id(id),x(x),y(y){}

	bool operator < (const Point &p)const {
		return id < p.id;
	}

	void print() {
		printf("%d\n",id);
	}

};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;


bool lessX(const Point &p1, const Point &p2) {
	return p1.x < p2.x;
}

bool lessY(const Point &p1, const Point &p2) {
	return p1.y < p2.y;
}

//2?¬???????????????¢?´¢??¨?????????
int makeKDTree(int l, int r, int depth) {

	if (l >= r) {
		return NIL;
	}

	int mid = (l + r) / 2;
	int t = np++;

	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	}
	else {
		sort(P + l, P + r, lessY);
	}

	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);

	return t;

}

//?????°??§???????????????????????????????????????ans????????????
void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {

	int x = P[T[v].location].x;
	int y = P[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		ans.push_back(P[T[v].location]);
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL) {
			if (sx <= x) {
				find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
			}
		}
		if (T[v].r != NIL) {
			if (x <= tx) {
				find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
			}
		}
	}
	else {
		if (T[v].l != NIL) {
			if (sy <= y) {
				find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
			}
		}
		if (T[v].r != NIL) {
			if (y <= ty) {
				find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
			}
		}
	}

}



int main(void)
{
	int x, y;
	
	scanf("%d",&N);

	for (int i = 0; i < N; i++) {
		scanf("%d %d",&x,&y);
		P[i] = Point(i,x,y);
		T[i].l = T[i].r = T[i].p = NIL;
	}

	np = 0;

	int root = makeKDTree(0,N,0);


	int q;
	scanf("%d",&q);
	int sx, tx, sy, ty;
	vector<Point> ans;

	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int j = 0; j < ans.size(); j++) {
			ans[j].print();
		}
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 15900
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)

typedef long long ll;

int main ()
{
    
    ll N,M;
    cin >> N >> M;

    if (N == 1) {
        cout << M << endl;
        return 0;
    }

    vector < ll > div;
    for (ll i = 1; i * i <= M; i++) {
        if (M % i == 0) {
            div.push_back(i);
            div.push_back(M / i);
        }
    }

    sort(div.begin(), div.end());
    reverse(div.begin(), div.end());

    REP(i,div.size()) {
        if (M / div[i] >= N) {
            cout << div[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, l;
    cin >> n >> l;
    int ans = 0;
    if(l>=0){
        for(int i = 2; i <= n; i++){
            ans += l+i-1;
        }
    }else{
        if(n - abs(l) > 0){
            for(int i = 1; i <= n; i++){
                ans += l+i-1;
            }
        }else{
            for(int i = 1; i <= n; i++){
                ans += l+i-1;
            }
            ans -= l+n-1;
            
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void readin(T &x) {
	x = 0;
	T fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	x *= fh;
}
template <typename T>
inline void wt(T x) {
	if (x > 9) wt(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void writeln(T x, char c) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	wt(x);
	putchar(c);
}
int f[10000005];
inline void dfs(int x, int dep, int tot) {
	f[x] = tot;
	if (dep >= 18) return;
	dfs(x << 1, dep + 1, tot);
	dfs(x << 1 | 1, dep + 1, tot + 1); 
}
char s[1000005];
int n, m[3], cnt;
inline int qp(int x, int y, int mod) {
	int res = 1;
	while(y) {
		if (y & 1) res = (1ll * res * x) % mod;
		x = (1ll * x * x) % mod;
		y >>= 1;
	}
	return res;
}
inline int work(int x) {
	int sum = 0;
	if (s[x] == '1') {
		sum = m[1];
		sum -= qp(2, n - x, cnt - 1);
		sum %= (cnt - 1);
		if (sum < 0) sum += cnt - 1;
	}
	else {
		sum = m[2];
		sum += qp(2, n - x, cnt + 1);
		sum %= (cnt + 1);
	}
	return sum;
}
int main() {
	dfs(0, 0, 0);
	readin(n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i ++) {
		if (s[i] == '1') cnt ++;
	}
	for (int i = 1; i <= n; i ++) {
		if (s[i] == '1') {
			if (cnt > 1) {
				m[1] = (m[1] + qp(2, n - i, cnt - 1)) % (cnt - 1);
			}
			m[2] = (m[2] + qp(2, n - i, cnt + 1)) % (cnt + 1);
		}
	}
	for (int i = 1; i <= n; i ++){
		if(s[i] == '1' && cnt == 1) {
			puts("0");
			continue;
		} 
		int k = work(i);
		int tim = 1;
		while(k) {
			k %= f[k];
			tim ++;
		}
		writeln(tim, '\n');
	}
	return 0;
}




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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    double r = -1;
    int water = 0, suger = 0;
    for (int i = 0; i <= 30; i++)
    {
        for (int j = 0; j <= 30; j++)
        {
            int twater = 100 * a * i + 100 * b * j;
            for (int m = 0; m * c <= f; m++)
            {
                for (int n = 0; d * n <= f; n++)
                {
                    if (100 * a * i + 100 * b * j + c * m + d * n <= f && (100 * a * i + 100 * b * j) * e >= 100 * (c * m + d * n))
                    {
                        int tsuger = c * m + d * n;
                        if (100. * tsuger / (twater + tsuger) >= r)
                        {
                            r = 100. * tsuger / (twater + tsuger);
                            water = twater;
                            suger = tsuger;
                        }
                    }
                }
            }
        }
    }
    cout << water + suger << " " << suger << endl;
}


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

bl = False
for n in range(N+1):
  x = n*M
  if x == K:
    bl = True
    break
  # 1列いじると(N-2n)
  d = N - 2 * n
  if d == 0:
    continue
  if (K-x) % d:
    continue
  m = (K - x) // d
  if 0 <= m <= M:
    bl = True
    break

answer = 'Yes' if bl else 'No'
print(answer)

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

const int INF = 1e9;
const ll LINF = 1e18;


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

    rep(i, 1262) {
        if ((int)(i * 0.08) == a && (int)(i * 0.10) == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d= a/b;
	r= a%b;
	f= (double) a/ (double) b;

	printf("%d %d %f\n",d,r,f);

	return 0;
}

Measured memory_bytes: 636
from math import sqrt

def factorization(n):
    l = set()
    for i in range(1, int(sqrt(n))+1):
        if not n % i:
            l.add(i)
            l.add(n//i)
    return l

N = int(input())
ans = 0
for m in factorization(N):
    m -= 1
    if m > 0 and N == (N//m)*(m + 1):
        ans += m
print(ans)

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

int main(){
  long long n,m;
  cin >> n >> m;
  vector<vector<int>> michi(n,vector<int>(0));
  vector<int> checked(n,0);
  for(int i=0;i < m;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    michi.at(a).push_back(b);
    michi.at(b).push_back(a);
  }
  long long ans = 0;
  int y = 1;
  int l = 0;
  while(y != 0){
  queue<int> q;
	q.push(l);
    checked.at(l) = 1;
	while(q.size()){
		int x = q.front();
		q.pop();
      
		for(int i=0;i< (int)michi.at(x).size();i++){
			int u = michi.at(x).at(i);
			if(checked.at(u) == 1){continue;}
			checked.at(u) = 1;
          q.push(u);
        }
	}
    y = 0;
    for(int i=l;i < n;i ++){
      if(checked.at(i) == 0){
        l = i;
        y = 1;
        //cout << l << endl;
        ans++;
        break;
        
      }
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 8768
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

int main(){
  long ii,jj,kk;
  vector<int> a;
  long long int n,min,max,val;

  cin >> n;

  min = 10e9+1;
  max = -10e9+1;

  for(ii=0;ii<n;ii++){
    cin >> val;

    if((ii != 0) && (val - min) > max){
      max = val -min;
    }
    
    if(ii==0){
      min = val;
    }
    
    if(val < min){
      min = val;
    }


  }

  cout << max << endl;
  
  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    if((n%10) == 3) cout << "bon" << endl;
    else if(n%10 == 1 || n%10 == 0 ||n%10 == 6 ||n%10 == 8){
      cout << "pon" << endl;  
    } 
    else cout << "hon" << endl;
    return 0;    
}

Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

string YorN(bool P) { if (P)return "Yes"; else return "No"; }

int main() {

    int N;
    cin >> N;
    
    cout << "ABC" << N << endl;

    return 0;

}

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

typedef long long ll;
int X,Y,Z;
const ll MOD = 1e9+7;

ll dp[44][1<<18];

int main(){
    dp[0][0] = 1;
    int N; scanf("%d%d%d%d",&N,&X,&Y,&Z);

    int B = X+Y+Z+1;
    int target = ((1<<(X+Y+Z))^(1<<(X+Y))^(1<<X)) >> 1;

    for(int i=0;i<N;i++) for(int j=0;j<(1<<B);j++) for(int k=1;k<=10;k++){
        int there = ((j<<k)^(1<<(k-1))) & ((1<<B)-1);
        if((there&target) != target){
            dp[i+1][there] += dp[i][j];
            dp[i+1][there] %= MOD;
        }
    }

    ll tot = 1;
    for(int i=1;i<=N;i++) tot = tot*10%MOD;
    ll sub = 0;
    for(int i=0;i<(1<<B);i++) sub = (sub + dp[N][i])%MOD;

    printf("%lld", (tot-sub+MOD)%MOD);
}


Measured memory_bytes: 82048
from bisect import bisect


def search_alphabet_index(string):
    cs = [[] for i in range(26)]
    for i, s in enumerate(string):
        j = ord(s) - ord("a")
        cs[j].append(i)
    return cs


def main():
    S = input()
    T = input()
    N = len(S)

    cs = search_alphabet_index(S)

    for c in set(T):
        if not cs[ord(c) - ord("a")]:
            ans = -1
            print(ans)
            exit()

    rnd = 0
    k = -1
    for t in T:
        ti = ord(t) - ord("a")
        i = bisect(cs[ti], k)
        if i == len(cs[ti]):
            k = cs[ti][0]
            rnd += 1
        else:
            k = cs[ti][i]
    ans = rnd * N + k + 1
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

long long dfs(int nd, vector<long long> &vis, vector<vector<int>> &adjList)
{
  vis[nd] += 1;
  long long ans = 0;
  for(int cd : adjList[nd])
  {
    if(!vis[cd])
    {
      ans += dfs(cd, vis, adjList);
      vis[nd] += vis[cd];
    }
  }
  ans += vis[nd] - 1;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, int>> d(n);
  vector<long long> sz(n, n);
  for(int i = 0; i < n; i++)
  {
    cin >> d[i].first;
    d[i].second = i + 1;
  }
  sort(d.begin(), d.end());
  vector<pair<int, int>> ans;
  vector<vector<int>> adjList(n + 1);
  for(int i = n - 1; i > 0; i--)
  {
    long long dval = d[i].first + (n - sz[i] + 1) - (sz[i] - 1);
    int pr = lower_bound(d.begin(), d.end(), make_pair(dval, 0)) - d.begin();
    if(pr >= i || d[pr].first != dval)
    {
      cout << "-1" << endl;
      return 0;
    }
    ans.push_back({d[i].second, d[pr].second});
    adjList[d[i].second].push_back(d[pr].second);
    adjList[d[pr].second].push_back(d[i].second);
    sz[pr] -= (n - sz[i] + 1);
  }
  vector<long long> vis(n + 1, 0);
  long long ver = dfs(d[0].second, vis, adjList);
  if(d[0].first != ver)
  {
    cout << "-1" << endl;
    return 0;
  }
  for(int i = 0; i < n - 1; i++)
  {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 15988
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b == 15) cout << '+' << endl;
	else if(a*b==15) cout << '*' << endl;
	else cout << 'x' << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] x = new int[n];
      int[] y = new int[n];
      for(int i = 0;i < n;i++){
        x[i]=sc.nextInt();
        y[i]=x[i];
      }
      Arrays.sort(x);
      for(int i = 0;i < n;i++){
      	if(y[i]<=x[n/2-1])System.out.println(x[n/2]);
        else System.out.println(x[n/2-1]);
      }
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

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

int main(void){
  double a,b,h,m; cin >> a >> b >> h >> m;
  double theta_h,theta_m;
  double pi = acos(-1);
  
  double omega_h = 2.*pi/(12.*60.);

  double h_min = 60.*h+m;
  theta_h = omega_h*h_min;
  theta_m = 2.*pi/60.*m;
  double phi = fabs(theta_m-theta_h);  
  
  double ans = a*a+b*b-2.*a*b*cos(phi);
  ans = sqrt(ans);
  
  printf("%.20f\n",ans);
  
  return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 200005;

int TC;
int n;

int a[N];

int main() {

	FAST;

	string s;
	cin >> s;
	int a = (s[0]) - '0';
	int b = (s[1]) - '0';
	int c = (s[2]) - '0';
	int d = (s[3]) - '0';
	int k = 8;
	for (int i = 0; i < k; i ++) {
		int ans = a;
		string x = "";
		for (int j = 0; j < 3; j ++) {
			if (i & (1 << j)) {
				if (j == 0) ans += b;
				if (j == 1) ans += c;
				if (j == 2) ans += d;
				x += "+";
			}
			else {
				if (j == 0) ans -= b;
				if (j == 1) ans -= c;
				if (j == 2) ans -= d;
				x += "-";
			}
		}
		if (ans == 7) {
			cout << a << x[0] << b << x[1] << c << x[2] << d << "=7" << '\n';
			return 0;
		}
	}
	return 0;
}

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

int main(){
	long long int n, a, b;
  	cin>>n>>a>>b;
  
  	long long int i=n/(a+b);
  	long long int sum=i*(a+b);
  	long long int cnt=i*a;
  	if(n-sum<=a){
    	cnt+=n-sum;
    }else{
    	cnt+=a;
    }
  	cout<<cnt<<endl;
}

Measured memory_bytes: 256
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def _cmb(N, mod):
    N1 = N + 1
    fact = [1] * N1
    inv = [1] * N1

    for i in range(2, N1):
        fact[i] = fact[i-1] * i % mod

    inv[N] = pow(fact[N], mod-2, mod)
    for i in range(N-1, 1, -1):
        inv[i] = inv[i+1]*(i+1) % mod

    def cmb(a, b):
        return fact[a] * inv[b] * inv[a-b] % mod
    return cmb

def resolve():
    K = int(input())
    s = input()
    ls = len(s) - 1
    mod = 10**9+7

    cmb = _cmb(ls+K, mod)

    ans = 0
    p25 = 1
    p26 = pow(26, K, mod)
    p26inv = pow(26,  mod-2, mod)
    for i in range(K+1):
        ans = (ans + cmb(ls+i, ls) * p25 * p26) % mod
        p25 = p25 * 25 % mod
        p26 = p26 * p26inv % mod
    print(ans)

if __name__ == "__main__":
    resolve()


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;

  string result;
  if (S == "Sunny")
    result = "Cloudy";
  else if(S == "Cloudy")
    result = "Rainy";
  else if(S == "Rainy")
    result = "Sunny";

  cout << result << endl;

}


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

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll a, b, c;
  cin >> a >> b >> c;
  cout << c - min(max(0ll, a-b), c) ;
  return 0;
} //good night.

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (stdIn.hasNextInt()) {
			int n = stdIn.nextInt();
			int a, b, c, d = 0;
			int count = 0;
			for (int w = 0; w < 10; w++) {
				for (int x = 0; x < 10; x++) {
					for (int y = 0; y < 10; y++) {
						for (int z = 0; z < 10; z++) {
							if (w + x + y + z == n)
								count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 17036
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<tuple<ll, ll, ll>> coordinate(n);
    int one_of_non_zero_h_idx = 2e9;
    rep(i, n)
    {
        int x, y, h;
        cin >> x >> y >> h;
        coordinate[i] = {x, y, h};
        if (h != 0)
        {
            one_of_non_zero_h_idx = i;
        }
    }
    
    int idx = one_of_non_zero_h_idx;
    
    for (int cx = 0; cx <= 100; ++cx)
    {
        for (int cy = 0; cy <= 100; ++cy)
        {
            ll H = get<2>(coordinate[idx]) + abs(get<0>(coordinate[idx]) - cx) + abs(get<1>(coordinate[idx]) -cy);
            bool all_ok = true;
            rep(i, n)
            {
                ll left_hand_side = get<2>(coordinate[i]);
                ll right_hand_side = (H - abs(get<0>(coordinate[i]) - cx) - abs(get<1>(coordinate[i]) -cy));
                right_hand_side = right_hand_side > 0 ? right_hand_side : 0;
                if (left_hand_side != right_hand_side)
                {
                    all_ok = false;
                    break;
                }
            }
            if (all_ok == true)
            {
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<pair<int, int>> A(N);
  REP(i, N){
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(ALL(A), greater<>());

  vector<vector<int>> dp(N+1, vector<int>(N+1, -INF));
  dp[0][0] = 0;
  REP(i, N) REP(j, i+1){
    chmax(dp[i+1][j+1], dp[i][j]+A[i].first*abs(A[i].second-j));
    chmax(dp[i+1][j],   dp[i][j]+A[i].first*abs((N-1-i+j)-A[i].second));
  }

  int ans = 0;
  REP(j, N+1) chmax(ans, dp[N][j]);

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 34616
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


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

int N; cin >> N;
VI A(N), B(N-1); rep(i, 0, N-1) cin >> B[i];

A[0] = B[0];
A[N-1] = B[N-2];
rep(i, 1, N-1){
    A[i] = min(B[i-1], B[i]);
}


cout << accumulate(ALL(A), 0) << endl;
}

// 境界，出力文字列 チェック



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

using namespace std;

int main() {
	int a, b; 
	cin >> a >> b;
	string s;
	cin >> s;

	bool flag = true;

	if(s[a] != '-'){
		cout << "No" << endl;
		return 0;
	}

	for(int i = 0; i <= (a + b); i++) {
		flag = false;
		if(i != a){
			int temp = s[i] - '0';
//			cout << temp << endl;
			for(int j = 0; j <= 9; j++){
				if(temp == j) flag = true;
			}
		}else{
			flag = true;
		}
		if(flag == false){
//			cout << i << endl;
			break;
		}
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const ll N = 2e5 + 5;

ll P[N];
ll n;
ll a[N];
ll R[N][22];
ll B[N];

ll ans;

ll RMQ (int l, int r){
    if (l < 1 || n < r)
        return N;
    int x = B[r - l + 1];
    int y = r - P[x] + 1;
    return max (R[l][x], R[y][x]);
}

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    P[0] = 1;
    for (int i = 1; i <= 20; i++)
        P[i] = P[i - 1] * 2;
    cin >> n;
    for (int i = 2; i <= n; i++){
        B[i] = B[i - 1];
        if ((i & (i - 1)) == 0)
            B[i]++;
    }
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        R[i][0] = a[i];
    }
    for (int I = 1; (1 << I) <= n; I++)
        for (int i = 1; i + P[I] <= n + 1; i++)
            R[i][I] = max (R[i][I - 1], R[i + P[I - 1]][I - 1]);
    for (ll i = 1; i <= n; i++){
        ll l1, l2, r1, r2;
        ll l = 0, r = i - 1;
        while (l < r){
            ll mid = l + r + 1 >> 1;
            if (RMQ (mid, i - 1) >= a[i])
                l = mid;
            else
                r = mid - 1;
        }
        l2 = l;
        l = 0, r = l2 - 1;
        while (l < r){
            ll mid = l + r + 1 >> 1;
            if (RMQ (mid, l2 - 1) >= a[i])
                l = mid;
            else
                r = mid - 1;
        }
        l1 = l;
        l = i + 1, r = n + 1;
        while (l < r){
            ll mid = l + r >> 1;
            if (RMQ (i + 1, mid) > a[i])
                r = mid;
            else
                l = mid + 1;
        }
        r1 = l;
        l = r1 + 1, r = n + 1;
        while (l < r){
            ll mid = l + r >> 1;
            if (RMQ (r1 + 1, mid) > a[i])
                r = mid;
            else
                l = mid + 1;
        }
        r2 = r;
        ll num = (r2 - r1) * (i - l2) + (l2 - l1) * (r1 - i);
        ans += num * a[i];
        //cout << i << " " << num << " " << l1 << " " << l2 << " " << r1 << " " << r2 << endl;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> t(N);
    for(int i = 0;i < N;i++){
        cin >> t[i];
    }
    vector<int> d(N - 1);
    for(int i = 0;i + 1 < N;i++){
        d[i] = t[i + 1] - t[i] - 1;
    }
    sort(d.begin(), d.end());
    cout << N + accumulate(d.begin(), d.begin() + max(N - K, 0), 0LL) << endl;
    return 0;
}



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

string s;

int main()
{
    cin >> s;
    if ((s.find('N') != string::npos) == (s.find('S') != string::npos) &&
        (s.find('W') != string::npos) == (s.find('E') != string::npos))
        printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,K = map(int, input().split())		# 5 7 2
A = [0] + list( map(int, input().split()) )	# 1 2 3 4 5 ...


M = [ [0,0] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]

p(M)

i = 1
x = y = 0
for k in range(K):
	x,y = M[i]
	
	if x==0:
		M[i][0] = A[i]
		M[i][1] = k
		i = A[i]
		continue
	
	
	a = K - y
	b = a % (k-y)
	for _ in range(b):
		i = A[i]
	
	p(x,y,k)
	p("M[1:]", M[1:])
	
	break

ans = i
print(ans)



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

using namespace std;

using ll = long long;

int main() {

  string a, b;
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.rbegin(), b.rend());
  if(b > a)cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

#define NUMBER 10000

int main(void){

        int a,b;
        int c[NUMBER] = {0};
        int d = -1; 
        int e = 0;

scanf("%d %d",&a,&b);

for(int i=0;i<b;i++){
        scanf("%d",&c[i]);
}

for(int j=0;j<b;j++){
        e += c[j];
}

if(a<e){
                printf("%d",d);
}else{
                printf("%d",a-e);
}
return 0;
}


Measured memory_bytes: 1772
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	unsigned long long r, D, x;
	cin >> r >> D >> x;

	for (auto i = 0; i < 10; ++i)
	{
		x = r * x - D;
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};

const int INF = 1010101;

int main(){
    int h,w;
    cin >>h >>w;
    vector<string> s(h);
    rep(i,h) cin >>s[i];

    auto IN = [&](int y, int x){
        return 0<=y && y<h && 0<=x && x<w;
    };

    int ans = 0;
    rep(sy,h)rep(sx,w)if(s[sy][sx]=='.'){
        vector<vector<int>> d(h,vector<int>(w,INF));
        d[sy][sx] = 0;
        queue<pi> que({{sy,sx}});
        while(!que.empty()){
            pi p = que.front();
            que.pop();
            rep(i,4){
                int ny = p.fi+dy[i], nx = p.se+dx[i];
                if(IN(ny,nx) && s[ny][nx]!='#' && d[ny][nx] > d[p.fi][p.se]+1){
                    que.push({ny,nx});
                    d[ny][nx] = d[p.fi][p.se]+1;
                }
            }
        }

        rep(i,h)rep(j,w)if(d[i][j]<INF) ans = max(ans, d[i][j]);
    }
    cout << ans << "\n";
    return 0;
}


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

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

int a, b;

int main()
{
    int i, j;
    scanf("%d%d", &a, &b);
    if(a<=0 && 0<=b) return !printf("Zero");
    if(1<=a || (b-a+1)%2==0) return !printf("Positive");
    return !printf("Negative");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

bool dp[100000 + 10];
char s[100000 + 10];

int main()
{
	scanf("%s", s);
	dp[0] = true;

	for (int i = 0; i < strlen(s); ++i)
	{
		if (dp[i] == false) continue;

		if (memcmp(s + i, "dream", 5) == 0)
		{
			dp[i + 5] = true;
			if (s[i + 5] == 'e' && s[i + 6] == 'r')
			{
				dp[i + 7] = true;
			}
		}
		else if (memcmp(s + i, "erase", 5) == 0)
		{
			dp[i + 5] = true;
			if (s[i + 5] == 'r')
			{
				dp[i + 6] = true;
			}
		}
	}

	printf(dp[strlen(s)] ? "YES\n" : "NO\n");

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

constexpr int N = 1e3+3;

int h,w;
int ch,cw,dh,dw;
int ans = -1;
string mp[N];
bool vis[N][N];

struct Point
{
    int x,y;
    int cnt;
};

bool inside(int x,int y)
{
    return x >= 0 and x < h and y >= 0 and y < w;
}

void bfs()
{
    deque<Point>dque;
    dque.push_front({ch,cw,0});
    while(!dque.empty())
    {
        Point tt = dque.front();
        int x = tt.x, y = tt.y, cnt = tt.cnt;
        dque.pop_front();
        if(x == dh && y == dw)
        {
            ans = cnt;
            break;
        }
        if(vis[x][y])continue;
        vis[x][y] = true;
        for(int i=0;i<4;++i)//正常能走的压入
        {
            int nx = x + dt[i][0];
            int ny = y + dt[i][1];
            if(inside(nx,ny) && mp[nx][ny] == '.')
            dque.push_front({nx,ny,cnt});
        }
        for(int nx=x-2;nx<=x+2;++nx)
        {
            for(int ny=y-2;ny<=y+2;++ny)
            {
                if(inside(nx,ny) && mp[nx][ny] == '.')
                dque.push_back({nx,ny,cnt+1});
            }
        }
    }
}

int main()
{
   IOS;
   cin >> h >> w;
   cin >> ch >> cw >> dh >> dw;
   --ch,--cw,--dh,--dw;//与string下标相对
   for(int i=0;i<h;++i) cin >> mp[i];
   bfs();
   cout << ans << endl;
}


Measured memory_bytes: 7380
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N;
    scan(N);
    vector<pair<int, int>> a(N);
    vector<int> ans;
    REP(i, N) {
        scan(a[i].first);
        a[i].second = i + 1;
    }
    SORT(a);
    for (auto &&i : a) {
        ans.emplace_back(i.second);
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 2168
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	
	ll a[5],memo = 10,ans = 0,memo_n = 0;
	
	
	rep(i,0,5){
		cin >> a[i];
		
		if(memo > a[i]%10 && a[i] % 10 != 0){
			memo = min(a[i] % 10,memo);
			memo_n = i;
		}
	}
	
	
	rep(i,0,5){
		if(i == memo_n){
			ans += a[i];
		}
		else{
			if(a[i] % 10 != 0) ans += a[i] + 10 - (a[i] % 10);
			else ans += a[i];
		}
	}
	
	cout << ans << endl;
	return 0;

}

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

int main() {
	int A, B;
	cin >> A >> B;

	int a, b, c;
	a = A + B;
	b = A - B;
	c = A * B;
	
	cout << max({ a, b, c }) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double x = sc.nextDouble();
    double th = 0;
    if(x>(a*a*b)/2){
     th = Math.toDegrees(Math.atan((2*a*a*b-2*x)/(a*a*a)));
    }else{
      th = Math.toDegrees(Math.atan((a*b*b)/(2*x)));
    }
  
  System.out.println(th);  
    
    
  }
  

  
}

Measured memory_bytes: 26580
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  ll a, b;
  int k;

  cin >> a >> b >> k;

  int itr = 0;
  for(;;){
    if(a%2 != 0){
      a--;
    }
    b = b + (a/2);
    a = a / 2;
    //cout << a << " " << b << endl;    
    itr++;
    if(itr == k) break;
    
    
    if(b%2 != 0){
      b--;      
    }
    a = a + (b/2);
    b = b / 2;
    //cout << a << " " << b << endl;
    itr++;
    if(itr == k) break;    
  }

  cout << a << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 256