akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;


int main()
{
    int n;
    cin >> n;
    vector<int> s;
    rep(i, n){ int tmp; cin >> tmp; s.push_back(tmp);}

    // c-1
    ll max_score = 0;
    for (int c = 1; c < n; c++)
    {
        ll score = 0;
        set<int> hasu;
        hasu.insert(0);
        hasu.insert(n-1);
        for(int x = 1; c * x < n; x++){
            if (c >= n-1-c*x) break;
            int cx = c*x;
            int ccx = n - 1 - cx; 
            score += s[cx];
            if (hasu.find(cx) != hasu.end()) break;
            hasu.insert(cx);
            score += s[ccx];
            if (hasu.find(ccx) != hasu.end()) break;
            hasu.insert(ccx);
            max_score = max(max_score, score);
        }

    }
    
    cout << max_score << endl;
}


Measured memory_bytes: 7416
n = int(input())
key = [0]*n
flag = True
ans = 0
for i in range(n):
  a = int(input())
  if i == 0:
    if a != 0:
      flag = False
      break
    continue
  if a > key[i-1]+1:
    flag = False
    break
  key[i] = a
  if a == 1:
    ans += 1
  elif a == key[i-1]+1:
    ans += 1
  else:
    ans += a
if flag:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 10868
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

long long int DP[110000];

int main(){
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
      DP[i] = 1;
    }
    for(int loop = 0; loop < K - 1; loop++){
      for(int i = N; i >= 1; i--){
        for(int j = i * 2; j <= N; j += i){
          DP[j] += DP[i];
        }
        DP[i] = 0;
      }
    }
    long long int ans = 0;
    for(int i = 1; i <= N; i++){
      ans += DP[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3816
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		 Scanner scanner=new Scanner(System.in);
		 int H=scanner.nextInt();
		 int W=scanner.nextInt();
		 int N=scanner.nextInt();
		 scanner.nextLine();
		 StringBuffer bf1=new StringBuffer();
		 for(int i=0;i<H;i++){
			bf1.append(scanner.nextLine().trim());
		 }
		 bf1.trimToSize();
		 scanner.close();
		 int start=bf1.indexOf("S");
		 List<Integer> list=new ArrayList<Integer>();
		 list.add(start);
		 int result=0;
		 for(int T=1;T<=N;T++){
		StringBuffer bf=new StringBuffer(bf1);//拷?一个副本
		bf.trimToSize();
		 int level=1;//??一次有几个
		 while(!list.isEmpty()){
			 result++;
			 int levlel_=0;
			 for(int i=0;i<level;i++){
				 int pos=list.remove(0);
				 char c=bf.charAt(pos);
				 if(c==(""+T).charAt(0)){//找到
					 list.clear();
					  break;
				 }
				 bf.setCharAt(pos, 'X');
				 if(pos%W+1<W&&bf.charAt(pos+1)!='X'&&!list.contains(pos+1)){//右
						list.add(pos+1);
						levlel_++;
				 }
				 
				 if(pos+W<bf.length()&&bf.charAt(pos+W)!='X'&&!list.contains(pos+W)){//下
						list.add(pos+W);
						levlel_++;
				 }
				 if(pos%W-1>=0&&bf.charAt(pos-1)!='X'&&!list.contains(pos-1)){//左
						list.add(pos-1);
						levlel_++;
				 }
				 if(pos-W>=0&&bf.charAt(pos-W)!='X'&&!list.contains(pos-W)){//上
						list.add(pos-W);
						levlel_++;
				 }
			 }
			 level=levlel_;
		 }
		 if(T<N){//?没有找完
		 bf1.setCharAt(start, '.');
		 start=bf1.indexOf(""+T);
		 bf1.setCharAt(start, 'S');
		 list.add(start);
		 }
		 bf=null;
		 }
		 System.out.printf("%d\n", result-N);

	}

}

Measured memory_bytes: 125684
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          int N = getInt();
          long A = getLong();
          long B = getLong();
          long output = 0;
          long mae = getLong();
          for(int i = 0; i < N - 1; i++){
            long x = getLong();
            long kyori = x - mae;
            if(kyori * A > B){
              output += B;
            }else{
              output += kyori * A;
            }
            mae = x;
          }
          myout(output);
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 45852
#include <stdio.h>



    int dataNum;
    int modNum[3000];
    int answer[1000000];

