akhauriyash/Code-Regression huggingface dataset:
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var m = int.Parse(line[0]);
        var d = int.Parse(line[1]);
        var count = 0;
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= d; j++)
                if (check(i, j)) count++;
        Console.WriteLine(count);
    }
    static bool check(int m, int d )
    {
        if (d < 10) return false;
        var d1 = d % 10;
        var d10 = d / 10;
        if (d1 < 2) return false;
        if (d10 < 2) return false;
        return d1 * d10 == m;
    }
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]

nx, ny = 0, 0
time = 0

ans = "Yes"
for i in range(N):
    t, x, y = TXY[i]
    dt = t - time
    move = abs(nx - x) + abs(ny - y)
    if move > dt:
        ans = "No"
        break
    if dt % 2 != move % 2:
        ans = "No"
        break
    time, nx, ny = t, x, y

print(ans)


Measured memory_bytes: 27340
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()


n = int(ri())
a = Ri()
ans = 0
a.sort()
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if a[i] != a[j] and a[j] != a[k] and a[i] + a[j] > a[k]:
                ans+=1
print(ans)

Measured memory_bytes: 68312
import sys
input = sys.stdin.readline
ABCD = list(map(int, list(input())[: -1]))
t = [[] for _ in range(4)]
t[0].append((ABCD[0], ""))
for i in range(3):
  for j in range(len(t[i])):
    t[i + 1].append((t[i][j][0] + ABCD[i + 1], t[i][j][1] + "+"))
    t[i + 1].append((t[i][j][0] - ABCD[i + 1], t[i][j][1] + "-"))
#print(t)
for i in range(len(t[-1])):
  if t[-1][i][0] == 7:
    print(str(ABCD[0]) + t[-1][i][1][0] + str(ABCD[1]) + t[-1][i][1][1] + str(ABCD[2]) + t[-1][i][1][2] + str(ABCD[3]) + "=7")
    exit(0)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    vector<int>a(n);
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int p;
    double b=sum*1.0/n;
    double c=floor(b);
    double d=ceil(b);
    c=b-c;
    d=d-b;
    if(c<=d)
        p=floor(b);
    else
        p=ceil(b);
    int sum2=0;
    for(int i=0; i<n; i++)
    {
        sum2+=(a[i]-p)*(a[i]-p);
    }
    cout<<sum2<<endl;
}


Measured memory_bytes: 3604
#include <stdio.h>
  
int  main(void){
         int h,w,i,j;
          while(1){
          scanf("%d %d",&h,&w);
           if( h==0 && w==0)
              break;
           for(i=1; i<=h; i++){
            for(j=1; j<=w; j++){
              if((i+j)%2 == 0)
              printf("#");
             else
              printf(".");
             }printf("\n");
            }printf("\n");
           }
            return 0;
}


Measured memory_bytes: 2036
from itertools import product
h, w, k = map(int, input().split())
c = [input() for _ in range(h)]
ans = 0
for bh in product((True, False), repeat=h):
    for bw in product((True, False), repeat=w):
        cnt = 0
        for i in range(h):
            if not bh[i]:
                continue
            for j in range(w):
                if not bw[j]:
                    continue
                cnt += c[i][j] == '#'
        ans += cnt == k
print(ans)


Measured memory_bytes: 68372
#include <stdio.h>

void InsertionSort(int n, int nums[]) {
  int i, j, k;
  int v;

  for (k = 0; k < n; k++) {
    printf("%d", nums[k]);
    if (k == n-1)  {
      putchar ('\n');
      break;
    }
    putchar(' ');
  }
  
  for (i = 1; i < n; i++) {
    v = nums[i];
    j = i-1;
    while (0 <= j && v < nums[j]) {
      nums[j+1] = nums[j];
      j--;
    }
    nums[j+1] = v;
    for (k = 0; k < n; k++) {
      printf("%d", nums[k]);
      if (k == n-1)  {
	putchar ('\n');
	break;
      }
      putchar(' ');
    }
  }
  
}

int main() {
  int n;
  int nums[100];

  scanf("%d", &n);

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

  InsertionSort(n, nums);

  return 0;
}



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

#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

