akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);


ll modnum = 1e9+7;

typedef pair<int, int> P;

vector<vector<int>> to(100005);
vector<P> dist_t;
vector<P> dist_a;


void dfs_t(int u, int dist=0, int par=-1) {
    if(to[u].size() == 1) {
        dist_t.emplace_back(u, dist);
    }
    for(auto v : to[u]) {
        if(v == par) continue;
        dfs_t(v, dist+1, u);
    }
}

void dfs_a(int u, int dist=0, int par=-1) {
    if(to[u].size() == 1) {
        dist_a.emplace_back(u, dist);
    }
    for(auto v : to[u]) {
        if(v == par) continue;
        dfs_a(v, dist+1, u);
    }

}

int main() {
    int n,u,v; cin >> n >> u >> v;
    u--; v--;
    rep(i, n-1) {
        int a,b; cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    dfs_t(u);
    dfs_a(v);

    sort(dist_t.begin(), dist_t.end());
    sort(dist_a.begin(), dist_a.end());

    vector<int> ans;

    rep(i, dist_t.size()) {
        if(dist_t[i].second < dist_a[i].second) {
            ans.push_back(dist_a[i].second);
        }
    }

    sort(ans.rbegin(), ans.rend());

    cout << ans[0]-1 << endl;


    return 0;
}



Measured memory_bytes: 9856
let (n1, n2) = (4, 16)

let area =
  [| [1; 4]; [0; 2; 5]; [1; 3; 6]; [2; 7]
   ; [0; 5; 8]; [1; 4; 6; 9]; [2; 5; 7; 10]; [3; 6; 11]
   ; [4; 9; 12]; [5; 8; 10; 13]; [6; 9; 11; 14]; [7; 10; 15]
   ; [8; 13]; [9; 12; 14]; [10; 13; 15]; [11; 14] |]

let md = Array.make_matrix n2 n2 0

let initialize_md () =
  for i = 0 to n2 - 2 do
    for j = 0 to n2 - 1 do
      md.(i+1).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done

let idastar a limit space_i lower goal =
  let rec doit i space_i moved lower =
    if i = limit then begin
      if a = goal then begin
        Printf.printf "%d\n" (List.length moved - 1);
        exit 0;
      end
    end else
      List.iter (fun j ->
        let x = a.(j) in
        if x = List.hd moved then () else
        let lower = lower - md.(x).(j) + md.(x).(space_i) in
        if lower + i > limit then ()
        else begin
          a.(j) <- 0;
          a.(space_i) <- x;
          doit (i + 1) j (x :: moved) lower;
          a.(j) <- x;
          a.(space_i) <- 0;
        end) area.(space_i) in
  doit 0 space_i [-1] lower

let () =
  initialize_md ();
  let a = Array.init n2 (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let rec f i =
    if i = n2 then assert false
    else if a.(i) = 0 then i
    else f (i + 1) in
  let space_i = f 0 in
  let rec g i acc =
    if i = n2 then acc
    else g (i + 1) (acc + md.(a.(i)).(i)) in
  let lower = g 0 0 in
  let goal = [|1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 0|] in
  for limit = lower to 45 do
    idastar a limit space_i lower goal
  done

Measured memory_bytes: 4544
<?php
/*
    Problem URL : http://abc060.contest.atcoder.jp/tasks/abc060_d

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('memory_limit', '256M');

// define('DEBUG', true);
define('DEBUG', false);

$ans = 0;
$mem = array();

fscanf(STDIN, "%d %d", $N, $M);
$arr = array_pad(array(), $N, 0);

for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $a, $b);
    if ($a == 1) {
        $arr[$b]++;
    } elseif($b == 1) {
        $arr[$a]++;
    } else {
        $arr[$a]++;
        $arr[$b]++;
    }
}

foreach ($arr as $num) {
    if ($num % 2 == 1) {
        echo "NO\n";
        exit;
    }
}

echo "YES\n";


Measured memory_bytes: 8952
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll a[410];
ll d[410][410];
int main()
{
	cin >>n;
	for (int i=1;i<=n;i++) cin >>a[i],a[i]+=a[i-1];
	for (int len=1;len<=n;len++)
	{
		for (int i=0;i<=n-len;i++)
		{
			int j=i+len-1;
			//cout <<i<<" "<<j<<" ########################\n";
			if (i==j)
			{
				d[i][j]=0;
				continue;
			}
			d[i][j]=1e18;
			for (int k=i;k<j;k++)
			{
				d[i][j]=min(d[i][j],d[i][k]+d[k+1][j]+a[j+1]-a[i]);
			    //cout <<k<<" "<<min(d[i][j],d[i][k]+d[k+1][j])<<" "<<a[j+1]-a[i]<<" ##\n"; 
			}
		}
	}
	cout <<d[0][n-1];
	return 0;
} 

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld",&n);
	long long int i;
	long long int a[100005];
	for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
	long long int b[100005];
	for(i=0;i<n;i++)
		b[i]=a[(i+1)%n]-a[i];
	long long int sum=0;
	for(i=0;i<n;i++)
		sum+=a[i];
	if(sum%(n*(n+1)/2)>0)
	{
		printf("NO\n");
		return 0;
	}
	sum/=n*(n+1)/2;
	for(i=0;i<n;i++)
		b[i]=sum-b[i];
	long long int cnt=0;
	for(i=0;i<n;i++)
	{
		if(b[i]%n>0)
		{
			printf("NO\n");
			return 0;
		}
		if(b[i]<0)
		{
			printf("NO\n");
			return 0;
		}
		cnt+=b[i]/n;
	}
	if(cnt==sum)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 1664
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m, x, y int
	fmt.Scan(&n, &m, &x, &y)
	xs := make([]int, n)
	for i := 0; i< n; i++ {
		fmt.Scan(&xs[i])
	}
	ys := make([]int, m)
	for i:=0; i<m; i++ {
		fmt.Scan(&ys[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(xs)))
	sort.Sort(sort.IntSlice(ys))
	if xs[0] < ys[0] && xs[0] < y && x < ys[0] {
		fmt.Println(("No War"))
	} else {
		fmt.Println(("War"))
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    bool F[N][5][2];
    for(int i=0; i<N; i++){
        for(int j=0; j<5; j++){
            cin >> F[i][j][0] >> F[i][j][1];
        }
    }
    int profit[N][11];
    for(int i=0; i<N; i++){
        for(int j=0; j<11; j++){
            cin >> profit[i][j];
        }
    }
    vector<int> money(N);
    int ans=-1000000000;
    
    for(int i=1; i<1024; i++){
        bool flag[10];
        int tmp0=i;
        for(int j=0; j<10; j++){
            flag[j]=tmp0%2;
            tmp0/=2;
        }
        for(int shop=0; shop<N; shop++){
            int cnt=0;
            for(int day=0; day<5; day++){
                for(int t=0; t<2; t++){
                    if(F[shop][day][t]==1 && flag[day*2+t]==1){
                        cnt++;
                    }
                }
            }
            money[shop]=profit[shop][cnt];
        }
        int tmp=0;
        for(int j=0; j<N; j++){
            tmp+=money[j];
        }
        ans=max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int S,W;
  cin>>S>>W;
  if(S<=W) cout << "unsafe" << endl;
  else cout<<"safe"<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;


template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,mod);
    if(n&1) resp = resp*x%m;
    return resp;
}

int main()
{
    int n;
    cin >> n;
    const ll m = 61;
    ve<ll> a(n);
    rep(i,n) cin >> a[i];
    
    ve<vl> d(n,vl(m+1,0));
    ve<vl> dd(n,vl(m+1,0));
    
    rep(i,n){
        for (ll j = 0; j <= m; j++) {
            if(a[i]>>j & 1) d[i][j]++;
            else dd[i][j]++;
            if(i!=n-1) d[i+1][j] += d[i][j],dd[i+1][j] += dd[i][j];
        }
    
    }
    ll ans = 0;
    rep(i,n){
        ll cc = 1;
        for (ll j = 0; j <= m; j++) {
            if(a[i]>>j & 1){
                ans += (dd[n-1][j]-dd[i][j])*cc%mod;
                ans %= mod;
            }else{
                ans += (d[n-1][j]-d[i][j])*cc%mod;
                ans %= mod;
            }
            cc*=2;
            cc%=mod;
        }
    }
    out(ans%=mod);

   // rep(i,n){ rep(j,m+1) cout << d[i][j] << " ";cout << endl; }
    //cout << endl;
    //rep(i,n){ rep(j,m+1) cout << dd[i][j] << " ";cout << endl; }

       
    
    
    return 0;
}


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

using namespace std;

long long int NUM(long long int A, long long int B) {

	if (A <= 0) { return 0; }
	if (A%B == 0) { return A / B; }

	return A / B + 1;

};

int main(void) {

	long long int N, K;

	cin >> N >> K;

	vector<long long int>A;
	A.push_back(0);

	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp;
		A.push_back(tmp);
	}

	long long int num = 0;

	long long int count = 0;

	num += K; count++;

	while (num < N) {
		num += K - 1; count++;

	}

	cout << count << endl;



/*	long long int m;

	for (m = 1; m <= N; m++) {
		if (A[m] == 1) { break; }
	}
*/

/*	long long int min_V = N;

	long long int tmp_V;

	if (K == N) { cout << 1 << endl; return 0; }
	else if (K == 2) { cout << N - 1 << endl; }

	for (int i = m - K + 1; i <= m; i++) {
		if (i<1 || i + K - 1>N) { continue; }
		tmp_V = NUM(i - 1, K - 1) + 1 + NUM(N - i - K + 1, K - 1);
		if (tmp_V < min_V) { min_V = tmp_V; }
	}

	cout << tmp_V << endl;
	*/


	//system("pause");
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long t;
  long long ans = 0;
  cin >> n >> t;
  long tt[n];
  int i;
  for(i=0;i<n;i++){
    cin >> tt[i];
  }
  for(i=0;i<n-1;i++){
    ans += min(t,tt[i+1]-tt[i]);
  }
  ans += t;
  cout << ans;
  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b; cin>>a>>b;
	string x1, x2;
	for(int i=0;i<a;i++){
		char ch = b+'0';
		x1+=ch;
	}
	for(int i=0;i<b;i++){
		char ch = a+'0';
		x2+=ch;
	}
	cout<< (x1<x2 ? x1 : x2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int H, W, D;
  cin >> H >> W >> D;
  vector<pair<int, int>> pos(H * W);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int A;
      cin >> A;
      pos[A - 1] = make_pair(i, j);
    }
  }
  vector<int> dist(H * W);
  for (int i = D; i < H * W; i++) {
    dist[i] = dist[i - D] + abs(pos[i - D].first - pos[i].first) +
              abs(pos[i - D].second - pos[i].second);
  }
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int L, R;
    cin >> L >> R;
    cout << (dist[R - 1] - dist[L - 1]) << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
#include <iostream>

int main(int argc, char const *argv[]) {
    int N,M;
    std::cin >> N>>M;
    int C[N];
    for (size_t i = 0; i < N; i++ ) {
       C[i] = 0;
   }
    for (size_t i = 0; i < M; i++) {
        int a,b;
        std::cin >> a>>b;
        C[a-1]++;
        C[b-1]++;
    }
    for (size_t i = 0; i < N; i++) {
        std::cout << C[i] << '\n';
    }
    return 0;
}


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

typedef long long ll;
const int MOD = 1e9+7;

signed main() {
  int n, m; cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  for(int i = 0; i < m; i++) cin >> c[i] >> d[i];

  for(int i = 0; i < n; i++) {
      int cnt;
      // MODが大きいから使っただけ
      ll minD = MOD;
      for(int j = 0; j < m; j++) {
          int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
          if(dist < minD) {
             cnt = j+1;
             minD = dist;
          }
      }
      cout << cnt << 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);
        // 整数の入力
        int a = sc.nextInt();
        if (a == 0) {
            System.out.print(1);
        }
        if (a == 1) {
            System.out.print(0);
        }
    }
}

