akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	static int[][]memo;
	static int s,n;
	static int[]a;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		s = sc.nextInt();
		a = sc.inArr(n);
		memo = new int[n][s+1];
		clear();
		int cnt = 0;
		for(int i=0;i<n;i++)
			cnt = add(cnt, nWays(i, 0));
		out.println(cnt);
		out.flush();
	}
	static void clear() {
		for(int[]b:memo)
			Arrays.fill(b, -1);		
	}
	static void print() {
		for(int[]b:memo)
			System.out.println(Arrays.toString(b));
	}
	static int nWays(int i,int sum) {
		if(i == a.length)
		{
			if(sum == s)
			{
				return 1;
			}
			return 0;
		}
		if(sum > s) return 0;
		int cnt = 0;
		if(sum == s)
		{
			cnt = add(1,nWays(i+1, sum));
		}else {
			if(memo[i][sum] != -1)
				return memo[i][sum];
			int take = nWays(i+1, sum+a[i]);
			int leave = nWays(i+1, sum);			
			cnt = add(take, leave);
		}
		return memo[i][sum] = cnt;
	}
	static final int mod = 998244353;
	static int add(int a,int b) {
		int c = a+b;
		if(c>=mod)
			c-=mod;
		return c;
	}
	static boolean isPalindrome(String s) {
		int l = s.length();
		char[] sa = s.toCharArray();
		for(int i=0;i<l/2;i++) {
			if(sa[i] != sa[l-i-1])
				return false;
		}
		return true;
	}

	static String reverse(String s) {
		int i = s.length();
		StringBuilder sb = new StringBuilder();
		while(i-->0) {
			sb.append(s.charAt(i));
		}
		return sb.toString();
	}
	static void merge(StringBuilder sb,Stack<Character> stack) {
		while(!stack.isEmpty())
			sb.append(stack.pop());		
	}
	static String max(String s,String s2) {
		if(s2.length() > s.length())
			return s2;
		return s;
	}

	static class Point extends java.awt.Point implements Comparable<Point>{
		public Point(int x,int y) {
			// TODO Auto-generated constructor stub
			super(x,y);
		}
		public String toString() {
			return x+" "+y;
		}
		@Override
		public int compareTo(Point p) {
			// TODO Auto-generated method stub
			if(x == p.x)
				return y - p.y;
			return x - p.x;
		}
		
	}
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public int[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(st.nextToken());
			}
			return a;
		}
	}

}

Measured memory_bytes: 82004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int>x(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }

  vector<int>A(N-K+1);
  for (int i = K-1; i < N; i++) {
    A.at(i-K+1) = x.at(i) - x.at(i-K+1);
    A.at(i-K+1) += min(abs(x.at(i)),abs(x.at(i-K+1)));
  }
  sort(A.begin(), A.end());
  cout << A.at(0) << endl;
}
 

Measured memory_bytes: 3656
import sys
from itertools import product
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(m)]
    P = list(map(int, input().split()))

    res = 0
    for pattern in product([0, 1], repeat=n):
        total = 0
        for i in range(m):
            cnt = 0
            for idx, p in enumerate(pattern):
                if p == 1 and idx + 1 in S[i][1:]:
                    cnt += 1
            if cnt % 2 == P[i]:
                total += 1
        if total == m:
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)

int n,m;
int a[50],b[50];

bool g[50][50];
bool vis[50];

