akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
//https://beta.atcoder.jp/contests/tenka1-2017/tasks/tenka1_2017_e

namespace Problem {
using namespace std;
struct Line {
  double a, b, c;
};
struct FindX {
  double operator()(Line &l, double y) {
    return (l.c - l.b * y) / l.a;
    //return (b.b * a.c - a.b * b.c) / (b.b * a.a - a.b * b.a);
  }
};
struct FindY {
  double operator()(Line &l, double x) {
    return (l.c - l.a * x) / l.b;
    //return (-b.a * a.c + a.a * b.c) / (b.b * a.a - a.b * b.a);
  }
};
struct sortByMinX {
  bool operator()(Line &a, Line &b) { return -a.a / a.b > -b.a / b.b; }
};
struct sortByMinY {
  bool operator()(Line &a, Line &b) { return -a.b / a.a > -b.b / b.a; }
};
template <typename T>
struct BIT {
  vector<T> bit;
  int size;
  BIT(int _size) : bit(vector<T>(_size + 1, 0)), size(_size) {}
  void add(int index, T value) {
    for (int i = index + 1; i <= size; i += (i & -i)) bit[i] += value;
  }
  T sum(int a, int b) {  //sum of[a,b)
    return sum(b) - sum(a);
  }
  T sum(int a) {  // sum of[0,a) = sum of bit[0]~bit[a]
    T ret = 0;
    for (int i = a; i > 0; i -= (i & -i)) ret += bit[i];
    return ret;
  }
};
class Solver {
 public:
  int n;
  vector<Line> line;
  Solver(LL n) : n(n), line(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> line[i].a >> line[i].b >> line[i].c;
    }
    cout << binarySearch<FindY, sortByMinX>() << ' ' << binarySearch<FindX, sortByMinY>() << endl;
  }
  template <class Calc, class S>
  double binarySearch() {
    Calc op;
    sort(line.rbegin(), line.rend(), S());
    double lb = -1e9, ub = 1e9;
    for (int i = 0; i < 80; ++i) {
      double mid = (lb + ub) / 2;
      vector<pair<double, int>> coord;
      for (int j = 0; j < n; ++j) {
        coord.emplace_back(op(line[j], mid), j);
      }
      sort(coord.begin(), coord.end());
      BIT<int> bit(n);
      int cnt = 0;
      for (int j = 0; j < n; ++j) {
        cnt += bit.sum(coord[j].second);
        bit.add(coord[j].second, 1);
      }
      DBG(mid, coord, cnt)
      if (cnt >= (n * (n - 1) / 2 + 1) / 2) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    return ub;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}

Measured memory_bytes: 2928
// Problem : E - Active Infants
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 2000 + 5;
const ll MOD = 1e9 + 7;

int n;
pll arr[maxN];
ll dp[maxN][maxN];

ll solve(int pocz, int kon) {
	if (pocz + kon == n) return 0;
	if (dp[pocz][kon] != -1) return dp[pocz][kon];
	int i = pocz + kon;
	ll ansPocz = arr[i].st * abs(arr[i].nd - pocz - 1);
	
	ansPocz += solve(pocz + 1, kon);
	ll ansKon = arr[i].st * abs(n - arr[i].nd - kon);
	ansKon += solve(pocz, kon + 1);
	//cout << pocz << " " << kon << " " << ansKon << " " << ansPocz << endl;
	dp[pocz][kon] = max(ansKon, ansPocz);
	return dp[pocz][kon];
}

// sprawdz MODULO!
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		arr[i] = {a, i + 1};
	}
	REP(i, n + 1) {
		REP(j, n + 1) {
			dp[i][j] = -1;
		}
	}
	sort(arr, arr + n, greater<pll>());
	// REP(i, n) {
		// cout << arr[i].st << " " << arr[i].nd << endl;
	// }
	cout << solve(0, 0);
	return 0;
}
 


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