int main(void){

    int n1 = scanf("%d",&dataNum);
    for(int i = 0;i< dataNum;i++){
        int n2 = scanf("%d",&modNum[i]);
    }
  //  printf("1st %d\n",dataNum);

/*    for(int n=0;n<dataNum;n++)
    printf("2nd %d\n",modNum[n]);*/


  /*  long overNum = 1;    
    for(int n=0;n<dataNum  ;n++){
    overNum *= modNum[n];
        if(overNum>100000)
        break;

    }
        
    for(int n=0;n<overNum;n++)
        answer[n] = 0;

    for(int i = 2;i<overNum;i++){
        for(int j = 0;j<dataNum;j++){
            answer[i] = answer[i] + modNum[j] - 1;
        }
    }
    

    for(int n=0;n<dataNum;n++)
    printf("3rd %d\n",answer[n]);
    

    for(int i=2;i<overNum;i++){
        if(max < answer[i]){
            printf("ya");
            max = answer[i];
        }
    }*/
    int max = 0;
    for(int j = 0;j<dataNum;j++){
            max +=  modNum[j] - 1;
        }

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


    return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n),ans;
	rep(i, 0, n) cin >> a[i];
	int mi, now = -1, idx = -1;
	rep(rotate, 0, k+1) {
		mi = 110,idx;
		rep(i, 0, n) {
			if (mi > a[i] && i != now) {
				idx = i;
				mi = a[i];
			}
		}
		rep(i, 0, n) {
			if (i != idx&&i!=now) {
				ans.push_back(i + 1);
				a[i]--;
			}
		}
		ans.push_back(idx + 1); a[idx]--;
		rep(i, 0, n) {
			if (a[i] < 0 && i != now) {
				cout << -1 << endl;
				return 0;
			}
		}
		now = idx;
	}
	cout << ans.size() << endl;
	rep(i, 0, ans.size()) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
static const ll MAX_L = (ll)1 << 62;

