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

const int MAX_N = 10000;
const int INF = 1<<29;

struct edge{
	int tar, dist, cost;
};

int N, M;
vector<edge> graph[MAX_N];
int dist[MAX_N], ids[MAX_N];

bool init(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++){
		graph[i].clear();
	}

	for(int i=0; i<M; i++){
		int u, v, d, c;
		scanf("%d%d%d%d", &u, &v, &d, &c);
		u--; v--;
		graph[u].push_back((edge){v, d, c});
		graph[v].push_back((edge){u, d, c});
	}
	return N > 0;
}

bool cmp(int i, int j){
	return dist[i] < dist[j];
}

struct state{
	int cur, dist;
};

bool operator>(const state& lhs, const state& rhs){
	return lhs.dist > rhs.dist;
}

int solve(){
	//dijkstra
	fill(dist, dist + N, INF);
	priority_queue<state, vector<state>, greater<state> > que;
	dist[0] = 0;
	que.push((state){0, 0});
	for(;!que.empty();){
		const int v = que.top().cur, d = que.top().dist;
		que.pop();
		if(dist[v] < d){
			continue;
		}
		for(int i=0; i<(int)graph[v].size(); i++){
			const int u = graph[v][i].tar, nd = d + graph[v][i].dist;
			if(dist[u] > nd){
				dist[u] = nd;
				que.push((state){u, nd});
			}
		}
	}

	//solve
	for(int i=0; i<N; i++){
		ids[i] = i;
	}
	sort(ids, ids+N, cmp);

	int ans = 0;
	for(int i=1; i<N; i++){
		int mini = INF;
		for(int j=0; j<(int)graph[i].size(); j++){
			const int u = graph[i][j].tar, d = graph[i][j].dist, c = graph[i][j].cost;
			if(dist[u] + d == dist[i] && c < mini){
				mini = c;
			}
		}
		ans += mini;
	}

	return ans;
}