Measured memory_bytes: 27052
using System;

namespace ABC058B
{
    class Program
    {
        static void Main(string[] args)
        {
            string O = Console.ReadLine();
            string E = Console.ReadLine();
            int curO = 0;
            int curE = 0;
            bool flag = false;

            while (curO < O.Length || curE < E.Length)
            {
                if (flag)
                {
                    Console.Write(E[curE]);
                    curE++;
                }
                else
                {
                    Console.Write(O[curO]);
                    curO++;
                }
                flag = !flag;
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>

class Triangle{
	u_int a, b, c;
public:
	Triangle(u_int x, u_int y, u_int z);
	~Triangle() = default;
	void isRightTriangle();
};

Triangle::Triangle(u_int x, u_int y, u_int z){
	a = x;
	b = y;
	c = z;
}

void Triangle::isRightTriangle(){
	if((a*a == b*b + c*c || b*b == c*c + a*a || c*c == a*a + b*b)){
		std::cout << "YES" << std::endl;
	}
	else{
		std::cout << "NO" << std::endl;
	}
}

int main(){
	u_int n;
	std::cin >> n;
	
	for(u_int i = 0; i < n; ++i){
		u_int a, b, c;
		std::cin >> a >> b >> c;
		Triangle triangle(a, b, c);
		triangle.isRightTriangle();
	}
	
	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
    ll r,d,x;
    cin>>r>>d>>x;
    ll a[10];
    a[0]=(r*x)-d;
    for(ll i=1;i<10;i++)
    {
        a[i]=(r*a[i-1])-d;
    }
    for(ll i=0;i<10;i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
    
}



Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
cnt = [-1,2,5,5,4,5,6,3,7,6]
n,m = ma()
A = lma()
use=[(cnt[a],a) for a in A]
use.sort(key=lambda x:x[1],reverse=True)
INF=10**9
dp = [0]+[-INF]*(n+10)
for i in range(n):
    if dp[i]==-INF:continue
    for c,a in use:
        dp[i+c]=max(dp[i+c],dp[i]+1)
l = dp[n]
ans = ["0"]*l
num = n
for i in range(l):
    for c,a in use:
        if dp[num-c]==dp[num]-1:
            ans[i]=str(a)
            num-=c
            break
print("".join(ans))


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

int main() {
    string S_1, S_2, S_3, S_out;
    cin >> S_1 >> S_2 >> S_3;
    
    cout << S_1.at(0);
    cout << S_2.at(0);
    cout << S_3.at(0) << endl;
}

Measured memory_bytes: 256
//#include <GOD>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define len length	
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define freo freopen("output.txt","w",stdout)
#define frei freopen("input.txt","r",stdin)

const ll mod=1e9+7;
const ll maxn=1e5+10,maxp=10110;

string s;
ll cnt;

int main(){
	FAST_IO;
	cin>>s;
	for(int i=0;i<s.len();i++){
		cnt+=s[i]-'0';
	}
	if(cnt%9){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}


Measured memory_bytes: 3712
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

N, M = map(int, readline().split())
data = np.int64(read().split()).reshape(-1, 3)

A = data[:N, 0]
B = data[:N, 1]
C = data[:N, 2]
D = data[N:, 0]
E = data[N:, 1]
F = data[N:, 2]

X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]

A, B, D = map(lambda x: np.searchsorted(X, x), (A, B, D))
C, E, F = map(lambda x: np.searchsorted(Y, x), (C, E, F))

H, W = len(X), len(Y)
N = H * W

@njit
def solve():
    def set_ng():
        ng = np.zeros((N, 4), np.bool_)

        for i in range(len(A)):
            for x in range(A[i], B[i]):
                v = x * W + C[i]
                ng[v][1] = 1
                ng[v - 1][0] = 1

        for i in range(len(D)):
            for y in range(E[i], F[i]):
                v = D[i] * W + y
                ng[v][3] = 1
                ng[v - W][2] = 1
        return ng

    ng = set_ng(A, B, C, D, E, F)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

x = solve()
if x == 0:
    print('INF')
else:
    print(x)

Measured memory_bytes: 179540
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	if(n == 1 && a != b) {
		cout << 0 << endl;
		return 0;
	}
	if(a > b) {
		cout << 0 << endl;
		return 0;
	}
	cout << b * (n-1) + a - a*(n-1)-b + 1LL << endl;
 	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
//int NUMOFDIV(int n) 素因数分解して+1してかける奴
int NUMOFDIV2(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0,dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N, x = 0,max=0;
	string S;
	cin >> N >> S;
	rep(i, N) {
		if (S[i] == 'I')
			x++;
		else
			x--;
		if (x > max)
			max = x;
	}
	cout << max;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>S;
    cin>>K;
}
//=============================
void func(){}
//=============================
void solve()
{
    set<string> st;
    priority_queue<string, vector<string>, greater<string>> q;

    int N = S.size();
    rep(i,N){
        for(int j=1; j<=K; ++j){
            // i to j substring
            string ts = S.substr(i,j);
            if (st.find(ts) != st.end())//found
            {
                // do nothing
            }
            else {
            st.insert(ts);
            q.push(ts);
            }
        }
    }

    vector<string> anss;
    rep(i,K){
        string x = q.top();
        q.pop();
        anss.push_back(x);
    }
    cout<<anss[K-1]<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int dp[151][11][80];

int main(){
	int n, m;
	while(cin >> n >> m, n|m){
		rep(i, n) rep(j, 11) rep(k, 80) dp[i][j][k] = INF;
		vector<vector<P> > stone(n);
		rep(i, n){
			int k;
			cin >> k;
			rep(j, k){
				int x, d;
				cin >> x >> d;
				stone[i].push_back(MP(x, d));
			}			
		}
		rep(i, 2) rep(j, stone[i].size()){
			dp[i][j][i] = 0;
		}
		int ans = INF;
		rep(i, n){
			rep(j, stone[i].size()){
				P from = stone[i][j];
				rep(l, m+1){
					if(i+1 < n){
						rep(k, stone[i+1].size()){
							P to = stone[i+1][k];
							int cost = abs(from.X-to.X)*(from.Y+to.Y);
							dp[i+1][k][l] = min(dp[i+1][k][l], dp[i][j][l]+cost);
						}
					}else{
						ans = min(ans, dp[i][j][l]);
					}
				}
				rep(l, m){
					if(i+2 < n){
						rep(k, stone[i+2].size()){
							P to = stone[i+2][k];
							int cost = abs(from.X-to.X)*(from.Y+to.Y);
							dp[i+2][k][l+1] = min(dp[i+2][k][l+1], dp[i][j][l]+cost);
						}
					}else{
						ans = min(ans, dp[i][j][l]);
					}
				}
			}
		}
		cout << ans << endl;
	}
 
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  char can[H][W];
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> can[i][j];
    }
  }
  
  int judge = 0;
  
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(can[i][j] == '#') {
        if(can[i][j-1] != '#' && can[i][j+1] != '#' && can [i-1][j] != '#' && can [i+1][j] != '#') {
          judge += 1;
        }
      }
    }
  }
  
  if (judge == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
  
  

Measured memory_bytes: 256
// AtCoder ABC054 D - Mixing Experiment
// 2020.1.24 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

typedef struct { int ab, a, b, c; } T;
T tbl[45]; int N;

void Qsort(T *a, int l, int r) {
	int i, j; int m; T t;
	
	i = l, j = r, m = a[(l+r) >> 1].ab;
	while (1) {
		while (a[i].ab > m) i++;
		while (m > a[j].ab) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

#define SFT 9
#define MSK 511
int dp[230000];

int main()
{
	int i, j, a, b, Ma, Mb;
	int ma, ans;
	
	N = in(), Ma = in(), Mb = in();
	for (i = 0; i < N; ++i) {
		a = in(), b = in();
		tbl[i].ab = (a << SFT) | b;
		tbl[i].a = a, tbl[i].b = b, tbl[i].c = in();
	}
	Qsort(tbl, 0, N-1);
	
//for (i = 0; i < N; ++i) printf("[%d] ab=%d, a=%d, b=%d, c=%d\n",
//	i, tbl[i].ab, tbl[i].a, tbl[i].b, tbl[i].c);
	
	ans = -1, ma = N*tbl[0].ab;
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	for (i = 0; i < N; ++i) {
		for (j = ma; j >= 0; --j) if (dp[j] >= 0) {
			int x = dp[j] + tbl[i].c;
			a = (j >> SFT) + tbl[i].a, b = (j & MSK) + tbl[i].b;
			if (a*Mb == b*Ma) {
//				printf("a=%d, b=%d, i=%d, ans=%d\n", a, b, i, ans);
				if (ans < 0 || ans > x) ans = x;
			}
			int k = (a << SFT) | b;
			if (dp[k] < 0 || dp[k] > x) dp[k] = x;
		}
	}
	if (ans >= 0) printf("%d\n", ans);
	else puts("-1");
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll d_min = h[K-1] - h[0], d;
    for ( int i = K; i < N; i++ ) {
        d = h[i] - h[i - K + 1];
        if ( d_min > d ) d_min = d;
    }
    cout << d_min << '\n';
    return 0;
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  
  char& ch = s[k-1];
  if(ch == 'A') ch = 'a';
  else if(ch == 'B') ch = 'b';
  else ch = 'c';
  
  cout << s << endl;
  
  return 0;
}


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

int main() {

  long long n, y;
  cin >> n >> y;
  int ans = 0;
  
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= n-i; j++) {
      int l = n - i - j;
      if(l < 0) continue;
      if((10000*i) + (5000*j) + (1000*l) == y) {
        cout << i << " " << j << " " << l << endl;
        return 0;
      } 
    }
  }
  cout << "-1 -1 -1 " << endl; 
}


Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


struct Query {
	int v, d, c;
} Q[MAXN];

vector <int> g[MAXN];

int used[MAXN];

int maxd[MAXN];

void dfs(int v, int d, int c) {
	if (maxd[v] >= d) {
		return;
	}
	maxd[v] = d;
	if (!used[v]) {
		used[v] = c;
	}
	for (int i : g[v]) {
		dfs(i, d - 1, c);
	}
}

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), m = readInt();
    for (int i = 1; i <= m; i++) {
    	int u = readInt(), v = readInt();
    	g[u].pb(v);
    	g[v].pb(u);
    }
    memset(maxd, -1, sizeof(maxd));
    int q = readInt();
    for (int i = 1; i <= q; i++) {
		Q[i].v = readInt();
		Q[i].d = readInt();
		Q[i].c = readInt();    	
    }
    for (int i = q; i >= 1; i--) {
		int cur_vertex = Q[i].v;
		dfs(cur_vertex, Q[i].d, Q[i].c);
    }
    for (int i = 1; i <= n; i++) {
    	cout << used[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 36856
/* original submission at https://atcoder.jp/contests/abc134/submissions/6473772 
   code by kayaryou */

#include<stdio.h>
int main(void){
    int n, a[200001], b[200001], sum=0;
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=n; i>=1; i--){
        int m=2*i;
        int s=0;
        while(m<=n){
            s+=b[m];
            m=m+i;
        }
        if(s%2==a[i]){
            b[i]=0;
        }else{
            b[i]=1;
        }
    }
    for(int i=1; i<=n; i++){
        sum+=b[i];
    }
    printf("%d\n", sum);
        for(int i=1; i<=n; i++){
            if(b[i]==1){
                printf("%d ", i);
            }
        }
    return 0;

}


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

all_sum = sum(A)
divisors = []
for i in range(1,all_sum+1):
    if i * i > all_sum:break
    if all_sum % i != 0:continue
    divisors.append(i)
    if all_sum // i != i:
        divisors.append(all_sum // i)

divisors.sort(reverse=True)
def ok(d):
    a = [x % d for x in A]
    move = n - sum(a) // d
    a.sort()
    return sum(a[:move]) <= k


for d in divisors:
    if ok(d):
        print(d)
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n, m;
    cin >> n >> m;
    ll facn = 1, facm = 1;
    REP(i,1,n + 1){
        (facn *= i) %= MOD;
    }
    REP(i,1,m + 1){
        (facm *= i) %= MOD;
    }

    if (n >= m + 2 || m >= n + 2) cout << 0 << endl;
    else if (n == m + 1 || m == n + 1) cout << (facn * facm) % MOD << endl;
    else cout << 2 * (facn * facm) % MOD << endl;
    
    return 0;
}

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

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

Measured memory_bytes: 384
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
cnt=0
for i in range(n):
	if h[i]>=k:
		cnt=i
		break
ans=n-cnt
if k<h[0]:
	ans=n
elif h[-1]<k:
	ans=0
print(ans)

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

int main() {
	int n,A[2000010],B[2000010],C[2000010];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i+1];
		B[A[i+1]]++;
	}
	for(int i=1;i<2000010;i++){
		B[i]=B[i]+B[i-1];
	}
	for(int i=n;i>=1;i--){
		int j=A[i];
		int k=B[j];
		C[k-1]=j;
		B[j]--;
	}
	for(int i=0;i<n;i++){
		if(i){cout<< " ";}
		cout <<C[i];
	}
	cout <<endl;
}


Measured memory_bytes: 26516
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
long long n,k,h;
int a[100+10];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=n;i>=n-k+1;i--)
	{
		h+=a[i];
	}
	cout<<h<<endl;
	return 0;
}