int main() {
  int n, ans = 1;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 1; i < n; i++) {
    if (s.at(i - 1) != s.at(i)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
import java.io.*;

class Main{

	public static void main(String[] args)throws IOException{
	
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strSec = br.readLine();
		int intSec = Integer.parseInt(strSec);
		int h = intSec / 3600;
		int m = (intSec % 3600) / 60;
		int s = (intSec % 3600) % 60;
		System.out.println(h + ":" + m + ":" + s);
	
	}
	
}

Measured memory_bytes: 17016
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    s = inputs[0]
    c_set = set()

    for c in s:
        c_set.add(c)

    for c in 'abcdefghijklmnopqrstuvwxyz':
        if c not in c_set:
            return c
    return 'None'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


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

#define MOD 998244353
#define MAX_N 200000

using namespace std;

typedef long long lint;

string s;

map <string, bool> ap;

int rez;

char getNr(char a, char b)
{
    if(a > b)
        swap(a, b);

    if(a == 'a' && b == 'b')
        return 'c';

    if(a == 'a' && b == 'c')
        return 'b';

    return 'a';
}

void bkt(int k, int &print)
{
    if(ap[s] == 1)
        return;

    ap[s] = 1;
    int i;
    rez ++;

    for(i = 0; i + 1 < s.size(); i ++)
    {
        if(s[i] != s[i + 1])
        {
            int ai = s[i];
            int aj = s[i + 1];
            s[i] = s[i + 1] = getNr(ai, aj);
            int aa = 0;
            bkt(k + 1, aa);

            s[i] = ai;
            s[i + 1] = aj;
        }
    }
}

int n;

lint dp[MAX_N + 1][3];
lint dp2[MAX_N + 1][3][3];

int main()
{
    cin >> s;

    int aa = 0;
    n = s.size();
    if(n < 4)
    {
        bkt(0, aa);

        cout << rez << "\n";

        return 0;
    }

    int i;
    int ok = 0;
    for(i = 0; i + 1 < n; i ++)
    {
        if(s[i] != s[i + 1])
            ok ++;
    }

    if(ok == 0)
    {
        cout << "1" << "\n";

        return 0;
    }

    int ss = 0;
    for(i = 0; i < n; i ++)
    {
        ss += s[i] - 'a';
    }

    ss %= 3;

    dp[1][0] = 1;
    dp[1][1] = 1;
    dp[1][2] = 1;

    int j, h;
    for(i = 1; i < n; i ++)
    {
        for(h = 0; h <= 2; h ++)
        for(j = 0; j <= 2; j ++)
        {
            dp[i + 1][(j + h) % 3] += dp[i][h];

            if(dp[i + 1][(j + h) % 3] >= MOD)
                dp[i + 1][(j + h) % 3] -= MOD;
        }
    }

    dp2[1][0][0] = 1;
    dp2[1][1][1] = 1;
    dp2[1][2][2] = 1;

    int l;
    for(i = 1; i < n; i ++)
    {
        for(h = 0; h <= 2; h ++)
        {
            for(j = 0; j <= 2; j ++)
            {
                for(l = 0; l <= 2; l ++)
                {
                    if(l != j)
                    {
                        dp2[i + 1][(h + l) % 3][l] += dp2[i][h][j];

                        if(dp2[i + 1][(h + l) % 3][l] >= MOD)
                            dp2[i + 1][(h + l) % 3][l] -= MOD;
                    }
                }
            }
        }
    }

    cout << ((MOD * 4LL + dp[n][ss] - dp2[n][ss][0] - dp2[n][ss][1] - dp2[n][ss][2] + (ok == n - 1)) % MOD )<< "\n";

    return 0;
}


Measured memory_bytes: 19332
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

A,B,C,D,E,F = I()
lim1 = F//(100*A)
lim2 = F//(100*B)
ans = 0
ansnum = 0
for i in range(lim1+1):
    for j in range(lim2+1):
        w = 100*i*A+100*j*B
        if i == j == 0:
            continue
        if w > F:
            continue
        r = F-w
        num = 0
        lim3 = min(r,(i*A+j*B)*E)//C
        for k in range(lim3+1):
            num = max(num,k*C+((min(r,(i*A+j*B)*E)-k*C)//D)*D)
        if 100*num/(w+num) > ansnum:
            ans = [w+num,num]
            ansnum = 100*num/(w+num)
if ans == 0:
    print(A*100,0)
else:
    print(*ans)

Measured memory_bytes: 77500
#include <bits/stdc++.h>
#define REPi(n) for(int i=0;i<n;i++)
#define REPj(n) for(int j=0;j<n;j++)

using namespace std;

int main(){
    int n,ans;
    ans=0;
    cin >> n ;
    ans=pow(n,3);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

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

//func factorial(n int) int {
//	switch n {
//	case 0, 1:
//		return 1
//	default:
//		return n * factorial(n-1) % 1000000007
//	}
//}
//
//func main() {
//	n := readInt()
//	fmt.Println(factorial(n))
//}
func main() {
	n := readInt()
	ans := 1
	for i := 2; i <= n; i++ {
		ans = ans * i % 1000000007
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import sys
input=sys.stdin.readline
k=int(input())
s=input().rstrip()
INF=10**9+7
ans=0
n=len(s)
def modinv(a,m):
    b=m
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while not b==0:
        q=a//b
        (a,b)=(b,a%b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx%m

x=26**k
y=modinv(26,INF)
c=1

for i in range(k+1):
    ans=(ans+c*x)%INF
    x=(x*25*y)%INF
    c=(c*(n+i)*modinv(i+1,INF))%INF

print(ans)


Measured memory_bytes: 81860
c=[]
d=[]
dd = []
a,b = map(int,input().split())
for i in range(a):
    c.append(list(input().split()))
    d.append([int(s) for s in c[i]])
for i in range(a) :
    f = sum(d[i])
    d[i].append(f)
for i in range(b+1):
    ff=0
    for j in range(a):
        ff = ff + d[j][i]
    dd.append(ff)
d.append(dd)
for i in range(a+1):
        print(*d[i])


Measured memory_bytes: 6872
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>

using namespace std;

int linear_serch(vector<int> A, int key) {
	A.push_back(key);
	int i = 0;
	while (A[i] != key) {
		++i;
	}
	return i != A.size() - 1;
}

int main() {
	int n;
	int q;
	cin >> n;
	vector<int> s(n);
	for (int i = 0; i < n; ++i)cin >> s[i];
	cin >> q;
	vector<int> t(q);
	for (int i = 0; i < q; ++i)cin >> t[i];

	int ans = 0;
	for (int i = 0; i < t.size(); ++i) {
		if(linear_serch(s, t[i])) ans++;
	}

	cout << ans << endl;

	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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 comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a[3][3];
    for( int i = 0; i < 3; ++i ) {
        for( int j = 0; j < 3; ++j ) {
            cin >> a[i][j];

        }
    }

    int n;
    cin >> n;
    for( int i = 0; i < n; ++i ) {
        int b;
        cin >> b;
        for( int j = 0; j < 3; ++j ) {
            for( int k = 0; k < 3; ++k ) {
                if( a[j][k] == b ) a[j][k] = -1;

            }
        }

    }

    if( a[0][0] + a[0][1] + a[0][2] == -3 ||
        a[0][0] + a[1][0] + a[2][0] == -3 ||
        a[0][0] + a[1][1] + a[2][2] == -3 ||
        a[0][1] + a[1][1] + a[2][1] == -3 ||
        a[0][2] + a[1][2] + a[2][2] == -3 ||
        a[1][0] + a[1][1] + a[1][2] == -3 ||
        a[2][0] + a[2][1] + a[2][2] == -3 ||
        a[0][2] + a[1][1] + a[2][0] == -3 ) {
        cout << "Yes";

    } else {
        cout << "No";

    }
    cout << endl;
    return 0;
}



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

#define rank Rank

using namespace std;

const int N=1e6+10;

int n,k;
int sa[N];
int rank[N];
int tmp[N];

string S,T;

bool cmp(int i,int j)
{
    if(rank[i]!=rank[j]) return rank[i]<rank[j];
    else
    {
        int ri=i+k<=n?rank[i+k]:-1;
        int rj=j+k<=n?rank[j+k]:-1;
        return ri<rj;
    }
}

void getSa()
{
    n=S.length();

    for(int i=0;i<=n;i++)
    {
        sa[i]=i;
        rank[i]=i<n?S[i]:-1;
    }

    for(k=1;k<=n;k<<=1)
    {
        sort(sa,sa+n+1,cmp);

        tmp[sa[0]]=0;
        for(int i=1;i<=n;i++)
        {
            tmp[sa[i]]=tmp[sa[i-1]]+(cmp(sa[i-1],sa[i])?1:0);
        }
        for(int i=0;i<=n;i++) rank[i]=tmp[i];
    }
}

bool contain()
{
    int l=0,r=S.length();
    while(r-l>1)
    {
        int mid=(l+r)>>1;
        if(S.compare(sa[mid],T.length(),T)<0) l=mid;
        else r=mid;
    }
    return S.compare(sa[r],T.length(),T)==0;
}

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

    cin>>S;

    int number;

    cin>>number;

    getSa();

    while(number--)
    {
        cin>>T;
        cout<<contain()<<endl;
    }

    return 0;
}



Measured memory_bytes: 15728
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    S = list(input().split())

    if "Y" in S:
        print("Four")
    else:
        print("Three")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
a, b = map(int, input().split())
s = input()
if s[a] == "-":
    c = 0
    for i in range(a+1+b):
        if s[i] == "-":
            c += 1
    if c >= 2:
        print("No")
    else:
        print("Yes")
else:
    print("No")

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


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;

/* vector<ll> v(N);
  小さい順: sort(v.begin(), v.end());
  逆順: reverse(v.begin(), v.end());
  vector<pair<ll, ll> > p; ＃ソートした場合、１つ目でソート
  tie(b, a) = p.at(i); #pairを分割
  tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
  xの二乗:  pow(x, 2.0);
  int: -2,147,483,648 ～ 2,147,483,647(2×10^9)
  ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807(9×10^18)
  long long型の2次元配列(3×4要素の)の宣言
  vector<vector<ll>> data(3, vector<ll>(4));
  string -> int : stoi(S);
  int -> string : to_string(N);
  Sのn文字以降をm文字取り出す : S.substr(n,m)
*/
 
 //126~
 //

int main() {
  
  ll N,n1,n2,K, count=0, ans=0;
  string S,s1,s2;
  
  cin >> S;
  n1=(S[0]-'0')*10+S[1]-'0';
  n2=(S[2]-'0')*10+S[3]-'0';

  if(1<=n1&&n1<=12)count++;
  if(1<=n2&&n2<=12)count+=10;

  switch(count){
    case 0: cout << "NA" << endl; break;
    case 1: cout << "MMYY" << endl; break;
    case 10: cout << "YYMM" << endl; break;
    case 11: cout << "AMBIGUOUS" << endl; break;

  }
  
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e;
  fin(5 + (n - 1) / min(a, min(b, min(c, min(d, e)))));
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


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

int main(){
  while(1){
    int N;
    cin>>N;
    if(N==0) break;
    int p[1000][1000]={};
    int px[4]={-1,0,1,0};
    int py[4]={0,-1,0,1};

    p[500][500]=1;

    int n,d;
    int x=500,y=500;
    int f[1000][1000];
    for(int i=0;i<1000;i++)
      for(int j=0;j<1000;j++) f[i][j]=10000000;

    f[x][y]=0;

    for(int i=1;i<=N-1;i++){
      cin>>n>>d;
      for(int k=0;k<1000;k++){
	for(int j=0;j<1000;j++){
	  if(f[k][j]==n){
	    p[k+px[d]][j+py[d]]=1;
	    x=k+px[d],y=j+py[d];
	    f[x][y]=i;
	  }
	}
      }
    }
    int count=0;
    int qx,qy;
    int max=0,miy=1000000;
    int mix=100000,may=0;

    for(int i=0;i<1000;i++){
      for(int j=0;j<1000;j++){
	if(p[i][j]==1){
	  qx=i;
	  qy=j;
	  if(max<qx) max=qx;
	  if(mix>qx) mix=qx; 
	  if(may<qy) may=qy;
	  if(miy>qy) miy=qy;
	}
      }
    }

  cout<<max-mix+1<<" "<<may-miy+1<<endl;
}
return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);

  int a, b, k;
  cin >> a >> b >> k;
  vector <int> Div;
  int x = min(a,b), y = max(a,b);
  for (int i = 1; i <= x ; i++)
    if ( !(x % i) && !(y % i))
      Div.push_back(i);  
  
  cout << Div[Div.size() - k] << endl;
}

Measured memory_bytes: 384
def main():

    burgur = [0] * 51
    burgur[0] = 1
    pate = [0] * 51
    pate[0] = 1
    for i in range(50):
        burgur[i+1] = burgur[i] * 2 + 3
        pate[i+1] = pate[i] * 2 + 1
    
    N, X = map(int, input().split())

    X -= 1
    ans = 0
    for i in reversed(range(1, N+1)):
        if X == burgur[i] - 1:
            ans += pate[i]
            break
        elif X >= burgur[i-1] + 1:
            ans += pate[i-1] + 1
            X -= (burgur[i-1] + 2)
        else: 
            X -= 1
    if X == 0:
        ans += 1
    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	double f=0.0;
	int  a = 0, b = 0,d = 0, r = 0;
	scanf("%d", &a);
	scanf("%d", &b);
	d = a / b;
	r = a%b;
	f = double(a) / double(b);
	printf("%d %d %.5f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 2664
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ.Volume1
{
    public class TwinPrime
    {
        public static int Main()
        {
            // 素数リストを作る
            var prime = new List<int>() { 2 };
            for (int i = 3; i <= 10000; i = i + 2)
            {
                bool is_prime = true;
                foreach (var p in prime)
                {
                    if (i % p == 0)
                    {
                        is_prime = false;
                        break;
                    }

                    if (p >= Math.Sqrt(i)) { break; }
                }
                if (is_prime) { prime.Add(i); }
            }
            // 双子素数リストを作る
            var twin = new List<int>();
            for (int i = 1; i < prime.Count; i++) { if (prime[i] - prime[i - 1] == 2) { twin.Add(prime[i]); } }

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                int p = twin.Where(x => x <= n).OrderByDescending(y => y).First();
                Console.WriteLine(string.Format("{0} {1}", p - 2, p));
            }

            return 0;
        }
    }
}

Measured memory_bytes: 10724
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <set>
#include <cmath>
#include <algorithm>
#include <locale>

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int (i)=0;(i)<(n);(i)++)
//#define ForJ(n) for(int j=0;j<n;j++)
//#define ForK(n) for(int k=0;k<n;k++)
#define Pr(n) cout<<n<<endl;
#define INS(v,n) for(int i=0;i<n;i++){cin >>v.at(i);}//vector 代入
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;

int Product_set_min(int la,int ra,int lb,int rb){//A<B
    int r=0;;
    if (la<ra&&ra<lb&&lb<rb) {
        r= 0;
    }else if(la<=lb&&lb<=ra&&ra<=rb){
        r= lb;
    }else if(lb<=la&&la<=ra&&ra<=rb){
        r= la;
    }else if(lb<=la&&la<=rb&&rb<=ra){
        r= la;
    }else if(lb<rb&&rb<la&&la<ra){
        r= 0;
    }
    return r;
}
int Product_set_max(int la,int ra,int lb,int rb){//A<B
    int r=0;;
    if (la<ra&&ra<lb&&lb<rb) {
        r= 0;
    }else if(la<=lb&&lb<=ra&&ra<=rb){
        r= ra;
    }else if(lb<=la&&la<=ra&&ra<=rb){
        r= ra;
    }else if(lb<=la&&la<=rb&&rb<=ra){
        r= rb;
    }else if(lb<rb&&rb<la&&la<ra){
        r= 0;
    }
    return r;
}
string min (string m){
    transform(m.begin(), m.end(), m.begin(),towlower);
    return m;
}
signed  main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1]=s[k-1]+0x20;
    Pr(s)
    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();
    int b=sc.nextInt();
    int c=a+b;
    if(c>=24)System.out.println(c-24);
    else System.out.println(c);
    
  }
}

Measured memory_bytes: 21844
M = 1000000007

import math

N = int(input())

ab_zero_count = 0
a_zero_count = 0
b_zero_count = 0

fish_list = []
for _ in range(N):
	a, b = map(int, input().split())
	if a == 0 and b == 0:
		ab_zero_count += 1
	elif a == 0:
		a_zero_count += 1
	elif b == 0:
		b_zero_count += 1
	else:
		if a < 0:
			a = -a
			b = -b
		g = math.gcd(a, b)
		if g > 1:
			a //= g
			b //= g
		fish_list.append((a, b))

#print(fish_list)

fish_table = {}
for f in fish_list:
	if f in fish_table:
		fish_table[f] += 1
	else:
		fish_table[f] = 1

fish_count_list = list(fish_table.items())
fish_index_table = {}
for i, (f, c) in enumerate(fish_count_list):
	fish_index_table[f] = i

#print(fish_count_list)

singles = 0
pair_list = []
checked = [False] * N

for i, (f, c) in enumerate(fish_count_list):
	a, b = f
	a, b = (-b, a)
	if a < 0:
		a = -a
		b = -b
	key = (a, b)
	if key in fish_index_table:
		j = fish_index_table[key]
		if checked[j] == False:
			f2, c2 = fish_count_list[j]
			pair_list.append((c, c2))
			checked[i] = True
	else:
		singles += c

if a_zero_count > 0 and b_zero_count > 0:
	pair_list.append((a_zero_count, b_zero_count))
else:
	singles += a_zero_count + b_zero_count

count = pow(2, singles, M)

#print(singles, pair_list, a_zero_count, b_zero_count)

for c1, c2 in pair_list:
	count = (count * (pow(2, c1, M) + pow(2, c2, M) - 1)) % M

count += ab_zero_count
count -= 1

print(count % M)


Measured memory_bytes: 151664
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)
	n := 0
	for i := 1; i <= k; i++ {
		n = (n*10 + 7) % k
		if n == 0 {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}


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

using ll=long long;
using ld=long double;

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll stool=0;
	for(int i=0;i<n-1;i++){
		if(a[i]>a[i+1]){
			stool+=(a[i]-a[i+1]);
			a[i+1] += (a[i]-a[i+1]);
		}
	}
	cout<<stool<<'\n';
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    int n;
    cin>>n;
    n=(n+n*n+n*n*n);
    cout<<n<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);
//操作を逆順見ることでマス目の色を自由に選べる
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> cum(n+1,0), pcum(n+1,0);
  for (int i = 0; i < n; i++) {
    cum[i + 1] = cum[i] + a[i];
    pcum[i + 1] = pcum[i] + max(0, a[i]);
  }

  ll res = -INF;

  for (int l = 0; l + k <= n; l++) {
    int r = l + k;
    ll tmp = max(0LL, cum[r] - cum[l]);
    tmp += pcum[l] + pcum[n] - pcum[r];
    res = max(res, tmp);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define hell                         1000000007 
#define M                            1000000007
#define Maxi                      10000000000000000
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
 
#define vll                          vector<ll>
#define vi                           vector<long long>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
//#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first  
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'
 
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;


int main()
{
    ll n,i,a;
    cin>>n;
    map<ll,ll>mp;
    for(i=1;i<=n;i++)
        mp[i]=0;
    for(i=2;i<=n;i++)
    {
        cin>>a;
        mp[a]++;
    }

    for(auto i:mp)
    {
        cout<<i.second<<endl;
    }
    return 0;
}

Measured memory_bytes: 16128
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B;

int main() {
	scanf("%lld %lld", &A, &B);
	ll ans = 0;
	for(int i = 0; i < 2; i++) {
		if(A >= B) {
			ans += A;
			A--;
		}
		else {
			ans += B;
			B--;
		}
	}
	printf("%lld\n", ans);

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

ll BIT[100001];
ll mod = 1e9 + 7;

void add(int A, int B) {
	while (A > 0) {
		BIT[A] += B;
		BIT[A] % mod;
		A -= A & -A;
	}
}

ll query(int A) {
	ll kotae = 0;
	while (A <= 100000) {
		kotae += BIT[A];
		A += A & -A;
	}
	return kotae % mod;
}

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


	int N, K;
	cin >> N >> K;

	int M[100000] = {};

	int rt = sqrt(N) + 0.00001;

	vector<int> V;
	rep1(i, rt) {
		V.pb(i);
		if (i != N / i) V.pb(N / i);
	}
	sort(V.begin(), V.end());
	vector<int> VN;
	int mae = 0;
	rep(i, V.size()) {
		VN.pb(V[i] - mae);
		mae = V[i];
	}
	int X = V.size();

	mae = 0;
	ll dp[100000] = {};
	rep(i, X) dp[i] = VN[i];
	
	rep(i, K - 1) {
		rep(j, 100000) BIT[j] = 0;
		rep(j, X) {
			add(X - j, dp[j]);
		}
		rep(j, 100000) dp[j] = 0;
		rep(j, X) {
			ll t = query(j + 1);
			dp[j] = t * VN[j] % mod;
		}
	}

	ll kotae = 0;
	rep(i, X) {
		kotae += dp[i];
		kotae %= mod;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 2428
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main(void)
{
	int N;
	

	scanf("%d", &N);
	cin.get();
	while(--N, N>=0){
		char instr[1001];
		char *t;

		gets(instr);
		while( (t = strstr(instr, "Hoshino")) != NULL){
			t += 6;
			*t = 'a';
		}

		printf("%s\n", instr);
	}


	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;
int n, a[131250];
struct node {
    int id, point;
} node[1<<18];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;

int main(){
  long long n, a, b;

  cin >> n >> a >> b;

  long long ans = n / (a+b) * a;
  long long rem = n % (a+b);
  ans += min(rem, a);

  cout << ans;
}

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

struct Graph {
    struct Vertex { int n; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    int dfs(int i, int p, int d) {
        int k = 1;
        if (d == 0) return k;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;
            k += dfs(o.i, i, d - 1);
        }
        return k;
    }
    int solve(int d) {
        int r = 0;
        if (d % 2 == 0) {
            for (int i = 0; i < n; i++) {
                r = max(r, dfs(i, -1, d / 2));
            }
        } else {
            for (int i = 0; i < n; i++) {
                for (int j = v[i].n; j >= 0; j = e[j].n) {
                    Edge& o = e[j];
                    if (o.i < i) continue;
                    r = max(r, dfs(i, o.i, d / 2) + dfs(o.i, i, d / 2));
                }
            }
        }
        return n - r;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, k;
    cin >> n >> k;

    Graph g(n, (n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    cout << g.solve(k) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll frac[200010];

ll modpow(ll n, ll a){
    ll res=1;
    while(a){
        if(a&1) res*=n;
        res%=MOD;
        n=n*n%MOD;
        a>>=1;
    }
    return res;
}

ll comb(ll n, ll m){
    ll res=frac[n];
    res*=modpow(frac[n-m],MOD-2);
    res%=MOD;
    res*=modpow(frac[m],MOD-2);
    res%=MOD;
    return res;
}

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;

    frac[0]=1;
    for(int i=1;i<=n;i++){
        frac[i]=frac[i-1]*i;
        frac[i]%=MOD;
    }

    for(int m=0;m<min(n,k+1);m++){
        ll buf=comb(n,m);
        buf%=MOD;
        buf*=comb(n-1,m);
        buf%=MOD;
        ans+=buf;
        ans%=MOD;
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
    using namespace std;
    int abs(int x,int y){
    	if(x>y) return (x-y);
    	else return (y-x);
    }
    int main(){
    	int a1,a2,a3,i,j;
    	cin>>a1>>a2>>a3;
    	int t=0,a[4]={0};
    	a[0]=abs(a1,a2),a[1]=abs(a2,a3),a[2]=abs(a3,a1);
    	sort(a,a+3);
    	cout<<a[0]+a[1];
    	return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100005];
    scanf("%s", s);
    int k;
    scanf("%d", &k);
    int i;
    int n = strlen(s);
    for (i = 0; i < n; i++)
    {
        if (s[i] != 'a')
        {
            if ('z' + 1 - s[i] <= k)
            {
                k -= 'z' + 1 - s[i];
                s[i] = 'a';
            }
        }
    }
    s[n - 1] += k % 26;
    if (s[n - 1] > 'z')
        s[n - 1] -= 26;
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;

#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define sz size()


 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 

signed main(){
  ll n;
    cin>>n;
  vector<ll> A(0);
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      A.push_back(i);
      if(i*i!=n){
        A.push_back(n/i);
      }
    }
  }
  SORT(A);
  ll a=A.sz;
  ll ans=INF;
  for(ll i=0;i<a;++i){
    chmin(ans,A[i]+n/A[i]);
  }
  cout<<ans-2<<endl;
}

Measured memory_bytes: 384
def solve(N, h):
    dp = [float('inf') for i in range(N+1)]
    dp[1] = 0
    for i in range(1, N+1):
        if i+1 <= N:
            dp [i+1] = min(dp[i+1],dp[i] + abs(h[i+1]-h[i]))
        if i+2 <= N:
            dp [i+2] = min(dp[i+2],dp[i] + abs(h[i+2]-h[i]))
    return dp[N]
N = int(input())
h = [0] + list(map(int, input().split()))
print(solve(N, h))

Measured memory_bytes: 20460
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;
const int INF = (1<<29);

vector<int> color;  // color[i] : 0は白、1は黒、-1は未訪問
vector<vector<int>> d(210, vector<int>(210));

bool dfs(const Graph &G, int v, int now = 0) {

    color[v] = now;

    for (auto u : G[v]) { 

        if(color[u] != -1) {

            if(color[u] == now) {
                return false;
            }
            else {
                continue;
            }
        }

        if(!dfs(G, u, 1-now)) {
            return false;
        }
    }

    return true;
}

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

    rep(i, n) {
        rep(j, n) {
            if(i != j) {
                d[i][j] = INF;
            }
        }
    }

    Graph G(n);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if(s[j] == '1') {
                G[i].push_back(j);
                G[j].push_back(i);
                d[i][j] = d[j][i] = 1;
            }
        }
    }

    color.assign(n, -1);
    bool nibugraph = true;
    rep(i, n) {

        if(color[i] != -1) {
            continue;
        }
        
        if(!dfs(G, i)) {
            nibugraph = false;
        }
    }

    if(nibugraph) {

        rep(k, n) {
            rep(i, n) {
                rep(j, n) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

        int ans = 0;
        rep(i, n) {
            rep(j, n) {
                if(d[i][j] != INF) {
                    ans = max(ans, d[i][j]);
                }
            }
        }

        cout << ans+1;
    }
    else {
        cout << -1;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#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 main() {
  int n, k;
  cin >> n >> k;
  vector<int> have(n);
  vector<int> d(k);
  rep(i,k) {
    int a;
    cin >> a;
    rep(j,a) {
      int b;
      cin >> b;
      have.at(b-1) = 1;
    }
  }
  int count = 0;
  rep(i,n) {
    if (have.at(i) == 1) continue;
    count++;
  }
  cout << count;
}


Measured memory_bytes: 3632
from collections import deque
def solve():
    H,W = map(int,input().split())
    Ch,Cw = map(lambda x:int(x)-1,input().split())
    Dh,Dw = map(lambda x:int(x)-1,input().split())
    A = [list(input()) for _ in range(H)]
    V = [[-1]*W for _ in range(H)]
    d = ((1,0),(0,1),(-1,0),(0,-1))

    def bfs_2d(sy,sx,v):
        que = deque()
        V[sy][sx] = v
        que.append((sy,sx))

        while que:
            uh, uw = que.popleft()
            for dy, dx in d:
                next_h = uh+dy
                next_w = uw+dx
                if 0 <= next_h < H and 0 <= next_w < W \
                    and A[next_h][next_w] == '.' \
                    and V[next_h][next_w] == -1:
                    V[next_h][next_w] = v
                    que.append((next_h,next_w))
    
    vertex = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#' or V[h][w] != -1:
                continue
            bfs_2d(h,w,vertex)
            vertex += 1

    G = [[] for _ in range(vertex)]
    used = [set() for _ in range(vertex)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                continue
            for dh in range(-2, 2+1):
                for dw in range(-2, 2+1):
                    if h + dh < 0 or H <= h + dh or w + dw < 0 or W <= w + dw:
                        continue
                    if A[h+dh][w+dw] == "#":
                        continue
                    if V[h][w] == V[h+dh][w+dw]:
                        continue
                    if V[h+dh][w+dw] in used[V[h][w]]:
                        continue
                    G[V[h][w]].append((V[h+dh][w+dw]))
                    used[V[h][w]].add((V[h+dh][w+dw]))
    
    # s = V[Ch][Cw]
    # g = V[Dh][Dw]

    # dist = [-1 for _ in range(vertex)]
    # que = deque()
    # dist[s] = 0
    # que.append(s)
    # while que:
    #     u = que.popleft()
    #     for v in G[u]:
    #         if dist[v] != -1:
    #             continue
    #         dist[v] = dist[u] + 1
    #         que.append(v)
    
    # print(dist[g])

    start_area_num = int(V[Ch][Cw])
    goal_area_num = int(V[Dh][Dw])

    dist = [-1] * vertex
    visited = [False] * vertex
    dist[start_area_num] = 0
    visited[start_area_num] = True

    q = deque()
    q.append((start_area_num,0))
    while len(q) > 0:
        cur_area_num, warp_cnt = q.popleft()
        if cur_area_num == goal_area_num:
            print(dist[cur_area_num])
            return
        
        for next_area_num in G[cur_area_num]:
            if not visited[next_area_num]:
                dist[next_area_num] = dist[cur_area_num] + 1
                visited[next_area_num] = True
                q.append((next_area_num, warp_cnt+1))
    else:
        print(-1)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 190968
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int cnt[100000] = { 0 };
#define MOD (1000000007)

int main()
{
	int N, A;
	bool ok = true;
	int ans = 1;

	cin >> N;
	rep(i, N) {
		cin >> A;
		cnt[A]++;
	}

	if (N % 2 == 0) {
		rep(i, N) {
			if (i % 2 == 0 && cnt[i] > 0) {
				ok = false;
				break;
			}
			else if (i % 2 == 1 && cnt[i] != 2) {
				ok = false;
				break;
			}
		}
	}
	else {
		rep(i, N) {
			if (i == 0 && cnt[i] != 1) {
				ok = false;
				break;
			}
			else continue;

			if (i % 2 == 1 && cnt[i] > 0) {
				ok = false;
				break;
			}
			else if (i % 2 == 0 && cnt[i] != 2) {
				ok = false;
				break;
			}
		}
	}

	if (ok) {
		rep(i, N / 2) ans = (ans * 2) % MOD;
	}
	else ans = 0;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    long h,n;
    cin >> h >> n;
    vector<pll> data(n);
    rep(i,n) cin >> data.at(i).first >> data.at(i).second;
    vector<vl> dp(n+1,vl(30000,1e12));
    dp.at(0).at(0) = 0;
    for(int i=0;i<n;i++){
        long a = data.at(i).first;
        long b = data.at(i).second;
        rep(j,h+20000){
            if(j - a >= 0) dp.at(i+1).at(j) = min(dp.at(i+1).at(j-a)+b , dp.at(i).at(j));
            else dp.at(i+1).at(j) = dp.at(i).at(j); 
        }
    }
    long ans = 1e12;
    int id = h;
    rep(i,10002){
        ans = min(ans,dp.at(n).at(id));
        id++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 236800
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] s = sc.nextLine().replace(',', ' ').replace('.', ' ').split(" ");
		boolean flag = false;
		for(int i=0;i<s.length;i++){
			if(3<=s[i].length() && s[i].length()<=6){
				if(flag==true) System.out.print(" ");
				System.out.print(s[i]);
				flag = true;
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 17140
#include <bits/stdc++.h>
using namespace std;
int main(){
  long r ,D,x;
  cin>>r>>D>>x;
  long ans;
  for(int i = 0;i<10;i++){
    ans = r*x-D;
    cout << ans << endl;
    x = ans;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [[0]*K for _ in range(2)]  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0][0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K):
            if j >= b:
                dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
            else:
                dp[i%2][j] = dp[1-i%2][j]
    if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)


Measured memory_bytes: 75040