int main(){
	for(;init();){
		printf("%d\n", solve());
	}

	return 0;
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  map<char, int> mp;
  rep(i, s.size()){
    mp[s.at(i)]++;
  }

  ll ans = 1;
  for(auto p : mp){
    for(auto p2 : mp){
      if(p2.first <= p.first) continue;
      ans += (ll)p.second * p2.second;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>

using namespace std;


int main()
{
	int n;
	scanf("%d",&n);
	
	vector<int> v;
	
	int ma = -100000000;
	int mi = 100000000;
	int maxnum,minnum;

	
	for(int i = 0;i < n;i++)
	{
		int tmp;
		scanf("%d",&tmp);
		v.push_back(tmp);
		if(ma < tmp)
		{
			ma = tmp;
			maxnum = i;
		}
		if(mi > tmp)
		{
			mi = tmp;
			minnum = i;
		}
	}
	
	vector<pair<int,int> > ans;
	
	if(abs(ma) > abs(mi))
	{
		for(int i = 0;i < n;i++)
		{
			ans.push_back(make_pair(maxnum,i));
		}
		
		for(int i = 0;i < n-1;i++)
		{
			ans.push_back(make_pair(i,i+1));
		}
	}
	else
	{
		for(int i = 0;i < n;i++)
		{
			ans.push_back(make_pair(minnum,i));
		}
		
		for(int i = n-1;i > 0;i--)
		{
			ans.push_back(make_pair(i,i-1));
		}
	}
	
	
	printf("%d\n",ans.size());
	
	for(int i = 0;i < ans.size();i++)
	{
		printf("%d %d\n",(ans[i].first)+1,(ans[i].second)+1);
	}
	
	/*
	for(int i = 0;i < ans.size();i++)
	{
		v[ans[i].second] += v[ans[i].first];
	}
	for(int i = 0;i < v.size();i++)
	{
		printf("%d ",v[i]);
	}
	*/
	
	return 0;
}

Measured memory_bytes: 256
h,w,k=[int(x) for x in input().rstrip().split()]
tate=[]
yoko=[]
l=[]
ans=0
for i in range(h):
  c=[x for x in input()]
  l.append(c)
  bl=0
  for s in c:
    if s=="#":
      bl+=1
  yoko.append(bl)

for i in range(w):
  bl=0
  for j in range(h):
    if l[j][i]=="#":
      bl+=1
  tate.append(bl)

# print(tate)
# print(yoko)
for i in range(2**w):
  for j in range(2**h):
    now=0
    for ii in range(w):
      for jj in range(h):
        if j>>jj & 1 and i>>ii & 1:
          if l[jj][ii] == "#":
            now+=1
    if now==k:
      ans+=1
print(ans)

      

Measured memory_bytes: 9136
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF INT_MAX
int n;
vi seg;
vi lazy;

void propagate(int k) {
  if (lazy[k] == 0) {
    return;
  }
  seg[k] += lazy[k];
  if (k < n) {
    lazy[k*2] += lazy[k];
    lazy[k*2+1] += lazy[k];
  }
  lazy[k] = 0;
}

// seg[k] : [l, r)
void range_add(int a, int b, int k, int l, int r, int x) {
  if (r <= a || b <= l) {
    return;
  }
  if (a <= l && r <= b) {
    lazy[k] += x;
    propagate(k);
    return;
  } else {
    propagate(k);
    range_add(a, b, k*2, l, (l+r)/2, x);
    range_add(a, b, k*2+1, (l+r)/2, r, x);
  }
}

int range_get(int x, int k, int l, int r) {
  propagate(k);
  if (x < l || r <= x) {
    return 0;
  }
  if (l == x && r == x+1) {
    return seg[k];
  } else {
    return range_get(x, k*2, l, (l+r)/2) + range_get(x, k*2+1, (l+r)/2, r);
  }
}

int get_query(int x) {
  return range_get(x, 1, 0, n);
}

int main() {
  int n_, q;
  scanf("%d %d", &n_, &q);
  n = (1 << (int)(ceil(log2(n_))));
  seg.assign(2*n, 0);
  lazy.assign(2*n, 0);
  int op, s, t, x;
  rep (i, q) {
    scanf("%d", &op);
    if (op == 0) {
      scanf("%d %d %d", &s, &t, &x);
      s -= 1;
      range_add(s, t, 1, 0, n, x);
    } else {
      scanf("%d", &x);
      x -= 1;
      printf("%d\n", get_query(x));
    }
  }

  return 0;
}

Measured memory_bytes: 5064
n,k=map(int,input().split())
Mod=10**9+7
M=n+10
fac=[0]*M
finv=[0]*M
inv=[0]*M

#finvに逆元、facに階乗のmod
def COMinit():
  fac[0]=fac[1]=1
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]*i%Mod)%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%Mod
def COM(n,k):
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return (fac[n]*(finv[k]*finv[n-k]%Mod)%Mod)%Mod

COMinit()
for i in range(1,k+1):
  print((COM(k-1,i-1)*COM(n-k+1,i))%Mod)


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

int main()
{
    string n;
    cin >> n;
    if (n[0] == n[1] && n[1] == n[2]) cout << "Yes" << endl;
    else if (n[1] == n[2] && n[2] == n[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, t int
	fmt.Scan(&a, &b, &t)

	if a > t {
		fmt.Print(0)
		return
	}

	time := 0
	maked := 0
	cnt := 1
	for time <= t {
		maked += b
		cnt++
		time = a * cnt
	}

	fmt.Print(maked)

}


Measured memory_bytes: 512
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,fma")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3022, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	if(s.back() == 's') s.push_back('e');
	cout << s << "s" << endl;
}


Measured memory_bytes: 3672
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int dp[400][400];
vector<pair<int,int> > v[400];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<400;i++)v[i].clear();
		for(int i=0;i<a;i++){
			int x,y,z;scanf("%d%d%d",&x,&y,&z);
			x--;y--;
			v[x].push_back(make_pair(y,z));
		}
		for(int i=0;i<400;i++)for(int j=0;j<400;j++)
			dp[i][j]=0;
		dp[0][0]=0;
		for(int i=0;i<370;i++){
			for(int j=i;j<370;j++){
				dp[i+1][max(i+1,j)]=max(dp[i+1][max(i+1,j)],dp[i][j]);
				if(i==j){
					for(int k=0;k<v[i].size();k++){
						dp[i+1][v[i][k].first+1]=max(dp[i+1][v[i][k].first+1],dp[i][j]+v[i][k].second);
						for(int l=k+1;l<v[i].size();l++){
							int L=min(v[i][k].first+1,v[i][l].first+1);
							int R=max(v[i][k].first+1,v[i][l].first+1);
							dp[L][R]=max(dp[L][R],dp[i][j]+v[i][k].second+v[i][l].second);
						}
					}
				}else{
					for(int k=0;k<v[i].size();k++){
						dp[min(j,v[i][k].first+1)][max(j,v[i][k].first+1)]=max(dp[min(j,v[i][k].first+1)][max(j,v[i][k].first+1)],dp[i][j]+v[i][k].second);
					}
				//	dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
				}
			}
		}
		int ret=0;
		for(int i=0;i<400;i++)for(int j=0;j<400;j++)ret=max(ret,dp[i][j]);
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1692
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int bit=0; bit<(1<<n); bit++) {
      vector<int> v;
      for(int i=0; i<n; i++) {
          if(bit & (1<<i)) {
              v.push_back(i);
          }
      }
      cout << bit << ":";
      for(int i=0; i<v.size(); i++) {
          cout << " " << v[i];
      }
      cout << endl;
  }
}