Measured memory_bytes: 256
def bubbleSort(numlist):
    n = len(numlist)
    swaptime = 0
    for i in range(n):
        for j in range(n - 1, i, -1):
            if numlist[j] < numlist[j - 1]:
                swaptime += 1
                numlist[j], numlist[j - 1] = numlist[j - 1], numlist[j]
    return swaptime

def print_numlist(numlist):
    if len(numlist) == 1:
        print(numlist[0])
    else:
        for i in range(0, len(numlist) - 1):
            print(numlist[i], end = ' ')
        print(numlist[-1])

if __name__ == '__main__':
    n = int(input())
    numlist = [int(i) for i in input().replace('\n', '').split(' ')]
    swapnum =  bubbleSort(numlist)

    print_numlist(numlist)
    print(swapnum)


Measured memory_bytes: 5616
#include<stdio.h>
#include<math.h>
 
int main(void){

    double a,b,C,S,L,h;
 
    scanf("%lf %lf %lf",&a,&b,&C);

    S = 0.5 * a * b * sin(2.0 * M_PI * C / 360.0);
    L = a + b + sqrt(a * a  + b * b - 2.0 * a * b * cos(2.0 * M_PI * C / 360.0));
    h = 2.0 * S / a;
 
   printf("%lf\n%lf\n%lf\n",S,L,h);

   return 0;
}


