akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  int H,W;
  int sy,sx;
  int cnt;
  boolean[][] map;
  int[] dy = {-1,0,1,0}, dx = {0,1,0,-1}; 
  public static void main(String[] args) {
    new Main().run();
  }
  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out) ) {

      String[] lines;
      // StringBuilder buf = new StringBuilder();
      while(true) {
        lines = in.readLine().split(" ");
        W = Integer.parseInt(lines[0]);
        H = Integer.parseInt(lines[1]);

        if( W==0 && H==0) break;

        map = new boolean[H][W];

        String line;
        for(int y=0; y<H; y++) {
          char ch;
          line = in.readLine();
          for(int x=0; x<W; x++) {
            ch = line.charAt(x);
            map[y][x] = ch == '#' ? false : true;
            if(ch == '@') {
              sy = y; sx = x;
            }
          }
        }

        cnt = 0;
        dfs(sy,sx);
        // buf.append(cnt).append("\n");
        out.println(cnt);
      }

      // System.out.print(buf);
      out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void dfs(int y, int x) {
    map[y][x] = false;
    cnt++;

    for(int i=0; i<4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if(0 <= ny && ny < H && 0 <= nx && nx < W && map[ny][nx]) {
        dfs(ny,nx);
      }
    }
    return;
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  queue<int> que;
  for (int i = 0; i < K; i++) {
    int a;
    cin >> a;
    que.push(a);
  }
  for (int i = 0; i < N - K; i++) {
    int a;
    cin >> a;
    que.push(a);
    int b = que.front();
    que.pop();
    if (b < a)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


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

using namespace std;

int ns, nt, suf[200005][26];
char s[200005], t[100005];
long long ans;

int main(void) {
  scanf("%s%s", s + 1, t + 1);
  ns = strlen(s + 1), nt = strlen(t + 1);
  for (int i = 1; i <= ns; ++i)
    s[i + ns] = s[i];
  for (int i = ns << 1; i >= 1; --i) {
    memcpy(suf[i - 1], suf[i], sizeof suf[i]);
    suf[i - 1][s[i] - 'a'] = i;
  }
  int cur = 0;
  for (int i = 1; i <= nt; ++i) {
    int nxt = suf[cur][t[i] - 'a'];
    if (nxt == 0) {
      printf("-1\n");
      return 0;
    }
    ans += nxt - cur;
    cur = nxt;
    if (cur > ns)
      cur -= ns;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 20864
import numpy as np
def calc_double(nn):
    return nn -x

x,n = list(map(int,input().split()))
p= list(map(int,input().split()))
p_all = list(range(-200,200,1))

l_in = [s for s in p_all if s not in p]

data2 = []
for val in l_in:
    data2.append(abs(calc_double(val)))

min_index =np.argmin(data2)
print(l_in[min_index])

Measured memory_bytes: 27152
//Love and Freedom.
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#define inf 20021225
#define ll long long
#define N 200100
#define mdn 1000000007
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
using namespace std;
int read()
{
	int f=1,s=0; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9')	s=s*10+ch-'0',ch=getchar();
	return f*s;
}
void upd(int &x,int y){x+=x+y>=mdn?y-mdn:y;}
int t[N<<2];
void pushup(int x){t[x]=(t[ls]+t[rs])%mdn;}
void modify(int x,int l,int r,int d,int val)
{
	if(l==r){upd(t[x],val); return;}
	if(d<=mid)	modify(ls,l,mid,d,val);
	else	modify(rs,mid+1,r,d,val);
	pushup(x);
}
int query(int x,int l,int r,int LL,int RR)
{
	if(LL<=l&&RR>=r)	return t[x]; int ans=0;
	if(LL<=mid)	upd(ans,query(ls,l,mid,LL,RR));
	if(RR>mid)	upd(ans,query(rs,mid+1,r,LL,RR));
	return ans;
}
struct node{int x,v,idx,idv;}a[N];
struct seg{int l,r;}s[N];
bool operator<(seg a,seg b){return a.r<b.r||(a.r==b.r&&a.l<b.l);}
bool cmpv(node x,node y){return x.v<y.v;}
bool cmpx(node x,node y){return x.x<y.x;}
int pre[N],suf[N],n,v[N];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)	a[i].x=read(),a[i].v=read();
	sort(a+1,a+n+1,cmpv);
	for(int i=1;i<=n;i++)	a[i].idv=i,v[i]=a[i].v;
	sort(a+1,a+n+1,cmpx); //suf[n+1]=inf*99;
	for(int i=1;i<=n;i++)
	{
		if(i==1)	pre[1]=a[1].idv;
		else
		{
			if(a[i].v>v[pre[i-1]])	pre[i]=a[i].idv;
			else	pre[i]=pre[i-1];
		}
		a[i].idx=i;
	}
	for(int i=n;i;i--)
	{
		if(i==n)	suf[n]=a[n].idv;
		else
		{
			if(a[i].v<v[suf[i+1]])	suf[i]=a[i].idv;
			else	suf[i]=suf[i+1];
		}
	}
	modify(1,0,n,0,1);
	for(int i=1;i<=n;i++)
	{
		int r=pre[a[i].idx],l=suf[a[i].idx];
		s[i].l=l; s[i].r=r;
	}
	sort(s+1,s+n+1);
	for(int i=1;i<=n;i++)
	{
		int l=s[i].l,r=s[i].r;
		int val=query(1,0,n,l-1,r);
		modify(1,0,n,r,val);
	}
	printf("%d\n",query(1,0,n,n,n));
	return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <list>
using namespace std;
#define MAX 100
int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    long long int K, A, B;
    cin >> K >> A >> B;
    /*
    B-A >  2 :: 交換がメリット
    K-1 >= A :: K-2回ポケットをたたき、K-1回目に円に交換し、K回目にビスケットに交換できる
    */
    if (B - A > 2 && K - 1 >= A)
    {
        K -= A - 1; //A枚になるまでポケットをたたき続けた
        if (K % 2 == 0)
        {
            cout << A + ((B - A) * (K / 2)) << endl;
        }
        else
        {
            cout << A + 1 + ((B - A) * ((K - 1) / 2)) << endl;
        }
    }
    else
    {
        cout << K + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

bool used[11];

int D, G, p[11], b[11];

int dfs(vector<int>& v, int depth) {
    if (depth == D)
    {
        int g = G;
        int tmp = 0;
        REP(i, v.size()) {
            int t = v[i];
            int num = p[t];
            int k = g / (t*100);
            if (g % (t*100) != 0) k++;
            if (k <= num)
            {
                return tmp + k;
            } else
            {
                g -= num * (t * 100);
                g -= b[t];
                if (g <= 0) {
                    return tmp + num;
                }
                tmp += num;
            }
        }
    }

    int res = INF;
    REPS(i, D)
    {
        if (used[i]) continue;
        used[i] = true;
        v[depth] = i;
        res = min(res, dfs(v, depth + 1));
        used[i] = false;
    }

    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> D >> G;
    REPS(i, D) {
        cin >> p[i] >> b[i];
    }

    vector<int> v(D);
    int ans = dfs(v, 0);
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

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

	int h, n;
	cin >> h >> n;

	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];

	int max_h = 30303;
	ll dp[max_h];
	ll INF = LLONG_MAX / 2;
	rep(i, max_h) dp[i] = INF;
	dp[0] = 0;

	rep(i, n) rep(j, max_h) {
		if(j - a[i] >= 0) dp[j] = min(dp[j], dp[j - a[i]] + b[i]); 
	}

	ll ans = INF;
	for(int x = h; x < max_h; x++){
		ans = min(ans, dp[x]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

int main(void){
    using namespace std;
    int a;

    cin >> a;

    long long a_l[a];
    long long b_l[a];

    long long num = 0;
    long long mean = 0;

    long long sum = 0;

    for(int i=0; i < a; i++){
        cin >> a_l[i];
        b_l[i] = a_l[i]-(i+1);
    }

    sort(b_l, b_l+a);

    if(a % 2 == 0){
        mean = (b_l[a/2-1] + b_l[a/2])/2;
    }else{
        mean = b_l[a/2];
    }

    for(int i=0; i<a; i++){
        num = a_l[i] - (mean + i+1);
        if(num < 0){
            num *= -1;
        }
        sum += num;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3328
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var li = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(li);
            var count = 0;
            for (var i = 0; i < li.Length - 2; i++)
            {
                for (var j = i + 1; j < li.Length - 1; j++)
                {
                    var threthold = li[i] + li[j];
                    var min = -1;
                    var max = li.Length;
                    while (max - min > 1)
                    {
                        var mid = (min + max) / 2;
                        if (li[mid] >= threthold) max = mid;
                        else min = mid;
                    }
                    if (min > j) count += min - j;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
typedef long double ld;
ll INF = 1000000009;
ll MOD = 1000000007;

vector<ll> adj[100010];
bool visited[100010];
ll ans[100010];

void solve(){

    ll n,m;
    cin >> n >> m;
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    rep(i,n){
        visited[i]=false;
        ans[i]=-1;
    }


    queue<ll> q;
    q.push(0);
    visited[0]=true;
    ans[0]=0;
    while(!q.empty()){
        ll p = q.front();
        q.pop();
        for(auto e:adj[p]){
            if(!visited[e]){
                ans[e]=p;
                visited[e]=true;
                q.push(e);
            }
        }
    }

    rep(i,n){
        if(ans[i]==-1){
            cout << "No" << endl;
            return;
        }
    }
    
    cout << "Yes" << endl;
    rep(i,n){
        if(i==0) continue;
        cout << ans[i]+1 << endl;
    }
}

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


Measured memory_bytes: 13188
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string c;

int main(void){
	scanf("%d",&n);
	cin >> c;
	vector<int> v;
	for(int i=0;i<c.size();i++){
		if(c[i]=='W'){
			v.push_back(i);
		}
	}
	int ans=0;
	int cur=0;
	for(int i=n-1;i>=0;i--){
		if(c[i]=='R'){
			if(cur<v.size() && i>=v[cur]){
				cur++;
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << '\n';
  return 0;
}


Measured memory_bytes: 3648
N = int(input())
a = list(map(int, input().split()))
for i in range(N-1):
    a[i+1] += a[i]
a.sort()
ans = 0
be = 1<<31
cnt = 0
for x in a:
    if x != be:
        ans += cnt*(cnt-1)//2
        be = x
        cnt = 1 if x == 0 else 0
    cnt += 1
ans += cnt*(cnt-1)//2
print(ans)


Measured memory_bytes: 26720
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long double ll;
struct node {
	ll x, y;


}r[1234567];
bool cmp(node a, node b) {
	return atan2(a.x, a.y) < atan2(b.x, b.y);
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r[i].x >> r[i].y;
	}
	sort(r, r + n, cmp);
	ll x, y, ans = 0;
	for (int i = 0; i < n; i++) {
		x = r[i].x; y = r[i].y;
		ans = max(ans, r[i].x * r[i].x + r[i].y * r[i].y);
		for (int j = (i + 1) % n; j != i; j = (j+1)%n) {
			x += r[j].x; y += r[j].y;
			ans = max(ans, x * x + y * y);
		}
	
	}
	cout << fixed << setprecision(30) << ((long double)sqrt(ans)) << '\n';
	return 0;
}





Measured memory_bytes: 256
import java.util.*;

class Main{

    public static void main(String args[]){
	Scanner sc=new Scanner(System.in);
	int n;
	n=sc.nextInt();
	int[] a=new int[n];
	for(int i=0;i<n;i++){
	    a[i]=sc.nextInt();
	}
	int cnt=0;
	for(int i=0;i<n;i++){
	    cnt+=(a[i]%2==1 ? 1:0);
	}

	if(cnt%2==0) System.out.println("YES");
	else System.out.println("NO");
	
	return;
    }
    

    
}


Measured memory_bytes: 50452
import sys
import math
import itertools

N=int(input())
if(N%4==0):
    x=3*N//4
    print(x,x,x)
    exit()
for x in range(3501):
    if(4*x-2*N>0 and (N*x)%(4*x-2*N)==0):
        h=(N*x)//(4*x-2*N)
        print(h,x,x)
        exit()
if(N>2000):st=-1
else:st=1
for h,n in itertools.product(range(1,3501)[::st],range(1,3501)[::st]):
    x=N*h*n
    y=4*n*h-N*n-N*h
    if(y>0 and x%y==0):
        print(h,n,x//y)
        break
"""
4/N=1/h+1/n+1/w
4/N=(nw+hw+hn)/nhw
4nhw/N=nw+hw+hn
4nhw=Nnw+Nhw+Nhn
(4nh-Nn-Nh)w=Nhn
w=Nhn/(4nh-Nn-Nh)

4/N=3/x
4x/N=3
4x=3N
h,n,w=3N/4  (N%4==0)

4/N=1/h+2/x
4/N-2/x=1/h
(4x-2N)/Nx=1/h
h=Nx/(4x-2N)
"""


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
using namespace std;
int main()
{
    long long n,T;
    cin>>n>>T;
    long long t[n];
    rep(i,n)
    {
        cin>>t[i];
    }
    long long ans=T;
    rep(i,n-1)
    {
        if(t[i+1]-t[i]>T)
        {
            ans+=T;
        }
        else
        {
            ans+=t[i+1]-t[i];
        }
    }
    W(ans)
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#define N 100009
using namespace std;
const int INF = 0x3f3f3f3f;
char s[N];
int ans[N];
int nx[4] = {1, 1, 0, 0};
int ny[4] = {1, 0, 0, 1};

bool check(int a, int b, int n)
{
    ans[0] = a; ans[1] = b;
    for(int i = 1; i < n - 1; i++)
    {
        if(s[i] == 'o')
        {
            if(ans[i]) ans[i + 1] = ans[i - 1];
            else ans[i + 1] = !ans[i - 1];
        }
        else
        {
            if(ans[i]) ans[i + 1] = !ans[i - 1];
            else ans[i + 1] = ans[i - 1];
        }
    }
    if(s[0] == 'o')
    {
        if(ans[0])
        {
            if(ans[1] != ans[n - 1]) return false;
        }
        else if(ans[1] == ans[n - 1]) return false;
    }
    else
    {
        if(ans[0])
        {
            if(ans[1] == ans[n - 1]) return false;
        }
        else if(ans[1] != ans[n - 1]) return false;
    }
    if(s[n - 1] == 'o')
    {
        if(ans[n - 1])
        {
            if(ans[0] != ans[n - 2]) return false;
        }
        else if(ans[0] == ans[n - 2]) return false;
    }
    else
    {
        if(ans[n - 1])
        {
            if(ans[0] == ans[n - 2]) return false;
        }
        else if(ans[0] != ans[n - 2]) return false;
    }
    return true;
}


int main()
{
    int n;
    scanf("%d %s", &n, s);
    for(int i = 0; i < 4; i++)
    {
        if(check(nx[i], ny[i], n))
        {
            for(int i = 0; i < n; i++)
            {
                if(ans[i]) printf("S");
                else printf("W");
            }
            printf("\n");
            exit(0);
        }
    }
    puts("-1");
    return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;


signed main() {
  int64_t n;
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >> u;
  
  if(s==u){
    cout << a-1 << " " << b << endl;
  }
  else{
    cout << a << " " << b-1 << endl;
  }
  return 0;
}




Measured memory_bytes: 3704
/*input
7
*/
#include <iostream>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);	
	cin.tie(0);
	cout.tie(0);
 	int n;
 	cin>>n;
 	if(n&1){
 		int k = (n+1)/2;
 		cout<<(k*1.0)/n;
 	}
 	else{
 		cout<<0.5;
 	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (i * j == N) {
                printf("%s\n", "Yes");
                return 0;
            }
        }
    }
    printf("%s\n", "No");
    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 998244353;


int main() {

	int k;
	string s;
	cin >> k >> s;

	if (s.size() <= k)cout << s << endl;
	else {
		REP(i, k)cout << s[i];
		cout << "..." << endl;
	}

}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
using P=pair<int,int>;

vector<int> x(100000,0);//関係分け
vector<vector<int>> frien(100000,vector<int>(0));
int cnt=1;


void dfs(int i){
    if(x[i]) return;
    x[i]=cnt;
    for(auto a : frien[i]) dfs(a);
    return;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    int f,g;
    vector<P> enemy(k);
    rep(i,m){
        cin>>f>>g;
        f --;
        g --;
        frien[f].push_back(g);
        frien[g].push_back(f);
    }
    rep(i,k){
        cin>>f>>g;
        f --;
        g --;
        enemy[i]=P(f,g);
    }
    
    rep(i,n){
        if(x[i]) continue;
        dfs(i);
        cnt ++; 
    }
    vector<int> w(n);
    rep(i,n) w[i]=x[i];
    sort(all(w));//数えるた
    vector<int> z(cnt+1,0);
    REP(i,1,cnt+1){
        f=upper_bound(all(w),i)-lower_bound(all(w),i);
        z[i]=f;
    }
    
    rep(i,n){
        w[i]=z[x[i]]-1-frien[i].size();
    }//x:組み合わせ、w:人数
    rep(i,k){
        f=enemy[i].first;
        g=enemy[i].second;
        if(x[f]==x[g]) {w[f] --;w[g] --;}
    }
    rep(i,n) cout<<w[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int MAX = 1e5 + 5;
vector <int> adj[MAX];
bool vis[MAX];
int len[MAX];
void init()
{
	for(int i = 0; i < MAX; i++)
	{
		vis[i] = false;
		len[i] = 0;
	}
}
int dfs(int x)
{
	if(vis[x])
	return len[x];
	
	vis[x] = true;
	for(int i = 0; i < adj[x].size(); i++)
	len[x] = max(len[x], 1 + dfs(adj[x][i]));
	return len[x];
}
int main()
{
	boost;
	int n, m, i, j, a, b, ans = 0;;
	init();
	cin >> n >> m;
	fo(i, 0, m)
	{
		cin >> a >> b;
		adj[a].pb(b);
	}
	foe(i, 1, n)
	ans = max(ans, dfs(i));
	cout << ans;
}

Measured memory_bytes: 8320
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
          		int sum = 0;
                int N = sc.nextInt();
                int K = sc.nextInt();
                for(int i = 1;i<= N;i++){
                	int x = sc.nextInt();
                  	if(x > Math.abs(x - K)){
                      sum = sum + 2 * Math.abs(x-K);
                    }else{
                    	sum = sum + 2 * x;
                    }
                }
                System.out.println(sum);
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    int A[N], B[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        B[i] = A[i] - (i + 1);
    }

    sort(B, B + N);

    int b = (N % 2 == 0)?B[N / 2 - 1]:B[(N + 1) / 2 - 1];

    long long sum = 0;
    for (int i = 0; i < N; ++i) sum += abs(B[i] - b);

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

int main(void){
  char s[1001];
  scanf("%s",s);
  int c=strlen(s);
  if(s[c-1]=='s'){
    printf("%s",s);
    printf("es\n");
  }else{
    printf("%s",s);
    printf("s\n");
  }
  return 0;
}


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

int gcd(int a, int b){return b? gcd(b,a%b):a;}

int main(){
  int n, k, a;
  cin >> n >> k >> a;
  bool ansis = (a >= k);
  for(int i=1; i<n; ++i){
    int x;
    cin >> x;
    a = gcd(a, x);
    if(x >= k) ansis = true;
  }
  cout << ((ansis && k%a == 0)? "POSSIBLE":"IMPOSSIBLE") << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

template<class U,class T>ostream& operator<<(ostream& out, pair<U,T> & P){
    return out << "[" << P.first << ", " << P.second << "]";
}
template<class T>ostream& operator<<(ostream& out, vector<T> & V){
    if(!V.empty())out << "[";
    for(int i = 0; i < sz(V); i++)out << V[i] << (i+1==sz(V)?"]":", ");
    return out;
}

int main(){
    ios_base::sync_with_stdio(false);
    unsigned long long L;
    cin >> L;
    if(L == 1){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 0; i < 64; i++){
        ull res = (1ull << i);
        if(res > L){
            cout << res-1 << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    for(int i=1;i<n;i++){
        int cnt = 0;
        for(char c='a';c<='z';c++){
            bool left = false;
            bool right = false;
            for(int ii=0;ii<i;ii++){
                if(s[ii] == c){
                    left = true;
                }
            }
            for(int ii=i;ii<n;ii++){
                if(s[ii] == c){
                    right = true;
                }
            }
            if(left && right){
                cnt++;
            }
        }
        ans = max(cnt, ans);
    }
    cout << ans << endl;
    return 0; 
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];for(int i = 0; n > i; i++)cin>>a[i];
  int q;cin>>q;
  for(int i = 0; q > i; i++){
    int b,e,k;cin>>b>>e>>k;
    cout << count(a+b,a+e,k) << endl;
  }
}


Measured memory_bytes: 3108
def main():
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 0:
        ans = (b - a) // 2
    else:
        if b - 1 < n - a:
            g = (b - a + 1) // 2
            ans = a + g - 1
        else:
            g = (2 * n + a - b + 1) // 2
            ans = 2 * n - b - g + 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61260
package main

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	count := 0
	for i := 0; i < N; i++ {
		if i == A[A[i] - 1] - 1 {
			count += 1
		}
	}
	fmt.Println(count / 2)
}

Measured memory_bytes: 6528
n = int(input())
s = [input() for _ in range(n)]
ans = set(s[0])
for i in range(1,n): ans = ans & set(s[i])
cnt = [0] * len(ans)
ans = sorted(list(ans))
for i in range(n):
    for j in range(len(ans)):
        if cnt[j] == 0: cnt[j] = s[i].count(ans[j])
        else:cnt[j] = min(cnt[j], s[i].count(ans[j]))

A = ""
for x,y in zip(ans,cnt):
    A += x*y
print(A)

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

char a[100010];
int al,ans;

int main(){
	cin>>a; al=strlen(a);
	for(int i=1;i<al;i++)
		if(a[i]!=a[i-1])
			ans++;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int A,B,ans=0;

    cin >> A >>B;

    if(A>=13){
        cout << B <<endl;
    }else if(A<=12 && 6<=A){
        cout << B/2 <<endl;
    }else{
        cout << 0 <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "2 3", "1 32", "2 63", "1 12" ].parse.expand.solve == "000001000002\n000002000001\n000001000001" );
	assert( [ "2 3", "2 55", "2 77", "2 99" ].parse.expand.solve == "000002000001\n000002000002\n000002000003" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto pyis = new long[ 3 ][ nm[ 1 ] ];
	foreach( i, ref pyi; pyis )
	{
		input.popFront;
		pyi = input.front.split.to!( long[] ) ~ i;
	}
	return tuple( nm[ 0 ], pyis );
}

auto solve( long n, long[ 3 ][] pyis )
{
	auto pcs = new long[ n + 1 ];
	auto rs = new string[ pyis.length ];
	
	foreach( pyi; pyis.sort!( ( x, y ) => x[ 1 ] < y[ 1 ] ) )
	{
		pcs[ pyi[ 0 ] ]++;
		rs[ pyi[ 2 ] ] = format( "%06d%06d", pyi[ 0 ], pcs[ pyi[ 0 ] ] );
	}
	
	return rs.join( "\n" );
}


Measured memory_bytes: 14332
#include<bits/stdc++.h>
#define pb push_back
#define int long long int
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int n; cin>>n;
    int a, b; cin>>a>>b;
    int f=1;
    for(int i=a; i<=b; i++){
        if(i%n==0){
            cout<<"OK"<<endl;
            f=0;
            break;
        }
    }
    if(f) cout<<"NG"<<endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;
import java.util.Stack;

public class Main{
	static boolean cheak(String s) {
		Stack<Character> stack = new Stack<>();
		for(int i=0;i<s.length();i++) {
			char c = s.charAt(i);
			if(c == '.') {
				break;
			}
			if(c == '(') {
				stack.push(')');
			}
			if(c == '[') {
				stack.push(']');
			}
			if(c == ')' || c == ']') {
				if(stack.isEmpty() || stack.pop() != c) {
					return false;
				}
			}
		}
		
		return stack.isEmpty();
	}
		
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNextLine()) {
				String s = sc.nextLine();
				if(s.equals(".")) break;
				if(cheak(s)) {
					System.out.println("yes");
				}
				else System.out.println("no");
			}
		}
	}
}



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

int main(){

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

    int x,ans = 0;
    for(int i=0;i<n;i++){
        cin >> x;
        int MinX = min(x,k-x);
        ans += 2*MinX;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

if A[0] < 0:
	sumP = 1
	sumM = A[0]
	countP = -A[0] + 1
	countM = 0
elif A[0] == 0:
	sumP = 1
	sumM = -1
	countP = 1
	countM = 1
else:
	sumP = A[0]
	sumM = -1
	countP = 0
	countM = A[0] + 1

for i in range(1, N):
	if sumP > 0:
		if A[i] + sumP >= 0:
			countP += A[i] + sumP + 1
			sumP = -1
		else:
			sumP += A[i]
	else:
		if A[i] + sumP <= 0:
			countP += -(A[i] + sumP) + 1
			sumP = 1
		else:
			sumP += A[i]
	
	if sumM > 0:
		if A[i] + sumM >= 0:
			countM += A[i] + sumM + 1
			sumM = -1
		else:
			sumM += A[i]
	else:
		if A[i] + sumM <= 0:
			countM += -(A[i] + sumM) + 1
			sumM = 1
		else:
			sumM += A[i]

print(min(countP, countM))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n; cin>>n;
  ll ans=0;
  vector<ll> a(n+1,1);
  rep(i,2,n+1){
    ll c=0;
    while(i*(c+1)<=n){
      c++;
      a[i*c]++;
    }
  }
  rep(i,1,a.size()) ans+=a[i]*i;
  co(ans);
  
  return 0;
}

Measured memory_bytes: 81340
T = list(input())

if len(T) == 1:
    print('D')
    exit()

if T[0] == '?':
    if T[1] == 'P':
        T[0] = 'D'
    else:
        T[0] = 'P'


for i in range(1, len(T)-1):
    if T[i] == '?':
        if T[i - 1] == 'D' and (T[i + 1] == 'D' or T[i + 1] == '?'):
            T[i] = 'P'
        else:
            T[i] = 'D'

if T[-1] == '?':
    T[-1] = 'D'

print(''.join(T))



Measured memory_bytes: 10852
n = int(input())
h = list(map(int,input().split()))
ls = []
d = 1
for i in range(n-1):
    ls.append(h[i])
    c = 0
    for j in range(len(ls)):
        if ls[j] <= h[i+1]:
            c += 1
        if c == len(ls):
            d += 1
        
print(d)

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

int main()
{
  int a;
  int b;
  int n;
  cin >> a;
  cin >> b;
 n = b-a+1;
 while (n <= b+a-1 ){
  cout << n << " ";
   n++;
 }
  cout << endl;
  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

const string pros = "POSSIBLE";
const string cons = "IMPOSSIBLE";

ll a,b;

int main(){
  cin >> a >> b;
  if((a+b)%2 == 0) cout << (a+b)/2 << endl;
  else cout << cons << endl;
}


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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int LIMIT = 2 * int(1e5) + 123;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

void solve() {
	int n;
	scanf("%d", &n);
	vector<int> nums(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &nums[ i ]);
	}
	sort(nums.begin(), nums.end());

	set<vector<int>> info;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			for(int k = j + 1; k < n; k++) {
				if(nums[ k ] < nums[ i ] + nums[ j ] && nums[ i ] != nums[ j ] && nums[ j ] != nums[ k ] && nums[ k ] != nums[ i ]) {
					info.insert({i, j, k});
				}
			}
		}
	}
	printf("%d\n", info.size());
}

Measured memory_bytes: 18876
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
    int a,b,m,ans1=9999999,ans2=9999999;
    cin >> a >> b >> m;
    int x[a],y[b];
    re(i,a){
        cin >> x[i];
        if(ans1>x[i])ans1=x[i];
    }
    re(i,b){
        cin >> y[i];
        if(ans2>y[i])ans2=y[i];
    }
    int xx[m],yy[m],c[m],q,w,ans=9999999;
    re(i,m){
        cin >> xx[i] >> yy[i] >> c[i];
        q=xx[i]-1;
        w=yy[i]-1;
        if(ans>x[q]+y[w]-c[i])ans=x[q]+y[w]-c[i];
    }
    if(ans>ans1+ans2)cout << ans1+ans2;
    else cout << ans;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n, m, dist[N];
vector<int> adj[N];
bool vis[N];

void dfs(int src) {
    vis[src] = true;
    for(int u : adj[src]) {
        if(vis[u]) {
            dist[src] = max(dist[src], dist[u] + 1);
            continue;
        }
        dfs(u);
        dist[src] = max(dist[src], dist[u] + 1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n>>m;
    f(i, m) {
        int u, v;
        cin>>u>>v;
        u--, v--;
        adj[u].pb(v);
    }
    f(i, n) {
        if(!vis[i]) dfs(i);
    }
    int ans = 0;
    f(i, n) ans = max(ans, dist[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se seoncd
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
int a[N],n,m,v,p;
ll s[N];

int chk(int x){
	int rem=v-x-p+1,t=n-p+1;
	return a[t]<=a[x]+m&&(ll)(t-x)*(a[x]+m)-(s[t]-s[x])>=(ll)rem*m;
}

int main(){
	read(n),read(m);
	read(v),read(p);
	rep(i,1,n) read(a[i]);
	sort(a+1,a+n+1);
	rep(i,1,n) s[i]=s[i-1]+a[i];
	int l=1,r=n-p+1,mid;
	while(l<r){
		mid=(l+r)>>1;
		if(chk(mid)) r=mid;
		else l=mid+1;
	}
	cout<<n-l+1<<endl;
	return 0;
}


Measured memory_bytes: 4740
<?php
//error_reporting(0);
$a = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$H =  explode(" ",trim(fgets(STDIN)));

if ($a >= 3200) {
  printf("%s\n",$s);
}
else {
  printf("red\n");
}


Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

inline bool check(int lim, int x, int y, int a, int b, int c) {
    ll cst;
    for(int i = 0; i <= x; i++) {
        cst = i * a;
        cst += 2LL * (x - i) * c;
        cst += min(max(0LL, 1LL * (y - (x - i)) * b), max(0LL, 2LL * (y - (x - i)) * c));
        if(cst <= lim)
            return 1;
    }
    return 0;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int a, b, c, x, y;
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> x >> y;
    int res = 0;
    for(int step = 1 << 29; step; step >>= 1) {
        if(check(res + step, x, y, a, b, c) == 0)
            res += step;
    }
    cout << res + 1;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
import fractions

N = int(input())
A = list(map(int, input().split()))
R = []
L = []
right = A[-1]
left = A[0]
R.append(right)
L.append(left)

for x in range(1,N):
    right = fractions.gcd(right, A[-x-1])
    left = fractions.gcd(left, A[x])
    R.append(right)
    L.append(left)

answer = max(R[N-2], L[N-2])

for x in range(N-2):
    test = fractions.gcd(R[x], L[-x-3])
    answer = max(answer, test)

print(answer)

Measured memory_bytes: 16124
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
	 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return (temp * temp)%1000000007;  
    else
    {  
        if(y > 0)  
            return (x * temp * temp)%1000000007;  
        else
            return (temp * temp)%1000000007 / x;  
    }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 

} 


void solve(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 0;
    int i = 0;
    int j = n-1;
    while(i < j){
        while(str[j]!='R' && j > i){
            j--;
        }
        while(str[i] != 'W' && i < n-1){
            i++;
        }
        if(i < j){
            ans++;
            i++; j--;
        }
    }
    cout << ans << "\n";
}
int main(){ 
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
	solve();
    }
    return 0; 
}





Measured memory_bytes: 3760
import math
n = int(input())
xl = list(map(int, input().split()))
xl_cnt = len(xl)
xl_sum = sum(xl)
xl_avg = xl_sum / xl_cnt
xl_diff = map(lambda x: x - int(format(xl_avg, '.0f')), xl)
xl_double = map(lambda x: x * x, xl_diff)
print(sum(xl_double))

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = min(a, b); i >= 1; i--) {
		if (a % i == 0 && b % i == 0) {
			k--;
			if (k == 0) {
				cout << i << '\n';
				return 0;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
while True:
    try:
        dis = 0
        kyori = []
        Data = list(map(int,input().split(",")))
        for i in range(10):
            dis += Data[i]
            kyori.append(dis)
        Ad = dis * Data[10] / (Data[10] + Data[11])
        for j in range(9):
            if kyori[j] < Ad < kyori[j + 1]:
                print(j + 2)
            elif kyori[j] == Ad:
                print(j + 1)

    except EOFError:
        break

Measured memory_bytes: 7476
#include <iostream>
#include <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
using namespace std;

typedef long long ll;

const int shift = 10;
const int maxn = 200010 * 2;

ll tree[maxn * 2];
ll sum[maxn], a[maxn];
pair<ll,int> b[maxn];

ll query(int k)
{
	ll ans = 0;
	while (k)
	{
		ans += tree[k];
		k -= k&-k;
	}
	return ans;
}

void mod(int k, ll x)
{
	while (k < maxn)
	{
		tree[k] += x;
		k += k&-k;
	}
}

int main()
{
	//freopen("E.in","r",stdin);
	int n,k;
	scanf("%d%d",&n,&k);
	sum[0] = 0;
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]), sum[i] = sum[i-1] + a[i];
	for (int i=1;i<=n;i++)
	{
		b[i] = make_pair(sum[i] - (ll)i*(ll)k, i);
	}
	b[n+1] = make_pair(0,0);
	sort(b+1,b+n+2);

	ll ans = 0;
	for (int i=1;i<=n+1;i++)
	{
		//cout<<b[i].first<<" "<<b[i].second<<endl;
		ll tmp = query(b[i].second + shift);
		ans += tmp;
		mod(b[i].second+shift,1LL);
		//cout<<tmp<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}

		

Measured memory_bytes: 14592
#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 main(){

	int* table = new int[151201];
	for(int i = 0; i <= 151200; i++)table[i] = -1;

	for(int i = 0; i <= 53; i++){
		for(int k = 0; k <= 95; k++){
			if((i*i*i+(k*(k+1)*(k+2))/6) > 151200)break;
			table[i*i*i+(k*(k+1)*(k+2))/6] = i*i*i+(k*(k+1)*(k+2))/6;
		}
	}

	for(int i = 1; i <= 151200; i++){
		if(table[i] == -1){
			table[i] = table[i-1];
		}
	}

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		printf("%d\n",table[N]);
	}

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int num[101010];
set<int> E[2][101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>x, num[x]++;
	int ret=0;
	x=y=0;
	FOR(i,100001) if(num[i]) {
		if(i%M==0) {
			x+=num[i];
			num[i]=0;
		}
		else if(M%2==0 && i%(M/2)==0) {
			y += num[i];
			num[i]=0;
		}
		else {
			E[num[i]%2][i%M].insert(i);
		}
	}
	ret = x/2+y/2;
	for(i=1;i<M;i++) {
		j=M-i;
		while(E[1][i].size()) {
			x=*E[1][i].begin();
			r=-1;
			if(E[1][j].size()) r=1;
			else if(E[0][j].size()) r=0;
			if(r==-1) break;
			
			y=*E[r][j].begin();
			E[1][i].erase(E[1][i].begin());
			E[r][j].erase(E[r][j].begin());
			num[x]--;
			num[y]--;
			ret++;
			if(num[x]>0) E[0][i].insert(x);
			if(num[y]>0) E[num[y]%2][j].insert(y);
		}
	}
	FOR(i,100001) ret+=num[i]/2;
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 14848