Measured memory_bytes: 3168
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var card = o.getArray(0);
    var A = card[0];
    var B = card[1];
    var C = card[2];
    var K = o.getValue(1);

    var i = 0;
    while(K > i++) {
        if (A >= B) {
            B = 2 * B;
            continue;
        }
        C = 2 * C;
    }
    return  (B > A && C > B) ? 'Yes' : 'No';
}

Measured memory_bytes: 29688
N,T = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]

dp = [[0]*T for _ in range(N+1)]

for i in range(N):
    for j in range(T):
        if j < L[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-L[i][0]]+L[i][1])
            
used = []
B = dp[N][T-1]
j = T-1
for i in range(N-1, -1, -1):
    if B == dp[i][j]:
        continue
    B -= L[i][1]
    used.append(i)
    j -= L[i][0]
        
ans = dp[N][T-1]
c = 0
for i in range(N):
    if i in used:
        continue
    c = max(c, L[i][1])
    
print(ans+c)

Measured memory_bytes: 116696
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 1005
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

typedef struct {
  int front;
  int rear;
  int data[20000000][2];
} queue;

queue que;

void initQueue(queue *p) {
  p->front = p->rear = 0;
}

bool emptyQueue(queue *p) {
  return p->front == p->rear;
}

bool fullQueue(queue *p) {
  return (p->front - 1 == p->rear) || (p->front == 0 && p->rear == 20000000 - 1);
}

void popLeft(queue *p) {
  if ( emptyQueue(p) ) {
    printf("UnderFlow\n");
    exit(1);
  } else {
    p->front++;
    if (p->front == 20000000)
      p->front = 0;
  }
}

void pop(queue *p) {
  if ( emptyQueue(p) ) {
    printf("UnderFlow\n");
    exit(1);
  } else {
    p->rear--;
    if (p->rear == -1)
      p->rear = 20000000 - 1;
  }
}

void push(queue *p, int y, int x) {
  if ( fullQueue(p) ) {
    printf("OverFlow\n");
    exit(1);
  } else {
    p->data[p->rear][0] = y;
    p->data[p->rear][1] = x;
    p->rear++;
    if ( p->rear == 20000000 )
      p->rear = 0;
  }
}

void pushLeft(queue *p, int y, int x) {
  if ( fullQueue(p) ) {
    printf("OverFlow\n");
    exit(1);
  } else {
    p->front--;
    if ( p->front == -1 )
      p->front = 20000000 - 1;
    p->data[p->front][0] = y;
    p->data[p->front][1] = x;
  }
}


int H, W, Ch, Cw, Dh, Dw;

char S[MAX][MAX];

int main(void) {
  scanf("%d %d", &H, &W);
  scanf("%d %d", &Ch, &Cw);
  scanf("%d %d", &Dh, &Dw);

  rep(i, 0, H) scanf("%s", S[i]);

  int dist[MAX][MAX];
  rep(i, 0, MAX) rep(j, 0, MAX) dist[i][j] = INF;


  int ax[4] = {0, 1, 0, -1};
  int ay[4] = {1, 0, -1, 0};

  initQueue(&que);
  pushLeft(&que, Ch-1, Cw-1);
  dist[Ch-1][Cw-1] = 0;
  while ( !emptyQueue(&que) ) {
    int y = que.data[que.front][0];
    int x = que.data[que.front][1];
    popLeft(&que);
    if ( y == Dh-1 && x == Dw-1 ) {
      printf("%d\n", dist[y][x]);
      return 0;
    }
    rep(i, 0, 4) {
      int ny = y + ay[i];
      int nx = x + ax[i];
      if ( ny < 0 || H <= ny ) continue;
      if ( nx < 0 || W <= nx ) continue;
      if ( S[ny][nx] == '#' ) continue;
      if ( dist[ny][nx] <= dist[y][x] ) continue;
      dist[ny][nx] = dist[y][x];
      pushLeft(&que, ny, nx); 
    }

    rep(by, -2, 3) rep(bx, -2, 3) {
      int ny = y + by;
      int nx = x + bx;
      if ( ny < 0 || H <= ny ) continue;
      if ( nx < 0 || W <= nx ) continue;
      if ( S[ny][nx] == '#' ) continue;
      if ( dist[ny][nx] <= dist[y][x] + 1 ) continue;
      dist[ny][nx] = dist[y][x] + 1;
      push(&que, ny, nx);
    }
  }
  printf("-1\n");
  return 0;
}


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

int main(){
  int n,k,l=0;
  cin >> n >> k;
  vector<long double> x(n,0);

  long double a=0.5,ans=0;

    for(int i=n;i>0;i--){
      if(i*powl(2,l)>=k){
        x.at(i-1)=powl(a,l);
      }else{
        l++;
        i++;
        }
    }

    for(int i=0;i<n;i++){
      ans+=x.at(i);
    }

    cout << setprecision(10) << ans/n << endl;
  

}

