akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=85;
bitset <N*320> dp[N][N];
ll a[N][N];
ll b[N][N];
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            cin >> b[i][j];
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            a[i][j]=a[i][j]-b[i][j];
            if (a[i][j]<0){
                a[i][j]=-a[i][j];
            }
        }
    }

    dp[0][1][160*85]=1;
    dp[1][0][160*85]=1;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if ((i==1 && j==1) || i>1){


                dp[i][j] |= (dp[i-1][j] >> a[i][j]);
                dp[i][j] |= (dp[i-1][j] << a[i][j]);
            }
            if (!(i==1 && j==1) && j==1){

                continue;
            }
            dp[i][j] |= (dp[i][j-1] >> a[i][j]);
            dp[i][j] |= (dp[i][j-1] << a[i][j]);

        }

    }
    ll ans=1e9;
    for (int i=0;i<=160*85;i++){
        if (dp[n][m][i]){
            ans=min(ans,160*85-i);
        }
    }
    for (int i=160*85;i<320*85;i++){
        if (dp[n][m][i]){
            ans=min(ans,i-160*85);
        }
    }
    cout << ans;
}


Measured memory_bytes: 22912
#include <stdio.h>

void dps(int il[50][50], int y, int x)	{
	il[y][x] = 0;
	
	for (int dy = -1; dy <= 1; dy++)	{
		for (int dx = -1; dx <= 1; dx++)	{
			if (dy == 0 && dx == 0)	continue;
			if (y+dy < 0 || y+dy >= 50 || x+dx < 0 || x+dx >= 50)	continue;
			if (il[y+dy][x+dx] == 1)	dps(il, y+dy, x+dx);
		}
	}
}