Measured memory_bytes: 2104
#!/bin/usr/python

n = input()

s = [0 for i in range(100)]
a = 0

for i in range(n):
  s[i] = input()
  a += s[i]

flag = True
if a % 10 == 0:
  s = sorted(s)
  for i in range(n):
    if s[-1*n + i] % 10 != 0:
      a -= s[-1*n + i]
      break

if a % 10 == 0:
  a = 0

print(a)

Measured memory_bytes: 2568
L, R = map(int,input().split())
mod = 2019
#連続するn個の数字の列はnの倍数を含む
if R-L >= 2019: print(0)
else:
    res=2018 #2019の剰余なので最大でも2018
    for i in range(L,R):
        for j in range(i+1,R+1):
            res = min(res, (i*j)%mod)
    print(res)


Measured memory_bytes: 40812
package main

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

func solve() {
	n := getInt()
	s := getString()

	ans := 0
	abc := "ABC"
	for i := 0; i+len(abc) <= n; i++ {
		if s[i:i+len(abc)] == abc {
			ans++
		}
	}
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

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

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, K;
    cin >> N >> K;

    ll num = (N-1)/2 + 1;
    
    if(num >= K){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

int M;
int type[10100],is[10100],js[10100];

vector<int> G[200];
bool reached[200];
int N;

void init_graph(){
	for(int i=0;i<N*2;i++) G[i].clear();
}

void add_edge(int t,int i,int j){
	if(t==1){
		G[i].push_back(j);
		G[j+N].push_back(i+N);
	}else if(t==2){
		add_edge(1,i,j);
		add_edge(1,j,i);
	}else if(t==4){
		G[i].push_back(j+N);
		G[j].push_back(i+N);
	}
}

bool bfs(int s1,int s2){
	for(int i=0;i<N*2;i++) reached[i]=false;
	reached[s1]=true;
	reached[s2]=true;
	queue<int> que;
	que.push(s1);
	que.push(s2);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int u=G[v][i];
			if(reached[u]) continue;
			reached[u]=true;
			if(u>=N){
				if(reached[u-N]) return false;
			}else{
				if(reached[u+N]) return false;
			}
			que.push(u);
		}
	}
	return true;
}