int main() {
	ll n; cin >> n;
	string s1; cin >> s1;
	string s2; cin >> s2;
	string t;

	ll i = 0;
	while (i < s1.size()) {
		if (s1[i] == s2[i]) {
			t += 'X';
			i++;
		}
		else {
			t += 'Y';
			i += 2;
		}
	}
	ll p = 0;

	if (t[0] == 'X') {
		p = 3;
	}
	else {
		p = 6;
	}

	rep(i, 1, t.size()) {
		if (t[i - 1] == 'X') {
			if (t[i] == 'X') {
				p = p * 2 % MOD;
			}
			else {
				p = p * 2 % MOD;
			}
		}
		else {
			if (t[i] == 'X') {
				p = p * 1 % MOD;
			}
			else {
				p = p * 3 % MOD;
			}
		}
	}
	cout << p << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define  s second
#define pii pair<int,int>
#define pll pair<ll,l>
#define ull unsigned ll
#define mp make_pair
#define pb push_back

using namespace std;


int main(){
	int n;cin>>n;
	ll d;cin>>d;
	int ans=0;
	for(int i=1;i<=n;i++){
		ll x,y;cin>>x>>y;
		if(x*x+y*y<=d*d)ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3556
N = int(input())

A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
C = [0 for _ in range(N)]

for i in range(N):
    A[i], B[i], C[i] = map(int, input().split())

dp = [[0, 0, 0] for _ in range(N)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1, N):
    
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + B[i]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i]

print(max(dp[-1]))

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

int n;
int a[10];


bool dfs(int i, int left, int right) {
    if (i == 9) return a[i] > left || a[i] > right;
    if (a[i] > left && dfs(i+1, a[i], right)) return true;
    if (a[i] > right && dfs(i+1, left, a[i])) return true;
    return false;
}

void solve() {
    if (dfs(0,0,0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}


Measured memory_bytes: 3008
import java.util.*;
public class Main {


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N_pathCount = Integer.parseInt(scan.next());
        int T_timeLimit = Integer.parseInt(scan.next());

        int minCost = 999999999;
        for(int i = 0; i < N_pathCount; i++){
           int cost = Integer.parseInt(scan.next());
           int time = Integer.parseInt(scan.next());

           if(time <= T_timeLimit){
               if(cost < minCost) minCost = cost;
           }
        }

        if(minCost == 999999999) {
            System.out.println("TLE");
        }else{
            System.out.println(minCost);
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


int main(){
    ld n,m,d,x=2;
    cin>>n>>m>>d;
    if(d==0)x=1; // n/n^2
    //ans=2*(n-2*d) d+1~n-d[i+d,i-d]   2通り
    //ans+=2*d      1~d[i+d] n-d~n[i-d] 1通り
    cout<<fixed<<setprecision(12)<<(m-1)*x*(n-d)/(n*n);;
}

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

using namespace std;

int main(void)
{
    int              n;
    string           stat;
    map<string, int> counter;
    cin >> n;
    while (n--)
    {
        cin >> stat;
        counter[stat]++;
    }
    cout << "AC x " << counter["AC"] << endl;
    cout << "WA x " << counter["WA"] << endl;
    cout << "TLE x " << counter["TLE"] << endl;
    cout << "RE x " << counter["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>

int calculate(double x1, double y1, double r1, double x2, double y2, double r2)
{
    double distance;

    distance = sqrt(pow((y1 - y2), 2) + pow(x1 - x2, 2));

    if(distance + r2 < r1) return 2;
    else if (distance > r1 + r2) return 0;
    else return 1;
}

int main(void)
{
    double x1, y1, x2, y2, r1, r2;
    int n, result;

    scanf("%d", &n);
    while (n){
        scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &r1, &x2, &y2, &r2);

        if (r1 >= r2) result = calculate(x1, y1, r1, x2, y2, r2);
        else if(r2 > r1) result = -calculate(x2, y2, r2, x1, y1, r1);
        if(result == -1) result = 1;
        printf("%d\n", result);
        n--;
    }
    return (0);
}


Measured memory_bytes: 2024
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vll b(60,0);
  rep(i,n){
    rep(j,60){
      if(a[i]&(1LL<<j)){
        b[j]++;
      }
    }
  }
  ll ans=0;
  rep(i,60){
    if(b[i]==n||b[i]==0) continue;
    ll now=1;
    rep(j,i) now=now*2%MOD;
    now%=MOD;
    ans+=(b[i]%MOD*((n-b[i])%MOD))%MOD*now;
    ans%=MOD;
  }
  COUT(ans);
}



Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
typedef long long LL;
using namespace std;

const LL mod = 1e9 + 7;
const int MAXN = 1e3 + 10;
char str[MAXN];

int main() {
	scanf("%s", str); 
	int len = strlen(str);
	for(int i = 0; i < len; ++i) {
		if(str[i] >= 'a' && str[i] <= 'z') printf("%c", str[i]);
		else printf(" ");
	}
	printf("\n");
	return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

void solve() {
  int n;
  cin >> n;

  vector <LL> a (n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];

  LL ans = 0;
  map <LL,int> have;

  for (int i = 1; i <= n; i++) {
    if (have.count(i - a[i])) ans += have[i - a[i]];
    have[i + a[i]]++;
  }

  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  int t = 1;
  for (int tc = 1; tc <= t; tc++) solve();
  return 0;
}


Measured memory_bytes: 17152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N[] = new int[4];
        int ans1 = 0, ans2 = 0;
        for (int i = 0; 4 > i; i++) {
            N[i] = sc.nextInt();
        }
        if (N[0] > N[2]) {
            ans1 = N[0];

        } else {
            ans1 = N[2];
        }
        if (N[1] > N[3]) {
            ans2 = N[3];
        } else {
            ans2 = N[1];
        }
        if (ans1 > ans2) {
            System.out.println("0");
        } else {
            System.out.println(ans2 - ans1);
        }
    }
}


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

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

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

  int cnt_A = 0;
  bool ok = true;
  rep(i, N) {
    string S;
    cin >> S;

    if (S == "A") cnt_A++;
    else if (S == "Un") {
      if (cnt_A <= 0) {
        ok = false;
      }
      cnt_A--;
    }
  }

  if (cnt_A != 0) ok = false;

  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

typedef long long ll;
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	int x;	cin >> x;

	if( x >= 30 )	cout << "Yes" << endl;
	else	 		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,z,w;
	cin>>n>>z>>w;
	vector<int> a(n);
	for(int& x:a) cin>>x;
	int res=abs(w-a[n-1]);
	if(n>=2) res=max(res,abs(a[n-1]-a[n-2]));
	cout<<res<<'\n';
}




Measured memory_bytes: 3672
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NX = ReadSplitInt();
            var L = ReadSplitInt();
            var N = NX[0];
            var X = NX[1];

            var s = new int[N + 1];
            for (int i = 0; i < N; i++)
            {
                s[i + 1] = s[i] + L[i];
            }

            Println(s.Count(x => x <= X));
        }


        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		int b = scn.nextInt();
		int c = scn.nextInt();

		if(c >= a && c <= b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N, K;
string S;

int main() {
    cin >> N >> K >> S;
    K--;
    int z = S[K] - 'A';
    S[K] = 'a' + z;
    cout << S << endl;
}


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
 
const int INF = 1<<29;
 
int N, M;
vector<int> change(int* a){
    vector<int> v(N);
    rep(i, N) v[i] = i+1;
    rep(i, M) swap(v[a[i]], v[a[i]-1]);
    return v;
}
 
int a[100];
 
int check(vector<int> &res, vector<int> &v){
    rep(i, N) if(res[i] != v[i]) return 10000;
 
    int h[10] = {};
    rep(i, M){
        int x = h[a[i]];
        rep(j, 10) h[j] = max(h[j], x);
        for(int j = -1; j <= 1; j++) h[a[i]+j] = x+1;
    }
    return *(max_element(h, h+10));
}
 
int main(){
 
    cin >> N >> M;
    rep(i, M) cin >> a[M-i-1];
    vector<int> res = change(a);
 
    int ans = 10000;
    sort(a, a+M);
    do{
        vector<int> v = change(a);
        ans = min(ans, check(res, v));
    }while(next_permutation(a, a+M));
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
typedef long long ll;


ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }


enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

int main()
{
    Compiler_Beso
    
    
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(all(v));
    cout<<abs(v[0]-v[n-1]);
    
    
    
    return 0;
}







Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
// import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int[] a = scanner.next().chars().map(c -> c - '0').toArray();
      String[] ops = {
        "+++",
        "++-",
        "+-+",
        "+--",
        "-++",
        "-+-",
        "--+",
        "---",
      };
      for (String op: ops) {
        if (solve(a,op) == 7) {
          show(a,op);
          return;
        }
      }
    } finally {
      scanner.close();
    }
  }
  
  private static int solve(int[] a, String op) {
    int ans = a[0];
    for (int i = 0; i < 3; i++) {
      switch(op.charAt(i)) {
        case '+':
          ans += a[i+1];
          break;

        case '-':
          ans -= a[i+1];
      }
    }
    return ans;
  }

  private static void show(int[] a, String op) {
    for (int i = 0; i < 4; i++) {
      System.out.print(a[i]);
      if (i != 3) System.out.print(op.charAt(i)); 
    }
    System.out.println("=7");
  }
}


Measured memory_bytes: 36116
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

ll mod = 998244353;
const int MAX = 1000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll dp[555][555];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,x;
    cin>>n>>x;
    dp[0][0] = 1;
    for(int i=0;i<=x;i++){
        for(int k=n-1;k>=0;k--){
            for(int j=0;j<512;j++){
                dp[k+1][j^i] += dp[k][j];
                dp[k+1][j^i] %= mod;
            }
        }
    }
    COMinit();
    ll ans = dp[n][x];
    for(int i=2;i<=n;i+=2){
        ll ret = dp[n-i][x];
        ll k = i/2;
        ret *= COM(x+k,k);
        ans += ret;
        ans %= mod;
    }
    cout << ans << endl;


}


