akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    int ans = -1;
    // [i][j] start
    rep(i,h) {
        rep(j,w) {
            if (s[i][j] == '#') continue;

            vector<vector<int>> dist(h, vector<int> (w,-1));
            dist[i][j] = 0;
            queue<pair<int,int>> q;
            q.push(make_pair(i,j));

            while (!q.empty()) {
                int x = q.front().first;
                int y = q.front().second;
                q.pop();
                rep(d,4) {
                    int nx = x+dx[d];
                    int ny = y+dy[d];
                    if (nx < 0 || nx > h-1 || ny < 0 || ny > w-1) continue;
                    if (s[nx][ny] == '#') continue;
                    if (dist[nx][ny] != -1) continue;

                    dist[nx][ny] = dist[x][y]+1;
                    q.push(make_pair(nx,ny));
                }
            }
            rep(k,h) {
                rep(l,w) {
                    ans = max(ans, dist[k][l]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef unsigned long long ull;

ull mypow(ull x, ull n) {
  if(n == 0ull) {
    return 1ull;
  } else if(n&1ull) {
    ull t = mypow(x, (n-1ull)/2ull);
    return t*t*x;
  } else {
    ull t = mypow(x, n/2ull);
    return t*t;
  }
}

const ull B = 127;
const int BN_SIZE = 1000006;
ull Bn[BN_SIZE];
int n, m;
string s;
set<ull> vis;

int main() {
  Bn[0] = 1ull;
  for(int i = 1; i < BN_SIZE; ++i) Bn[i] = Bn[i-1] * B;

  while(cin >> n >> m) {
    cin >> s;
    ull h = s[0];
    int l, r;
    l = 0; r = 1;
    vis.clear();
    while(m--) {
      string q;
      cin >> q;
      if(0) {
      } else if(q == "L++") {
	h = h - s[l] * Bn[l];
	++l;
      } else if(q == "L--") {
	--l;
	h = h + s[l] * Bn[l];
      } else if(q == "R++") {
	h = h + s[r] * Bn[r];
	r++;
      } else if(q == "R--") {
	r--;
	h = h - s[r] * Bn[r];
      }
      vis.insert(h * Bn[n-l]);
    }
    cout << vis.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 23348
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define mp make_pair
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
	{
		return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
	}
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
	{
		x=0;static char ch;T f=1;
		for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
		for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
		x*=f;
	}

	template<typename T>inline void write(T x,char ch='\n')
	{
		if(!x)*nowps++='0';
		if(x<0)*nowps++='-',x=-x;
		static uint32 sta[111],tp;
		for(tp=0;x;x/=10)sta[++tp]=x%10;
		for(;tp;*nowps++=sta[tp--]^48);
		*nowps++=ch;
	}
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("water.in","r",stdin);
	freopen("water.out","w",stdout);
#endif
}

const int MAXN=(1<<15)+7;

static int ed[17],n,m;

inline void init()
{
	read(n);read(m);
	static int u,v;
	Rep(i,1,m)read(u),read(v),ed[u-1]|=1<<v-1;
}

static int mx,dp[MAXN];

const int mod=1e9+7;

inline int ad(int u,int v){return(u+=v)>=mod?u-mod:u;}

inline void solve()
{
	mx=(1<<n)-1;dp[0]=1;
	static int x,cnt,sm;
	Rep(i,2,mx)if((i&1) == ((i>>1)&1))
		for(x=i;x;x=(x-1)&i)if((x&1) == ((x>>1)&1)&&dp[i^x])
		{
			cnt=1;
			Rep(j,0,n-1)if(i&(1<<j))
			{
				if(x&(1<<j))cnt=((uint64)cnt<<
					__builtin_popcount(ed[j]&(i^x)))%mod;
				else cnt=(uint64)cnt*((1<<
					__builtin_popcount(ed[j]&x))-1)%mod;
			}
			dp[i]=ad(dp[i],(uint64)cnt*dp[i^x]%mod);
			//cerr<<i<<' '<<x<<' '<<dp[i]<<endl;
		}
	static int ans=1;
	Rep(i,1,m)ans=ad(ans,ans);
	printf("%d\n",ad(ans,mod-dp[mx]));
}

int main()
{
    init();
    solve();
    return 0;
}


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

int main() {
    ll n, m, w, v, dp[200000], ans(0);
    cin >> n >> m;
    for (ll i = 0; i < n; i++) {
        cin >> w >> v;
        for (ll j = m; j >= w; j--) {
            dp[j] = max(dp[j], dp[j-w]+v);
        }
    }
    for (ll i = 0; i <= m; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4376
#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
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005,N1=2005;
int x[N],y[N];
char c[N];
int a[N1][N1],pre[N1][N1];
int fun(int x1,int y1,int x2,int y2)
{
  if(x2<0 || y2<0) return 0;
  if(x1==0 && y1==0) return pre[x2][y2];
  else if(!x1) return pre[x2][y2]-pre[x2][y1-1];
  else if(!y1) return pre[x2][y2]-pre[x1-1][y2];
  else return pre[x2][y2]-pre[x2][y1-1]-pre[x1-1][y2]+pre[x1-1][y1-1];
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,k;
  cin>>n>>k;
  rep(i,1,n+1)
    {
      cin>>x[i]>>y[i]>>c[i];
      if(c[i]=='B') y[i]+=k;
      int x1=x[i]%(2*k),y1=(y[i]%(2*k));
      a[x1][y1]++;
    }
  rep(i,0,2*k)
    rep(j,0,2*k)
    {
      if(i==0 && j==0) pre[i][j]=a[i][j];
      else if(!i) pre[i][j]=pre[i][j-1]+a[i][j];
      else if(!j) pre[i][j]=pre[i-1][j]+a[i][j];
      else
    	pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+a[i][j];
    }
  int ans=0;
  rep(i,0,k)
    rep(j,0,k)
    {
      int tmp=fun(i,j,i+k-1,j+k-1)+fun(i+k,j+k,2*k-1,2*k-1)+fun(0,0,i-1,j-1)+fun(i+k,0,2*k-1,j-1)+fun(0,j+k,i-1,2*k-1);
      ans=max(ans,max(tmp,n-tmp));
    }
  cout<<ans<<endl;
  return 0 ;
}


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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 300, MAXN = 300;
struct edge
{
	int u,v;
	ll cap,flow;
};
vector<edge>e;

vector<int>graph[maxn];

int dist[maxn];
int ptr[maxn];


void add_edge(int u , int v, ll cap)
{
	edge e1 = {u,v,cap,0LL};
	edge e2 = {v,u,0LL,0LL};

	graph[u].push_back(e.size());
	e.push_back(e1);
	
	graph[v].push_back(e.size());
	e.push_back(e2);
}


bool bfs(int s, int t)
{
	memset(dist,-1, sizeof(dist));
	queue<int>q;
	q.push(s);
	dist[s] = 0;
	while(q.size() && dist[t] == -1)
	{
		int u = q.front();
		q.pop();

		for(int i = 0; i < graph[u].size(); i++)
		{
			int id = graph[u][i];
			int v = e[id].v;

			if(dist[v] == -1 && e[id].cap > e[id].flow)
			{
				q.push(v);
				dist[v] = dist[u] + 1;
			}
		}
	}

	return dist[t] != -1;
}

ll dfs(int u , ll flow, int t)
{
	if(!flow)
		return 0;
	if(u == t)
		return flow;
	for(; ptr[u] < graph[u].size(); ptr[u]++)
	{
		int id = graph[u][ptr[u]];
		int v = e[id].v;

		if(dist[v] != dist[u] + 1)
			continue;
		
		ll pushed = dfs(v, min(flow, e[id].cap - e[id].flow), t);
		
		if(pushed)
		{
			e[id].flow += pushed;
			e[id^1].flow -= pushed;
			return pushed;
		}

	}
	return 0;
}


ll dinic(int s, int t)
{
	ll ans = 0;
	while(bfs(s,t))
	{
		memset(ptr,0,sizeof(ptr));
		while(ll pushed = dfs(s, (1LL << 55), t) )
			ans += pushed;
	}
	return ans;
}


ll v[MAXN + 5];
int main(){
	ios::sync_with_stdio(0);
	//cin.tie(0); cout.tie();
	int N;
	cin >> N;
	ll sum = 0;
	for(int i = 2; i <= N+1; i++) {
		cin >> v[i];
		if(v[i] > 0) sum += v[i];
	}


	for(int i = 2; i <= N+1; i++){
		if(v[i] >= 0) add_edge(i, N+2, v[i]);
		else add_edge(1, i, -v[i]);
	}

	for(int i = 1; i <= N; i++)
		for(int j = i+i; j <= N; j+=i)
			add_edge(i+1, j+1, (1LL << 50));

	ll ans = dinic(1, N+2);

	cout << sum - ans << "\n";
	return 0;
}

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

int main(){

int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
int64_t ans;
if(a+b<=c*2){
    ans=a*x+b*y;
}
else{
if(x>y){
    ans+=y*2*c;
    if(a<2*c){
      ans+=a*(x-y);
    }
    else{
      ans+=2*(x-y)*c;
    } 
}
if(y>=x){
     ans+=x*2*c;
     if(b<2*c){
      ans+=b*(y-x);
     }
    else{
      ans+=2*(y-x)*c;
    }     
}
}  
  
cout << ans << endl;
    return 0;  
  

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define R register

typedef long long LL;

const int MN = 2e5 + 5;

inline int read(){
	R int x; R bool f; R char c;
	for (f = 0; (c = getchar()) < '0' || c > '9'; f = c == '-');
	for (x = c ^ '0'; (c = getchar()) >= '0' && c <= '9'; x = (x << 1) + (x << 3) + (c ^ '0'));
	return f ? -x : x;
}

int n;
LL sum[MN], ans;

inline int solve(int l, int r) {
	R int mid, ll, rr, pos;
	for (ll = l, rr = r; ll < rr; ) {
		mid = ll + rr >> 1;
		if (sum[mid] - sum[l - 1] < sum[r] - sum[mid]) ll = mid + 1;
		else rr = mid - 1;
	}
	R LL res = sum[n];
	for (R int i = std::max(l,ll - 2); i <= ll + 2 && i < r; ++i) {
		if (abs(sum[i] - sum[l - 1] - (sum[r] - sum[i])) < res){
			res = abs(sum[i] - sum[l - 1] - (sum[r] - sum[i])) ;
			pos = i;
		}
	}
	return pos;
}

int main() {
	n = read();
	for (R int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + read(); ans = sum[n];
	for (R int i = 2; i < n; ++i) {
		R int x, y;
		x = solve(1, i), y = solve(i + 1, n);
		R LL max, min;
		max = std::max(sum[x], sum[i] - sum[x]);
		max = std::max(max, std::max(sum[n] - sum[y], sum[y] - sum[i]));
		min = std::min(sum[x], sum[i] - sum[x]);
		min = std::min(min, std::min(sum[n] - sum[y], sum[y] - sum[i]));
		ans = std::min(ans, max - min);
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define l 100
#define INFTY (1<<21)
#define max 100000

int n , m[l][l];
int d[l];

int head,tail;
int q[max];

void initialize()
{
	head = tail = 0;
}

int isEmpty()
{
	if(head == tail)
	{
		return 1;
	}
	else{
		return 0;
	}
}

int isFull()
{
	if(head == (tail + 1) % max)
	{
		return 1;
	}
	else{
		return 0;
	}
}

void enqueue(int x)
{
	if(isFull() == 1)
	{
		fprintf(stderr,"エラー");
	}
	else{
		q[tail] = x;
		if(tail + 1 == max)
		{
			tail = 0;
		}
		else{
			tail++;
		}
	}
}

int dequeue()
{
	int x;
	if(isEmpty() == 1)
	{
		fprintf(stderr,"エラー");
		exit(0);
	}
	else{
		x = q[head];
		if(head + 1 == max)
		{
			head = 0;
		}
		else{
			head++;
		}
		return x;
	}
}

void bfs(int s)
{
	enqueue(s);
	for(int i= 0; i <n; i++)
	{
		d[i] = INFTY;
	}
	d[s] = 0;
	int u;
	while(!isEmpty())
	{
		u = dequeue();
		for( int v = 0; v < n; v++)
		{
			if(m[u][v] == 0){continue;}
			if(d[v] != INFTY){continue;}
			d[v] = d[u] + 1;
			enqueue(v);
		}
	}
	for(int i = 0; i < n; i++)
	{
		printf("%d ",i+1);
		if(d[i] == INFTY) printf("-1\n");
		else printf("%d\n",d[i]);
	}
}

int main(void)
{
	int u, k,v;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			m[i][j] = 0;
		}
	}
	for( int i = 0; i < n; i++)
	{
		scanf("%d",&u);
		scanf("%d",&k);
		u--;
		for(int j = 0; j < k; j++)
		{
			scanf("%d",&v);
			v--;
			m[u][v] = 1;
		}
	}
	bfs(0);
	return 0;
}


Measured memory_bytes: 2108
/**
 * Я слил Atcoder Beginner Contest 172, решив всего две задачи!
 * Я не могу апнуть синего!
 * Я постоянно сливаю раунды, либо не решив тупую задачу, либо набрав штрафа!
 * Я постоянно уступаю всем своим друзьям и знакомым в контестах и нахожу этому оправдания!
 * Я постоянно придумываю сложные неверные решения к простым задачам!
 * -------------------------------------------------------------
 * -Решать сложные задачи
 * -Участвовать в контестах
 * -Делать виртуальные соревнования
 * -------------------------------------------------------------
 * Не уберу это, пока не начну нормально решать задачи, а не заниматься ерундой!!!
**/
  
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 200010;
const int INF = 1e8;
const ll LL_INF=1e10;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
 // cin>>questions;
 
 while(questions--)
 {
   
   int a,b,c;
   cin>>a>>b>>c;
   int k;
   cin>>k;
   while(k && b<=a)
   {
             b*=2;
             k--;
   }
   while(k && c<=b) 
   {
             c*=2;
             k--;
   }
   if(b>a && c>b) cout<<"Yes";
   else cout<<"No";
   
   
          
          
          
         
 }
 
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int ma=1e7;
  vector<bool>sosu(ma,1);
  sosu[0]=sosu[1]=0;
  for(int i=4;i<ma;i+=2)sosu[i]=0;
  for(int i=3;i<ma;i+=2)
    for(int j=i*3;j<ma;j+=i*2)sosu[j]=0;
  int in;
  while(cin>>in,in){
    while(1){
      if(sosu[in]&&sosu[in-2]&&sosu[in-6]&&sosu[in-8])break;
      in--;
    }
    cout<<in<<endl;
  }
}

Measured memory_bytes: 2328
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int MOD = (int)1e9 + 7;

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

    void run() {

        int n = sc.nextInt();
        long m = sc.nextLong();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) {
            arr[i] = sc.nextInt() - 1;
        }

        boolean[] flag = new boolean[n];
        flag[0] = true;


        int pre = 0;
        int cle = 1;

        List<Integer> list = new ArrayList<>();
        list.add(0);

        int idx = 0;
        while (true) {
           int next = arr[idx];
            if (flag[next]) break;
            flag[next] = true;
            list.add(next);
            idx = next;
        }

//        System.out.println(arr[idx]);

//        for (int i=0; i<n; i++) System.out.println(flag[i]);

//        System.out.println(list);

        pre = list.indexOf(arr[idx]);
        cle = list.size() - pre;

//        System.out.println(cle);

        if (m < pre) {
            System.out.println(list.get((int)m) + 1);
        } else {
            long rem = (m - pre) % cle;
            System.out.println(list.get(pre+(int) rem) + 1);

        }


    }

}



Measured memory_bytes: 60896
from itertools import product
H, W, K = map(int,input().split())
C = [input() for _ in range(H)]

ans = 0
for row_bit in product(range(2), repeat=H):
    for col_bit in product(range(2), repeat=W):
        cnt = 0
        for row in range(H):
            for col in range(W):
                if C[row][col] == "#" and (not (row_bit[row] or col_bit[col])):
                    cnt += 1
        
        if cnt == K:
            ans += 1

print(ans)

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

int main(void) {
	
	int n,t;
	int tn[n+2];
	int vn[n+2];
	
	scanf("%d",&n);
	scanf("%d",&t);
	for (int i=1;i<=n;i++){
		scanf("%d",&tn[i]);
	}
	
	for (int i=1;i<=n-1;i++){
		vn[i] = min(tn[i+1] - tn[i],t);
	}
	
	int ans;
	
	for (int i=1;i<=n-1;i++){
		ans = ans + vn[i];
	}
	
	printf("%d\n",ans+t);
	
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    ll a,b;
    cin >> a >> b;
    if(a == 1 || b == 1){
        cout << 1 << endl;
    }else{
        cout << (a*b+1) / 2;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll n, k, f[4010], t[1050], mi[4010], m = 998244353;

ll qexp(ll a, ll b) {
    a %= m;
    ll res = 1, base = a;
    while (b) {
        if (b & 1) {
            res *= base;
            res %= m;
        }
        base *= base;
        base %= m;
        b >>= 1;
    }
    return res % m;
}

inline ll choose(ll n, ll k) {
	if (n < k or k < 0 or n < 0) return 0;
	return (((f[n] * mi[k]) % m) * mi[n-k])%m;
}

ll add(ll a, ll b) {
	b %= m;
	a += b;
	a %= m;
	return a;
}

int main() {
	fastio;
	cin >> k >> n;
	f[0] = 1; FOR(i, 1, 4005) f[i] = (i * f[i-1]) % m;
	mi[4005] = qexp(f[4005], m-2); DEC(i, 4004, 0) mi[i] = (mi[i+1] * (i+1))%m;
	t[0] = 1; FOR(i, 1, 1040) t[i] = (2 * t[i-1]) % m;
	FOR(i, 2, 2*k) {
		ll p = (i-1)/2 - max(0LL, i-k-1), ans = 0;
		if (i&1) {
			FOR(q, 0, p) {
				ans = add(ans, ((choose(n+k-2*p-1, q+k-2*p-1) * choose(p, q)) % m) * t[q]);
			}
		} else {
			FOR(q, 0, p) {
				ans = add(ans, ((t[q]*choose(p, q))%m) * add(choose(n+k-2*p-2, q+k-2*p-2), choose(n+k-2*p-3, q+k-2*p-2)));
			}
		}
		cout << ans << "\n";
	}
}


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

#define MAX_V 100
#define INF (1<<24)

struct edge { int to, cap, cost, rev;};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init_edge(){
  for(int i=0;i<V;i++)G[i].clear();
}

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update=true;
    while(update){
      update=false;
      for(int v=0;v<V;v++){
        if(dist[v]==INF)continue;
        for(int i=0;i< (int) G[v].size();i++){
          edge &e = G[v][i];
          if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v;
            preve [e.to] = i;
            update = true;
          }
        }
      }
    }
    if(dist[t]==INF)return -1;
    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*dist[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

void init(){
  for(int i=0;i<MAX_V;i++){
    G[i].clear();
  }
}

int main(){
  int N,M;
  int a[20],b[20];
  while(1){
    init();
    scanf("%d %d",&N,&M);
    if(N==0&&M==0)break;
    V=N+M+2;
    for(int i=0;i<N;i++){
      scanf("%d",&a[i]);
      add_edge(N+M,i,1,0);
    }
    for(int i=0;i<M;i++){
      scanf("%d",&b[i]);
      add_edge(N+i,N+M+1,1,0);
    }


    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        int d=abs(a[i]-b[j])-30;
        int k=abs(a[i]-b[j])*d*d;
        add_edge(i,N+j,1,-k);
      }
    }
    cout<< -min_cost_flow(N+M,N+M+1,min(N,M)) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1244
X, N = input().split()
p = input().split()
X = int(X)
N = int(N)
min = 101
ans = -100
for i in range(-101, 102):
    if str(i) in p:
        continue
    a = abs(i - X)
    if a < min:
        min = a
        ans = i
print(ans)

Measured memory_bytes: 9188
dp = [0]*(110000)
A = int(input())
h = list(map(int,input().split()))
for i in range(1,A):
    if i == 1:
        dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[A-1])

Measured memory_bytes: 14692
#include <stdio.h>

int A[20];
int n;

int solve(int p, int t);
int sort(void *a, void *b);

int main(void) {
	int i, q, M, j;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	
	qsort(A, n, sizeof(A[0]), sort);
	
	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &M);
		for (j = 0; A[j] > M; ++j);
		if (solve(j - 1, M)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

int solve(int p, int t) {
	if ((p == n) || (t == 0)) return t == 0;
	if ((t >= A[p + 1]) && (solve(p + 1, t - A[p + 1]))) return 1;
	return solve(p + 1, t);
}

int sort(void *a, void *b) {
	return *(int*)b - *(int*)a;
}

Measured memory_bytes: 584
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun dprint(v: Any?, indent: Int = 0) {
    val indentStr = (1..indent).joinToString("") { " " }
    when (v) {
        is Iterable<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is Array<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is IntArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is LongArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is DoubleArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        else -> System.err.println(indentStr + v)
    }
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> min(vararg a: A) = a.reduce { acc, x -> min(acc, x) }
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b
fun <A : Comparable<A>> max(vararg a: A) = a.reduce { acc, x -> max(acc, x) }

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    val sc = Scanner(System.`in`)
//    for (t in 1..sc.next().toInt()) {
    Problem.solve(sc, pw)
//    }
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()
        val A = Array(N) { sc.next().toLong() }.sorted().toLongArray()
        val BC = Array(M) {
            Pair(sc.next().toInt(), sc.next().toLong())
        }.sortedBy { -it.second }
        var i = 0
        BC.forEach {
            var b = it.first
            val c = it.second
            while (b > 0 && i < N && A[i] < c) {
                A[i] = c
                b--
                i++
            }
        }
        pw.println(A.sum())
    }
}


Measured memory_bytes: 82848
n = int(input())
l = list(map(int,input().split()))
count = 0
count += l[0]
a = l[0]
for i in range(1,n):
    if l[i] > a:
        count += l[i]-a
        a = l[i]
    else:
        a = l[i]
print(count)



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

int main() {
  string s;cin>>s;
  for (int i=0;i<(int)s.size();i++) {
    if (i%2 == 0) {
      if (s[i] == 'L'){
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (s[i] == 'R'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0) 
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int inf = ~0u >> 1;
int main() {
    IO;
    string s;
    cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC") << endl;
    return 0;
}

Measured memory_bytes: 3556
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

        String[] figure = new String[8];
        int[] pos = new int[8];

        String input;

        while ((input = br.readLine()) != null) {
            for (int i = 0; i < 8; i++) {
                pos[i] = 0;
            }

            int counter = 0;

            figure[0] = input;
            if ((pos[0] = input.indexOf("1")) != -1) {
                counter++;
            }

            for (int i = 1; i < 8; i++) {
                input = br.readLine();
                figure[i] = input;

                if ((pos[i] = input.indexOf("1")) != -1) {
                    counter++;
                }
            }
            br.readLine(); // 空行処理

            String result = "";
            int forward = 0; // 探査用

            switch (counter) {
            case 1:
                result = "C";
                break;
            case 4:
                result = "B";
                break;
            case 2:
                forward = 0;
                while (pos[forward] == -1) {
                    forward++;
                }
                if (pos[forward] == pos[forward + 1]) {
                    result = "A";
                    break;
                } else if (pos[forward] < pos[forward + 1]) {
                    result = "E";
                    break;
                } else if (pos[forward] > pos[forward + 1]) {
                    result = "G";
                    break;
                }
                break; // unreachable
            case 3:
                forward = 0;
                while (pos[forward] == -1) {
                    forward++;
                }
                if(pos[forward] == pos[forward+1]){
                    result = "F";
                    break;
                }else if(pos[forward] > pos[forward+1]){
                    result = "D";
                    break;
                }
                break; // unreachable
            }

            System.out.println(result);
        }
    }
}


Measured memory_bytes: 23960
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;


public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Stack<Integer> SlopeStack = new Stack<Integer>();
		Stack<Pool> poolStack = new Stack<Pool>();

		String ch;
		int are=0;
		int sum = 0;
		ch = sc.nextLine();
		for (int i=0; i<ch.length(); i++){
			
			switch(ch.charAt(i)){
			case'\\':
				SlopeStack.push(i);
				break;
			case '/':
				if (!SlopeStack.isEmpty()) {
					Pool v = new Pool(SlopeStack.pop(),i);
					while (!poolStack.isEmpty()) {
						Pool latest = poolStack.pop();
						if (!v.isChild(latest)) {
							poolStack.push(latest);
							break;
						}
						v.addSize(latest.getSize());
					}
					poolStack.push(v);
				}
				break;
			case '_':
				break;
			}
		}

		int[] areaSize = new int[poolStack.size()];
		for (int i = 0; i < areaSize.length; i++) {
			areaSize[i] = poolStack.pop().getSize();
			sum += areaSize[i];
		}
		System.out.println(sum);
		System.out.print(areaSize.length);
		for (int i = areaSize.length - 1; i >= 0; i--) {
			System.out.print(" " + areaSize[i]);
		}
		System.out.println();
	}
}
class Pool {
	int left;
	int right;
	int area;
	Pool(int left, int right) {
		this.left = left;
		this.right = right;
		this.area = right - left;
	}
	void pool(){
		left = 0;
		right = 0;
	}
	public void addSize(int i){
		area += i;
	}
	public boolean isChild(Pool pool) {
		return left < pool.left && right > pool.right;
	}
	public int getSize() {
		return area;
	}
}


Measured memory_bytes: 29568
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,m;
	cin>>n>>m;
	if(n+m==15)cout<<"+"<<endl;
	else if(m*n==15)cout<<"*"<<endl;
	else cout<<"x"<<endl;
	
	
	return 0;
}


Measured memory_bytes: 892
#include  <cstdio>
int N,C;
int s[100000] ,t[100000] ,c[100000];
int sm [200002];
int tt [200002];
int  main(){
	scanf ("%d%d",&N,&C);
	for(int i=0;i<N;i++)
		scanf ("%d%d%d",&s[i],&t[i],&c[i]);
	for(int i=1;i<=C;i++){
		for(int j=0;j <200002;j++)
			tt[j]=0;
		for(int j=0;j<N;j++)
			if(c[j]==i)tt[s[j]*2-1]++ ,tt[t[j]*2]--;
		for(int j=1;j <200002;j++)
			tt[j]+=tt[j-1];
		for(int j=0;j <200002;j++)
			if(tt[j]>0)sm[j]++;
	}
	int mx=0;
	for(int j=0;j <200002;j++)
		if(mx <sm[j])mx=sm[j];
	printf ("%d\n",mx);
}

Measured memory_bytes: 2944
import java.util.HashMap;
import java.util.Scanner;

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

		HashMap<String, Integer> smap = new HashMap<String, Integer>();
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			Integer tmp = smap.get(str);
			if (tmp == null) {
				smap.put(str, 1);
			} else {
				smap.put(str, tmp + 1);
			}
		}

		int m = sc.nextInt();
		HashMap<String, Integer> mmap = new HashMap<String, Integer>();
		for (int i = 0; i < m; i++) {
			String str = sc.next();
			Integer tmp = mmap.get(str);
			if (tmp == null) {
				mmap.put(str, 1);
			} else {
				mmap.put(str, tmp + 1);
			}
		}

		int max = 0;
		for (String key : smap.keySet()) {
			int val1 = smap.get(key);
			Integer val2 = mmap.get(key);
			if(val2 == null) {
				max = Math.max(max, val1);
			} else {
				max = Math.max(max, val1 - val2);
			}
		}

		System.out.println(max);

	}
}

Measured memory_bytes: 23252
n = int(input())
S = list(map(int, input().split(' ')))

q = input()
T = list(map(int, input().split(' ')))

cnt = 0

for i in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            cnt += 1
            break
        elif i < S[mid]:
            right = mid
        else:
            left = mid + 1

print(cnt)

Measured memory_bytes: 18820
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
// using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define _GLIBCXX_DEBUG
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())       // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))    //最大値を求める
#define MIN(x) *min_element(ALL(x))    //最小値を求める
//定数
#define INF 1000000000000  // 10^12:極めて大きい値,∞
#define inf 2147483647     // int値の最大値
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back                             // vectorヘの挿入
#define MP make_pair                             // pairのコンストラクタ
#define F first                                  // pairの一つ目の要素
#define S second                                 // pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x)  //小数点以下の桁数指定
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
//各桁の和
int sumDight(int x) {
    int sum = 0;
    while (x > 0) {
        sum += (x % 10);
        x /= 10;
    }
    return sum;
}
//回文数
int divideReverse(int x) {
    int reverse = 0;
    int r;
    while (x > 0) {
        r = x % 10;
        reverse = reverse * 10 + r;
        x /= 10;
    }
    return reverse;
}

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

    int k;
    cin >> k;
    rep(i, k) cout << "ACL";
    cout << endl;
}


Measured memory_bytes: 3600
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();

		if ((g * 10 + b) % 4 == 0 ) {
			System.out.print("YES");
		} else {
			System.out.println("NO");
	    }
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    
    long arr[n];
    
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    
    int min=1000;
    
    for(i=0;i<n;i++)
    {
        int cnt=0;
        
        while(arr[i]%2==0)
        {
            cnt++;
            arr[i]=arr[i]/2;
        }
        if(cnt<min)
        {
            min=cnt;
        }
    }
    printf("%d\n",min);
    return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

Q, H, S, D = MAP()
N = INT()

if N%2:
	ans = min(4*Q*(N-1), 2*H*(N-1), S*(N-1), D*(N//2)) + min(4*Q, 2*H, S)
else:
	ans = min(4*Q*N, 2*H*N, S*N, D*(N//2))

print(ans)

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

int main(){
  int N;  //都市の数
  int M;  //道路の数

  cin >> N >> M;
  
  int Route;               // 都市iから出ている道路の数
  vector <int> RoadA(M);   // 道路i  都市Aiの番号
  vector <int> RoadB(M);   // 道路i  都市Biの番号

  for (int i=0; i<M; i++){
    cin >> RoadA.at(i) >> RoadB.at(i);
  }

  for (int i=1; i<=N; i++){
    Route=0;
    for (int j=0; j<M; j++){
      if (RoadA.at(j) == i){
        Route +=1;
      }
      if (RoadB.at(j) == i){
        Route +=1;
      }
    }
    cout << Route << endl;
  }
}

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

bool is_prime(long long n){
  if(n==1) return false;

  long long m = sqrt(n);
  for (long long i = 2; i <= m; i++) if(n%i==0) return false;
  return true;
}

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

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

  int ans = n;
  int i = 0;
  int minn;
  for(auto m:mp){
    int a = m.first;
    int b = m.second;
    int sqa = sqrt(a);
    if(i==0){
      minn = a;
    }
    i++;
    
    if(minn )

    if(b>1){
      ans-=b;
      continue;
    }

    if(a!=1 && mp[1]>0){
      ans--;
      continue;
    }

    for (long long i = 2; i <= sqa; i++){
      if(a%i==0){
        if(mp[i]>0 || mp[a/i]>0){
          ans--;
          break;
        }
        if(a/i < minn){
          break;
        }
      }
    }    
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 20780
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;


int  main (){
	int n, m; cin >>  n;
	int sum = 0;
	vector <int> v;
	for (int i = 0; i < 2*n ; i++) {
		cin >> m;
		v.push_back(m);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < 2*n; i++) {
		if (i % 2 == 0)
			sum+=v[i];
	}
	cout << sum <<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int al, ar, bl, br;
		double calc = a / 0.08;
		if(calc == (int) calc) {
			al = (int) calc;
		} else {
			al = (int) calc + 1;
		}
		calc = (a + 1) / 0.08;
		if(calc == (int) calc) {
			ar = (int) calc - 1;
		} else {
			ar = (int) calc;
		}
		calc = b / 0.1;
		if(calc == (int) calc) {
			bl = (int) calc;
		} else {
			bl = (int) calc + 1;
		}
		calc = (b + 1) / 0.1;
		if(calc == (int) calc) {
			br = (int) calc - 1;
		} else {
			br = (int) calc;
		}
		if(al > br || bl > ar) {
			System.out.println(-1);
		} else {
			int ans = 0;
			if(al <= bl) {
				ans = bl;
			} else {
				ans = al;
			}
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

vector<bool> prime_table(100001);

void make_prime_table(){
    
    for(int i=0; i<=100000; i++) prime_table[i] = true;
    for(int i=2; i<=100000; i++){
        if(prime_table[i] == false) continue;

        int a = 2*i;
        while(a <= 100000){
            prime_table[a] = false;
            a += i;
        }
    }
}

int main(){
    vector<int> cnt(100001, 0);

    make_prime_table();
    for(int i=2; i<=100000; i++){
        if(i%2 == 1 && prime_table[i] == true && prime_table[(i+1)/2] == true) cnt[i] = cnt[i-1]+1;
        else cnt[i] = cnt[i-1];
    }

    int q; cin >> q;
    for(int i=0; i<q; i++){
        int l, r; cin >> l >> r;
        cout << cnt[r] - cnt[l-1] << endl;
    }
}

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

N=int(input())
ST=[input().split() for i in range(N)]

for i in range(N):
    ST[i][1]=int(ST[i][1])

ST.sort()

ST2=[]
for i in range(N):
    if i>0 and ST[i][0]==ST[i-1][0]:
        continue
    ST2.append((ST[i][0],ST[i][1]))
ST=ST2


FDICT=dict()
BDICT=dict()

for s,i in ST:
    FDICT[s[::-1]]=i
    BDICT[s[::-1]]=i

    for j in range(1,len(s)):
        if not(s[:j][::-1] in BDICT):
            BDICT[s[:j][::-1]]=1<<60
        if not(s[-j:][::-1] in FDICT):
            FDICT[s[-j:][::-1]]=1<<60

ANS=1<<60
flag=0
for rep in range(1<<60):
    flag=0
    for f in FDICT:
        lf=len(f)
        for s,i in ST:
            ls=len(s)

            if lf == ls:
                if s==f:
                    ANS=min(ANS,FDICT[f]+i)
            elif ls>lf:
                if s[-lf:]==f and BDICT[s[:-lf][::-1]]>FDICT[f]+i:
                    BDICT[s[:-lf][::-1]]=FDICT[f]+i
                    flag=1
            else:
                if f[-ls:]==s and FDICT[f[:-ls]]>FDICT[f]+i:
                    FDICT[f[:-ls]]=FDICT[f]+i
                    flag=1
                    

    for b in BDICT:
        lb=len(b)
        for s,i in ST:
            ls=len(s)

            if lb == ls:
                if s==b:
                    ANS=min(ANS,BDICT[b]+i)
            elif ls>lb:
                if s[:lb]==b and FDICT[s[lb:][::-1]]>BDICT[b]+i:
                    FDICT[s[lb:][::-1]]=BDICT[b]+i
                    flag=1
                    
            else:
                if b[:ls]==s and BDICT[b[ls:]]>BDICT[b]+i:
                    BDICT[b[ls:]]=BDICT[b]+i
                    flag=1
    if flag==0:
        break
                    

for f in FDICT:
    if f==f[::-1]:
        ANS=min(ANS,FDICT[f])

for b in BDICT:
    if b==b[::-1]:
        ANS=min(ANS,BDICT[b])

if ANS==1<<60:
    print(-1)
else:
    print(ANS)

Measured memory_bytes: 74680
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            if (N / 100 == N % 10)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        /*public long C(long n, long r)
        {
            if (r == 0 || r == n) return 1L;
            if (n < r) return 0L;
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }*/

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
        a[i]=a[i]-1-i;
    }
    
    sort(a,a+n);
    ll ans=0;
    for (ll i=0;i<n;i++){
        ans+=abs(a[i]-a[n/2]);
    }
    cout << ans << endl;
    return 0;
}




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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

bool isOdd(int n) {
  if (n % 2 != 0) return true;
  return false;
}

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

  i64 a, b, c;
  cin >> a >> b >> c;

  if (isOdd(a) || isOdd(b) || isOdd(c)) cout << 0 << "\n";
  else if (a == b && b == c) cout << -1 << "\n";

  else {
    int i = 1;
    while (true) {
      int tmpa = a, tmpb = b, tmpc = c;
      a = (tmpb / 2) + (tmpc / 2);
      b = (tmpa / 2) + (tmpc / 2);
      c = (tmpa / 2) + (tmpb / 2);
      if (isOdd(a) || isOdd(b) || isOdd(c)) {
        cout << i << "\n";
        return 0;
      }
      ++i;
    }
  }

  return 0;
}

Measured memory_bytes: 256