void dfs(int v) {
	vis[v] = true;
	for (int v2 = 0; v2 < n; ++v2) {
		if (g[v][v2] == false) continue;
		if (vis[v2] == true) continue;
	dfs(v2);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--,b[i]--;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}

	int res = 0;

	for(int i=0;i<m;i++){
		g[a[i]][b[i]] = g[b[i]][a[i]] = false;

		for(int i=0;i<n;i++){
			vis[i] = false;
		}

		dfs(0);

		int cr = 0;
		for(int i=0;i<n;i++) if(!vis[i]) cr = 1;
		if(cr) res += 1;

		g[a[i]][b[i]] = g[b[i]][a[i]] = true;

	}

	cout << res;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool a[1<<20];
main()
{
	int s;
	cin>>s;a[s]=1;
	for(int i=2;;i++)
	{
		s=s%2?3*s+1:s/2;
		if(a[s])
		{
			cout<<i<<endl;
			return 0;
		}
		a[s]=1;
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int N=1e9;
int main()
{
    ll s;
    cin>>s;
    ll x2=N,x3=1,y2,y3;
    y3=s/N+1,y2=y3*N-s;
    if(y2==N)   {y2=0;y3--;}
    cout<<0<<" "<<0<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  rep(i,1,50001){
    if(i*108/100==n){
      cout<<i<<endl;
      break;
    }
    if(i==50000)ans3(false);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX 510000
using namespace std;
typedef long long ll;
const int mod = 998244353;
#define V vector<ll>
#define VV vector<V>
#define VVV vector<VV>

signed main(void)
{
	int N, A, X;
	cin >> N >> A;
	int x[N + 1];

	X = A;
	x[0] = 0;
	for (int i = 1; i <= (N); i++)
	{
		cin >> x[i];
		X = max(x[i], X);
	}
	VVV dp(N + 1, VV(N + 1, V(N * X + 1, 0)));
	dp[0][0][0] = 1;
	for (int j = 0; j <= N; j++)
	{
		for (int k = 0; k <= N; k++)
		{
			for (int s = 0; s <= N * X; s++)
			{
				if (s < x[j] && j >= 1)
					dp[j][k][s] = dp[j - 1][k][s];
				else if (k >= 1 && j >= 1)
					dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
			}
		}
	}
	ll ans = 0;
	for(int k = 1; k <= N; k++)
		ans += dp[N][k][k * A];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 55188
S = input()
ans = 'NO'

while True:
    if S[-7:] == 'dreamer':
        S = S[:-7]
        if S == '':
            ans = 'YES'
            break
    elif S[-6:] == 'eraser':
        S = S[:-6]
        if S == '':
            ans = 'YES'
            break
    elif S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[:-5]
        if S == '':
            ans = 'YES'
            break
    else:
        break

print(ans)

Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
    int iInputN, iInputX;
    int i, j, k;
    int count;

    while (1)
    {
        scanf("%d %d", &iInputN, &iInputX);
        if (iInputN == 0 && iInputX == 0) break;
        count = 0;
        for (i = 1; i <= iInputN; i++) {
            for (j = i + 1; j <= iInputN; j++) {
                for (k = j + 1; k <= iInputN; k++) {
                    if ((i + j + k) == iInputX) count++;
                }
            }
        }
        printf("%d\n", count);
    }

    return 0;
}


Measured memory_bytes: 2036
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
vector<int> g[114514];
bool used[114514];
int main() {
	IOS;
	ll n;
	cin >> n;
	map<ll, ll> mp;
	REP(i, n) {
		int x;
		cin >> x;
		mp[x] = i + 1;
	}
	vector<int> a(n), b(n);
	REP(i, n) {
		a[i] = (i + 1) * 30000;
		b[i] = (n - i) * 30000;
		a[i] += mp[i+1];
	}
	REP(i, n) {
		if (i)cout << " ";
		cout << a[i];
	}
	cout << endl;
	REP(i, n) {
		if (i)cout << " ";
		cout << b[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,k;
  cin>>n>>k;
  int a[n+1]={0};
  for(int i=0;i<k;i++){
   int d;
    cin>>d;
    for(int i=0;i<d;i++){
     int x;
      cin>>x;
      a[x]++;
    }
  }
   int count=0;
  for(int i=1;i<=n;i++)
  {
    if(a[i]==0)
      count++;
  }
  cout<<count<<"\n";
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> field = new ArrayList<>(Arrays.asList(0,0,0));
		long scoreCount = 0;
		int outCount = 0;
		int finishedGame = 0;
		try {
			int gameNumber = Integer.parseInt(br.readLine());
			while (finishedGame < gameNumber) {
				String line = br.readLine();
				if(line.equals("HIT")) {
					if(field.get(2)==1) {
						scoreCount++;
					}
					field.remove(2);
					field.add(0, 1);
				}else if(line.equals("OUT")) {
					outCount++;
					if (outCount == 3) {
						System.out.println(scoreCount);
						scoreCount = 0;
						outCount = 0;
					field =field.stream().map(a -> a =0).collect(Collectors.toList());
						finishedGame++;
					}
				}else if(line.equals("HOMERUN")) {
					scoreCount += 1 + field.stream().filter(base -> base==1).count();
					field =field.stream().map(a -> a =0).collect(Collectors.toList());
				}
			}
			
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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

const int INF = 10000;
vector<vector<char> > M(52, vector<char>(52, '#'));

// 解説見た。再帰を使ったdfs
int main() {
  int h, w;
  cin >> h >> w;
 
  int ans = 0;
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) {
      char c = s[j];
      if (c == '.') ans++;
      M[i + 1][j + 1] = c;
    }
  }

  vector<vector<int> > dist(52, vector<int>(52, INF));
  dist[1][1] = 1;

  queue<P> Q;
  Q.push(make_pair(1, 1));
  while(!Q.empty()) {
    P p = Q.front(),first;
    int y = p.first, x = p.second;  // それぞれ行、列
    int d = dist[y][x];
    Q.pop();

    if (M[y - 1][x] == '.' && dist[y - 1][x] == INF) {
      dist[y - 1][x] = d + 1;
      Q.push(make_pair(y - 1, x));
    }

    if (M[y + 1][x] == '.' && dist[y + 1][x] == INF) {
      dist[y + 1][x] = d + 1;
      Q.push(make_pair(y + 1, x));
    }

    if (M[y][x - 1] == '.' && dist[y][x - 1] == INF) {
      dist[y][x - 1] = d + 1;
      Q.push(make_pair(y, x - 1));
    }

    if (M[y][x + 1] == '.' && dist[y][x + 1] == INF) {
      dist[y][x + 1] = d + 1;
      Q.push(make_pair(y, x + 1));
    }
  }

  if (dist[h][w] != INF) {
    ans -= dist[h][w];
  } else {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
m[5]['= r'],W,z,k,i;f(i){m[k][i]=m[4][i]+47?0:m[k][i]?:1+f(i+(1+k%2*W)*(k/2?:-1));}main(t){for(scanf("%*d%d",&W);m[4][++i-~W]=~getchar(););for(;k--?:(t=k=3,--i);z=z<-t?-t:z)t-=f(i-~W);printf("%d",z);}

Measured memory_bytes: 78464
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      int[] a = new int[n];
      for(int i=0;i<n;i++){
        a[i] = Integer.parseInt(sc.next());
      }
      int[] b = new int[n];
      for(int i=0;i<n;i++){
        b[i] = Integer.parseInt(sc.next());
      }
      int[] c = new int[n-1];
      for(int i=0;i<n-1;i++){
        c[i] = Integer.parseInt(sc.next());
      }

      int ans = 0;

      for(int i=0;i<n;i++){
        ans += b[a[i]-1];
        if(i!=0 && a[i]==a[i-1]+1){
          ans += c[a[i-1]-1];
        }
      }



      System.out.println(ans);

    }
}


Measured memory_bytes: 21844
use std::io::*;
use std::collections::BTreeMap;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn main() {
    let n = read::<usize>();
    let s = read_vec_char();
    let mut map: BTreeMap<(Vec<char>,Vec<char>),usize> = BTreeMap::new();
    for i in 0..1<<n {
        let mut v1 = vec![];
        let mut v2 = vec![];
        for j in 0..n {
            if 1<<j & i != 0 {
                v1.push(s[j]);
            } else {
                v2.push(s[j]);
            }
        }
        *map.entry((v1,v2)).or_insert(0) += 1;
    }
    let mut map2: BTreeMap<(Vec<char>,Vec<char>),usize> = BTreeMap::new();
    for i in 0..1<<n {
        let mut v1 = vec![];
        let mut v2 = vec![];
        for j in 0..n {
            if 1<<j & i != 0 {
                v1.push(s[n+j]);
            } else {
                v2.push(s[n+j]);
            }
        }
        v1.reverse();
        v2.reverse();
        *map2.entry((v1,v2)).or_insert(0) += 1;
    }
    let mut ans = 0;
    for (k,v) in map.iter() {
        if let Some(x) = map2.get(k) {
            ans += v * x;
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 108796
#include <stdio.h>

int main(){
   int a,b;
   char s[5];
    
   scanf("%s",s);
   a=(s[0]-'0')*10+(s[1]-'0');
   b=(s[2]-'0')*10+(s[3]-'0');
   if (a>0 && a<13 && b>0 && b<13) puts("AMBIGUOUS");
   else if (a>0 && a<13 && (b==0 || b>12)) puts("MMYY");
   else if ((a==0 || a>12) && b>0 && b<13) puts("YYMM");
   else puts("NA");
   return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <queue>

using namespace std;

typedef long long ll;

int t;

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false);
	ll n, a, b;
	while (cin >> n >> a >> b) {
		if (a > b) swap(a, b);
		if ((b - a) % 2 == 0) {
			cout << (b - a) / 2 << endl;
		}
		else {
			ll ans = 0;
			if (a - 1 < n - b) {
				ans = a;
				b = b - a;
				a = 1;
				ans += (b - a) / 2;
			}
			else {
				ans = n - b + 1;
				a = a + (n - b + 1);
				b = n;
				ans += (b - a) / 2;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
dp = [ [0,1e18] for i in range(n+1) ]
for i in range(n):
  d = int(s[i])
  dp[i+1][0] = min(dp[i][0], dp[i][1])+d
  dp[i+1][1] = min(dp[i][0], dp[i][1]-2)+11-d
print(min(dp[n][0],dp[n][1]))

Measured memory_bytes: 157628
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int a[105];

signed main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	double m;
	int n;
	cin>>n>>m;
	int x=m;
	if(n<m)
	{
		cout<<"No"<<endl;
		return 0;
	}
	double ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ans+=a[i];
	}
	m=ans/(m*4);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if((double)a[i]>=m)
		{
			cnt++;
		}
	}
	puts(cnt>=x?"Yes":"No");
	return 0;
}

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

using ll = long long;

int H, W;
int N;
set<pair<int, int>> painted;

set<pair<int, int>> used;
ll ans[10];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> H >> W >> N;
	for (int i = 0; i < N; i++) {
		int x, y; cin >> x >> y;
		painted.emplace(x, y);
	}

	for (auto p : painted) {
		for (int x = p.first - 1; x <= p.first + 1; x++) {
			for (int y = p.second - 1; y <= p.second + 1; y++) {
				if (x - 1 < 1 || x + 1 > H || y - 1 < 1 || y + 1 > W || used.count({x, y})) {
					continue;
				}
				used.emplace(x, y);
				int has = 0;
				for (int a = x - 1; a <= x + 1; a++) {
					for (int b = y - 1; b <= y + 1; b++) {
						has += painted.count({a, b});
					}
				}
				ans[has]++;
			}
		}
	}

	ans[0] = ll(H-2) * (W-2);
	for (int c = 1; c < 10; c++) {
		ans[0] -= ans[c];
	}

	for (int c = 0; c < 10; c++) {
		cout << ans[c] << '\n';
	}

	return 0;
}


Measured memory_bytes: 47104
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n; cin>>n;
	vector<int> d(n);
	int ans = 0;
	REP(i,n) cin>>d[i];
	REP(i,n-1){
		FOR(j,i+1,n){
			ans += d[i]*d[j];
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from builtins import enumerate
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, k = map(int, input().split())
    p_s = [0] + list(map(int, input().split()))

    avr_s = [0]
    cumsum = 0
    for i in range(1, 1001):
        cumsum += i
        avr_s.append(cumsum / i)

    ans = 0
    val = 0
    for i in range(1, len(p_s)):
        val += avr_s[p_s[i]]
        if i < k:
            continue
        elif i == k:
            ans = val
        else:
            val -= avr_s[p_s[i - k]]
            ans = max(ans, val)

    print(ans)


# テストクラス


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """5 3
1 2 2 4 5"""
        output = """7.000000000000"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """4 1
6 6 6 6"""
        output = """3.500000000000"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10 4
17 13 13 12 15 20 10 13 17 11"""
        output = """32.000000000000"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 40076
n = int(input())
point_list = []
for i in range(n):
  x, y = map(int, input().split())
  point_list.append((x, y))

sabun_dict = {}

if n == 1:
  print(1)
  exit()

for i in range(n):
  for j in range(n):
    x = point_list[i][0] - point_list[j][0]
    y = point_list[i][1] - point_list[j][1]
    if x == 0 and y == 0:
      continue
    if (x, y) in sabun_dict:
      sabun_dict[(x, y)] = sabun_dict[(x, y)] + 1
    else:
      sabun_dict[(x, y)] = 1

max_v = max(sabun_dict.values())

print(n - max_v)


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

void run(void){
  char *s=(char *)calloc(100000+1,sizeof(char));
  scanf("%s",s);
  int l=0;
  int r=strlen(s)-1;
  int ans=0;
  while(l<r){
    if(s[l]==s[r]){
      l++;r--;
    } else if(s[l]=='x'){
      ans++;
      l++;
    } else if(s[r]=='x'){
      ans++;
      r--;
    } else {
      printf("-1\n");
      return;
    }
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int b, r, g, c, s, t;
	while(scanf("%d%d%d%d%d%d", &b, &r, &g, &c, &s, &t), b|r|g|c|s|t){
		int ans = b*15 + r*15 + g*7 + c*2 + b*5*13 + r*3*13;
		printf("%d\n", 100+ans-(t-b*5-r*3-s)*3);
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =
			new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

//		while(true) {
			String[] line = br.readLine().split(" ");
			int a = Integer.parseInt(line[0]);
			int b = Integer.parseInt(line[1]);
			int c = Integer.parseInt(line[2]);
			int count = 0;

			for(int i = a; i <= b; i++) {
				if(c % i == 0) {
				count++;
				}
			}
			System.out.println(count);
//		}
	}
}

Measured memory_bytes: 24412
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC50(void);
void ABC51(void);
void ABC52(void);
void ABC53(void);
void ABC54(void);
void ABC55(void);
void ABC56(void);
void ABC57(void);
void ABC58(void);
void ABC59(void);

int main(void){
    ABC55();
}

void ABC55(){
    long long int n,i,ans=1;
    int d=1e+9+7;
    cin>>n;
    for(i=1;i<=n;i++){
        ans*=i;
        if(ans>d)ans%=d;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
n,d = map(int,input().split())
a = [list(map(int, input().split())) for i in range(n)]
count = 0

for i in range(n-1):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (a[i][k] - a[j][k])**2
        if math.sqrt(dis) == int(math.sqrt(dis)):
            count += 1
print(count)


Measured memory_bytes: 9128
import sys
input = sys.stdin.readline

s = list(input().split())
stack=[]
for x in s:
    if x=="+":
        a=stack.pop()
        b=stack.pop()
        stack.append(a+b)
        continue
    if x=="*":
        a=stack.pop()
        b=stack.pop()
        stack.append(a*b)
        continue
    if x=="-":
        b=stack.pop()
        a=stack.pop()
        stack.append(a-b)
        continue
    stack.append(int(x))
print(stack[0])



Measured memory_bytes: 5604
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n, nmem;
	int x = 0;
	cin >> n;
	nmem = n;
	lp(8) {
		x += nmem % 10;
		nmem = nmem / 10;
	}
	if (n%x == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      String[] lines = br.readLine().split(" ");
      int r = Integer.parseInt( lines[0] );
      int c = Integer.parseInt( lines[1] );
      int[][] sheet = new int[r+1][c+1]; 
      int sumR = 0;
      int[] sumC = new int[c+1];
      Arrays.fill( sumC, 0 );

      for ( int i = 0; i < sheet.length; i++ ) {
        if ( i != (sheet.length-1) ) lines = br.readLine().split(" ");
        for( int j = 0; j < sheet[i].length; j++) {
          if( i == (sheet.length-1) ) {
            if( j == (sheet[i].length-1)) sheet[i][j] = sumR;
            else {
              sheet[i][j] = sumC[j];
              sumR += sheet[i][j];
            }
          }
          else if( j == (sheet[i].length-1) ) sheet[i][j] = sumR;
          else {
            sumR += (sheet[i][j] = Integer.parseInt(lines[j]));
            sumC[j] += sheet[i][j];
          }
        }
        sumR = 0;
      }

      System.out.println(
        Stream.of(sheet)
              .map( a -> Stream.of(a)
                               .collect(Collectors.mapping(b -> ArrayToString(b),
                                      Collectors.joining(""))) )
              .collect(Collectors.joining("\n"))
      );
    }
  }
  public static String ArrayToString(int[] a) {
      if (a == null)
          return "null";
      int iMax = a.length - 1;
      if (iMax == -1)
          return "[]";

      StringBuilder b = new StringBuilder();
      for (int i = 0; ; i++) {
          b.append(a[i]);
          if (i == iMax)
              return b.toString();
          b.append(" ");
      }
  }
}


Measured memory_bytes: 32132
f(x){scanf("%d",x);}a[100],l,r,p;main(c){for(;f(&r),c*=l=r;printf("%d\n",c)){for(;c=l;)f(a+--l);for(f(a);l<r&&!++c|a[p=l+r>>1]-*a;)a[p]<*a?r=p:(l=p+1);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
    int sx,sy,tx,ty;
    int dx,dy;
    cin >> sx >> sy >> tx >> ty;
    dx = tx-sx;
    dy = ty-sy;
    cout << std::string(dy,'U') << std::string(dx,'R') << std::string(dy,'D') << std::string(dx,'L');
    cout << 'L' << std::string(dy+1,'U') << std::string(dx+1,'R') << 'D';
    cout << 'R' << std::string(dy+1,'D') << std::string(dx+1,'L') << 'U';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int g=0;
int n;
cin >> n;
vector<vector<int>> b(n,vector<int>(2));
for(int i=0;i<n;i++){
  for(int p=0;p<2;p++){
    cin >> b.at(i).at(p);
  }
}
for(int i=0;i<n-2;i++){
  if(b.at(i).at(0)==b.at(i).at(1) &&
     b.at(i+1).at(0)==b.at(i+1).at(1) &&
     b.at(i+2).at(0)==b.at(i+2).at(1)){
    g++;
  }
}
if(g>0){ cout << "Yes" << endl;}
else{cout << "No" << endl;}
  
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <string.h>
 
int main(void){
    int n,i;
    int a = 0, b = 0;
    char s[101],t[101];
     
    scanf("%d",&n);
     
    for(i = 0;i < n; i++){
        scanf("%s %s",s,t);
        if(strcmp(s,t)>0) a+=3;
        else if(strcmp(s,t)<0) b+=3;
        else{
            a++;
            b++;
        }
    }
    printf("%d %d\n",a,b);
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
int INF = 1e9+7;


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

    int count = 0;
    for (int i=1; i<n-1; i++) {
        if (p[i-1] < p[i] & p[i] < p[i+1]) count++;
        if (p[i-1] > p[i] & p[i] > p[i+1]) count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

var b2i = map[bool]int{false: 0, true: 1}

func nextInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func main() {
	N := nextInt()
	dic := map[int]int{}

	for range make([]struct{}, N) {
		a := nextInt()
		dic[a]++
	}

	ans := 0
	for k, v := range dic {
		ans += v - k*b2i[v >= k]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	ll cur=1;
	ll ans = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i]<cur) continue;
		if(a[i]==cur)
		{
			cur++;
			continue;
		}
		ans+=(a[i]-1)/cur;
		if(cur==1) cur++;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long

using pi = pair<int, int>;

typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 2e5+100;
const int Mod = 1e9+7;

int arr[mxn], qs[mxn];
int bitOn[55];
map<int,int>Mp, cnt, op;
vector<int>Pi, Ans;
vector<int>G[mxn];
set<int>seet[mxn];

int main()
{
     ios::sync_with_stdio(false);
     int x, y, z, k;
     cin>>x>>y>>z>>k;
     vector<long long>v1(x), v2(y), v3(z);
     vector<long long>tmp, Ans;
     for(int i=0 ; i<x ; i++) cin>>v1[i];
     for(int i=0 ; i<y ; i++) cin>>v2[i];
     for(int i=0 ; i<z ; i++) cin>>v3[i];

     for(int i=0 ; i<x ; i++){
        for(int j=0 ; j<y ; j++){
            tmp.push_back(v1[i]+v2[j]);
        }
     }

     sort(tmp.rbegin(), tmp.rend());

     int sz1 = tmp.size();
     int sz = min(3000, sz1);
     for(int i=0 ; i<z ; i++){
        for(int j=0 ; j<sz ; j++){
            Ans.push_back(tmp[j]+v3[i]);
        }
     }
     sort(Ans.rbegin(), Ans.rend());
     for(int i=0 ; i<k ; i++) cout<<Ans[i]<<endl;

     return 0;
}




Measured memory_bytes: 57704
#include <iostream>
#include <vector>

void Eratosthenes(int N, std::vector<bool> &is_prime)
{
    is_prime.clear();
    for(int i=0; i<N+1; i++) is_prime.push_back(true);
    is_prime[0] = false; is_prime[1] = false;

    for(int i=2; i<=N; i++){
        if(is_prime[i] == false) continue;
        for(int j=2; j<N; j++){
            if(i*j > N) break;
            is_prime[i*j] = false;
        }
    }
}

int main()
{
    int Q;
    std::cin >> Q;
    std::vector<int> l(Q), r(Q);
    for(int i=0; i<Q; i++) scanf(" %d %d", &l[i], &r[i]);

    std::vector<bool> is_prime;
    Eratosthenes(1e+5, is_prime);
    std::vector<bool> is_like(1e+5 + 1, false);
    std::vector<int> sum(1, 0);
    for(int i=1; 2*i+1 <= 1e+5; i++){
        if(is_prime[2*i+1] == true && is_prime[i+1] == true) is_like[2*i+1] = true;
    }
    for(int i=1; i<=1e+5; i++){
        if(is_like[i] == true) sum.push_back(sum.back()+1);
        else sum.push_back(sum.back());
    }

    for(int i=0; i<Q; i++) printf("%d\n", sum[r[i]] - sum[l[i]-1]);
}

Measured memory_bytes: 1916
function main(input) { 
  var continuityNum = input.split(" ")[0];
  var selectNum = input.split(" ")[1];

  var nowNum = 1;
  var endFlg = 0;
  
  var count = 0;
  while(1){
    var judge　= nowNum;
    if(Number(judge) + Number(selectNum) -1 <= continuityNum){
        nowNum++;
      	count++;
   	}else{
        console.log(count);
      	break;
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 7372
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <deque>
#include <algorithm>
#include <math.h>
#include <random>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define double long double
#define Matrix vector<vector<int> >
#define kektor vector

using namespace std;

typedef long long ll;

int RandInt(int min, int max) {
  if (max < min) {
    return 0;
  }
  random_device rd;
  mt19937 mt(rd());
  uniform_int_distribution<int> dist(min, max);
  return dist(mt);
}

const int maxn = 1e4, mod = 1e9 + 7;
bool debug = false;
int n;
int dp[maxn][2], cnt[maxn][2];

void solve()  {
    cin >> n;
    for (int j = 0; j < 2; ++j) {
        for (int i = 0; i < n; ++i) {
            cin >> cnt[i][j];
        }
    }
    dp[0][0] = cnt[0][0];
    dp[0][1] = dp[0][0] + cnt[0][1];
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 2; ++j) {
            if (j == 0) {
                dp[i][0] = dp[i - 1][0] + cnt[i][0];
            } else {
                dp[i][1] = max(dp[i - 1][1] + cnt[i][1], dp[i - 1][0] + cnt[i - 1][1] + cnt[i][1]);
            }
        }
    }
    cout << dp[n - 1][1];
}

signed main() {
    /*!

    !*/
    cout.precision(10);
    cout << fixed;
    if (!debug) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
    return 0;
}


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

main(){
    int H, W;
    string S[55];
    string Result[55];

    cin >> H >> W;

    for (int i = 1; i <= H;i++) cin >> S[i];
    for (int i = 1; i <= W;i++) S[0] += '.';
    for (int i = 1; i <= W;i++) S[H+1] += '.';

    for (int i = 1; i <= H; i++){
        string befores = S[i-1];
        string currents = S[i];
        string afters = S[i+1];
        for (int j = 0; j < W; j++){
            if (currents[j] == '.'){
                int count = 0;
                if (j > 0){
                    if (befores[j-1] == '#') count++;
                    if (currents[j-1] == '#') count++;
                    if (afters[j-1] == '#') count++;
                }
                if (befores[j] == '#') count++;
                if (currents[j] == '#') count++;
                if (afters[j] == '#') count++;
                if (j < W - 1){
                    if (befores[j+1] == '#') count++;
                    if (currents[j+1] == '#') count++;
                    if (afters[j+1] == '#') count++;
                }
                string countc = to_string(count);
                Result[i] += countc;
            }
            else{
                Result[i] += "#";
            }
        }
    }

    for(int i = 1;i <= H;i++) cout << Result[i] << endl;

    return 0;
} 

Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String args[]) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(reader.readLine());
			boolean flag = false, flag2 = false;
			for(int i = 0;i < n;i++) {
				String t = reader.readLine();
				String u = reader.readLine();
				if(t.length() > 80 || u.length() > 80)
					flag = true;
				String s[] = {t, u};
				int j = s[0].length()-1 >= s[1].length()-1 ? s[0].length()-1 : s[1].length()-1;
				int k = s[0].length()-1 <= s[1].length()-1 ? s[0].length()-1 : s[1].length()-1;
				int l = s[0].length()-1 >= s[1].length()-1 ? 0 : 1;
				int o;
				int a[][] = {new int[j+1], new int[k+1]};
				for(int m = 0;m < j+1;m++) {
					a[0][m] = s[l].charAt(m)-'0';
				}
				int f = Math.abs(l-1);
				for(int m = 0;m < k+1;m++) {
					a[1][m] = s[f].charAt(m)-'0';
				}
				while(j>=0) {
					if(k >= 0)
						o = a[1][k];
					else
						o = 0;
					a[0][j] = a[0][j] + o;
					if(a[0][j]>9) {
						if(j>0) {
							a[0][j] %= 10; 
							a[0][j-1]++;
						}
						else if(j==0){
							flag2 = true;
							break;
						}
					}
					j--;
					k--;
				}
				if(flag || a[0].length +1 > 80 && flag2)
					System.out.print("overflow");
				else {
					for(int q = 0;q < a[0].length;q++) {
						System.out.print(a[0][q]);
					}
				}
				System.out.println("");
				flag = false;
				flag2 = false;
			}
		}
		catch(IOException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16896
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	long long n, a, b; cin >> n >> a >> b;
	long long t = (a + b) / 2;
	if (t - a == b - t) {
		cout << t - a << endl;
		return 0;
	}
	long long ans = min(b - 1, n - a);
	ans = min(ans, a + (b - a + 1) / 2 - 1);
	ans = min(ans, (n - b + 1) + n - (a + (n - b + 1) + n) / 2);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi pair<ll,ll>
#define pii pair<pi,ll>
#define fr freopen("in.txt","r",stdin)
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define f first
#define s second

int main() {
    ll N,K;
    cin >> N >> K;
    ll ans = 1;
    rep(j,N) {
        ans = ans + min(ans,K);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int n, p;

	while(true){
		scanf("%d %d\n",&n, &p);
		if(n==0 && p==0){return 0;}
		int max = p;
		int* player = new int[n];
		for(int i=0; i<n; i++){ player[i] = 0;}
		
		for(int i=0; i<1000000; i++){
			if(p>0){
				p--;
				player[i%n]++;
			}
			else{
				p = player[i%n];
				player[i%n] =0;
			}
			if(player[i%n] == max){
				cout << i%n << endl;
				break;
			}
		}
		delete[] player;
	}	
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;
Node *nil;
Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}
void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}
void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
void deleteFirst(void) {
  deleteNode(nil->next);
}
void deleteLast(void) {
  deleteNode(nil->prev);
}
void deleteKey(int key) {
  deleteNode(listSearch(key));
}
void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
int main(void) {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') insert(key);
    else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L') deleteLast();
      } else deleteKey(key);
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 32940
#include<iostream>

int main()
{
    int i, count, in, max = -1000000, min = 1000000;
    long int sum = 0;

    std::cin >> count;

    for (i = 0; i < count; i++)
    {
        std::cin >> in;
        sum += in;
        if (max < in) max = in;
        if (min > in) min = in;
    }
    std::cout << min << " " << max << " " << sum << std::endl;

    return 0;
}


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


int main() {
    string A, B;
    cin >> A >> B;

    if (A.size() > B.size()) {
        cout << "GREATER" << endl;
    } else if (A.size() < B.size()) {
        cout << "LESS" << endl;
    } else if (A.size() == B.size()) {
        for (int i = 0; i < A.size(); ++i) {
            if (A[i] > B[i]) {
                cout << "GREATER" << endl;
                return 0;
            } else if (A[i] < B[i]) {
                cout << "LESS" << endl;
                return 0;
            } else if (A[i] == B[i])
                if (i == A.size()-1) {
                    cout << "EQUAL" << endl;
                }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n; cin >> n;
	ll ans = 0;
	rep(i, 1, n){
		if(i%3 != 0 && i%5 != 0){
			ans += i;
		}
	}
	print(ans)
	return 0;
}

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

int main(){
  int N,sum;
  cin >> N;
  int M=N;
  sum=0;
  while(N>0){
    sum += N%10;
    N /= 10;
  }
  if(M%sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=sorted(map(int,input().split()),reverse=True)
m=n-1
for i in range(n//2):
    if aa[2*i]!=m or aa[2*i+1]!=m:
        print(0)
        sys.exit()
    m-=2
print((2**(n//2))%(10**9+7))

Measured memory_bytes: 14004
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		for (int i = 1;; i++) {
			if (i * i > n) {
				System.out.println((i - 1) * (i - 1));
				return;
			}
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#define N 400
using namespace std;

int n, a, b, c, m1, m2, mn = 1e9, d[805][805];
int main()
{
	int i, j;
	cin >> n >> m1 >> m2;
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N; j++) {
			d[i][j] = 1e9;
		}
	}
	d[0][0] = 1;
	while (n--) {
		scanf("%d %d %d", &a, &b, &c);
		for (i = N; i >= 0; i--) {
			for (j = N; j >= 0; j--) {
				if (d[i][j] < 1e9) {
					d[i + a][j + b] = min(d[i + a][j + b], d[i][j] + c);
				}
			}
		}
	}
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			if (i % m1 == 0 && j % m2 == 0 && i / m1 == j / m2) mn = min(mn, d[i][j]);
		}
	}
	if (mn == 1e9) mn = 0;
    cout << mn - 1 << endl;
    return 0;
}

Measured memory_bytes: 1536
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ce = [[0] * 10 for i in range(10)]
for i in range(1,n+1):
    tmp = str(i)
    a = int(tmp[0]); b = int(tmp[-1])
    ce[a][b] += 1
res = 0
for i in range(10):
    for j in range(10):
        res += ce[i][j] * ce[j][i]
print(res)

Measured memory_bytes: 66536
import sys
input = sys.stdin.readline

def main():
    N, M = (int(_) for _ in input().split())
    A = sorted([int(_) for _ in input().split()])
    BC = sorted([[int(_) for _ in input().split()] for __ in range(M)], key=lambda x:-x[1])

    itr = 0
    for i in range(N):
        if itr >= M: break
        if A[i] >= BC[itr][1]:
            break
        A[i] = BC[itr][1]
        BC[itr][0] -= 1
        if BC[itr][0] == 0:
            itr += 1

    print(sum(A))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 30948
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    string N;
    cin >> N;
    if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    n=int(input())
    u,k,v=0,0,[[] for _ in range(n+1)]
    for i in range(n):
        l=list(map(int,input().split()))
        u=l[0]
        for j in l[2:]:
            v[u].append(j)
    d=[0]*(n+1)
    f=[0]*(n+1)

    def dfs(s,t):
        d[s]=t
        for i in v[s]:
            if d[i]==0:
                t=dfs(i,t+1)
        f[s]=t+1
        return t+1

    s,t=1,1
    while 0 in d[1:]:
        T=dfs(s,t)
        for i in range(1,n+1):
            if d[i]==0:
                s=i
                t=T+1
                break

    for i in range(1,n+1):
        print(i,d[i],f[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 5716
import itertools
N, M = map(int, input().split())
K = []
S = []
for i in range(M):
    temp = list(map(int, input().split()))
    K.append(temp[0])
    S.append(temp[1:len(temp)])
p = list(map(int, input().split()))

L = list(itertools.product([0,1], repeat=N))
ans=0
for l in L:
    i=0
    ans_count = 1
    for s in S:
        c=0
        for j in range(K[i]):
            c += l[s[j]-1]
        if c%2!=p[i]:
            ans_count=0
        i+=1
    ans+=ans_count
print(ans)

Measured memory_bytes: 3188