Measured memory_bytes: 5412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  double ans;
  
  if(N%2==0)
    ans = 1.0/2.0;
  else
    ans = (N/2+1.0)/N;
  cout << ans << endl;
}

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

#define int ll

const int maxN = 1 << 17, INF = 1 << 30;

ll n;
int A[maxN], B[maxN], S[maxN], F[maxN << 1];

void add(int id) {
//	cout << "ADD " << id << endl;
	id += maxN;
	for(; id < 2 * maxN; id += id & -id) F[id]++;
}

int get(int id) {
//	cout << "GET " << id << endl;
	id += maxN;
	int s = 0;
	for(; id; id -= id & -id) s += F[id];
	return s;
}

bool check(int x) {
//	cout << "CHK " << x << endl;
	for(int i = 0; i < n; i++) if(A[i] >= x) B[i] = -1;
	add(0);
	int r = 0;
	for(int i = 0; i < n; i++) {
		S[i + 1] = S[i] + B[i];
		r += get(S[i + 1] - 1);
		add(S[i + 1]);
	}
	for(int i = 0; i < n; i++) B[i] = 1;
	for(int i = 0; i < 2 * maxN; i++) F[i] = 0;
//	cout << r << endl;
	return (r > n * (n + 1) / 4);
}

int32_t main() {
	//Input
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> A[i];
		B[i] = 1;
	}

	//Solve
	int l = 0, r = INF;
	while(l + 1 < r) {
//		cout << l << " " << r << endl;
		int m = (l + r) >> 1;
		if(check(m)) r = m;
		else l = m;
	}

	//Output
	cout << l;
	return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    char s[20][20];
    int used[20][20];
    int maxi=0;
    int dx[4]={-1,0,1,0};
    int dy[4]={0,-1,0,1};
    rep(i,h)rep(j,w)cin>>s[i][j];
    rep(i,h)rep(j,w){
        if(s[i][j]=='#')continue;
        rep(k,h)rep(l,w)used[k][l]=-1;
        queue<P> pq;
        pq.push({i,j});
        used[i][j]=0;
        int tmp=0;
        while(!pq.empty()){
            P p=pq.front();pq.pop();
            int k=p.first,l=p.second;
            if(s[k][l]=='#'){
              used[k][l]=-2;
              continue;
            }
            tmp=max(tmp,used[k][l]);
            rep(m,4){
                int nx=k+dx[m];
                int ny=l+dy[m];
                if(nx<0||nx>=h||ny<0||ny>=w)continue;
                if(used[nx][ny]!=-1)continue;
                pq.push({nx,ny});
                used[nx][ny]=used[k][l]+1;
            }
        }
        if(maxi<tmp)maxi=tmp;
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 256
r2a[128];
main(){
	char s[256];
	r2a['I']=1;
	r2a['V']=5;
	r2a['X']=10;
	r2a['L']=50;
	r2a['C']=100;
	r2a['D']=500;
	r2a['M']=1000;

	while(~scanf("%s",s)){
		int sum=0,i;
		for(i=0;s[i+1];i++){
			if(r2a[s[i]]>=r2a[s[i+1]])	sum+=r2a[s[i]];
			else						sum-=r2a[s[i]];
		}
		sum+=r2a[s[i]];
		printf("%d\n",sum);
	}

	exit(0);
}

Measured memory_bytes: 0
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(AB),
    get_number(BC),
    get_number(CA),
    X is AB * BC div 2,
    writeln(X).
 

Measured memory_bytes: 8172
#include <bits/stdc++.h>
using namespace std;
long long MOD;
unsigned long long modpow(unsigned long long b){
  unsigned long long ans = 1;
  long long a = 10;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
unsigned long long gp(int i, unsigned long long N){
  //1+10^i+10^2i+...+10^(N-1)i
  if (N == 1){
    return 1;
  } else {
    if (N % 2 == 0){
      unsigned long long ans = gp(i, N / 2);
      ans *= modpow(N / 2 * i) + 1;
      ans %= MOD;
      return ans;
    } else {
      unsigned long long ans = gp(i, N - 1);
      for (int j = 0; j < i; j++){
        ans *= 10;
        ans %= MOD;
      }
      ans++;
      ans %= MOD;
      return ans;
    }
  }
}
unsigned long long apgp(int i, unsigned long long N){
  //N+(N-1)*10^i+(N-2)*10^2i+...+1*10^(N-1)i
  if (N == 1){
    return 1;
  } else {
    if (N % 2 == 0){
      unsigned long long ans = apgp(i, N / 2);
      ans *= modpow(N / 2 * i) + 1;
      ans %= MOD;
      ans += gp(i, N / 2) * (N / 2 % MOD) % MOD;
      ans %= MOD;
      return ans;
    } else {
      unsigned long long ans = apgp(i, N - 1);
      for (int j = 0; j < i; j++){
        ans *= 10;
        ans %= MOD;
      }
      ans += N;
      ans %= MOD;
      return ans;
    }
  }
}
long long apgp2(unsigned long long lb, unsigned long long ub, unsigned long long B, int i){
  unsigned long long len = (ub - lb) / B + 1;
  unsigned long long ans = 0;
  if (lb > B){
    ans += gp(i, len) % MOD * ((lb - B) % MOD) % MOD;
  } else {
    ans -= gp(i, len) % MOD * ((B - lb) % MOD) % MOD;
    ans += MOD;
  }
  ans %= MOD;
  ans += (B % MOD) * apgp(i, len) % MOD;
  ans %= MOD;
  return ans;
}
int main(){
  long long L, A, B, M;
  cin >> L >> A >> B >> M;
  MOD = M;
  long long C = A + B * (L - 1);
  long long r = A % B;
  long long ans = 0;
  long long mn = C + 1;
  unsigned long long digit_cnt = 0;
  for (int i = 18; i >= 1; i--){
    long long lb = 1;
    for (int j = 0; j < i - 1; j++){
      lb *= 10;
    }
    long long ub = lb * 10;
    lb = (lb - r + B - 1) / B * B + r;
    ub = (ub - r - 1) / B * B + r;
    if (lb <= C && A <= ub && lb <= ub){
      lb = max(lb, A);
      ub = min(ub, C);
      if (ub >= mn){
        break;
      }
      ans += apgp2(lb, ub, B, i) * modpow(digit_cnt) % MOD;
      digit_cnt += i * ((ub - lb) / B + 1);
      mn = lb;
    }
  }
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<vector<int>> v(n);

	vector<int> c(m, 0);

	for(int i = 0; i < n; ++i){
		cin >> a[i];
		v[i].resize(a[i]);
		for(auto& x : v[i]){
			cin >> x;
			++c[--x];
		}
	}
	cout << count(c.begin(), c.end(), n) << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
  public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		String[] str = br.readLine().split(" ");
		long cnt;
		
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		cnt = invCount(A);
		
		System.out.println(cnt);
	}
	
	public static long invCount(int[] data){
		if(data.length < 2){
			return 0;
		}
		
		int middle = (data.length + 1) / 2;
		int[] left = Arrays.copyOfRange(data, 0, middle);
		int[] right = Arrays.copyOfRange(data, middle, data.length);
		
		return invCount(left) + invCount(right) + merge(data, left, right);
	}
	
	public static long merge(int[] array, int[] left, int[] right){
		int i = 0, j = 0;
		long count = 0;
		
		while(i < left.length || j < right.length){
			if(i == left.length){
				array[i + j] = right[j];
				j++;
			}else if(j == right.length){
				array[i + j] = left[i];
				i++;
			}else if(left[i] <= right[j]){
				array[i + j] = left[i];
				i++;
			}else{
				array[i + j] = right[j];
				count += left.length - i;
				j++;
			}
		}
		
		return count;
	}
}

Measured memory_bytes: 62356
#include<stdio.h>
int main(void)
{
	int d[3],a,b,c;
	for(a=0;a<3;a++){
		scanf("%d",&d[a]);
	}
	for(a=0;a<3;a++){
		for(b=a+1;b<3;b++){
				if(d[a]>d[b]){
				c=d[a];
				d[a]=d[b];
				d[b]=c;
		}
	}
}
	for(a=0;a<3;a++){
		printf("%d",d[a]);
		if(a<2){
			printf(" ");
	}
	}
	printf("\n");
	return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{s<<"{";if(SZ(v))s<<join(v,", ");s<<"}";return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll N; cin >> N;
    
    ll w[2] = {9, 6};
    ll dp[4][100004];
    fill((ll *)dp, (ll *)dp + 3 * 100004, INF);
    
    dp[0][0] = 0;
    REP(i, 2) REP(j, N+1) FOR(k, 1, 10) {
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        if (j+(ll)pow(w[i], k) <= N) 
            dp[i+1][j+(ll)pow(w[i], k)] = min(dp[i+1][j+(ll)pow(w[i], k)], dp[i+1][j] + 1);
    }
    
    REP(j, N+1) {
        dp[3][j] = dp[2][j];
        if (j >= 1)
            dp[3][j] = min(dp[3][j], dp[3][j-1] + 1);
    }
    cout << dp[3][N] << endl;
    
    return 0;
}

Measured memory_bytes: 3328
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		long a = scan.nextInt();
		long b = scan.nextInt();
		
		int max = (int) Math.max(a, b);
		int aa = 1;
		int bb = 1;
		
		for (int i = max; 0 < i; i--) {
			if (a % i == 0 && b % i == 0) {
				max = i;
				break;
			}
			
		}
		
		long ans = a * b / max;
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll a, b;
  ll ans = 0;
  ll minb = big;
  for(int i=0;i<N;++i) {
    cin>>a>>b;
    ans += a;
    if(a>b) minb = min(minb, b);
  }
  if(minb==big) cout<<0<<endl;
  else cout<<ans-minb<<endl;
}



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

void fnInput(vector<int>& rvnLife)
{
  int nLiftSiz;
  cin >> nLiftSiz;
  rvnLife.resize(nLiftSiz);

  for (int& rnLife : rvnLife)
    cin >> rnLife;
}

int fnGcd(int nDividend, int nDivisor)
{
  while ( nDividend % nDivisor )
  {
    int nRemain = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nRemain;
  }
  return nDivisor;
}

int fnMinLife(const vector<int>& cnrvnLife)
{
  vector<int> vnSrtLift(cnrvnLife);
  sort(begin(vnSrtLift), end(vnSrtLift));

  int nMinLife = vnSrtLift[0];

  for (int i = 1; i < vnSrtLift.size(); i++)
  {
    int nDividend = vnSrtLift[i];
    int nDivisor  = nMinLife;
    nMinLife = min(nMinLife, fnGcd(nDividend, nDivisor));
  }
  return nMinLife;
}
 
int main()
{
  vector<int> vnLife;

  fnInput(vnLife);
  cout << fnMinLife(vnLife) << endl;

  return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int INF = 1LL << 60;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vector<int> C(M);
    REP(i,M){
        cin >> C[i];
    }
    vector<int> dp(N+1);
    REP(i,N+1){
        dp[i] = i;
    }
    REP(i,M){
        int c = C[i];
        REP(j,N){
            if (j+c>N)break;
            dp[j+c]=min(1+dp[j],dp[j+c]);
        }        
    }
    cout << dp[N]<<endl;

}




Measured memory_bytes: 3284
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double num = sc.nextDouble();
		double ans;
		ans=Math.ceil(num/2);
		int a;
		a=(int)ans;
		System.out.println(a);
		return;
		}
	}