bool check(int K){
	init_graph();
	for(int i=0;i<K;i++) add_edge(type[i],is[i],js[i]);
	bool ok=true;
	for(int i=0;i<K;i++){
		if(type[i]==3){
			int u=is[i],v=js[i]+N;
			bool flg=bfs(u,v);
			u+=N;
			v-=N;
			bool flg2=bfs(u,v);
			if(flg==false&&flg2==false){
				return false;
			}
		}else if(type[i]==5){
			int u=is[i],v=js[i];
			bool flg=bfs(u,v);
			if(!flg) return false;
		}
	}
	return true;
}

int main(){
	while(true){
		scanf("%d%d",&N,&M);
		if(N==0&&M==0) break;
		for(int i=0;i<M;i++){
			scanf("%d%d%d",type+i,is+i,js+i);
			is[i]--;js[i]--;
		}
		int lb=1,ub=M+1;
		while(ub-lb>1){
			int mid=(ub+lb)/2;
			bool flg=check(mid);
			if(flg) lb=mid;
			else ub=mid;
		}
		printf("%d\n",lb);
	}
	return 0;
}

Measured memory_bytes: 1532
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                max = Math.max(max, a[i] - min);
                min = Math.min(a[i], min);
            }
            out.println(max);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}




Measured memory_bytes: 26720
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ret = r*g*b

