akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
  int home[100000],elec[100000],num_data,home_num,elec_num,result;
  cin >> num_data;
  for(int i = 0;i < num_data;i++){
    cin >>home_num >>elec_num;

    
    for(int k = 0;k < home_num;k++){
      cin >>home[k];
    }

    if(home_num <= elec_num){
      cout << "0" << endl;
      continue;
    }


    result = home[home_num-1]-home[0];
    if(elec_num == 1){
      cout << result << endl;
      continue;
    }

    for(int k = home_num-1; k>=1;k--){
      home[k] = home[k]-home[k-1];
    }

    home[0] = 0;
    sort(home,home+home_num);
    for(int k = 1;k<=elec_num-1;k++){
      result -= home[home_num-k];
    }
    cout << result << endl;
  }
}



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

int main(){
    int n;
    cin >> n;
    if(n%10 == 7){
        cout << "Yes" << endl;
        return 0;
    }
    if((n/10)%10 == 7){
        cout << "Yes" << endl;
        return 0;
    }
    if(n/100 == 7){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(auto i=0; i<(n); ++i)
#define REP(i,start,end) for(auto i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

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

	int cnt = 0;
	while (n != 0)
	{
		n /= k;
		cnt++;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
A,B,h,M = list(map(int,input().split()))
#余弦定理よりL^2=A^2+B^2-2ABcosα 
import math
H = h + M/60 #M分だけ移動した時針　
cos = math.cos(math.radians(6*abs(5*H-M)))
print(math.sqrt(A ** 2 + B ** 2 - 2*A*B*cos))

Measured memory_bytes: 9240
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef pair<int,int> P;
typedef long long ll;

int r[100000010];

int main(void){

	int N,a,d,M,K,i;
	cin >> N >> a >> d >> M;
	for(i=1;i<=M;i++){
		int x,y,z;
		cin >> x >> y >> z;
		if(x==0){
			if(r[y]==0 && r[z]==0){
				r[y]=a+(z-1)*d; r[z]=a+(y-1)*d;
			}

			else if(r[y]==0 && r[z]!=0){
				r[y]=r[z]; r[z]=a+(y-1)*d;
			}

			else if(r[y]!=0 && r[z]==0){
			    r[z]=r[y]; r[y]=a+(z-1)*d;
			}

			else{
				swap(r[y],r[z]);
			}


		}else{
			if(r[z]!=0){
				r[y]=r[z];
			}

			else{
				r[y]=a+(z-1)*d;
			}
		}

	}

	cin >> K;

	if(r[K]==0) cout << a+(K-1)*d << endl;
	else cout << r[K] << endl;

	return 0;
}

Measured memory_bytes: 9372
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    ll a[n],b[n],c[n-1];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    for(ll i=0;i<n;i++){
        cin>>b[i];
    }
    for(ll i=0;i<n-1;i++){
        cin>>c[i];
    }
    ll ans=b[a[0]-1];
    for(ll i=0;i<n-1;i++){
        ans+=b[a[i+1]-1];
        if(a[i+1]==a[i]+1){
            ans+=c[a[i]-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String args[]) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = in.readLine();
			if(str.equals("1")) {
				System.out.println("Hello World");
			}
			else if(str.equals("2")){
				String str1 = in.readLine();
				String str2 = in.readLine();
				System.out.println(Integer.valueOf(str1)+Integer.valueOf(str2) );
			}
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 21332
N,Q=map(int,input().split())
A=[[]for _ in range(N+1)]
for _ in range(N-1):
    a,b=map(int,input().split())
    A[a].append(b)
    A[b].append(a)
B=[0]*(N+1)
for _ in range(Q):
    p,x=map(int,input().split())
    B[p]+=x

from collections import deque

dist=[-1]*(N+1) # 出力に合わせて適宜変更
dist[0]=0
dist[1]=0

D=deque()
D.append(1)

while D:
    V=D.popleft()
    for i in A[V]:
        if dist[i]!=-1:
            continue
        dist[i]=0
        B[i]+=B[V] # 出力に合わせて適宜変更（答えに直結するので最重要）
        D.append(i)

print(*B[1:])

Measured memory_bytes: 58132
from math import ceil
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
    exit()

if w % 2 == 0:
    ans = (w // 2) * h
else:
    ans = (w // 2) * h + (ceil(h / 2))
print(ans)

Measured memory_bytes: 3060
#ifndef _MSC_VER
#include <bits/stdc++.h>
#endif // ! _MSC_VER

using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<uint, uint> Pos;

static const uint m_max = 100001;
static const uint mod = 1000000007;

// bool m[m_max+2][m_max+2];
// uint c[m_max+2][m_max+2];

const uint dx[] = { 2, 1, 0, 1 };
const uint dy[] = { 1, 2, 1, 0 };

// int mwA[1001];
// int mwB[1001];

int main(int, char**)
{
	unsigned int n, W;
	cin >> n >> W;

	vector<unsigned int> mwA(m_max, INT_MAX);
	vector<unsigned int> mwB(m_max, INT_MAX);
	unsigned int* mw1;
	unsigned int* mw2;

	mwB[0] = 0;
	unsigned int i;
	for (i = 0; i < n; i++) {
		unsigned int w,v;

		mw1 = (i%2==0) ? &(mwA[0]) : &(mwB[0]);
		mw2 = (i%2==0) ? &(mwB[0]) : &(mwA[0]);
		
		cin >> w >> v;
		for (unsigned int j = 0; j < m_max; j++) {
			if (j < v)
				mw1[j] = mw2[j];
			else
				mw1[j] = min(mw2[j], mw2[j-v]+w);
		}

	}

	unsigned int id = 0;
	for (unsigned int i = 0; i < m_max; ++i) {
		if (mw1[i] <= W) id = i;
	}
	cout << id << endl;

	return 0;
}



Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**9)

N = int(input())
adjL = [[] for _ in range(N)]
edges = []
for _ in range(N-1):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    adjL[A].append(B)
    adjL[B].append(A)
    edges.append((A, B))

colors = dict()
def dfs(vNow, vPar, color):
    c = 1
    for v2 in adjL[vNow]:
        if v2 == vPar: continue
        if c == color:
            c += 1
        A, B = vNow, v2
        if A > B:
            A, B = B, A
        colors[(A, B)] = c
        dfs(v2, vNow, c)
        c += 1

dfs(0, -1, 0)
#print(colors)

anss = []
for A, B in edges:
    anss.append(colors[(A, B)])

print(max(colors.values()))
print('\n'.join(map(str, anss)))


Measured memory_bytes: 77292
from sys import stdin
for l in stdin:
  a,b,c,d,e,f = map(int,l.split())
  x = round((c*e-b*f)/(a*e-b*d),3) + 0.000
  y = round((c*d-a*f)/(b*d-a*e),3) + 0.000
  print("%s %s"%("{0:.3f}".format(x),"{0:.3f}".format(y)))

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

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

  for(int i = 0; i < N; i++){
    int x, y, b, p;
    cin >> x >> y >> b >> p;

    int ans = x * b + y * p;

    for(int b_use = b; b_use <= 6; b_use++){
      for(int p_use = p; p_use <= 6; p_use++){
        int price = x * b_use + y * p_use;

        //割引適用
        if(b_use >= 5 && p_use >= 2){
          price = price * 80 / 100;
        }

        ans = min(ans, price);
      }
    }

    cout << ans << endl;
  }
}

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

int main() {
	string s,t;cin >>s>>t;
	int min_ch = s.size() + 1;
	for (int i=0;i<s.size()- t.size() + 1;++i){
		auto sub = s.substr(i,t.size());
		int change = 0;
		for(int j=0;j<t.size();++j){
			if(sub[j]!=t[j])++change;
		}
		min_ch = min(min_ch, change);
	}
	cout << min_ch << endl;
	return 0;
}

Measured memory_bytes: 3648
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())
def main():
  m, d = an()

  cnt = 0
  for mm in range(1, m+1):
    for i in range(10, d+1):
      d1, d2 = str(i)
      d1 = int(d1)
      d2 = int(d2)
      if d1 >= 2 and d2 >= 2 and d1 * d2 == mm:
        cnt += 1
  print(cnt)

main()

Measured memory_bytes: 3316
import math

a, b = map(int, input().split())
min_a = math.ceil(a / 0.08)
max_a = math.ceil((a+1) / 0.08)

max_b = math.ceil((b+1) / 0.1)
min_b = math.ceil(b / 0.1)

a_range = set(list(range(min_a, max_a)))
b_range = set(list(range(min_b, max_b)))
t = a_range & b_range
if len(t) > 0:
    print(min(list(t)))
else:
    print(-1)

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

int main() {
    int n;

    cin >> n;
    if (n <= 9) {
        cout << n << endl;
    }
    else if (n <= 99) {
        cout << 9 << endl;
    }
    else if (n <= 999) {
        cout << 9 + (n - 99) << endl;
    }
    else if (n <= 9999) {
        cout << 909 << endl;
    }
    else if (n <= 99999) {
        cout << 909 + (n - 9999) << endl;
    }
    else {
        cout << 90909 << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main(){
int a,b;
std::string s;
cin>> a >> b;
if (a<b) {s="<";
} else if (a==b) {s="==";
} else {s=">";
}
printf("a %s b\n", s.c_str());
}



Measured memory_bytes: 3264
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int calc(int x,int y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

int main(){

	int p,q,common,limit;
	scanf("%d %d",&p,&q);

	common = calc(p,q);

	p /= common;
	q /= common;

	limit = sqrt(q);

	int ans = 1;

	for(int i = 2; i <= limit; i++){
		if(q%i == 0){
			ans *= i;
			while(q % i == 0)q /= i;
		}
	}

	ans *= q;

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

	return 0;
}

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

int main() {
  long long mod = 998244353;
  long long A,B;
  cin >> A >> B;
  for (int i=B-A+1; i<=B+A-1; i++) {
    if (i == B-A+1) {
      cout << i;
      continue;
    }
    cout << " " << i;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        a: [u64; n],
    }

    let mut r = 1000u64;
    for i in 0..n - 1{
        if a[i] < a[i + 1] {
            r += (r / a[i]) * (a[i + 1] - a[i]);
        }
    }
    println!("{}", r);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

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


Measured memory_bytes: 3632
def solve():
    n = int(input())
    A = [0] + list(map(int, input().split()))
    for i in range(n // 2, 0, -1):
        t = len([1 for k in range(i, n + 1, i) if A[k] == 1]) & 1
        if A[i] != t:
            A[i] = 1 - A[i]
    print(sum(A))
    print(*list(i for i in range(1, n + 1) if A[i]))
solve()


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


int main(){
	int n, a[10000],count;
	cin >> n;
	count = 0;

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

	for (int i = 0; i < n; i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			count++;
		}
	}

	cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int cnt=0;
    for(int j=1;j<=n;j++){
      if(i%j==0) cnt++;
    }
    if(cnt==8) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        Set<String> hash_set = new HashSet<String>();
        
        
        String s = scan.nextLine();


        for (int i = 0; i < n; i++) {
            hash_set.add(scan.nextLine());   
        }


        System.out.println(hash_set.size());
 
        scan.close();
    }
}


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

long n;
long a, b, c;
long sub() {
  long x = a + b;
  if (x < c) return -1;
  if (x % 2 != c % 2) return -1;
  long cap = (x - c) / 2;
  if (cap & c) return -1;
  long rem = a - cap;
  if (rem < 0) return -1;
  long ans = cap;
  for (int k = 50; k >= 0; --k) {
    if ((1ll << k) > rem) continue;
    if (c & (1ll << k)) {
      ans += 1ll << k;
      rem -= 1ll << k;
    }
  }
  cerr << ans << endl;
  return ans;
}

int main() {
  cin >> n;
  cin >> a >> b;
  for (int i = 2; i < n; ++i) {
    long p;
    cin >> p;
    c ^= p;
  }
  
  long ans = sub();
  if (ans <= 0) {
    cout << -1 << endl;
  } else {
    cout << a - ans << endl;
  }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K, tmp;
    cin >>N >>M >>K;
    vector<int> A;
    vector<int> B;
    for(int i = 0; i< N; i++){
        cin >> tmp;
        A.push_back(tmp);
    }
    for(int i = 0; i< M; i++){
        cin >> tmp;
        B.push_back(tmp);
    }
    int Aread = 0;
    for(int i = 0; K >= A[i] && i < A.size(); i ++){
        K-=A[i];
        Aread ++;
    }
    int Bread = 0;
    for(int i = 0; K >= B[i] && i < B.size(); i++){
        K-=B[i];
        Bread ++; 
    }
    int max = Aread + Bread;
    int count = max;
    while(Aread > 0){
        Aread --;
        K += A[Aread];

        for(int i = Bread; K >= B[i] && i < B.size(); i++){
        K-=B[i];
        Bread ++; 
        }

        if(max < Aread+Bread)
            max = Aread+Bread;
    }
    cout << max<<endl;

    return 0;
}

Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

//昇順
int acs(const void *a, const void *b)
{
  return *(char *)a - *(char *)b;
}

//降順
int des(const void *a, const void *b)
{
  return *(char *)b - *(char *)a;
}

int main() {
  char s[105], t[105];
  scanf("%s%s", s, t);
  int ls, lt;
  ls = strlen(s);
  lt = strlen(t);
  qsort(s, ls, sizeof(char), acs);
  qsort(t, lt, sizeof(char), des);
  if (strcmp(s, t) < 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


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

int N;
int arr[MAX];
int brr[MAX];
queue<int> q;

int test(int idx)
{
	if (idx == 0) return brr[0] > brr[1] + brr[N - 1];
	if (idx == N - 1) return brr[N - 1] > brr[0] + brr[N - 2];
	return brr[idx] > brr[idx - 1] + brr[idx + 1];
}

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; i++) cin >> arr[i];
	for (int i = 0; i < N; i++) cin >> brr[i];
	for (int i = 0; i < N; i++)
	{
		if (test(i)) q.push(i);
	}
	long long ans = 0;
	while (!q.empty())
	{
		int cur = q.front();
		q.pop();
		int prv;
		int nxt;
		if (cur) prv = cur - 1;
		else prv = N - 1;
		if (cur < N - 1) nxt = cur + 1;
		else nxt = 0;
		if (brr[prv] + brr[nxt] == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		int increment = (brr[cur] - arr[cur]) / (brr[prv] + brr[nxt]);
		ans += increment;
		brr[cur] -= increment * (brr[prv] + brr[nxt]);
		if (test(prv)) q.push(prv);
		if (test(nxt)) q.push(nxt);
	}
	for (int i = 0; i < N; i++)
	{
		if (arr[i] != brr[i])
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		int ans=0;
		for (int i=0;i<N;i++) {
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
		}

		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int p=x[i]-x[j];
				int q=y[i]-y[j];
				int cnt=0;
				for (int k=0;k<N;k++) {
					for (int l=0;l<N;l++) {
						if (x[k]-x[l]==p && y[k]-y[l]==q) {
							cnt++;
						}
					}
				}
				ans=Math.max(ans,cnt);
			}
		}
		System.out.println(N-ans);
	}
}

Measured memory_bytes: 24916
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define dep(i, l, r) for(int i = r; i >= l; --i)
int n, x, s, maxl;
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int f(int b, int n){
    int ans = 0;
    while(n) ans += n % b, n /= b;
    return ans;
}
signed main(){
    n = read(), s = read(), maxl = ceil(sqrt(n));
    if(n == s){ printf("%lld", n + 1); return 0;}
    rep(i, 2, maxl) if(f(i, n) == s){ printf("%lld", i); return 0;}
    dep(i, 1, sqrt(n - s)) if((n - s) % i == 0){
        x = (n - s) / i + 1; if(x == 1) continue;
        if(f(x, n) == s){ printf("%lld", x); return 0;}
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 3808
//15-6
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    int C,N;
    cin >> C >> N;
    bool s[1000][1000];//y,x(r,c)
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            char tmp;
            cin >> tmp;
            if(tmp == '0') s[i][j] = false;
            else s[i][j] = true;
        }
    }

    int ans = 0;
    int wrong = 0;
    for(int i=0; i<N/2; i++){
        for(int j=0; j<N/2; j++){
            if(s[i][j]==s[N-1-i][j] && s[i][j]==s[i][N-1-j] && s[i][j]==s[N-1-i][N-1-j]){

            }
            else{
                wrong++;
            }
        }
    }
    if(wrong == 0) ans++;

    for(int k=0; k<C-1; k++){
        int D;
        cin >> D;
        for(int l=0; l<D; l++){
            int r,c;
            cin >> r >> c;
            r--;
            c--;
            if(s[r][c]==s[N-1-r][c] && s[r][c]==s[r][N-1-c] && s[r][c]==s[N-1-r][N-1-c]){
                s[r][c] = !s[r][c];
                wrong++;
            }
            else{
                s[r][c] = !s[r][c];
                if(s[r][c]==s[N-1-r][c] && s[r][c]==s[r][N-1-c] && s[r][c]==s[N-1-r][N-1-c]){
                    wrong--;
                }
            }
            
        }
        if(wrong == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}



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

int v, e;
bool edge[110][110];
bool visited[110];

bool dfs(int now, int s){
    visited[now]=true;
    bool tf=false;
    for(int i=0; i<v; i++){
        if(edge[now][i]){
            if(i==s) return true;
            if(visited[i]) continue;
            tf |= dfs(i, s);
        }
    }
    return tf;
}

int main(void){
    cin >> v >> e;
    for(int i=0; i<v; i++){
        visited[i]=false;
        for(int j=0; j<v; j++){
            edge[i][j]=false;
        }
    }
    
    
    for(int i=0; i<e; i++){
        int s, t;
        cin >> s >> t;
        edge[s][t]=true;
    }
    bool ans=false;
    for(int i=0; i<v; i++){
        fill(visited, visited+v, false);
        ans |= dfs(i, i);
    }
    cout << (ans? 1: 0) << "\n";
    
    return 0;
}



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

int main(){
	int n;
	while(cin >> n){
		if(!n)
			break;
		int pos[100];
		int a=0;
		while(n!=0){
			int dn = n%-10;
			if(dn >= 0){
				pos[a++] = dn;
				n/=-10;
			}else{
				n-=10;
				pos[a++] = 10 + n%-10;
				n/=-10;
				
			}
			
		}
		for(int i=a-1;i>=0;i--){
			cout << pos[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
S = list(input())
T = list(input())
slis = [None]*26
tlis = [None]*26
for s,t in zip(S,T):
    sn = ord(s) - 97
    tn = ord(t) - 97
    if slis[sn] == None and tlis[tn] == None:
        slis[sn] = tn
        tlis[tn] = sn
    else:
        if slis[sn] == tn and tlis[tn] == sn:
            continue
        else:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 6704
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef map<int, int> I2imap;

int main(int argc, char *argv[]) {
	I2imap get_map;
	vector<int> num_list;
	
	// init map
	for (int i = 1; i < 101; i++) {
		get_map.insert(I2imap::value_type(i, 0));
	}
	// load
	while (true) {
		int rcv;
		if (EOF == fscanf(stdin, "%d", &rcv)) {
			break;
		}
		get_map[rcv]++;
	}
	// search max mode value
	int max_mv = 0;
	I2imap::iterator itr = get_map.begin();
	while (itr != get_map.end()) {
		if ((*itr).second > max_mv) {
			max_mv = (*itr).second;
		}
		itr++;
	}
	// get number having max mode value
	itr = get_map.begin();
	while (itr != get_map.end()) {
		if ((*itr).second == max_mv) {
			num_list.push_back((*itr).first);
		}
		itr++;
	}
	sort(num_list.begin(), num_list.end());
	// print result
	vector<int>::iterator v_itr = num_list.begin();
	while (v_itr != num_list.end()) {
		printf("%d\n", (*v_itr));
		v_itr++;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
	int n, k;
	cin >> n >> k;
	hei(llint) h(n);
	rep(i,0,n)cin>>h[i];
	sort(h);
	llint ans = 1000000000;
	rep(i, 0, n - k + 1) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
	
	return 0;
}




  


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
class LowestCommonAncestor{
    private:
        const int LOG;
        vector<int> depth;
        vector<vector<int>> par,g;
    public:
        LowestCommonAncestor(vector<vector<int>> &g):g(g),depth(g.size()),LOG(32){
            par.resize(LOG,vector<int>(g.size()));
        }
        void dfs(int v,int p,int d){
            par[0][v] = p;
            depth[v] = d;
            for(int u:g[v]){
                if (u != p) dfs(u,v,d+1);
            }
        }
        void build(int root){
            dfs(root,-1,0);
            rep(k,LOG-1){
                rep(i,depth.size()){
                    if (par[k][i] < 0) par[k+1][i] = -1;
                    else par[k+1][i] = par[k][par[k][i]];
                }
            }
        }
        int lca(int u,int v){
            if (depth[u] > depth[v]) swap(u,v);
            rep(k,LOG){
                if ((depth[v]-depth[u]) >> k & 1){
                    v = par[k][v];
                }
            }
            if (u == v) return u;
            for (int k = LOG - 1; k >= 0; k--){
                if (par[k][u] != par[k][v]){
                    u = par[k][u];
                    v = par[k][v];
                }
            }
            return par[0][u];
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,c;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i,n){
        cin >> k;
        rep(j,k){
            cin >> c;
            g[i].push_back(c);
            g[c].push_back(i);
        }
    }
    LowestCommonAncestor tree(g);
    int q,u,v;
    cin >> q;
    tree.build(0);
    rep(i,q){
        cin >> u >> v;
        PRINT(tree.lca(u,v));
    }
}



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

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  int v = 0;
  rep(i, n) {
    string s;
    cin >> s;
    if (v < ++m[s]) v = m[s];
  }
  for (auto& e : m)
    if (e.second == v) cout << e.first << endl;
  return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	double a;
	cin >> a;
	a /= 3;
	cout << fixed << setprecision(10) << a * a * a << endl;

}





Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define MAX 100000



int main(){
  int i,j,k,l,n,p[N+1],m[N+1][N+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=MAX;
      for(k=i;k<=j-1;k++){
	if(m[i][j]<(m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]))
	  m[i][j]=m[i][j];
	else m[i][j]=m[i][k]+m[k+1][j]+(p[i-1]*p[k]*p[j]);
      }
    }
  }

  printf("%d\n",m[1][n]);


  return 0;
}



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

int main(){
  int n;
  bool zero = false;
  cin >> n;
  vector<ll> nums(n);
  rep(i,n){
  cin >> nums[i];
  if(nums[i] == 0){zero = true;break;}
  }
  ll ans = 0;
  if(!zero){
  ans = 1;
  rep(i,n){
    if(ans > powl(10,18)/nums[i]){
      ans = -1;
      break;
    }
    ans *= nums[i];
  }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3996
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char in[305];
int dp[305][305][305];
int main() {
	int N, K, i, j, k;
	scanf("%s %d", in+1, &K);
	N = strlen(in + 1);

	for (i = N; i >= 1; i--) {
		for (k = 0; k <= K; k++) dp[i][i][k] = 1;
		for (j = i + 1; j <= N; j++) {
			for (k = 0; k <= K; k++) {
				dp[i][j][k] = max(dp[i + 1][j][k], dp[i][j - 1][k]);
				if (in[i] == in[j]) dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j - 1][k] + 2);
				if (k) dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j - 1][k - 1] + 2);
			}
		}
	}
	return !printf("%d\n", dp[1][N][K]);
}

Measured memory_bytes: 110464
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="Sunny")
		cout<<"Cloudy"<<endl;
	else if(s=="Cloudy")
		cout<<"Rainy"<<endl;
	else
		cout<<"Sunny"<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * author: moririn_cocoa       
**/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

int main(void) {
  
  int N;
  int R;
  
  cin >> N;
  cin >> R;
  
  if ( N < 10 ) {
    
    cout << 100 * ( 10 - N ) + R << endl;
  }
  
  else if ( N >= 10 ) {
    
    cout << R << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	string S;

	cin >> S;
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;
}



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

int main()
{
    int N, K;
    cin >> N >> K;
    
    double ans = 0.0;
    int l, r;
    r = max(0, N - K + 1);
    l = N - r;
    ans += (double)r / N;
    for (int i = 1; i <= l; i++) {
        ans += 1.0 / N * pow(0.5, ceil(log2((double)K/i)));
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 2000
ll n, a[N];
ll g[N];
int main(){
	n=read();
	g[0]=1000;
	for (int i=1;i<=n;i++){
		a[i]=read();
		for (int j=1;j<i;j++)
			g[i]=max(g[i],g[j]+g[j]/a[j]*(a[i]-a[j]));
		for (int j=0;j<i;j++)
			g[i]=max(g[i],g[j]);
	}
	cout<<g[n]<<endl;
    return 0;
}

Measured memory_bytes: 3624
package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	sc     = bufio.NewScanner(os.Stdin)
)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()

	var L = make([]int, 0, N)
	for i := 0; i < N; i++ {
		L = append(L, nextInt())
	}
	sort.Ints(L)

	var cnt int
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			for k := j + 1; k < N; k++ {

				if L[i] == L[j] || L[j] == L[k] {
					continue
				}

				if L[i]+L[j] > L[k] {
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1776
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int gtime[30000];
int ttime[30000];

struct comp{
  bool operator()(const int &x, const int &y)const{
    return (x > y);
  }
};

int main()
{
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) {break;}
    
    gtime[0] = 0;
    for (int i = 1; i <= n + m; i++){
      cin >> gtime[i];
    }
    sort(gtime, gtime + n + m + 1);
    for (int i = 0; i < n + m; i++) {
      ttime[i] = abs(gtime[i] - gtime[i + 1]);
      //cout << i << " " << ttime[i] << endl;
    }
    //if (n + m - 1 == 0) ttime[0] = gtime[0];
    sort(ttime, ttime + (n + m), comp());
    cout << ttime[0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n, s;
    cin >> n >> s;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll MOD = 998244353;

    ll dp[n][4000];
    rep(i,n)rep(j,4000)dp[i][j] = 0;

    rep(i,n){
        if(i == 0){
            dp[0][0] = 2;
            dp[0][a[i]] = 1;
        }else{
            rep(j,4000){
                dp[i][j] = dp[i-1][j] * 2 % MOD;
            }
            rep(j,4000){
                if(j + a[i] < 4000){
                    dp[i][j+a[i]] += dp[i-1][j];
                    dp[i][j+a[i]] %= MOD;
                }
            }
        }
    }

    cout << dp[n-1][s] << endl;
    return 0;
}




Measured memory_bytes: 97360
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aF = [0]*iN
    aP = [0]*iN
    #for i in range(iN):
    #   aF[i] = int(input().rstrip().replace(' ',''),2)
    aF = list(map(lambda x:int(input().rstrip().replace(' ',''),2),range(iN)))
    #for i in range(iN):
    #   aP[i] = [int(_) for  _ in input().split()]
    aP = list(map(lambda x:[int(_) for _ in input().split()],range(iN)))
    iD = 2**10
    iMax = -1*(10**10)
    for i in range(1,iD):
        #iM = 0
        iM = sum(map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))
        #for j in range(iN):
        #   iM += aP[j][bin(aF[j] & i).count("1")]
        if iMax < iM:
            iMax = iM
    print(iMax)
解()


Measured memory_bytes: 3064
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int xSubA = x-a;
        while(xSubA >= b){
            xSubA = xSubA - b;
        }
        System.out.println(xSubA);
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}
template<class T,class L>ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}

int main(){
    ll l,r;
    cin>>l>>r;
    if(r-l+1>2019){
        cout<<0;
    }
    else if(l%2019>r%2019){
        cout<<0;
    }
    else{
      ll ans=2019;
    	rep(i,l,r) rep(j,i+1,r+1){
          chmin(ans,i*j%2019);
        }
      cout<<ans;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int compare (const void *a, const void *b)
{
    if(*(intmax_t *)a - *(intmax_t *)b < 0)
        return -1;
    if(*(intmax_t *)a - *(intmax_t *)b > 0)
        return 1;
    return 0;
}

int main (void)
{
    intmax_t N, v[50];
    double ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &v[i]);
    }

    qsort(v, N, sizeof(intmax_t), compare);

    ans = (v[0] + v[1]) / 2.0;
    for (size_t i = 2; i < N; i++) {
        ans = (ans + v[i]) / 2.0;
    }

    printf("%.6f\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    int a[105];
    int ans = 0;
    int avg;
    int sum = 0;
    int i;

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

        a[i] *= n;

        sum += a[i];
    }

    avg = sum / n;
    for (i = 1; i < n; i++) {
        if (abs(avg - a[ans]) > abs(avg - a[i])) {
            ans = i;
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static double[] getLine(double x1, double y1, double x2, double y2){
		double[] ans = new double[3];
		double mid_x = (x1 + x2) / 2;
		double mid_y = (y1 + y2) / 2;
		ans[0] = y1 - y2;
		ans[1] = x1 - x2;
		ans[2] = - mid_y * (y1 - y2) - mid_x * (x1 - x2);
		return ans;
	}

	public static void main(String[] args){
		int n = scan.nextInt();
		double[] pt = new double[6];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < pt.length; j++){
				pt[j] = scan.nextDouble();
			}
			double[] l1 = getLine(pt[0], pt[1], pt[2], pt[3]);
			double[] l2 = getLine(pt[0], pt[1], pt[4], pt[5]);

			double x = (l1[0] * l2[2] - l1[2] * l2[0]) /
						(l1[1] * l2[0] - l1[0] * l2[1]);
			double y;
			if(l1[0] != 0){
				y = (l1[1] * x + l1[2]) / - l1[0];
			} else{
				y = (l2[1] * x + l2[2]) / - l2[0];
			}
			double r = Math.sqrt(Math.pow(x - pt[0], 2) +
					Math.pow(y - pt[1], 2));
			System.out.printf("%.3f %.3f %.3f\n", x, y, r);
		}
	}
}

Measured memory_bytes: 28324
def main():
    X,Y  = map(int, input().split()) 
    XY = [False]*(600)
    for i in range(X+1):
        XY[(X-i)*2+i*4]=True
    if XY[Y]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long ans=1;
    while(ans*ans<=n){
        ans++;
    }
    ans--;
    cout<<ans*ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,tmp,tmp1;
  cin >> n;
  vector<int> a(n),b(n);
  for (int i =0;i < n;i++)  {
    cin >> b[i];
    b[i]--;
  }
  for (int i =0;i < n ;i++) {
  	tmp=a[b[i]];
  	if (b[i]>i) {
  		cout << -1;
  		return 0;
  	}
    for (int j = b[i];j<n-1;j++) {
      tmp1=a[j+1];
      a[j+1]=tmp;
      tmp=tmp1;
    }
    a[b[i]]=b[i];
  }
  for (int i =0;i < n;i++) {
   if (a[i]>i) {
   	cout <<-1;
   	return 0;
   }
  }
  for (int i =0;i < n;i++) {
   cout << a[i]+1 << endl;
  }
 return 0; 
}

Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	int n, m;
	cin >> n >> m;
	vector < string > s(n);
	vector < vector < bool > > was(n, vector < bool > (m));
	for (int i = 0; i < n; i++)
	{	
		cin >> s[i];
	}
	int x = 0, y = 0;
	if (s[0][0] != '#')
	{
		cout << "Impossible" << endl;
		return 0;
	}
	while(true)
	{
		was[x][y] = true;
		if (x < n - 1 && s[x + 1][y] == '#')
		{
			x++;
		}
		else if (y < m - 1&& s[x][y + 1] == '#')
			y++;
		else 
			break;
	}
	if (x != n - 1 || y != m - 1)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (!was[i][j] && s[i][j] == '#')
			{
				 cout << "Impossible" << endl;
				 return 0;
			}
		}
	}
	cout << "Possible" << endl;

	return 0;
}



Measured memory_bytes: 256
from collections import defaultdict
n, m = map(int, input().split())
h = list(map(int, input().split()))
d = defaultdict(set)
num = 0
for _ in range(m):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)
num += len(set(range(1,n+1)) - set(d))
for i, v in d.items():
    flag = False
    for j in v:
        if h[i-1] <= h[j-1]:
            flag = True
    if not flag:
        num += 1
print(num)

Measured memory_bytes: 140252
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const LL MOD=1e9+7;
const LL N=100005;
char ss[N];
LL a[N],b[N];
LL cnt[N];
LL cnt1[N];
LL pow[N];
LL pow1[N];
int main()
{
	scanf("%s",ss+1);
	LL n=strlen(ss+1);
	pow[0]=1;for (int u=1;u<=n;u++) pow[u]=pow[u-1]*3%MOD;
	pow1[0]=1;for (int u=1;u<=n;u++) pow1[u]=pow1[u-1]*3%MOD;
	bool tf=false;
	for (int u=1;u<=n;u++)
	{
		cnt[u]=cnt[u-1];
		if (ss[u]=='?') cnt[u]++;
	}
	for (LL u=1;u<=n;u++)
	{
		a[u]=a[u-1];
		if (ss[u]=='A')a[u]++;
	}
	for (LL u=n;u>=1;u--)
	{
		b[u]=b[u+1];
		if (ss[u]=='C')	b[u]++;
	}
	LL ans=0;
	for (LL u=1;u<=n;u++)
		if (ss[u]=='?'||ss[u]=='B')
		{
			ans=ans+a[u-1]*b[u+1]%MOD*pow[cnt[n]-cnt[u]]%MOD*pow1[cnt[u-1]]%MOD;
			if (cnt[n]-cnt[u]>=1)
			ans=ans+a[u-1]*(cnt[n]-cnt[u])%MOD*pow[cnt[n]-cnt[u]-1]%MOD*pow1[cnt[u-1]]%MOD;
			if (cnt[u-1]>=1&&(cnt[n]-cnt[u]>=1)) 
			ans=ans+cnt[u-1]*(cnt[n]-cnt[u])%MOD*pow[cnt[n]-cnt[u]-1]%MOD*pow1[cnt[u-1]-1]%MOD;
			if (cnt[u-1]>=1) 
			ans=ans+cnt[u-1]*b[u+1]%MOD*pow[cnt[n]-cnt[u]]%MOD*pow1[cnt[u-1]-1]%MOD;
			ans=ans%MOD;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    string S;
    cin >> S;
    int N = S.size();
    // 7文字とる
    for(int i = 0; i < N; i++){
        string tmp;
        for(int j = 0; j < N; j++){
            bool ok = true;
            rep(k,N-7){
                if(j == i + k)ok = false;
            }
            if(ok)tmp.push_back(S[j]);
        }
        if(tmp == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


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

int main() {
    int n; cin >> n;
    string s;
    set<string> se;
    for (int i = 0; i < n; i++) {
        string t; cin >> t;
        if (i == 0 || (s.back() == t.front() && !se.count(t))) se.emplace(s = t);
        else return !(cout << "No" << endl);
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
    int A, B, C, D;
    bool x = true;
    cin >> A >> B >> C >> D;

    while(x)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes";
            break;
        }

        A -= D;

        if (A <= 0)
        {
            cout << "No";
            break;
        }
    }
}

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

int main()
{
	int n,t,a;
	cin >> n >> t >> a;
	int arr[n],ind=0,minm = 1e9+7;
	a *= 1000;	
	for(int i = 0 ; i < n ; i++)
	{
		cin >> arr[i];
		int curr = 1000*t-6*arr[i];
		if(abs(curr-a) < minm){
			minm = abs(curr-a);
			ind = i;		}
//		cout << arr[i] << endl;
	}
	cout << ind+1 ;
}

Measured memory_bytes: 256