Measured memory_bytes: 24916
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  int n;
  ll k;
  cin >> n >> k;
  map<int, ll> dp;
  while(n--) {
    int a, b;
    cin >> a >> b;
    dp[a] += b;
  }
  for(auto x: dp) {
    k -= x.second;
    if(k <= 0) {
      cout << x.first << "\n";
      break;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int H, W;
const int INF = 1000000000;
const int MAX_H = 20;
const int MAX_W = 20;
int d[MAX_H][MAX_W+1];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
vector<string> S;

int bfs(int sx, int sy, int gx, int gy) {
  queue<P> q;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      d[i][j] = INF;
    }
  }
  q.push(P(sx, sy));
  d[sx][sy] = 0;

  while(q.size()) {
    P p = q.front(); q.pop();
    if (p.first == gx && p.second == gy) break;

    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];

      if (0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] != '#' && d[nx][ny] == INF) {
        q.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
      
    }
  }
  return d[gx][gy];
}

int main() { 
  cin >> H >> W;
  S.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          if(S[i][j] == '#' || S[k][l] == '#') continue;
          ans = max(ans , bfs(i, j, k, l));
        }
      }
    }
  }
  cout << ans << endl;
  

  return 0;
}

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

int main()
{
  long long int N, M, K;
  cin>>N>>M>>K;
  long long int A[N+1], B[M+1], sa[N+1], sb[M+1];
  sa[0]=0;
  sb[0]=0;
  long long int b_max=M,a_max=N,max=0;
  for(long long int i=1; i<=N; i++)
  {
    cin>>A[i];
    sa[i]=sa[i-1]+A[i];
  }
  for(long long int i=1; i<=M; i++)
  {
    cin>>B[i];
    sb[i]=sb[i-1]+B[i];
  }
  for(long long int i=0; i<=N; i++)
  {
  	if(sa[i]<K)
  	{
  		long long int j = b_max;
    	for(;(K<(sb[j]+sa[i]))&&(j>0);j--)
    	{
    		continue;
		}
    	b_max = j;
    	if(max<b_max+i)
    		max=b_max+i;
    	else
    		continue;
  	}
  	else
  		break ;
  }
  for(long long int i=0; i<=M; i++)
  {
  	if(sb[i]<K)
  	{
  		long long int j = a_max;
    	for(;(K<(sa[j]+sb[i]))&&(j>0);j--)
    	{
    		continue;
		}
    	a_max = j;
    	if(max<a_max+i)
    		max=a_max+i;
    	else
    		continue;
  	}
  	else
  		break ;
  }
  cout<<max;
  return 0;
}