#define int long long
typedef pair <int, int> pii;

const int maxn = 2e5 + 5;
pii P[maxn];
int seg[4 * maxn];
vector <int> compress;

void add(int id, int L, int R, int l, int r, int x) {
	if (r <= L || R <= l)
		return;
	if (L >= l && R <= r) {
		seg[id] += x;
		return;
	}
	int mid = (L + R) / 2;
	add(2 * id + 0, L, mid, l, r, x);
	add(2 * id + 1, mid, R, l, r, x);
}

int get(int id, int L, int R, int idx) {
	if (idx < L || idx >= R)
		return 0;
	if (R == L + 1)
		return seg[id];
	int mid = (L + R) / 2;
	return get(2 * id + 0, L, mid, idx) + get(2 * id + 1, mid, R, idx) + seg[id];
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, d, a;
	cin >> n >> d >> a;
	for (int i = 0; i < n; i++) {
		cin >> P[i].first >> P[i].second;
		compress.push_back(P[i].first);
	}
	sort(P, P + n);
	sort(compress.begin(), compress.end());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		add(1, 0, n, i, i + 1, P[i].second);
		if (get(1, 0, n, i) > 0) {
			int x = upper_bound(compress.begin(), compress.end(), P[i].first + 2 * d) - compress.begin();
			ans += (get(1, 0, n, i) + a - 1) / a;
			add(1, 0, n, i, x, -a * ((get(1, 0, n, i) + a - 1) / a));
		}
	}
	cout << ans;
}



Measured memory_bytes: 10992
#include <bits/stdc++.h>
//#include<iostream>
//#include<vector>
//#include<map>
//#include<math.h>
//#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();
    if(n==1) {
        cout << 0 << endl;
    } else {
        int ans = 0;
        rep(i,n/2) {
            if(s[i] != s[n-1-i]) {
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
} /*atcoder*/



Measured memory_bytes: 3616
# define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

#define A_MAX 1000

void dispa(int a[],int n);
void insertisionSort(int a[], int n);

int main (void) {

	int n;
	int i;

	int a[A_MAX];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	dispa(a, n);

	insertisionSort(a, n);
	
	return 0;
}

void insertisionSort(int a[], int n) {
	
	int i;
	int j;
	int v;

	for (i = 1; i <= n - 1; i++) {
		v = a[i];
		j = i - 1;

		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}
		dispa(a, n);
	}
}

void dispa(int a[], int n) {

	int i;

	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		if (i + 1 != n) {
			printf(" ");
		}
		else {
			printf("\n");
		}
	}

}

Measured memory_bytes: 608
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    long[] A = new long[N];
    for(int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    long mod = (long)Math.pow(10,9)+7;
    
    long sum = 0; //累積和
    long ans = 0; //答え
    for(int i=0; i<N; i++) {
      ans = (ans+A[i]*sum)%mod;
      sum = (A[i]+sum)%mod;
    }
    
    System.out.println(ans);  
  }
}

Measured memory_bytes: 63116
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]

inputs=[]
n,m=map(int,input().split())
for i in range(m):
    a=[int(j) for j in input().split()]
    inputs.append((a[0],a[1]+10**5,1))
    inputs.append((a[0]+10**5,a[1]+2*10**5,1))
    inputs.append((a[0]+2*10**5,a[1],1))
S,T=map(int,input().split())

g = Graph()
for src, dst, weight in inputs:
    g.add_edge(src, dst, weight)

d = Dijkstra(g, S)   
ans=d.shortest_distance(T)

if ans>10**9+7:
    print(-1)
else:
    if ans%3==0:
        print(ans//3)
    else:
        print(-1)






Measured memory_bytes: 157160
#include <stdio.h>
int main(void){
int h,w,i,j;
while(1){
scanf("%d%d",&h,&w);
if(h==0&&w==0)break;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(i%2==j%2)printf("#");
else printf(".");
}printf("\n");}printf("\n");}
return 0;
}

Measured memory_bytes: 572
def input_one_number():
    return int(input())


D = input_one_number()

def input_multiple_number_as_list():
    return list(map(int, input().split()))

c = input_multiple_number_as_list()