Measured memory_bytes: 1792
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll h, w;
  cin >> h >> w;

  map<char, ll> mp;
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) { mp[s[j]]++; }
  }

  ll fours = 0;
  ll twos = 0;
  for (auto& kv : mp) {
    fours += kv.second / 4;
    twos += (kv.second % 4) / 2;
  }

  ll fq = (h / 2) * (w / 2);
  ll tq = (h % 2) * w / 2 + (w % 2) * h / 2;

  while(tq > 0){
    if(twos == 0){
      if(fours == 0){
        puts("No");
        return 0;
      } else {
        fours--;
        twos++;
        tq--;
      }
    } else {
      twos--;
      tq--;
    }
  }

  if(fours == fq){
    puts("Yes");
  } else{
    puts("No");
  }

  return 0;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 10000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 struct sch{
	ll s,e,t;
};
bool sortinrev(const struct sch &a, const struct sch &b) 
{ 
    return (a.s < b.s); 
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int main()
{
	ll n,m,x;
	cin>>n>>m>>x;
	ll c[n];
	ll a[n][m];
	for(ll i=0;i<n;i++)
	{
		cin>>c[i];
		for(ll j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	ll asum[m],ans=-1;
	for(ll i=0;i<(1<<n);i++)
	{
		ll cost = 0;
		memset(asum,0,sizeof(asum));
		for(ll i1=0;i1<n;i1++)
		{	
			if((1<<i1)&i)
			{ 
			//	cout<<i<<" "<<i1<<endl;
				cost += c[i1];
				for(ll j=0;j<m;j++)
				{
					asum[j] += a[i1][j];
				}
			}
		}
		int flag = 1;
		for(ll i=0;i<m;i++)
		{
			if(asum[i]<x)
			{
				flag = 0;
			}
		}
		if(flag)
		{
			if(ans != -1)
			{
				ans = min(cost,ans);
			}
			else
			{
				ans = cost;
			}
		}
	}
	cout<<ans<<endl;

}

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

int recusion(int i, int x) {
    if (x % 10 == 3)  {
        cout << " " << i;
        return 0;
    };
    x /= 10;
    if (x) recusion(i, x);
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
            continue;
        }

        recusion(i, x);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc136d
int main(){
    string s;
    cin >> s;
    int n = s.size();
    char pre = 'R';
    int l=0, r=0;
    int aa[n+1];
    rep(i, n) aa[i] = 0;
    rep(i, n){
        char tmp = s[i];
        if (tmp == 'L'){
            l++;
            pre = tmp;
        }else if ((tmp=='R' and pre=='L')){
            aa[i-l] = (l+r)/2;
            aa[i-l-1] = (l+r)/2;
            if ((l+r)%2){
                if (l<r) {
                    aa[i-l-(r%2)]++;
                }else if (r<l){
                    aa[i-l-1+(l%2)]++;
                }
            }
            l = 0;
            r = 1;
            pre = tmp;
        }else{
            r++;
            pre = tmp;
        }
        if (i==n-1){
            aa[i-l+1] = (l+r)/2;
            aa[i-l] = (l+r)/2;
            if ((l+r)%2){
                if (l<r) {
                    aa[i-l+1-(r%2)]++;
                }else if (r<l){
                    aa[i-l+(l%2)]++;
                }
            }
        }
    }
    rep(i, n) cout << aa[i] << ' ';
    return 0;
}


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


int main() {
	int n, key;
	cin >> n;
	string command;
	list<int> dl;

	for (int i=0; i<n; ++i) {
		cin >> command;
		if (command[0] == 'i') {
			cin >> key;
			dl.push_front(key);
		} else if (command[0] == 'd') {
			if (command.length() == 6) {
				//cout << command << endl;
				cin >> key;
				list<int>::iterator it = dl.begin();
				while (it != dl.end()) {
					if (*it == key) {
						dl.erase(it);
						break;
					}
					++it;
				}
			} else {
				if (command[6] == 'F') {
					dl.pop_front();
				} else if (command[6] == 'L') {
					dl.pop_back();
				}
			}
		}
	}
	int i=0;
	for (list<int>::iterator it = dl.begin(); it != dl.end(); ++it) {
		if (it != dl.begin()) cout << " ";
		cout << *it;
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 34416
package main

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

func main() {
	H := oneInt()
	W := oneInt()
	if H == 1 || W == 1 {
		fmt.Print(1)
		return
	}

	if H*W%2 != 0 {
		fmt.Print(H*W/2 + 1)
	} else {
		fmt.Print(H * W / 2)
	}
}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int W,H,N;
void input(){
    fast_io();
    cin >> W >> H >> N;
}

int solve(){
    vector<vector<int>> C(W+1,vector<int>(H+1,0));
    for (int i = 0; i < N; i++)
    {
        int x,y,a; cin >> x >> y >> a;
        if(a==1){
            C[0][0]++;
            C[x][0]--;
        }
        else if(a==2){
            C[x][0]++;
            // C[H-1][0]--;
        }
        else if(a==3){
            C[0][0]++;
            C[0][y]--;
        }
        else if(a==4){
            C[0][y]++;
            // C[0][y]--;
        }
    }

    for (int i = 0; i < W; i++)
    {
        for (int j = 0; j < H; j++)
        {
            C[i][j+1]+=C[i][j];
        }
        
    }

    for (int j = 0; j < H; j++)
    {
        for (int i = 0; i < W; i++)
        {
            C[i+1][j]+=C[i][j];
        }
        
    }
    int ans = 0;
    for (int i = 0; i < W; i++)
    {
        for (int j = 0; j < H; j++)
        {
            if(C[i][j]==0) ans++;
        }
        
    }
    cout << ans << endl;
    return 0;
}   

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

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


def divisors(n):
    x = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            x.append(i)
            if i != n // i:
                x.append(n // i)
    return sorted(x)


def test(N, K):
    if K == 1:
        return False
    while N % K == 0:
        N //= K
    return N % K == 1


cand = divisors(N) + divisors(N - 1)

ans = 0
for d in cand:
    if test(N, d):
        ans += 1
print(ans)


Measured memory_bytes: 3444
N,W=map(int,input().split())
DP=[[0 for j in range(W+1)] for i in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)

for i in range(1,N+1):
    v[i],w[i]=map(int,input().split())
    
for i in range(1,N+1):
    for j in range(1,W+1):
        if j-w[i]<0:
            DP[i][j]=DP[i-1][j]
        else:
            if v[i]+DP[i-1][j-w[i]]>DP[i-1][j]:
                DP[i][j]=v[i]+DP[i-1][j-w[i]]
            else:
                DP[i][j]=DP[i-1][j]
print(DP[N][W])


Measured memory_bytes: 25940
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
// #define int long long

const int N = 4e6 + 5;

bitset<N> dp;
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	dp.set(0);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		sum += a;
		dp |= (dp << a);
	}
	sum = (sum + 1) / 2;
	for (int i = sum; ; ++i) {
		if (dp[i]) {
			cout << i << endl;
			break;
		}
	}
	return 0;	
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll dp[60][4];
const ll INF = 1e15;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(true){
    cin >> n;
    if(n == 0) break;
    ll p[n], t[n];
    rep(i,n) cin >> p[i] >> t[i];
    rep(i,60) rep(j,4) dp[i][j] = INF;

    dp[0][0] = 0;
    bool flag2 = true;

    rep(i,n){
      bool flag = false;
      rep(j,4){
        if(dp[i][j] == INF) continue;
        ll times;
        ll cost;
        if(j <= 2) {
          if(i-1 < 0){
            times = p[i];
            cost = p[i];
          }
          else{
            times = (j+1) * abs(p[i] - p[i-1]) + t[i-1];
            cost = abs(p[i]-p[i-1]);
          }

          if(times <= t[i]){
            dp[i+1][j+1] = min<ll>(dp[i+1][j+1], dp[i][j] + cost);
            flag = true;
          }
        }

        if(j > 0 && i-1 >= 0){
          times = (j+1) * abs(p[i-1]) + p[i] + t[i-1];
          cost = p[i-1] + p[i];
          if(times <= t[i]){
            dp[i+1][1] = min<ll>(dp[i+1][1], cost + dp[i][j]);
            flag = true;
          }
        }

      }

      if(flag == false){
        cout << "NG " << i+1 << endl;
        flag2 = false;
        break;
      }
    }

    if(flag2){
      ll ans = INF;
      rep(i,4){
        ans = min(dp[n][i], ans);
      }

      cout << "OK ";
      cout << ans + p[n-1] << endl;
    }
  }


  return 0;

}



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

int main(){
  int n,k,q,a,score[110000];
  cin>>n>>k>>q;
  for(int i=0;i<n;i++){
    score[i]=k-q;
  }
  for(int i=0;i<q;i++){
    cin>>a;
    score[a-1]+=1;
  }
  for(int i=0;i<n;i++){
    if(score[i]<=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define MAXN 100000
#define MAXM 200000
#define INF INT_MAX
int n,m;
struct node
{
    int next,to,w;
}e[MAXM*2+5];
int b[MAXN+5];
int x,y,z,cnt,s,t,ans;
map<int,int> Ncolor[MAXN+5];
int dist[MAXN+5];
priority_queue < pair<int,int> > Q;
void fpush(int u,int v,long long w)
{
    e[++cnt].next=b[u];
    e[cnt].w=w;
    e[cnt].to=v;
    b[u]=cnt;
}
void Dijkstra()
{
     Q.push({0,s});
    dist[s]=1;
    while(!Q.empty())
    {
        int now=Q.top().second,xval=-Q.top().first;
        Q.pop();
        for(int i=b[now];i;i=e[i].next)
        {
            int xnext=e[i].to,color=e[i].w;
            int val=xval;
            if(!Ncolor[now].count(color))val++;
            if(dist[xnext]>val)
            {
                Ncolor[xnext].clear();
                Ncolor[xnext][color]=1;
                dist[xnext]=val;
                Q.push({-val,xnext});
            }
            if(dist[xnext]==val)Ncolor[xnext][color]=1;
        }
    }
}
int main()
{
    fill(dist+1,dist+MAXN+1,INF);
    scanf("%d%d",&n,&m);
    s=1,t=n;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        fpush(x,y,z);
        fpush(y,x,z);
    }
    Dijkstra();
    if(dist[n]!=INF)printf("%d",dist[n]);
    else printf("-1");
}


Measured memory_bytes: 20216
#include <iostream>
#include <cstring>
#include <cmath> 
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;   
int main()  
{ 
    int x,y;
    cin>>x>>y;
    int cnt=0;
    for(int i=x;i<=y;i++){
        int a=i/10000;
        int b=i/1000%10;
//        int c=i/100%10;
        int d=i/10%10;
        int e=i%10;
        if(a==e&&b==d)cnt++;}
    cout<<cnt<<endl;
        


    system("pause");
    return 0;
}

Measured memory_bytes: 504
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
graph = [list(map(int,input().split())) for _ in range(m)]
ans = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
            uf.union(graph[j][0]-1, graph[j][1]-1)
    if uf.group_count() != 1:
        ans += 1
print(ans)

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

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

    int ans = 0;
    for(int i=1; i<N; i++){
        int now = 0;
        vector<int> cntL(26, 0), cntR(26,0);
        
        rep(j,i) cntL[S[j]-'a']++;
        for(int j=i; j<N; j++) cntR[S[j]-'a']++;

        rep(j,26){
            if(cntL[j] > 0 && cntR[j] > 0) now++;
        }
        ans = max(ans, now);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n, y = [int(i) for i in input().split()]

for a in range(n + 1):
    if 10000 * a <= y:
        tmp_a = y - 10000 * a

        for b in range(n + 1 - a):
            if 5000 * b <= tmp_a:
                tmp_b = tmp_a - 5000 * b

                c = n - a - b
                if 1000 * c <= tmp_b:
                    tmp_c = tmp_b - 1000 * c
                    if tmp_c == 0:
                        print("%d %d %d" % (a , b, c))
                        exit(0)

print("-1 -1 -1")


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

const int INF = 2*1e9;

int main(){
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	int dp[n+1]={};
	
	
	for(int i=2; i<=n; i++){
		
		dp[i] = INF;
		
		for(int j=i-1; j>=max(1,i-k); j--){
			
			dp[i] = min( dp[i], dp[j] + abs(arr[i-1] - arr[j-1]) );
			
		}
	}
	cout<<dp[n]<<endl;
	
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int w[4010][2010];
int b[4010][2010];
int ww[2010];
int bb[2010];
int dp[4010][2010];

int main(){
    int n;
    cin >> n;
    rep(i,2*n){
        char c;
        int a;
        cin >> c >> a;
        
        if(c=='B'){
            bb[a] = i;
            for(int j=a;j<=n;j++){
                b[i][j]++;
            }
        }else{
            ww[a] = i;
            for(int j=a;j<=n;j++){
                w[i][j]++;
            }
        }
    }
    // for(int j=1;j<=n;j++){
    //     cerr << 0 << " " << j << " " << b[0][j] << " " << w[0][j] << endl;
    // }
    for(int i=2*n-1;i>=0;i--){
        for(int j=1;j<=n;j++){
            b[i][j] += b[i+1][j];
            w[i][j] += w[i+1][j];
            //cerr << i << " " << j << " " << b[i][j] << " " << w[i][j] << endl;
        }
    }
    
    Fill(dp,inf);
    dp[0][0] = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i!=0){
                dp[i][j] = min(dp[i][j],dp[i-1][j]+bb[i]-(i+j-1)+b[bb[i]+1][i-1]+w[bb[i]+1][j]);
            }
            if(j!=0){
                dp[i][j] = min(dp[i][j],dp[i][j-1]+ww[j]-(i+j-1)+b[ww[j]+1][i]+w[ww[j]+1][j-1]);
            }
        }
    }
    cout << dp[n][n] << endl;
    return 0;
}

Measured memory_bytes: 94592
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<pair<int,int> > e[maxn];
int vis[maxn], label[maxn];
long long cnt[3], tot;
pair<bool, int> dfs(int u, int lab){
	vis[u] = 1;
	label[u] = lab;
	cnt[lab]++;
	tot++;
	bool ok = true;
	int eds = e[u].size();
	for(auto ee : e[u]){
		int v, w; tie(v, w) = ee;
		int nw = (lab + w) % 3;
		if(vis[v]){
			ok = ok && label[v] == nw; 
		} else {
			auto s = dfs(v, nw);
			ok = ok && s.first;
			eds += s.second;
		}
	}
	return make_pair(ok, eds);
}
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; i++){
		int u, v; cin >> u >> v;
		e[u].push_back({v, 1});
		e[v].push_back({u, 2});
	}
	long long ans = 0;
	for(int i = 1; i <= n; i++) if(!vis[i]){
		tot = cnt[0] = cnt[1] = cnt[2] = 0;
		auto s = dfs(i, 0);
		if(s.first){
			if(cnt[1] && cnt[2]) ans += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];
			else ans += s.second / 2;
		} else {
			ans += tot * tot;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12800
// AOJ 1625 Origami, or the art of folding paper
// 2019.3.25 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//// 入力処理
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()  // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int H, W;
int map[2][70][70];

int main()
{
	int i, t, p, r, c, id;

	while (W = in()) {
		H = in(), t = in(), p = in();
		memset(map, 0, sizeof(map));
		for (r = 0; r < H; r++) for (c = 0; c < W; c++) map[0][r][c] = 1;
		for (id = 0, i = 0; i < t; i++, id = !id) {
			int d = in(), e = in();
			if (d == 1) {	// 横方向に折る
				for (r = 0; r < H; r++) for (c = e; c < 2 * e; c++)
					map[id][r][c] += map[id][r][2 * e - c - 1];
				if (W - e > e) W -= e; else W = e;
				memset(map[!id], 0, sizeof(map[0]));
				for (r = 0; r < H; r++) for (c = 0; c < W; c++)
					map[!id][r][c] = map[id][r][c + e];
			}
			else {        // 縦に（上下に）折る
				for (r = e; r < 2 * e; r++) for (c = 0; c < W; c++)
					map[id][r][c] += map[id][2 * e - r - 1][c];
				if (H - e > e) H -= e; else H = e;
				memset(map[!id], 0, sizeof(map[0]));
				for (r = 0; r < H; r++) for (c = 0; c < W; c++)
					map[!id][r][c] = map[id][r + e][c];
			}
		}
		for (i = 0; i < p; i++) {
			c = in(), r = in();
			printf("%d\n", map[id][r][c]);
		}
	}
	return 0;
}


Measured memory_bytes: 2036
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
S = [input() for _ in range(H)]
# print(S)
INF = 1001001001

dp = [[INF]*W for _ in range(H)]
if S[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

for r in range(H):
    for c in range(W):
        if r:
            if S[r][c] == '#' and S[r-1][c] == '.':
                dp[r][c] = min(dp[r][c], dp[r-1][c]+1)
            else:
                dp[r][c] = min(dp[r][c], dp[r-1][c])
        if c:
            if S[r][c] == '#' and S[r][c-1] == '.':
                dp[r][c] = min(dp[r][c], dp[r][c-1]+1)
            else:
                dp[r][c] = min(dp[r][c], dp[r][c-1])

print(dp[H-1][W-1])


Measured memory_bytes: 3188
#include <iostream>
#define NMAX 100005
using namespace std;
int n,a[NMAX],i,d[NMAX];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    d[2]=abs(a[2]-a[1]);
    for(i=3;i<=n;i++)
        d[i]=min(d[i-1]+abs(a[i]-a[i-1]),d[i-2]+abs(a[i]-a[i-2]));
    cout<<d[n];
    return 0;
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

// lnt powmod(lnt a, lnt p, lnt m){
// 	lnt res = 1, tmp = a;
// 	while(p != 0){
// 		if(p % 2) res = (res*tmp) % m;
// 		tmp = (tmp*tmp) % m;
// 		p /= 2;
// 	}
// 	return res;
// }

lnt powmod(lnt a, lnt p, lnt m){
	if(p == 0) return 1;
	return powmod(a*a%m, p/2, m)*(p%2 ? a : 1) % m;
}

int main(){
	summon_tourist;

	lnt N; cin >> N;

	lnt c00 = 0, c01 = 0, c10 = 0;
	vector<plnt> X;
	map<plnt, lnt> mp;

	REP(i, N){
		lnt a, b; cin >> a >> b;
		if(a==0 and b==0) c00++;
		else if(a==0) c01++;
		else if(b==0) c10++;
		else X.eb(a, b);
	}

	for(plnt &p: X){
		lnt a = p.first, b = p.second;
		lnt g = gcd(abs(a), abs(b));
		a /= g; b /= g;
		if(a < 0){
			a*=-1; b*=-1;
		}
		mp[{a, b}]++;
		if(b < 0){
			lnt ta = -b, tb = a;
			a = ta; b = tb;
		}
		p = {a, b};
	}
	sort(ALL(X));
	X.erase(unique(ALL(X)), X.end());
	lnt ans = (powmod(2, c01, MOD) + powmod(2, c10, MOD) - 1 + MOD) % MOD;
	for(plnt p: X){
		lnt a = p.first, b = p.second;
		cerr << a << ' ' << b << ln;
		lnt A = b, B = -a;
		lnt c0 = mp[p], c1 = mp[{A, B}];
		ans = ans * ((powmod(2, c0, MOD) + powmod(2, c1, MOD) - 1 + MOD) % MOD) % MOD;
	}
	
	cout << (ans-1+c00+MOD) % MOD << ln;
}

Measured memory_bytes: 35880
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define printd(x) printf("%.12f\n", ans);
#define print(x) cout << (x) << endl;
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;


vector<vector<bool>> vvi(15, vector<bool>(15, false));

int main(void) {
    int n, m;
    cin >> n >> m;

    ll anss = 0, ansp = 0;
    map<int, int> mp, wcnt;
    rep (i, m) {
        int p; string s;
        cin >> p >> s;
        p--;
        if (s == "AC") {
            if (!mp[p]) anss++;
            mp[p]++;
        }
        if (s == "WA" && !mp[p]) {
            wcnt[p]++;            
        }
    }
    
    rep (i, n) {
        if (mp[i]) ansp += wcnt[i];
    }
    cout << anss << " " << ansp <<endl;;
    return 0;
}


Measured memory_bytes: 9600
require 'prime'

class Integer
  def my_divisor_list
    return [1] if self == 1
    Prime.prime_division(self).map do |e|
      Array.new(e[1]+1).map.with_index do |element, i|
        e[0]**i
      end
    end.inject{|p,q| p.product(q)}.map do |a|
      [a].flatten.inject(&:*)
    end.sort
  end
end

n, m = gets.chomp.split.map(&:to_i)

puts m.my_divisor_list.select{|e| e <= m/n}.max


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


#define MAXN 10000001
int spf[MAXN];

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 


void solve()
{
	sieve();
	int n;
	cin>>n;
	ll ans = 1;
	for (ll i = 2; i <= n; ++i)
	{
		if(spf[i]==1)
		{
			ans+= 2*i;
			continue;
		}
		ll t = 1;
		map<ll,ll> m;
		ll x = i;
		while(x!=1)
		{
			m[spf[x]]++;
			x /= spf[x];
		}
		// m[x]++;
		ll e = 1;
		for(auto& j:m)
		{
			e *= (j.second+1);
		}
		// e -= t;
		// printf("%lld\n", e);
		ans += e*i;
	}	
	printf("%lld\n", ans);
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 42772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  int i, p = 0;
  int i1, i2, i3, i4;
  for(i = a; i < b + 1; i++){
    i1 = i / 10000;
    i2 = (i - i1 * 10000) / 1000;
    i3 = (i - i1 * 10000 - i2 * 1000) / 100;
    i4 = (i - i1 * 10000 - i2 * 1000 - i3 * 100) ;
    if(i2 * 10 + i1 == i4){
      p++;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;

int main() {

	vector<int> c;
	rep(i, 9) {
		int x;
		cin >> x;
		c.push_back(x);
	}

	int X, Y, A,B;
	X = c[0] - c[5];
	Y = c[5] - c[2];
	A = c[1] - c[0];
	B = c[2] - c[1];

	bool is_exist = true;
	//if (!(c[7] - c[4] == X && c[4] - c[1] == Y)) is_exist = false;
	//if (!(c[6] - c[3] == X && c[3] - c[0] == Y)) is_exist = false;
	if (!(c[5] - c[4] == B && c[4] - c[3] == A)) is_exist = false;
	if (!(c[8] - c[7] == B && c[7] - c[6] == A)) is_exist = false;


	if (is_exist) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n , ans , sum , a , b ,arr[mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		double ans , r;
		cin>> r;
		ans = 2*r*PI;
		cout << fixed;
		cout << setprecision(6);
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 3804
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <cstdio>
#include<algorithm>
#include <utility>
using namespace std;
#define output for (int k = 0; k < n-1; k++) {cout << a[k] << " ";}cout << a[n - 1] << endl;
int main() {
	int n,v,j;
	vector<int> a(10000);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j>=0 && a[j]>v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}
		output;
	}
	return 0;
}

Measured memory_bytes: 3120