Measured memory_bytes: 9760
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int a[3],b[3],dat=1;

	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
		int h=0,n=0;

		for(int j=0;j<4;j++){
			cin>>dat;
			b[j]=dat;
	}
	for(int k=0;k<4;k++){
			if(a[k]==b[k]){
				h++;
			}

		for(int o=0;o<4;o++){
			if(a[k]!=b[k] && a[k]==b[o]){
				n++;
			}
		}
	}
	cout<<h<<" "<<n<<endl;
	}
	return 0;
}	

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main()
{
  cout << fixed << setprecision(10);
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  bool ok = false;
  int M = 0;
  int g = 0;
  rep(i,N) 
  {
    cin >> A[i];
    if(A[i]==K)
    {
      ok = true;
    }
    M = max(M,A[i]);
    if(i==0) g = A[0];
    g = gcd(A[i],g);
  }
  if(g==1)
  {
    ok = true;
  }
  else
  {
    if(gcd(g,K)!=g)
    {
      ok = false;
    }
    else
    {
      ok = true;
    }
  }
  if(M<K)
  {
    ok = false;
  }
  if(ok)
  {
    cout << "POSSIBLE" << endl;
  }
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    cout << min(A * N, B) << endl;
    return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

int to[_],ne[_],he[_]={0},ecnt=1;
void adde(int a,int b){to[++ecnt]=b,ne[ecnt]=he[a],he[a]=ecnt;}

int n,lim,ans=0,nex[_],dep[_]={0};

void dfs(int x)
{
	dep[x]=1;
	for(int i=he[x];i;i=ne[i]){int b=to[i];dfs(b),dep[x]=max(dep[x],dep[b]+1);}
	if(nex[x]!=1 && dep[x]>=lim)ans++,dep[x]=0;
}

int main()
{
	n=ty(),lim=ty();
	for(int i=1;i<=n;i++)nex[i]=ty();
	if(nex[1]!=1)ans++,nex[1]=1;

	for(int i=2;i<=n;i++)adde(nex[i],i);
	dfs(1),printf("%d\n",ans);

	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  string S;
  cin >> S;
  ll N = S.size(); //stringの長さ求める
  ll ans = 0;
  ll bit,i;
  for(bit=0;bit<(1<<(N-1));bit++){ //1<<iは2^iを表す
    ll tmp = 0;
    for(i=0;i<=N-2;i++){
      tmp *= 10;
      tmp += S[i] - '0'; //stringでもS[i]で参照できる
      if(bit & (1<<i)) ans += tmp,tmp = 0; //if(bit & (1<<i))はi桁目が1の時true、つまり+
      }
    tmp *= 10;
    tmp += S.back() - '0';
    ans += tmp;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) throws java.lang.Exception{
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        ArrayList<Integer> divisorArray = new ArrayList<Integer>();

        for(int i = a; i <= b; i++){
            if((c % i) == 0){
                divisorArray.add(i);
            }
        }
        System.out.println(divisorArray.size());
    }
}


Measured memory_bytes: 26260
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}

	ans := 0
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			ans = max(ans, abs(a[i]-a[j]))
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int b[110];
int main(){
	int a;scanf("%d",&a);for(int i=0;i<a;i++)scanf("%d",b+i);
	std::sort(b,b+a);
	int ret=0;
	for(int i=0;i<a;i++){
		if(i==0||b[i]!=b[i-1])ret++;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import Counter

def main():
    S = input()

    cnt = Counter()
    for c in "abc":
        cnt[c] = 0
    cnt.update(S)

    v = sorted(cnt.values())
    ok = v[2] - v[0] <= 1
    print("YES" if ok else "NO")

if __name__ == "__main__": main()


Measured memory_bytes: 3444