for i in range(1,int((n+1)/2)):
	for j in range(0,n-2*i):
		if(s[j] != s[j+i]) and (s[j+i] != s[j+2*i]) and (s[j+2*i] != s[j]):
			ret -= 1
#			print(i,j,j+i,j+2*i,s[j],s[j+i],s[j+2*i]," !!")
#		else:
#			print(i,j,j+i,j+2*i,s[j],s[j+i],s[j+2*i],)

print(ret)

Measured memory_bytes: 73604
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

const vector<int> dy = {0,1,0,-1};
const vector<int> dx = {-1,0,1,0};
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        int N; cin >> N;
        if (N == 0) break;
        vector<int> A(N-1),d(N-1),x(N),y(N);
        x[0] = y[0] = 0;
        rep(i,N-1) cin >> A[i] >> d[i];
        
        rep(i,N-1) {
            x[i+1] = x[A[i]] + dx[d[i]];
            y[i+1] = y[A[i]] + dy[d[i]];
        }
        sort(all(x)); sort(all(y));

        cout << x[N-1] - x[0] + 1 << " " << y[N-1] - y[0] + 1 << endl;
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define int long long
using namespace std;

int solve(string s, string& t) {
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        ans += (s[i] != t[i]);
    }
    return ans;
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        string s, t;
        cin >> s >> t;
        int ans = LLONG_MAX;
        for (int i = 0; i <= s.length() - t.length(); i++) {
            ans = min(solve(s.substr(i, t.length()), t), ans);
        }
        cout << ans;
    }
    return 0;
}


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