int main()	{
	
	int w, h, cnt;
	int il[50][50];
	
	while (true)	{
		
		scanf("%d %d", &w, &h);
		if (w == 0)	break;
		
		cnt = 0;
		
		for (int y = 0; y < 50; y++)	{
			for (int x = 0; x < 50; x++)	{
				il[y][x] = 0;
			}
		}
		
		for (int y = 0; y < h; y++)	{
			for (int x = 0; x < w; x++)	{
				scanf("%d", &il[y][x]);
			}
		}
		
		for (int y = 0; y < h; y++)	{
			for (int x = 0; x < w; x++)	{
				if (il[y][x] == 1)	{
					dps(il, y, x);
					cnt++;
				}
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}


Measured memory_bytes: 2772
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
#define F first
#define S second
using namespace std;

int n,m,x,y,z;
vector<pair<P,P>> ta[8];
int cnt1,cnt2,cnt3,ans;

signed main(){
	cin>>n>>m;
	rep(i,n){
		cin>>x>>y>>z;
		ta[0].push_back({{x+y+z,x},{y,z}});
		ta[1].push_back({{-x+y+z,x},{y,z}});
		ta[2].push_back({{x-y+z,x},{y,z}});
		ta[3].push_back({{x+y-z,x},{y,z}});
		ta[4].push_back({{-x-y+z,x},{y,z}});
		ta[5].push_back({{-x+y-z,x},{y,z}});
		ta[6].push_back({{x-y-z,x},{y,z}});
		ta[7].push_back({{-x-y-z,x},{y,z}});
	}
	rep(i,8){
		sort(all(ta[i]));
		reverse(all(ta[i]));
		cnt1=0,cnt2=0,cnt3=0;
		rep(j,m){
			cnt1+=ta[i][j].F.S;
			cnt2+=ta[i][j].S.F;
			cnt3+=ta[i][j].S.S;
		}
		ans=max(ans,(abs(cnt1)+abs(cnt2)+abs(cnt3)));
	}
	cout<<ans<<endl;
}


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

int N;
string S;

vector<int> solve(int a, int b) {
    int M = N * 2;
    vector<int> res(M);
    res[0] = a, res[1] = b;
    for(int i = 1; i < M - 1; ++i) {
        if(S[i] == 'o') {
            if(res[i]) res[i + 1] = res[i - 1]; // S
            else res[i + 1] = 1 ^ res[i - 1]; // W
        } else {
            if(res[i]) res[i + 1] = 1 ^ res[i - 1]; // S
            else res[i + 1] = res[i - 1]; // W
        }
    }
    if(res[0] == res[N] && res[1] == res[N + 1]) return res;
    return vector<int> ();
}

int main() {
    cin >> N >> S;
    S += S;
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < 2; ++j) {
            auto ans = solve(i, j);
            if(!ans.empty()) {
                for(int k = 0; k < N; ++k) {
                    cout << (ans[k] ? "S" : "W");
                }
                cout << '\n';
                return 0;
            }
        }
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 1436
a,b,c,d=map(int,input().split())
n=int(input())
if a*4==min(a*4,b*2,c,d//2):
    print(n*a*4)
elif b*2==min(a*4,b*2,c,d//2):
    print(n*b*2)
elif c==min(a*4,b*2,c,d//2):
    print(n*c)
else:
    if n==1:
        ans=d*(n//2)
        if a*4==min(a*4,b*2,c):
            ans+=a*4
        elif b*2==min(a*4,b*2,c):
            ans+=b*2
        elif c==min(a*4,b*2,c):
            ans+=c
        print(ans)
    elif n%2==0:
        print((n*d)//2)
    else:
        ans=d*(n//2)
        if a*4==min(a*4,b*2,c):
            ans+=a*4
        elif b*2==min(a*4,b*2,c):
            ans+=b*2
        elif c==min(a*4,b*2,c):
            ans+=c
        print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int abs(int a)
{
    return a>0?a:-a;
}

int main()
{
    int n;
    int a[100];
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    
    int max=-1000000000;
    int min=1000000000;
    for(int i=0;i<n;i++)
    {
        if(max<a[i]) max=a[i];
        if(min>a[i]) min=a[i];
    }
    printf("%d\n",abs(max-min));

}

Measured memory_bytes: 128
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int h, n;
  cin >> h >> n;
  int sum = 0;
  rep(i, n){
    int a;
    cin >> a;
    sum += a;
  }
  if (h <= sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define MAXN 11111

const int INF = 1 << 29 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
    ios::sync_with_stdio(0) ;
    ll x ,y  , count = 1;
    cin >> x >> y ;
    while((x <<=1LL)<=y) count++ ;
    cout << count << endl ;
    return 0 ;
}

Measured memory_bytes: 256
int main(void)
{
	int H, W;
	int i, j;

	scanf("%d %d", &H, &W);
	
	while (!(H == 0 && W == 0)) {
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++)
				putchar('#');
			putchar('\n');
		}
		putchar('\n');

		scanf("%d %d", &H, &W);
	}

	return 0;
}

Measured memory_bytes: 572
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
        String s[] = sc.next().split("");
        String t[] = sc.next().split("");

        int count = 0;

        for (int i = 0; i < 3; i++) {
            if (s[i].equals(t[i])) {
                count++;
            }
        }

        System.out.println(count);
	}
}


Measured memory_bytes: 21588
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(String.format("%d %d", a * b, 2 * (a + b)));
        }
    }
}



Measured memory_bytes: 26096
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;


double x1, x2, x3, y1_, y2, y3;

int main(){
    cin >> x1 >> y1_ >> x2 >> y2 >> x3 >> y3;
    double a, b, c, s, S, M, r, x;
    a = sqrt(pow(x1-x2, 2) + pow(y1_-y2, 2));
    b = sqrt(pow(x2-x3, 2) + pow(y2-y3, 2));
    c = sqrt(pow(x3-x1, 2) + pow(y3-y1_, 2));
    s = (a+b+c)/2;
    S = sqrt(s*(s-a)*(s-b)*(s-c));
    M = max(a, max(b, c));
    r = 2*S/(a+b+c);
    x = M / (2+M/r);
    printf("%.10lf\n", x);
    //cout << x << endl;
}

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

int main(){
  int A,B;cin >> A >> B;
  if (A>=B+1){
    cout << 2*A-1 <<endl;
  }else{
    if(A==B){
      cout << 2*A <<endl;
    }else{
      cout << 2*B-1 <<endl;
    }
  }
}


Measured memory_bytes: 256
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Measured memory_bytes: 75480
#include<stdio.h>
#define n 45

int N;
int fibnacci(int);

int main(){
  int Ans;

  scanf("%d",&N);
  Ans=fibonacci(N);
  printf("%d\n",Ans);
  return 0;
}
int fibonacci(int k){
  int i,F[N+1];
  
  F[0]=1;
  F[1]=1;
  for(i=2;i<=N;i++){
      F[i]=F[i-2]+F[i-1];
  }
  
  return F[N];

 
}

Measured memory_bytes: 596
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int n = sc.nextInt();
		if (n == 1) return;
		out.print(n + ":");

		for (int d = 2; d <= n; d++) if (d % 7 == 1 || d % 7 == 6) {
			if (n % d == 0 && isp(d))
				out.print(" " + d);
		}
		out.println();
	}

	boolean[] checked = new boolean[300000 + 10];
	boolean[] memo = new boolean[300000 + 10];
	boolean isp(int n) {
		if (checked[n]) return memo[n];
		boolean res = true;
		for (int d = 2; d * d <= n; d++) if (d % 7 == 1 || d % 7 == 6) {
			if (n % d == 0) {
				res = false;
				break;
			}
		}
		checked[n] = true;
		memo[n] = res;
		return res;
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 23440
/*#include <stdio.h>
int main()
{
    int a,b,c,i=0;
    scanf("%d %d %d",&a,&b,&c);
    while(a>=i&&b>=i*2&&c>=i*4)
    {
        i++;
    }
    printf("%d\n",(i-1)*7);
	return 0;
}*/
#include <stdio.h>
int main()
{
    int a[100],i,n,m,sum=0,x,y;
    scanf("%d",&n);
    for(i=0;n>i;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    scanf("%d",&m);
    for(i=1;m>=i;i++)
    {
        scanf("%d %d",&x,&y);
        printf("%d\n",sum-a[x-1]+y);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
typedef pair<int,string>XXX;
#define F first
#define S second

int dp[101][9];

signed main(){
    int h,w,k;
    cin>>h>>w>>k;
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<(1<<w-1);j++){
            int f=0;
            for(int x=0;x<w;x++){
                if((j&(1<<x))&&(j&(1<<(x+1))))f++;
            }
            //cout<<j<<' '<<f<<endl;
            if(f)continue;
            for(int x=0;x<w;x++){
                if(x&&(j&(1<<(x-1))))dp[i+1][x-1]+=dp[i][x],dp[i+1][x-1]%=1000000007;
                else if(j&(1<<(x)))dp[i+1][x+1]+=dp[i][x],dp[i+1][x+1]%=1000000007;
                else dp[i+1][x]+=dp[i][x],dp[i+1][x]%=1000000007;
            }
        }
        //cout<<dp[i+1][0]<<' '<<dp[i+1][1]<<' '<<dp[i+1][2]<<endl;
    }
    cout<<dp[h][k-1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}

int main() {
  int x;
  cin >> x;
  cout << (x ^ 1) << endl;
  return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  while(ans < c and b >= a){
    b -= a;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iterator>
using namespace std;

int main(){
    #ifdef INPUT
        freopen("input","r",stdin);
//        freopen("output","w",stdout);
    #endif // INPUT
//    ios::sync_with_stdio(false);
//    cin.fill(NULL);

    int n,temp;
    int ans;
    vector<int> v;
    while(scanf("%d",&n)!=EOF)
    {
        ans = 0;
        for(int i=0; i<n; ++i)
        {
            scanf("%d",&temp);
            v.push_back(temp);
        }
        for(int i=0; i<n; ++i)
        {
            for(int j=i+1; j<n; ++j)
            {
                ans += v[i]*v[j];
            }
        }
        printf("%d\n",ans);
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] sw = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var ans = "safe";
        if (sw[0] <= sw[1])
        {
            ans = "unsafe";
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28300
import math
from functools import reduce
import collections
import itertools
n = input()
a = list(map(int,input().split()))
m =  sum(a)/len(a)
ans = 0
sabun = 1000000000000000000
for (i, x) in enumerate(a):
   # print(i)
    if abs(x - m) < sabun:
        sabun = abs(x-m)
        ans = i
print(ans)

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

public class Main {
    static final int MOD=1000000007;
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(f.readLine());
        int n = Integer.parseInt (st.nextToken());
        int m = Integer.parseInt (st.nextToken());
        char[][] arr=new char[n][m];

        for(int i=0;i<n;i++){
            arr[i]=f.readLine().toCharArray();
        }
        long dp[][]=new long[n][m];
        dp[0][0]=1;
        for(int i=1;i<n;i++){
            if(arr[i][0]=='#'){
                break;
            }
            dp[i][0]=1;
        }
        for(int i=1;i<m;i++){
            if(arr[0][i]=='#'){
                break;
            }
            dp[0][i]=1;
        }
        for(int i=1;i<n;i++){
            p:
            for(int j=1;j<m;j++){
                if(arr[i][j]=='#')continue p;
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=MOD;

            }
        }
//        for(int i=0;i<n;i++){
//            System.out.println();
//            for(int j=0;j<m;j++){
//                System.out.print(dp[i][j]+" ");
//            }
//        }
        System.out.println(dp[n-1][m-1]);
        f.close();

        //print to System. out.println

    }

}


Measured memory_bytes: 37252
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e4 + 5;
typedef bitset < 2 * maxN > bs;
int n;
int x[maxN], y[maxN];
bs g[2 * maxN];
vector < pair < int, int > > f;
bs not_used;
int his_pos[2 * maxN];
bs pref_ones[2 * maxN];
vector < int > order;
int comp[2 * maxN];
void dfs1(int v) {
    not_used[his_pos[v ^ 1]] = false;
    while (true) {
        int p = (not_used & g[v])._Find_first();
        if (p == 2 * maxN) break;
//        cout << " EDGE " << v << " " << (f[p].second ^ 1) << endl;
        dfs1(f[p].second ^ 1);
    }
    order.emplace_back(v);
}
void dfs2(int v, int cl) {
    comp[v] = cl;
    not_used[his_pos[v]] = false;
    while (true) {
        int p = (not_used & g[v ^ 1])._Find_first();
        if (p == 2 * maxN) break;
        dfs2(f[p].second, cl);
    }
}
bool ok(int d) {
    not_used = pref_ones[2 * n - 1];
    for (int i = 0; i < f.size(); i++) {
        int ourcord = f[i].first;
        auto it = lower_bound(f.begin(), f.end(), make_pair(ourcord + d, -1)) - f.begin();
        int r = it - 1;
        it = lower_bound(f.begin(), f.end(), make_pair(ourcord - d + 1, -1)) - f.begin();
        int l = it;
        //add edges from l .. r
        g[f[i].second] = pref_ones[r];
        if (l > 0) g[f[i].second] ^= pref_ones[l - 1];
        g[f[i].second][i] = false;
    }
    order.clear();
    for (int i = 0; i < 2 * n; i++) {
        if (not_used[his_pos[i ^ 1]]) dfs1(i);
    }
    for (int i = 0; i < 2 * n; i++) {
        comp[i] = -1;
    }
    reverse(order.begin(), order.end());
    int sz = 0;
    not_used = pref_ones[2 * n - 1];
    for (int v : order) {
        if (comp[v] == -1) {
            dfs2(v, sz++);
        }
    }
    for (int i = 0; i < 2 * n; i++) {
        if (comp[i] == comp[i ^ 1]) return false;
    }
    return true;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    pref_ones[0][0] = true;
    for (int i = 1; i <= 2 * n; i++) {
        pref_ones[i] = pref_ones[i - 1];
        pref_ones[i][i] = true;
    }
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        f.emplace_back(x[i], 2 * i);
        f.emplace_back(y[i], 2 * i + 1);
    }
    sort(f.begin(), f.end());
    for (int i = 0; i < f.size(); i++) {
        his_pos[f[i].second] = i;
    }
    int l = 0;
    int r = 1e9 + 10;
//    cout << ok(1) << endl;
//    exit(0);
//    cout << ok(4) << endl;
//    exit(0);
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (ok(mid)) l = mid;
        else r = mid;
    }
    cout << l;
    return 0;
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    cout << setprecision(15);
    ll n;
    cin >> n;
    if (n == 1) cout << 1 << '\n';
    else if (n % 2 == 1) cout << (n + 1.00) / 2 / n << '\n';
    else cout << .5 << '\n';
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <map>


using namespace std;


int mod(int a, int b) {
    int r = a % b;
    return r < 0 ? r + b : r;
}


int main() {
    long long l, r; cin >> l >> r;
    int ans = 1001001001;

    if (r-l > 2019) {
        ans = 0;
    }
    else {
        for (int i=l; i<r; i++) {
            for (int j=i+1; j<=r; j++) {
                ans = min(ans, (i%2019)*(j%2019)%2019);
            }
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#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++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
    ll n, h, w;
    cin >> n >> h >> w;
    int res = 0;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        if(a >= h && b >= w)res++;
    }
    cout << res << endl;
}





Measured memory_bytes: 3148
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            S = ReadLine();
            var t = new List<char>() { 'S', 'W' };
            foreach(var t1 in t)
            {
                foreach (var t2 in t)
                {
                    types = new char[N];
                    types[0] = t1;
                    var ret = dfs(1, t2);
                    if(ret)
                    {
                        WriteLine(types);
                        return;
                    }
                }
            }
            WriteLine(-1);
        }
        static string S;
        static char[] types;
        static bool dfs(int n, char t)
        {
            if (n == types.Length)
            {
                if (types[0] != t) return false;
                if ((t == 'S' && S[0] == 'o') || (t == 'W' && S[0] == 'x'))
                {
                    if (types[n - 1] == types[1]) return true;
                    return false;
                }
                else
                {
                    if (types[n - 1] != types[1]) return true;
                    return false;
                }
            }
            types[n] = t;
            if ((t == 'S' && S[n] == 'o') || (t == 'W' && S[n] == 'x'))
            {
                return dfs(n + 1, types[n - 1]);
            }
            else
            {
                if (types[n - 1] == 'S')
                    return dfs(n + 1, 'W');
                return dfs(n + 1, 'S');
            }
        }
    }
}

Measured memory_bytes: 17620
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
constexpr int SIZE = 100;
#else
#define dbg(...) {}
constexpr int SIZE = 4096;
#endif

int val[2][2005][2005];

int main(){
  int n,d;
  cin>>n>>d;
  vector<vector<int>> v(d,vector<int>(d,0));
  rep(i,n){
    int x,y;
    cin>>x>>y;
    v[x%d][y%d]++;
  }

  long l = 1, r = n*d;
  while(r-l > 1) {
    long mid = (l+r)/2;
    auto f = [&](){
      if (mid * mid < n) return false;
      if (mid%d==0){
        rep(i,d)rep(j,d) if(v[i][j] > (mid/d) * (mid/d)) return false;
        return true;
      }
      rep(i,d) rep(j,d) if(v[i][j] > (mid/d+1) * (mid/d+1)) return false;

      fill(val[0][0], val[2][0], 0);
      rep(i,1,d+1) rep(j,1,d+1){
        val[0][i][j] = val[0][i+d][j] = val[0][i][j+d] = val[0][i+d][j+d] = v[i-1][j-1] <= (mid/d + 1)*(mid/d);
        val[1][i][j] = val[1][i+d][j] = val[1][i][j+d] = val[1][i+d][j+d] = v[i-1][j-1] <= (mid/d)*(mid/d);
      }
      rep(k,2){
        rep(i,2*d+1){
          rep(j,2*d+1){
            if(i>0) val[k][i][j] += val[k][i-1][j];
            if(j>0) val[k][i][j] += val[k][i][j-1];
            if(i>0 && j>0) val[k][i][j] -= val[k][i-1][j-1];
          }
        }
      }

      rep(i,d) rep(j,d){
        if(val[1][i + d][j + d] - val[1][i + d][j + mid%d] - val[1][i + mid%d][j + d] + val[1][i + mid%d][j + mid%d] != (d - mid%d)*(d - mid%d)) continue;
        if(val[0][i + mid%d][j + d] - val[0][i][j + d] - val[0][i + mid%d][j + mid%d] + val[0][i][j + mid%d] != (d - mid%d)*(mid%d)) continue;
        if(val[0][i + d][j + mid%d] - val[0][i + d][j] - val[0][i + mid%d][j + mid%d] + val[0][i + mid%d][j] != (d - mid%d)*(mid%d)) continue;
        return true;
      }
      return false;
    };
    if (f()) r = mid;
    else l = mid;
  }

  cout << l << endl;

  return 0;
}


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


using ll = long long int;
using namespace std;





int main()
{
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB")
	{
		cout << "No";
	}
	else
	{
		cout << "Yes";
	}
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())

cards = []
v = ["S", "H", "C", "D"]
number = list(range(1,14))

for i in v:
    for num in number:
        cards.append("{} {}".format(i, num))

my_cards = []
if n == 52:
    exit(0)
    
for i in range(n):
    my_cards.append(input())

# https://qiita.com/Toitu_Prince/items/222b50594b4bb7b189ee
result = [i for i in cards if i not in my_cards]
print("\n".join(map(str, result)))


Measured memory_bytes: 5608
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
X = [deque() for _ in range(N)]
P = [-1] * N
for i in range(N-1):
    a, b = map(int, input().split())
    X[a-1].append((i, b-1))
    #print(X)
    #P[b-1] = a-1
#print(X)

Q = deque([(0, -1)])
ANS = [-1] * (N-1)
cmax = 0
while Q:
    x, c0 = Q.pop()
    c = 1
    for i, y in X[x]:
        if c == c0: c += 1
        ANS[i] = c
        Q.appendleft((y, c))
        c += 1
    cmax = max(cmax, c-1)

print(cmax)
for ans in ANS:
    print(ans)

Measured memory_bytes: 82308
fn main() {
    let n: String = read();
    let n: Vec<char> = n.chars().collect();

    for i in &n {
        if i == &'9' {
            println!("Yes");
            break;
        } else if i == &n[n.len()-1] {
    println!("No");
        }
    }
}



use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed toparse token")
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc127/tasks/abc127_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 この問題は結局のところ
 A1..ANおよびC1枚のB1と・2枚のB2・...・CM枚のBMがあるカードの中から
 N枚選択した時の最大値を出力せよ
 
 になる。あとはmapなどで個数管理して計算するだけ
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    map<ll,ll> mp;
    for(int i = 0; i < N;i++){
        ll a; cin >> a;
        mp[a]++;
    }
    for(int i = 0; i < M;i++){
        ll b,c; cin >> b >> c;
        mp[c]+=b;
    }
    
    for(auto it = mp.rbegin(); it!=mp.rend();it++){
        res += it->first*min(N,it->second);
        N -= min(N,it->second);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 12800
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] L = new int[2 * N];
		for (int i = 0; i < 2 * N; ++i) {
			L[i] = sc.nextInt();
		}
		Arrays.sort(L);
		int ans = 0;
		for (int i = 0; i < N; ++i) {
			ans += L[2 * i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 10068
N,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
a.sort()
for i in range(N):
  if x-a[i]>=0:
    cnt+=1
    x-=a[i]
    if i == N-1 and x > 0:
      cnt-=1
  else:
    break

print(cnt)

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)
	m := map[string]int{}

	for _, v := range S {
		if _, ok := m[string(v)]; ok {
			fmt.Println("no")
			return
		}
		m[string(v)]++
	}
	fmt.Println("yes")
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int n = 1; n <= N; n += 2) {
		int counter = 0;
		for (int p = 1; p * p <= n; p++) {
			if (n % p == 0) {
				if (p * p == n)counter++;
				else counter += 2;
			}
		}
		if (counter == 8)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let mut n:usize = r.readl();

    let mut res = "Yes";

    let mut pre_x = 0;
    let mut pre_y = 0;
    let mut pre_t = 0;

    for _ in 0..n {
        let t:i32 = r.reads();
        let x:i32 = r.reads();
        let y:i32 = r.readl();

        if( ((t - pre_t) - (x - pre_x).abs() - (y - pre_y).abs()) >= 0 && ((t - pre_t) - (x - pre_x).abs() - (y - pre_y).abs()) % 2 == 0 ){
            pre_x = x;
            pre_y = y;
            pre_t = t;
        }else{
            res = "No";
            break
        }
    }

    println!("{}",res);
}


Measured memory_bytes: 4352
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))

s = 0

for i in range(K):
    s += P[i]

s_max = s

for i in range(N - K):
    s = s - P[i] + P[i+K]
    if s > s_max:
        s_max = s

print((s_max + K) / 2)

Measured memory_bytes: 31936
#include <iostream>
const int N=100010;
using namespace std;
int a[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    bool h=false;
    int pos=1;
    int res=1;
    for(int i=1;i<=n;i++){
        pos=a[pos];
        res++;
        if(pos==2){
            h=true;
            break;
        }
        
    }
    if(h)
        cout<<res-1<<endl;
    else cout<<"-1"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
const int N = 158;
int n, k, mod;
int g[N][N], f[N][N][N];
//
inline void reduce(int &x) {
  x += x >> 31 & mod;
}
inline void add(int &x, int y) {
  x += y - mod;
  reduce(x);
}
inline int mul(int x, int y) {
  return 1ll * x * y % mod;
}
void solve0() {
  g[0][0] = g[1][0] = 1;
  k /= 2;
  for (int i = 1; i <= n; i++) {
    add(g[i + 1][0], g[i][0]);
    for (int j = 1; j <= min(i, k); j++) {
      add(g[i][j], g[i - 1][j - 1]);
      add(g[i + 1][0], g[i][j]);
    }
  }
  int sum = 0, res = 0;
  rep(i, k + 1) add(sum, g[n / 2][i]);
  if (n & 1) ++n;
  rep(i, k + 1) add(res, g[n / 2][i]);
  cout << mul(res, sum) << endl;
}
void solve1() {
  int c0 = 0, c1 = 0, c;
  for (int i = 2; i <= n; i += 2) {
    if (i - k <= 0) ++c0;
  }
  for (int i = 1; i <= n; i += 2) {
    if (i + k > n) ++c1;
  }
  c = (n - c0 - c1) / 2;
  //cout <<c0 << " " << c << " " << c1 << endl;
  f[0][0][0] = 1;
  for (int i = 1; i <= c0; i++) {
    rep(j, i) add(f[i][0][0], f[i - 1][0][j]);
    for (int j = 1; j <= i; j++) {
      add(f[i][0][j], f[i - 1][0][j - 1]);
    }
  }
  for (int i = c0 + 1; i <= c0 + c + c1; i++) {
    if (i <= c0 + c) rep(j, N) {
      for (int x = 0; x <= k; x++) {
        add(f[i][0][j], f[i - 1][x][j - 1]);
      }
    }
    rep(x, N) add(f[i][0][0], f[i - 1][0][x]);
    rep(j, k + 1) rep(k, N) {
      add(f[i][0][0], f[i - 1][j][k]);
    }
    for (int j = 2; j <= k; j++) {
      for (int x = 0; x < N; x++) {
        add(f[i][j][0], f[i - 1][j - 1][x]);
      }
    }
    if (i <= c0 + c) rep(j, k) for (int x = 0; x < N - 1; x++) {
      add(f[i][max(j, x) + 1][x + 1], f[i - 1][j][x]);
    }
    rep(j, N) rep(x, N) if (f[i][j][x]) {
      //cout << i << " " << j << " " << x << " " << f[i][j][x] << endl;
    }
  }
  int res = 0;
  rep(i, k + 1) rep(j, N) add(res, f[c + c0 + c1][i][j]);
  cout << res << endl;
}
int main() {
  n = getint(); k = getint(); mod = getint();
  if (!(k & 1)) {
    solve0();
  }
  else {
    solve1();
  }
  return 0;
}


Measured memory_bytes: 12928
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b, c, x, y = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    pizzamax = [x for x in range(max(x,y)+1)]
    pizzamax.sort(reverse=True)

    paymin = 5000 * 2 * 10**5
    for i in pizzamax:
        pay = 2 * i * c
        if i < x:
            pay += (x-i) * a
        if i < y:
            pay += (y-i) * b
        paymin = min(paymin, pay)

    print(paymin)
resolve()

Measured memory_bytes: 44912
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    vector<int> v(3);
    cin >> v.at(0) >> v.at(1) >> v.at(2);
    sort(v.begin() , v.end());
    cout << v.at(2)*10 + v.at(0) + v.at(1) << endl;
}


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

int main() {
    map<int ,int> mp;
    int n;
  	cin >> n;
    rep(i, n) {
      	int a;
        cin >> a;
        mp[a]++;
    }
  
  	int ans = 0;
  
  	for(auto x : mp) {
    	ans++;
    }

    cout << ans << endl;

  	return 0;
}


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

int main(void) {
	int n;
	double x[2], y[2], r[2];
	double d;
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%lf %lf %lf %lf %lf %lf", &x[0], &y[0], &r[0], &x[1], &y[1], &r[1]);
		d = sqrt( (x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]) );
		if (d > r[0]+r[1])
			printf("0\n");
		else if (d < r[0]-r[1])
			printf("2\n");
		else if (d < r[1]-r[0])
			printf("-2\n");
		else
			printf("1\n");
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

static class Program
{
    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

    static List<int> Draw(List<int>[] edges, bool[] visited, int n)
    {
        var path = new List<int>();
        while (true)
        {
            visited[n] = true;
            path.Add(n);
            var nexts = edges[n].Where(edge => !visited[edge]);
            if (nexts.Count() == 0) { return path; }
            n = nexts.ElementAt(0);
        }
    }
    static void Main(string[] args)
    {
        int[] args1 = ReadInts();
        int N = args1[0];
        int M = args1[1];
        var edges = new List<int>[N];
        for (int i = 0; i < N; ++i) { edges[i] = new List<int>(); }
        for (int i = 0; i < M; ++i)
        {
            int[] args2 = ReadInts();
            int A = args2[0] - 1;
            int B = args2[1] - 1;
            edges[A].Add(B);
            edges[B].Add(A);
        }
        bool[] visited = new bool[N];
        var path = new List<int>();
        for (int i = 0; i < N; ++i)
        {
            if (edges[i].Count > 0)
            {
                visited[i] = true;
                if (edges[i].Count > 0)
                {
                    path.AddRange(Draw(edges, visited, edges[i][0]));
                    path.Reverse();
                }
                path.Add(i);
                var nexts = edges[i].Where(edge => !visited[edge]);
                if (nexts.Count() > 0)
                {
                    path.AddRange(Draw(edges, visited, nexts.ElementAt(0)));
                }
                break;
            }
        }
        Console.WriteLine(path.Count);
        Console.WriteLine(string.Join(" ", path.Select(n => n + 1)));
    }
}


Measured memory_bytes: 31856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n, k;
  cin >> n >> k;
  map<int, int> mp;

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

  vector<pair<int, int>> v;
  for (auto &e : mp)
  {
    v.emplace_back(e);
  }
  sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });

  int cnt = 0;
  if (v.size() > k)
    for (int i = 0; i < v.size() - k; ++i)
    {
      cnt += v[i].second;
    }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 12792