s = [[]*26 for _ in range(D)]

for i in range(D):
	s[i] = input_multiple_number_as_list()

for day in range(D):
	m = max(s[day])
	print(s[day].index(m)+1)

Measured memory_bytes: 9332
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
	int x, y;
	scanf("%d%d", &x, &y);
	int X=x<0?-x:x;
	int Y=y<0?-y:y;
	int a;
	if(X>Y){
		a=(x>0)+(X-Y)+(y>0);
	}else if(X<Y){
		a=(x<0)+(Y-X)+(y<0);
	}else{
		a=(x!=y);
	}
	printf("%d\n", a);
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second>b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    int n,k;
    IN n>>k;
    map<int,int> count;
    loop(i,0,k)
    {
        int d;
        IN d;
        loop(j,0,d)
        {
            int temp;
            IN temp;
            count[temp]++;
        }
    }
    int ans=0;
    loop(i,1,n+1)
    {
        if(!count[i])
        {
            ans++;
        }
    }
    OUT ans<<endl
    return 0;
}

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

#define  lson l,mid,rt<<1
#define  rson mid+1,r,rt<<1|1
using namespace std;
typedef long long ll;

const int N=5e5+100;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int n;
ll p[500][500];
int vis[500][500];

void floyd()
{
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(p[i][j]>p[i][k]+p[k][j]) {
                    cout<<-1;
                    return ;
                }
                else if(p[i][j]==p[i][k]+p[k][j]&&i!=k&&j!=k)
                     vis[i][j]=1;
            }
        }
    }
    ll sum=0;
   // cout<<n<<endl;
    for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++) {
        if(!vis[i][j])
        sum+=p[i][j];
    }
    cout<<sum<<endl;
}
int main()
{
   cin>>n;

   for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        cin>>p[i][j];
    }
   }
   floyd();
   return 0;
}



Measured memory_bytes: 5412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

ll N, K;
vector<ll> A, F;

bool achievable(ll m) {
  ll n = 0;
  rep(i, N) n += max(0LL, A[i] - m / F[i]);
  return n <= K;
}