//4方向ベクトル→↑←↓
const int px[4] ={1,0,-1,0};
const int py[4] ={0,-1,0,1};

int board[15][15];
int x,y,size;
int ans1,ans2;
int main()
{
  ans1 = 0;
  for(int i = 0;i <10;i++){
    for(int j = 0;j < 10;j++){
      board[i][j] = 0;
    }
  }
  while(scanf("%d,%d,%d",&x,&y,&size) !=EOF){
    if(x <0||y < 0||x >10 ||y >10){
      continue;
    }
    if(size ==1){
      board[y][x] +=1;
      for(int j = 0;j < 4;j++){
	int nx = x + px[j];
	int ny = y + py[j];
	if(nx <0 ||ny < 0||nx > 10||ny >10)
	  continue;
	board[ny][nx] += 1;
      }
    }else if(size ==2){
      for(int i = -1;i <=1;i++){
	for(int j = -1;j <=1;j++){
	 int nx = x +j;
	 int ny = y +i;
	  if(nx <0 ||nx >=10||ny <0||ny >=10)
	    continue;
	  board[ny][nx] +=1;
	}
      }
    }else if(size ==3){
      for(int i = -2;i <=2;i++){
	for(int j = -2;j <=2;j++){
	  if(y +i<0||y+i >10||x +j < 0||x+j>10)
	    continue;
	  if(i == -2&&j ==0){
	    board[y+i][x] +=1;
	  }else if(i == -1&&(j !=-2&&j !=2)){
	    board[y+i][x+j] +=1;
	  }else if(i == 0){
	    
	    board[y+i][x+j] +=1;
	  }else if(i == 1&&(j !=-2&&j !=2)){
	    board[y+i][x+j] +=1;
	  }else if(i ==2&&j ==0){
	    board[y+i][x] +=1;
	  }
	}
      }
    }
  }
  ans2 = 0; 
  for(int i = 0;i <10;i++){
    for(int j = 0;j < 10;j++){
      if(board[i][j] == 0){
	ans1++;
      }
      if(board[i][j] > ans2){
	ans2 = board[i][j];
      }
    }
  }
  cout <<ans1<<endl;
  cout <<ans2<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>

void change(int,int);
int muki = 0,flag = 0;

int main(){
	int i,j,x = 0,y = 0,wall_x[4][5],wall_y[5][4];
	for(i = 0;i < 9;i++){
		if(i % 2 == 0) for(j = 0;j < 4;j++) scanf("%1d",&wall_x[j][i / 2]);
		else for(j = 0;j < 5;j++) scanf("%1d",&wall_y[j][(i - 1)/ 2]);
	}
	do{
		if(muki == 0){
			if(x != 4 && wall_x[x][y] == 1){
				flag = 0;
				change(x,y);
				putchar('R');
				x++;
			}else change(x,y);
		}else if(muki == 1){
			if(y != 4 && wall_y[x][y] == 1){
				flag = 0;
				change(x,y);
				putchar('D');
				y++;
			}else change(x,y);
		}else if(muki == 2){
			if(x != 0 && wall_x[x - 1][y] == 1){
				flag = 0;
				change(x,y);
				putchar('L');
				x--;
			}else change(x,y);
		}else if(muki == 3){
			if(y != 0 && wall_y[x][y - 1] == 1){
				flag = 0;
				change(x,y);
				putchar('U');
				y--;
			}else change(x,y);
		}
	}while(x != 0 || y != 0);
	puts("");
	return 0;
}

void change(int x,int y){
	int i;
	if(!flag){
		flag = 1;
		muki = (muki + 3) % 4;
	}
	else muki = (muki + 1) % 4;
}

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

void print_rectangle(int H, int W);

int main() {
	int H, W;
	while(cin >> H >> W){
		if (H == 0 && W == 0) break;
		print_rectangle(H, W);
	}
}

void print_rectangle(int H, int W){
	for (int h=0; h != H; ++h){
		for (int w=0; w != W; ++w){
			cout << '#';
		}
		cout << endl;
	}
	cout << endl;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int n = sc.nextInt();
    int sumAtk = 0;
    for (int i = 0; i < n; i++) {
      sumAtk += sc.nextInt();
    }
    System.out.println(sumAtk >= h ? "Yes" : "No");
  }
}


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

int main() 
{
	int x, y;
	double f;
	cin >> x >> y;
	f = 1.0*x / y;
	cout << x/y << " " << x%y << " " << fixed << setprecision(6) <<  f << endl;
}




Measured memory_bytes: 3288
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))


N,M = MI()
A = LI()
s = sum(A)
l = [a for a in A if a>=(s/(4*M))]

if len(l)>=M:
	print(('Yes'))
else:
	print('No')

Measured memory_bytes: 38384
#include<stdio.h>
int main(void)
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12){
		if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12) printf("Yes\n");
		else printf("No\n");
	}
	else if(x==4 || x==6 || x==9 || x==11){
		if(y==4 || y==6 || y==9 || y==11) printf("Yes\n");
		else printf("No\n");
	}
	else if(x==2 && y==2) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128