#include <bits/stdc++.h>
#define DEBUG false
#define coutd if(DEBUG) cout
#define debugf if(DEBUG) printf
#define ff first
#define ss second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define FOR(i, x) for(int i=0; i<x; i++)
#define FOR1(i, x) for(int i=1; i<=x; i++)
#define REAP(i, x) for(int i=x-1; i>=0; i--)
#define REAP1(i, x) for(int i=x; i>0; i--)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<string> vs(n);
	FOR(i, n) cin >> vs[i];
	int l=0; int r=0; int b=0;
	ll ans=0;
	FOR(i, n){
		if(vs[i][0]=='B' && vs[i][sz(vs[i])-1]!='A') l++;
		else if(vs[i][0]!='B' && vs[i][sz(vs[i])-1]=='A') r++;
		else if(vs[i][0]=='B' && vs[i][sz(vs[i])-1]=='A') b++;
		for(int j=0; j<sz(vs[i])-1; j++){
			if(vs[i][j]=='A' && vs[i][j+1]=='B') ans++;
		}
	}
	if(b>0){
		ans+=b-1;
		if(l>0){
			l--;
			ans++;
		}
		if(r>0){
			r--;
			ans++;
		}
	}
	coutd << "l:" << l << " r:" << r << " b:" << b <<  endl;
	cout << ans+min(l,r) << endl;
}