int main() {
  cin >> N >> K;
  A.resize(N), F.resize(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];

  sort(all(A));
  sort(all(F), greater<ll>());
  assert(A[0] <= A[N - 1]);
  assert(F[0] >= F[N - 1]);

  ll l = -1, r = 1e12;
  while (r - l > 1) {
    ll m = (l + r) / 2;

    if (achievable(m)) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin>>s;
    if(s.size()==1){
        cout<<s[0]-'0'<<endl;
        return 0;
    }
    ll ans=0;
    reverse(all(s));
    rep(i,s.size()){
        ll now=s.size()-2;
        for(ll j=0;j<=i;j++){
            ans+=(s[i]-'0')*pow(10,j)*(1<<now);
            if(j==i&&i!=s.size()-1) ans+=(s[i]-'0')*pow(10,j)*(1<<now);
            now=max((ll)0,now-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100005];
struct sd{int num,w;bool operator < (const sd &fu) const {return w<fu.w;};}b[100005];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i) b[i]=(sd){i,a[i]};
	sort(b+1,b+1+n);int sum=0;
	for(int i=1;i<=n;++i) if(abs(b[i].num-i)&1) ++sum;
	printf("%d",sum/2);
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char S[100001];

int main() {
  int N, K, result;
  int i;
  scanf ("%d %d", &N, &K);
  scanf ("%s", S);
  result = 0;
  for (i=1;i<N;i++) {
    if (S[i]==S[i-1]) {
    	result++;
    }
  }
  
  result += K*2;
  if (result >= N) result = N-1;
  
  printf("%d", result);
  return 0;
}




Measured memory_bytes: 256
n, k = map(int,input().split())
x = list(map(int,input().split()))

ans = float('inf')
for i in range(n-k+1):
    ans = min(ans, min(abs(x[i]) + abs(x[i+k-1]-x[i]), abs(x[i+k-1]) + abs(x[i+k-1]-x[i])))
print(ans)

Measured memory_bytes: 20140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000;
//2次元配列 vector<vector<int>> vec(a,vector<int>(b))
int main() {
	ll N;
	cin >> N;
	vector<ll> A(N); vector<ll> a(N);
	ll first = 0;
	ll second = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		a[i] = A[i];
	}
	sort(a.begin(),a.end());
	first = a[N - 1];
	second = a[N - 2];
	for (int i = 0; i < N; i++) {
		if (A[i] == first) cout << second << endl;
		else cout << first << endl;
	}
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
    int n;
    cin >> n;
    vector<char> s(n);
    set<char> ss;
    rep(i,n){
        cin >> s.at(i);
        ss.insert(s.at(i));
    }
    if(ss.size()==3)cout << "Three"<< endl;
    else if(ss.size()==4)cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

int n,m;
double a[22],b[22],c[22];
double ans;

double calc(bool *used){
  double res = 0;
  rep(i,n){
    if(!used[i]) continue;
    REP(j,i+1,n){
      if(!used[j]) continue;
      res += pow(a[i]-a[j],2) + pow(b[i]-b[j],2) + pow(c[i]-c[j],2);
    }
  }
  return res;
}

void solve(bool *used,int idx,int cnt){
  if(idx == n){
    if(cnt == m) ans = max(ans,calc(used));
    return;
  }
  if(cnt > m) return;

  solve(used,idx+1,cnt);

  used[idx] = true;
  solve(used,idx+1,cnt+1);
  used[idx] = false;
}

int main(void){
  while(cin>>n>>m){
    rep(i,n){
      cin>>a[i]>>b[i]>>c[i];
    }

    bool used[22];
    memset(used,0,sizeof(used));
    ans = 0;
    solve(used,0,0);
    printf("%.8f\n",ans);
  }
}

Measured memory_bytes: 0
class Problem
  N = 10**5
  M = 30
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n,@m = gets.to_s.split.map{ |v| v.to_i }
    @s,@t,@c = Array.new(n){ gets.to_s.split.map{ |v| v.to_i } }.transpose
    @c.map!{|v|v-1}
  end

  def solve
    dp = Array.new(M){ Array.new(N+1,0) }
    n.times do |i|
      dp[c[i]][s[i]] += 1
      dp[c[i]][t[i]] -= 1
    end

    a = Array.new(N+1,0)
    M.times do |i|
      N.times do |j|
        if 0 < dp[i][j+1]
          a[j] += dp[i][j+1]
        end

        if dp[i][j] < 0
          a[j] += dp[i][j]
        end
      end
    end

    cs = a.each_with_object([0]) { |v, h| h << h[-1] + v }
    cs.max
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 48568
N = int(input())
s = input()
ls = ['SS', 'SW', 'WS', 'WW']
for l in ls:
  ans = []
  m = [0]*N
  m[0] = l[0]
  m[1] = l[1]
  for i in range(1,N):
    
    if m[i]=='S':
      flag = True
    else:
      flag = False
      
    if i==N-1:
      if flag:
        if s[i]=='o':
          if m[0]==m[N-2]:
            ans = m
            break
        else:
          if m[0]!=m[N-2]:
            ans = m
            break
      else:
        if s[i]=='o':
          if m[0]!=m[N-2]:
            ans = m
            break
        else:
          if m[0]==m[N-2]:
            ans = m
            break
      break
          
    if flag:
      if s[i]=='o':
        m[i+1] = m[i-1]
      else:
        if m[i-1]=='S':
          m[i+1] = 'W'
        else:
          m[i+1] = 'S'
    else:
      if s[i]=='o':
        if m[i-1]=='S':
          m[i+1] = 'W'
        else:
          m[i+1] = 'S'
      else:
        m[i+1] = m[i-1]
        
  if ans:
    if ans[0]=='S':
      if s[0]=='o':
        if ans[1]==ans[N-1]:
          break
        else:
          ans = []
          continue
      else:
        if ans[1]!=ans[N-1]:
          break
        else:
          ans = []
          continue
    else:
      if s[0]=='o':
        if ans[1]!=ans[N-1]:
          break
        else:
          ans = []
          continue
      else:
        if ans[1]==ans[N-1]:
          break
        else:
          ans = []
          continue
if ans:
  print(''.join(ans))
else:
  print(-1)

Measured memory_bytes: 4980
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	int N,A;
	cin >> N;
	int i;
	for(i=0;i<N;i++){
		cin >> A;
		if(A%2==0){
			if(A%3!=0&&A%5!=0){
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, m, mem[N];
bool vis[N];
vector<int> adjList[N];

int dp(int v) {
	if (vis[v]) {
		return mem[v];
	}
	vis[v] = true;

	int ans = 0;
	for(int u : adjList[v]) {
		ans = max(ans, dp(u) + 1);
	}

	return mem[v] = ans;
}

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

	cin >> n >> m;

	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		adjList[a].emplace_back(b);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dp(i));
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 8320
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_M=10e5;
int X[MAX_M];
int main(void){
	int N,M;
		cin >> N >> M;
	for(int i=0;i<M;i++)
		cin >> X[i];
	sort(X,X+M);
	for(int i=1;i<M;i++)
		X[i-1]=X[i]-X[i-1];
	sort(X,X+M-1);
	
	int res=0;
	for(int i=0;i<M-N;i++)
		res+=X[i];
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int T = scanner.nextInt();

    long total = (long) N * T;
    long prev = -1;
    for (int i = 0; i < N; i++) {
      int t = scanner.nextInt();
      if (prev >= 0 && (t - prev) < T) {
        total -= T - (t - prev);
      }
      prev = t;
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 62456
#include <bits/stdc++.h>
using namespace std;
 int main () {
   long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0 ;i < n;i++) {
      cin >> a[i];
  } 
    long long int b[n];
    for (int i = 0 ;i < n;i ++) {
        if (i==0) {
            b[i] = a [0];
        }else {
            b[i] = b[i-1] + a[i] ;
        }
    }


  sort (b , b + n);


    long long int temp =0;
    long long int ans = 0;
    for (int i = 0 ;i< n;i++) {
        if (i != 0 && b[i-1] == b[i] ) {
            temp ++ ;
        }else {
            ans += temp * (temp +1) /2;
            temp = 0;
        }
        //cout << "i = " << i <<" ,a[i] =" <<a[i]<< " , b[i] = "<< b[i] << " ,temp = "<< temp << " ,ans = "<< ans << endl;
    }
    ans += temp * (temp +1) /2;
    temp = 0;
    //cout <<"ans = " <<ans <<endl;
    for (int i=0; i < n;i++){
        if (b [i] ==0 ) {
            ans ++ ; 
        }

    }
    cout << ans<< endl;


 }


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

int main() {
  long long  A, B, C, X, Y;

  cin >> A >> B >> C >> X >> Y;

  int max_loop = max(X, Y);
  long long ans = 100000000000;
  long long money;
  
  for (long long i = 0; i <= max_loop; i++) {
    if ((X-i) >= 0 and (Y-i) >= 0) {
      money = A * (X-i) + B * (Y-i) + C * 2 * i;
    } else {
      if (X < i) {
	money = B * (Y-i) + C * 2 * i;
      } else {
	money = A * (X-i) + C * 2 * i;
      }
    }
    ans = min(money, ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
const double EPS = 1e-8;
const int INF = 1e9;

int main(){
    double vv;
    while(cin >>vv){
        double v = 0, t = 0, y;
        for(y = 0; v < vv; y += 5){
            t = sqrt(y / 4.9);
            v = 9.8 * t;
        }
        cout <<y / 5<<endl;
    }
    return 0;
}

Measured memory_bytes: 1272
#include <stdio.h>

void count_char(int *n, char c)
{
    if (c >= 'A' && c <= 'Z')
    {
        n[c - 'A']++;
    }
    if (c >= 'a' && c <= 'z')
    {
        n[c - 'a']++;
    }
}

int main(void)
{
    char ch;
    int count[26] = {0};

    while (scanf("%c", &ch) != EOF)
    {
        count_char(count, ch);
    }

    int i = 0;
    char alphabet;
    for (alphabet = 'a'; alphabet <= 'z'; alphabet++)
    {
        printf("%c : %d\n", alphabet, count[i]);
        i++;
    }

    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 200000; 
int main() {
    int n;
    cin >> n;
    int R[MAX];
    for(int i=0;i<n;i++){
        cin >> R[i];
    }
    int MAX1 = R[1]-R[0];
    int MINr =R[0];
    for(int k=1;k<n;k++){
        MAX1 = max(R[k]-MINr,MAX1);
        MINr = min(MINr,R[k]);
        
    }
    cout << MAX1 << endl;
}



Measured memory_bytes: 3860
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n), c(n-1);
    ll ans = 0;
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i, n) {
        ll b;
        cin >> b;
        ans += b;
    }
    rep(i, n-1) {
        cin >> c[i];
    }

    rep(i, n-1) {
        if(a[i] + 1 == a[i+1]) {
            ans += c[a[i]];
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
import sys
N = int(input())
print(0)
s = input()
x = s
if s=='Vacant':
  sys.exit()
l = 0
r = N
while True:
  p = (l+r)//2
  print(p)
  s = input()
  if s=='Vacant':
    sys.exit()
  if p%2==0:
    if s==x:
      l = p
    else:
      r = p
  else:
    if s==x:
      r = p
    else:
      l = p
  

Measured memory_bytes: 3660
import java.io.*;
import java.util.*;

class Main{
	public static void main(String []args)throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
      String str = br.readLine();
      String s[] = str.split(" ");
      
      int N = Integer.parseInt(s[0]);
      long K = Long.parseLong(s[1]);
      
      str = br.readLine();
      String arr[] = str.split(" ");
      int town[] = new int[N + 1];
      
      for(int i = 0; i < arr.length; i++){
      	town[i + 1] = Integer.parseInt(arr[i]);
      }
      
      boolean visited[] = new boolean[N + 1];
      
      Arrays.fill(visited, false);
      visited[1] = true;
      int cycleStart, nextTown = town[1], edgesTillCycle = 0;
      //for(int i = 1; i <= N; i++){
      while(true){
     	edgesTillCycle++;
        if(visited[nextTown]){
          cycleStart = nextTown;
          break;
        }
      	visited[nextTown] = true;
        nextTown = town[nextTown];
      }
      
      int lengthCycle = 0;
      nextTown = town[nextTown];
      while(true){
        lengthCycle++;
        if(nextTown == cycleStart)
          break;
        nextTown = town[nextTown];
      }
      
      int beforeCycle = edgesTillCycle - lengthCycle;
      
      if(K > beforeCycle){
        K = K - beforeCycle;
        K = K % lengthCycle;
        nextTown = cycleStart;
      }
      else{
        nextTown = 1;
      }
      
       while(K != 0){
          K--;
          nextTown = town[nextTown];
        }
        System.out.println(nextTown);        
    }
}

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

signed main() {
    string s; cin >> s;
    int n = s.size();
    string r = s;
    rep(i, n) r[i] = r[i] == '0' ? '1' : '0';
    int a = n, b = n;
    rep(i, n) {
        if (s[i] == '1') {
            int tmp = max(i, (signed)(n - i - 1));
            a = min(a, tmp);
        }
        if (r[i] == '1') {
            int tmp = max(i, (signed)(n - i - 1));
            b = min(b, tmp);
        }
    }
    cout << max(a, b) << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int i,n;
    int a[10001];
    int max = -1000001, min = 1000001;
    double sum = 0;

    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for(i=0; i<n; i++){
        if(a[i]>=max) max = a[i];
        if(a[i]<=min) min = a[i];
        sum += a[i];
    }
    printf("%d %d %.0lf\n", min, max, sum);
}


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

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

    static class Fouradjacent {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int is_two = 0;
            int is_four = 0;
            int is_one = 0;
            for (int i = 0; i < n; i++) {
                long a = in.nextLong();
                if (a % 4 == 0) {
                    is_four++;
                } else if (a % 2 == 0) {
                    is_two++;
                } else {
                    is_one++;
                }
            }

            if (is_two > 0) {
                is_one++;
            }
            if (is_one > (is_four + 1)) {
                out.print("No");
            } else {
                out.print("Yes");
            }
        }

    }
}



Measured memory_bytes: 58196
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, K;
    cin >> N >> K;

    vector<int> dp(N, 2e9);
    vector<int> heights(N);
    REP(n, N) {
        int h;
        cin >> h;
        heights[n] = h;
        if (n == 0) {
            dp[n] = 0;
        }
        else {
            FOR(k, 1, K + 1) {
                if (n - k >= 0) {
                    dp[n] = min(dp[n], dp[n - k] + abs(heights[n - k] - heights[n]));
                }
            }
        }
    }
    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


long long r, d;
long long x[11];

int main()
{
	scanf("%lld%lld%lld", &r, &d, &(x[0]));
	for (int i = 1 ; i <= 10 ; i++)
		x[i] = r * (x[i - 1]) - d;
		
	for (int i = 1 ; i <= 10 ; i++)
		printf("%d\n", x[i]);
	
	return 0;
}


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

int main(){

	string s;
	int n;
	cin >> n;
	cin >> s;
	if(n%2 == 0){
		if(s.substr(0, n/2).compare(s.substr(n/2, n)) == 0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    ll r;
    cin >> r;
  	if(r<1200) {
	    cout << "ABC";
        return 0;
    } else if (r < 2800) {
        cout << "ARC";
        return 0;
    } else {
        cout << "AGC";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(),v.end()


bool judge(vector<ll> v,int n){
    vector<ll> a=v;
    sort(all(a));
    unique(all(a));

    if(n!=unique(all(a))-a.begin()){
        return false;
    }else{
        return true;
    }
}

signed main(){
    int n,ans=0;cin>>n;
    vector<ll> g(n),r(n),ind(n+1,-1);
    for(int i=0;i<n;i++){
        cin>>g[i]>>r[i];
        ind.at(r[i])=i;
    }

    if(!judge(g,n)|| !judge(r,n)){
        cout<<-1<<endl;
        return 0;
    }

    for(int i=0;i<n;i++){
        if(g[i]!=r[i]){
            ans++;
            int rind=ind.at(g[i]);
            swap(r[i],r[rind]);
            swap(ind[r[i]],ind[r[rind]]);

        }
    }
            
    cout<<ans<<endl;

}


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

bool isBingo(const vector<bool>&);

int main() {
  vector<int> table(9);
  vector<bool> ischecked(9);
  for (int i = 0; i < 9; i++) {
    cin >> table[i];
  }
  
  int n;
  cin >> n;
  int choose;
  
  for (int i = 0; i < n; i++) {
    cin >> choose;
    for (int i = 0; i < 9; i++) {
      if (table[i] == choose) {
        ischecked[i] = true;
      }
    }
  }
  
  if(isBingo(ischecked)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

bool isBingo(const vector<bool> &v) {
  bool yoko = ((v[0] && v[1] && v[2]) || (v[3] && v[4] && v[5]) || (v[6] && v[7] && v[8]));
  bool tate = ((v[0] && v[3] && v[6]) || (v[1] && v[4] && v[7]) || (v[2] && v[5] && v[8]));
  bool naname = ((v[0] && v[4] && v[8]) || (v[2] && v[4] && v[6]));
  return (yoko || tate || naname);
}


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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;

  ll v = 1;
  for (; v <= n; v++) {
    if ((1 + v) * v / 2 >= n) {
      break;
    }
  }

  while (n > 0) {
    if (v <= n) {
      cout << v << endl;
      n -= v;
    }
    v--;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i = 0;i < s.size();++i) {
        if(s[i]!=t[i])++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
	int k;
	scanf("%d", &k);
	
	std::queue<ll> que;
	for(int i=1; i<10; i++) que.push(i);
	while(k--){
		ll a = que.front();
		que.pop();
		if(k==0){
			printf("%ld\n", a);
			return 0;
		}
		if(0<a%10) que.push(a * 10 + a%10-1);
		que.push(a * 10 + a%10);
		if(a%10<9) que.push(a * 10 + a%10+1);
	}
	return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main() {
  int N;
  string s;
  cin>>N>>s;
  int cntr(0),cntb(0);
  for(int i(0);i<N;i++){
    if(s[i] == 'R') cntr++;
    if(s[i] == 'B') cntb++;
  }
  if(cntr > cntb) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(n int) int {
	min := math.MaxInt64
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			d, m := i, n/i
			l := d + m - 2
			if min > l {
				min = l
			}
		}
	}
	return min
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int A=0, T=0, R=0, N = 0, K = 1;
char H = 'a';
vector<int> M(5);

for(int i = 0;i< 5;i++){
	cin >> M.at(i);
	if(M.at(i) == 0) T = i+1;
}

cout << T << endl;

}

Measured memory_bytes: 3596
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char as = 'a';
        while(as<='z'&&!judge(s,as)){
            as ++;
        }
        if(as>'z'){
            System.out.println("None");
        } else {
            System.out.println(as);
        }
    }
    public static boolean judge(char[] s,char as){
        for(int i=0;i<s.length;i++){
            if(as==s[i]){
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 23892
program d
    implicit none
    integer(16):: K, A, B, c
    read(*,*) K, A, B

    if(A+1 >= B .or. K <= A) then
        write(*,*) K+1
    else
        c = K - A - 1
        if(mod(c,2)==0) then
            write(*,*) B + (B-A)*c/2
        else
            write(*,*) B + (B-A)*(c-1)/2+1
        end if
    end if
    stop

end program d

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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vi p(A), q(B), r(C);
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];
    sort(ALL(p), greater<>());
    sort(ALL(q), greater<>());
    sort(ALL(r), greater<>());

    vi eat;
    REP(i, X) eat.push_back(p[i]);
    REP(i, Y) eat.push_back(q[i]);
    sort(ALL(eat));
    int sum = 0;
    REP(i, eat.size()) sum += eat[i];
    int ans = sum;
    REP(i, min((int)eat.size(), C))
    {
        sum -= eat[i];
        sum += r[i];
        chmax(ans, sum);
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 26;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int D;
  cin >> D;
  vector<int> C(N);
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  vector<vector<int>> S(D, vector<int>(N));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < N; j++) {
      cin >> S[i][j];
    }
  }

  int score = 0;
  vector<int> last_day(N, -1);
  for (int d = 0; d < D; d++) {
    int pos = 0;
    cin >> pos;
    pos--;
    last_day[pos] = d;
    score += S[d][pos];
    for (int i = 0; i < N; i++) {
      score -= C[i] * (d - last_day[i]);
    }
    cout << score << '\n';
  }
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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;}

const ll mod = 1000000007;
const int INF = 1<<29;

int main(){
  int X; cin >> X;
  int res = 0;
  int num_500 = 0;
  int num_5 = 0;
  num_500 = X / 500;
  num_5 = (X % 500) / 5;
  res = 1000 * num_500 + 5 * num_5;
  cout << res << endl;
}


Measured memory_bytes: 256
/* ex 5_4
   takaoga */

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

int main(void){
    char input[11],*ptr;
    int lengthATCG = 0,count = 0;
    scanf("%s", &input[0]);
    ptr = input;
    while(*ptr){
        if(*ptr == 'A' | *ptr == 'C' | *ptr == 'G' | *ptr == 'T'){//ATCG文字列の頭を探す
            count++; //見つかったらそこから文字数をカウントする毎にcountを加算
        }else{
            if(lengthATCG < count) lengthATCG = count;
            count = 0; //そうでなければcountを0にする。この時、もしlengthATCGがcountより小さければcountの値をlengthATCGに代入
        }
        ptr++;
    }
    if(lengthATCG < count) lengthATCG = count;//最後の文字がATCGでその文字を含む文字列が一番長い場合、ここでlengthATCGを更新する
    printf("%d\n", lengthATCG);
    return 0;
}

Measured memory_bytes: 1712
import java.util.*;
public class Main {	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int aa = sc.nextInt();
		double x[] = new double[aa];
		for(int n = 0; n < aa; n++){
			x[n] = sc.nextDouble();
		}
		Arrays.sort(x);
		double ans = x[0];
		for(int n=1;n<aa;n++){
			ans = (ans + x[n]) / 2;
		}
		System.out.println(ans);
	}
	
}

Measured memory_bytes: 22484