Measured memory_bytes: 768
from collections import deque
INF = float("inf")

N, M = map(int, input().split())

# i + 0*N -> (3の倍数)回で移動できるi
# i + 1*N -> (3の倍数+1)回で移動できるi
# i + 2*N -> (3の倍数+2)回で移動できるi

# 有向グラフなので、u -> vのみ （v -> u は通れない）
G = [[] for _ in range(3 * N)]
for _ in range(M):
    u, v = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append(v + N)
    G[u + N].append(v + 2 * N)
    G[u + 2 * N].append(v)

S, T = map(int, input().split())
S, T = S - 1, T - 1

ans = [INF] * (3 * N)
ans[S] = 0
dq = deque([S])

# BFS
while dq:
    now = dq.popleft()
    for next in G[now]:
        if ans[next] != INF:
            continue
        ans[next] = ans[now] + 1
        dq.append(next)

# 3の倍数回で移動できる、Tへの最短距離 = ans[T + 0*N]
if ans[T] != INF:
    print(ans[T] // 3)
else:
    print(-1)


Measured memory_bytes: 114952
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

//#define __DBG__


void solve(void){

  int N;
  cin >> N;
  
  string S[N];
  
  map<string,int> T;
  
  REP(i,N){
    cin >> S[i];
    if(T.count(S[i])){
      T.at(S[i])++;
    }
    else{
      T[S[i]]=1;
    }
  }
  
  int max_count=0;
  
  for(auto ptr:T){
    max_count=max(max_count,ptr.second);
  }
  
  vector<string> P;
  
  for(auto ptr:T){
    if(ptr.second==max_count){
      P.push_back(ptr.first);
    }
  }
  
  sort(ALL(P));
  
  REP(i,P.size()){
    cout << P.at(i) << endl;
  }

  return;
}

int main(int argc, const char * argv[]) {


    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}





Measured memory_bytes: 27120
A = int(input())
B = int(input())
C = int(input())
X = int(input())

pat_list = []
for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      price = 500 * a + 100 * b + 50 * c
      pat_list.append(price)
print(pat_list.count(X))

Measured memory_bytes: 13928