akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef unsigned long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

vector<int> Snum[30];

int main(){
    string s,t;
    cin>>s>>t;
    ll S=s.size(), T=t.size();
    for(int i=0;i<S;i++){
        int k=s.at(i)-'a';
        Snum[k].push_back(i);
    }

    bool able=true;
    ll ans=0;

    for(int i=0;i<T;i++){
        int k=t.at(i)-'a';
        ll amari=ans%S;
        ll shou=ans/S;
        if(i==0) {amari=S-1; shou=-1;}
        if(Snum[k].size()==0) able=false;
        else if(Snum[k].at(Snum[k].size()-1)<=amari) ans=(shou+1)*S+Snum[k].at(0);
        else ans=shou*S+*upper_bound(Snum[k].begin(),Snum[k].end(),amari);
        //cout<<t.at(i)<<ans<<endl;
        //if(ans>=100*S) able=false;
        if(!able) break;
    }

    if(able) cout<<ans+1<<endl;
    else cout<<-1<<endl;

    
    


}

Measured memory_bytes: 1216
const MOD_N: u64 = 1000000007;

fn bit_cnt_add(bit_cnt: &mut Vec<Vec<u32>>, x: u64) {
    for i in 0..64 {
        let bit_x = ((x >> i) & 1) as usize;
        bit_cnt[i][bit_x] += 1;
    }
}

fn xor_add_bits(bit_cnt: &Vec<Vec<u32>>, xor_x: u64) -> u64 {
    let mut result = 0u64;

    for i in 0..64 {
        let bit_x = if ((xor_x >> i) & 1) == 0 { 1usize } else { 0usize };

        let nr_one = bit_cnt[i][bit_x] as u64;
        let shift = (1 << i) % MOD_N;

        result += (nr_one * shift) % MOD_N;
        result %= MOD_N;
    }

    result
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let a_s = buf.split_whitespace()
        .map(|x| x.parse::<u64>().unwrap())
        .collect::<Vec<_>>();

    let mut bit_cnt = vec![vec![0u32; 2]; 64];

    let mut ans = 0u64;

    for i in (1..n).rev() {
        bit_cnt_add(&mut bit_cnt, a_s[i]);
        ans += xor_add_bits(&bit_cnt, a_s[i-1]);
        ans %= MOD_N;
    }

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


Measured memory_bytes: 14456
from math import ceil

# def prime(n):
#     prime_list = [2]
#     for i in range(3, n, 2):
#         cnt = 0
#         for j in range(2, int(i**(0.5))-1):
#             if i % j == 0:
#                 cnt += 1
#             # if j == int(i ** (0.5)):
#             #     continue
#         if cnt == 0:
#             prime_list.append(i)
#
#     return prime_list
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

p_list = primes(10**5)
p_set = set(p_list)
cnt = 0
a = [0] * 10**5
for i in range(10**5):
    if i in p_set:
        if ceil(i/2) in p_set:
            cnt += 1
            # print(i)
    a[i] = cnt
# print(p_list)
# print(a)

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    print(a[c] - a[b-1])


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

int main() {
	int N; cin >> N;
	long long x[110], y[110];
	long long h[110];
	int z = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[z] >> y[z] >> h[z];
		if (h[z] == 0) continue;
		z++;
	}
	if (z == 1) {
		cout << x[0] <<" "<< y[0] <<" "<< h[0];
		return 0;
	}
	long long i, j;
	for (i = 0; i <= 100; i++) {
		for (j = 0; j <= 100; j++) {
			int c = 1;
			for (int k = 1; k < z; k++) {
				long long H = h[k] - h[k - 1];
				long long C = -abs(i - x[k]) - abs(j - y[k]) + abs(i - x[k-1]) + abs(j - y[k-1]);
				if (H != C)break;
				c++;
			}
			if (c == z) {
				cout << i << " " << j << " " << h[0] + abs(i - x[0]) + abs(j - y[0]);
				return 0;
			}
		}
	}

}

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

  	if(k % 2 == 0)
  		ans = pow(k/2, 2);
	else
      	ans = (k/2) * (k/2 + 1);
  
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n;
	cin >> n;
	int h[n + 1];
	int i;
	for (i = 0; i < n; i++)cin >> h[i];

	int dp[n + 1];
	dp[0] =  0;
	dp[1] = abs(h[1] - h[0]);
	for (i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]) , dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return;
}

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


Measured memory_bytes: 5172
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int a, b, c; cin >> a >> b >> c;
  set<int> s = {a, b, c};
  auto ans = s.size() == 2 ? "Yes" : "No";
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=100100;
int s[N],t[N];
int n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",s+i),t[i]=s[i];
	std::sort(t+1,t+n+1);
	ans=0;
	for(int i=1;i<=n;i++)
	{
		s[i]=std::lower_bound(t+1,t+n+1,s[i])-t;
		ans+=(s[i]&1)^(i&1);
	}
	printf("%d\n",ans/2);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdlib>

#define N 100000
using namespace std;


typedef struct{
  int num[N];
  int head;
  int tail;
}Queque;


//grobal
Queque que;

//add to head position
void Enqueue(int);
//delete head position
void Dequeue(void);
//return now of stck
int front(void);


int main(){
  //format
  que.head=0;
  que.tail=0;

  int pasttime=0;
  int i,n,q,tim=0;
  string name[N];
  int finishcount=0;
  int flag[N];
  int st;

  //load n and q
  cin >>n>>q;

  //load name and time
  for(i=0;i<n;i++){
    cin >>name[i]>>tim;
    Enqueue(tim);
  }

  //format flag
  for(i=0;i<n;i++){
    flag[i]=0;
  }
  
  i=0;

  while(1){
    if(finishcount==n) break;
    //i->n i=0 continue
    else if(i==n){
      i=0;
      continue;
      }
    //flag=1 go next
      else if(flag[i]==1){
      i++;
      continue;
    }
    //load
    st=front();

    if(st>q){
      Enqueue(st-q);
      Dequeue();
      pasttime+=q;
    }

    else{
      Dequeue();
      pasttime+=st;
      flag[i]=1;
      finishcount++;
      //print
      cout <<name[i]<<" "<<pasttime<<endl;
    } 
    
    i++;
  }
    
  
  return 0;
  
}

//add to head position
void Enqueue(int x){
  que.num[que.tail]=x;
  que.tail++;
//if over N tail=0
  if(que.tail>=N)que.tail=0; 
}
//delete head position
void Dequeue(void){
  que.head++;
}
//return now of stck
int front(void){
  return que.num[que.head];
}

Measured memory_bytes: 0
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()
 
v_odd_common.append((0,0))
v_even_common.append((0,0))
 
if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))

Measured memory_bytes: 21084
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] =x;
    tail = (tail+1)%LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head+1)%LEN;
    return x;
}

int min(int a, int b){return a<b ? a:b;}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for(i=1; i<=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head=1; tail=n+1;

    while(head!=tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t>0) enqueue(u);
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}



Measured memory_bytes: 11928
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

ans = 0
z = 0
o = 0
for c in input():
    if c == '0':
        if o > 0:
            o -= 1
            ans += 2
        else:
            z += 1
    else:
        if z > 0:
            z -= 1
            ans += 2
        else:
            o += 1
print(ans)


Measured memory_bytes: 3188
n,c,k = map(int, input().split())
t = [0] * n
for i in range(n):
        t[i] = int(input())
t.sort()
ans = 0
t_from = 0 #一人目の客がバスに乗った時間
p = 0 #乗客の数
for i in range(n):
        if p == 0:
                ans += 1
                p = 1
                t_from = t[i]
        elif p < c:
                if t_from + k >= t[i]: #乗せてもOK
                        p += 1
                else: # i番目の人は次のバスに乗る場合
                        ans += 1
                        t_from = t[i]
                        p = 1
        else:
                ans += 1
                p = 1
                t_from = t[i]


print(ans)

Measured memory_bytes: 7472
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n - 1));
	vector<bool> done(n, false);

	int cnt = 0;
	rep(i, n) rep(j, n - 1)
	{
		int tmp;
		scanf("%d", &tmp);
		tmp--;
		a[i][j] = tmp;
	}
	map<int, int> ite;
	bool yet = true;
	bool fail = false;
	vector<vector<bool>> today(n, vector<bool>(n * n, true));
	//vector<bool>today(n,true);
	int day = 0;
	bool dec = false;
	deque<int> ydy;
	rep(i, n)
	{
		ydy.pb(i);
	}
	while (yet)
	{
		deque<int> tomorrow;
		rep(i, ydy.size())
		{
			if (ite[ydy[i]] != n - 1 && today[ydy[i]][day])
			{
				int j = a[ydy[i]][ite[ydy[i]]];
				if (ite[j] != n - 1 && today[j][day])
				{
					if (a[j][ite[j]] == ydy[i])
					{
						//cout<<i<<" "<<j<<endl;
						//if(i==j)cout<<i<<"  ww"<<ite[i]<<a[i][ite[i]]<<endl;
						dec = true;
						ite[ydy[i]]++;
						ite[j]++;
						tomorrow.pb(j);
						today[ydy[i]][day] = false;
						today[j][day] = false;
						if (ite[ydy[i]] == n - 1 && !done[ydy[i]])
						{
							done[ydy[i]] = true;
							//cout << ydy[i] << "done" << endl;
							cnt++;
						}else{
							tomorrow.pb(ydy[i]);
						}
						if (ite[j] == n - 1 && !done[j])
						{
							done[j] = true;
						//	cout << j << "done" << endl;
							cnt++;
						}else{
							tomorrow.pb(j);
						}
					}
				}
			}
		}
		day++;
		//cout << day << endl;
		ydy = tomorrow;

		if (cnt == n)
		{
			yet = false;
			break;
		}
		if (!dec)
		{
			fail = true;
			yet = false;
			break;
		}
		dec = false;
	}
	if (!fail)
	{
		cout << day << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}


Measured memory_bytes: 126464
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 105, maxp = 205, inf = 0x3f3f3f3f;
struct Edge {
    int next, to, cap, flow;
    Edge(int a=0, int b=0, int c=0) : 
	next(a), to(b), cap(c), flow(0) {}
};
vector<Edge> e(2);
int head[maxp];
void Add(int u, int v, int c) {
    e.push_back(Edge(head[u], v, c)); head[u] = e.size() - 1;
    e.push_back(Edge(head[v], u, 0)); head[v] = e.size() - 1;
}

int N, M;
char s[maxn];

int src, sink, cur[maxp], d[maxp], vis[maxp], T;
queue<int> q;
bool bfs() {
    vis[src] = ++T, q.push(src);
    while(!q.empty()) {
	int x = q.front(); q.pop();
	for(int i = head[x]; i; i = e[i].next) {
	    int to = e[i].to;
	    if(vis[to] != T && e[i].cap > e[i].flow) {
		vis[to] = T;
		d[to] = d[x] + 1;
		q.push(to);
	    }
	}
    }
    return vis[sink] == T;
}
int dfs(int x, int a) {
    if(x == sink || !a) return a;
    int flow = 0, f;
    for(int &i = cur[x]; i; i = e[i].next) {
	int to = e[i].to;
	if(d[to] == d[x] + 1 && (f = dfs(to, min(a, e[i].cap - e[i].flow))) > 0){
	    e[i].flow += f;
	    e[i ^ 1].flow -= f;
	    flow += f;
	    a -= f;
	    if(!a) break;
	}
    }
    return flow;
}
int dinic() {
    int flow = 0;
    while(bfs()) {
	memcpy(cur, head, sizeof cur);
	flow += dfs(src, inf);
    }
    return flow;
}

int main() {
    scanf("%d%d", &N, &M);
    src = N + M + 1, sink = src + 1;
    int sx, sy, tx, ty;
    for(int i = 1; i <= N; ++i) {
	scanf("%s", s + 1);
	for(int j = 1; j <= M; ++j) {
	    if(s[j] == '.') continue;
	    Add(i, j + N, 1);
	    Add(j + N, i, 1);
	    if(s[j] == 'S') sx = i, sy = j;
	    if(s[j] == 'T') tx = i, ty = j;
	}
    }
    if(sx == tx || sy == ty) {
	puts("-1");
    } else {
	Add(src, sx, inf); Add(src, sy + N, inf);
	Add(tx, sink, inf); Add(ty + N, sink, inf);
	printf("%d\n", dinic());
    }
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> s(h, vector<char>(w));
  int cnt = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> s[i][j];
      if (s[i][j] == '#') {
        cnt++;
      }
    }
  }

  vector<vector<int>> costs(h, vector<int>(w, -1));
  queue<array<int, 3>> q;
  q.push({0, 0, 0});
  while (!q.empty()) {
    auto [i, j, cost] = q.front();
    q.pop();
    if (i < 0 || i > h - 1 || j < 0 || j > w - 1 || costs[i][j] != -1 ||
        s[i][j] == '#') {
      continue;
    }

    costs[i][j] = cost;
    q.push({i - 1, j, cost + 1});
    q.push({i + 1, j, cost + 1});
    q.push({i, j - 1, cost + 1});
    q.push({i, j + 1, cost + 1});
  }

  int cost = costs[h - 1][w - 1];
  if (cost < 0) {
    cout << -1 << '\n';
  } else {
    cout << h * w - (cost + 1) - cnt << '\n';
  }

  return 0;
}

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

#define MAX_N 100000

using namespace std;

int s1[MAX_N + 2];
int s2[MAX_N + 2];

int n;
int v[MAX_N + 2];

int main()
{
    cin >> n;

    int i;
    for(i = 1; i <= n; i ++)
    {
        cin >> v[i];
        s1[i] = s1[i - 1] + abs(v[i] - v[i - 1]);
    }

    v[n + 1] = 0;

    for(i = n; i >= 1; i --)
    {
        s2[i] = s2[i + 1] + abs(v[i + 1] - v[i]);
    }

    for(i = 1; i <= n; i ++)
    {
        cout << s1[i - 1] + s2[i + 1] + abs(v[i - 1] - v[i + 1]) << "\n";
    }

    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC062C_ChocolateBar();
#if 1
int main()
{
	ABC062C_ChocolateBar();
	fflush(stdout);
	return 0;
}
#endif

static LLONG ABC062C_getMin(LLONG bfrMin, LLONG targ, LLONG other)
{
	LLONG min = bfrMin;
	for (int i = 1; (i < targ) && min; i++) {
		LLONG tmp = i * other;
		LLONG blk1 = ((targ - i) * other) / 2LL;
		blk1 -= tp_min(blk1 % (targ - i), blk1 % other);

		LLONG plus = tp_min<LLONG>(other * ((targ - i) % 2LL), (targ - i) * (other % 2LL));
			
		LLONG max = tp_max(tmp, blk1 + plus);
		LLONG tmpMin = tp_min(tmp, blk1);

		min = tp_min<LLONG>(min, max - tmpMin);
	}

	return min;
}

static void ABC062C_ChocolateBar()
{
	LLONG H, W;
	get2int<LLONG>(H, W);
	
	LLONG min = (H % 3LL) * W;
	min = tp_min<LLONG>(min, (W % 3LL) * H);

	min = ABC062C_getMin(min, W, H);
	min = ABC062C_getMin(min, H, W);

	printf("%lld\n", min);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define TCI int t;cin>>t;while(t--)
#define cinl for(int i=0;i<n;i++)
#define ln "\n"
#define vpair vector< pair <ll , ll > >
#define fr first 
#define sc second 
#define pb emplace_back
#define vll vector<ll>
using namespace std;

const int N=1e5;

void solve()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<ln;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 VI a(3);
 rep(i,3)cin >> a.at(i);
 sort(a.begin(),a.end());
 int ans=a.at(0)+a.at(1);
 cout << ans << endl;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)

using ll = long long;
using namespace std;

int h[100010];
int dp[100010] = {0};

int main() {
    int N;
    cin >> N;
    rep1(i, N) cin >> h[i];
    
    rep1(i, N) {
        if(i == 1) dp[i] = 0;
        else if(i == 2) dp[i] = 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]));
    }
    
    cout << dp[N];
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

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

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int gl[100010];
    int gr[100010];
    gl[0] = A[0];
    gr[N-1] = A[N-1];
    for (int i = 1; i < N; i++) {
        gl[i] = gcd(gl[i-1], A[i]);
        gr[N-i-1] = gcd(gr[N-i], A[N-i-1]);
    }

    int res = 1;

    for (int i = 0; i < N; i++) {
        if (i == 0) {
            res = gr[i+1];
        }
        else if (i == N-1) {
            res = max(res, gl[i-1]);
        }
        else {
            res = max(res, gcd(gl[i-1], gr[i+1]));
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define decimal fixed << setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> ans(n+1, 0);
  rep(i,n-1){
    if(s[i]=='A'&&s[i+1]=='C') ans[i+1]++;
  }
  rep(i,n) ans[i+1]+=ans[i];
  
  rep(i,q){
    int l,r;
    cin>>l>>r;
    cout<<ans[r-1]-ans[l-1]<<endl;
  }
  
}

Measured memory_bytes: 1408
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <stdint.h>
using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;//トッピングの種類
int A,B;//生地とトッピングの値段
int C;//生地のカロリー
int v[150];//トッピングのカロリー
long long sum1;//金額の合計
long long sum2;//カロリーの合計
int main()
{
  cin>>n;
  cin>>A>>B;
  cin>>C;
  for(int i = 0;i< n;i++){
    cin>>v[i];
  }
  sort(v,v+n,greater<int>() );
  sum1 = A;
  sum2 = C;
  int ans =C/A;
  for(int i = 0;i <n;i++){
    sum1 +=B;
    sum2 +=v[i];
    int pos =sum2/sum1;
    if(ans>pos){
      break;
    }
    ans =pos;
  }
  cout <<ans<<endl;
  return 0;
}

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

H = list(map(int, input().split()))
dp = [0]*N
# 初期を入れる
dp[0] = 0
dp[1] = abs(H[1]-H[0])

for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))

print(dp[-1])


Measured memory_bytes: 13908
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  for (;;) {
    auto rd = readln.split.map!(to!int);
    auto n = rd[0], x = rd[1];
    if (n == 0 && x == 0) break;

    auto r = 0;
    foreach (i; 1..n+1)
      foreach (j; i+1..n+1) {
        auto k = x - i - j;
        if (k > j && k <= n) ++r;
      }

    writeln(r);
  }
}

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

int main()
{
	//freopen("test.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll cnt=0;
	for(ll i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		if(x>=k)
			cnt+=1;
	}
	cout<<cnt<<"\n";


}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int A;
	cin >> A;
	int ans = 0;
	rep1(i, 10) {
		if ((A%i == 0) & (A / i < 10)) {
			ans = 1;
			break;
		}
	}
	if (ans == 1) {
		print("Yes");
	}
	else {
		print("No");
	}
}

Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;



int point[10001];
int done[10001];
int edge[10001][10001];
int score[10001];
int edgenum[10001];

int used = 0;
void dfs(int node) {
	int flag = 1;
		done[node] = 1;
		for (int i = 0; i < 10001; i++) {
			if (edge[node][i] == 0) {
				
				break;
			}
			if (done[edge[node][i]] != 1) {
				dfs(edge[node][i]);
				
			
			}
		}

		point[node] = score[used];
		used++;
	

}

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


	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		edgenum[a] =edgenum[a]+ 1;
		edgenum[b] = edgenum[b] + 1;;
		edge[a][edgenum[a] - 1] = b;
		edge[b][edgenum[b] - 1] = a;

	}


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

	for (int i = n; i < 10001; i++) {
		score[i] = 100001;
	}

	sort(score,score + 10001);
	long long ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans = ans + score[i];
	}

	dfs(1);

	cout << ans << endl;

	cout << point[1];
	for (int i = 2; i < n + 1; i++) {
		cout << " " << point[i];
	}
	return 0;

}

Measured memory_bytes: 388224
/*Author- Soumak Poddar*/

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

#define ll long long int
#define sll signed long long int
#define ull unsigned long long int
#define um unordered_map
#define mp make_pair
#define pb push_back
#define M 1000000007

void solve();
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("error.txt", "w", stderr);
      freopen("output.txt", "w", stdout);
   #endif
   
   int t=1;
   //cin>>t;
   while(t--)
   {
      solve();
      cout<<"\n";
   }
   cerr<<"Time Taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}
void solve()
{
   int n;
   cin>>n;
   if(n<=1000)
   {
      cout<<1000-n;
   }
   else
   {
      int i=2;
      int amt=1000;
      while(i*amt<n)
      {
         i++;
      }
      cout<<abs(i*amt-n);
   }
}

Measured memory_bytes: 3796
ary=$stdin.readlines
od=Array.new
ev=Array.new
n = ary[0].to_i
array=ary[1].split.map!(&:to_i)
p=0
while p<n
  od.push(array[p]) if p%2==0
  ev.push(array[p]) if p%2==1
  p+=1
end

  sd_n_ns_od = od.group_by{|i| i}.sort_by{|k,v| v.size}
  sd_n_ns_ev = ev.group_by{|i| i}.sort_by{|k,v| v.size}



if sd_n_ns_od.size == 1 && sd_n_ns_ev.size == 1
  if sd_n_ns_od.last.first == sd_n_ns_ev.last.first
    answer = n/2
  else
    answer= 0
  end
else
most_n_od = sd_n_ns_od.last.first
most_n_ev = sd_n_ns_ev.reject{|k,v| k == most_n_od}.last.first
answer1=0
answer1+=od.reject{|i| i==most_n_od}.size
answer1+=ev.reject{|i| i==most_n_ev}.size

most_n_ev = sd_n_ns_ev.last.first
most_n_od = sd_n_ns_od.reject{|k,v| k== most_n_ev}.last.first
answer2=0
answer2+=ev.reject{|i| i==most_n_ev}.size
answer2+=od.reject{|i| i==most_n_od}.size

 answer = (answer1 <= answer2)?  (answer1):(answer2)
=begin
 if  sd_n_ns_od.size == 1
   answer=answer1
 end

 if  sd_n_ns_ev.size == 1
   answer=answer2
 end
=end
 end
puts answer

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;


int bipartite_matching(VVI& G, VI& matchU, VI& matchV){
  int N = G.size();
  fill(ALL(matchU), -1);
  fill(ALL(matchV), -1);
  vector<int> level(N);
  vector<bool> finished(N);

  int total = 0;
  for(bool up=true;up;){
	up = false;

	// bfs
	fill(ALL(level), -1);
    queue<int> Q;
	REP(i,N){
	  if(matchU[i] == -1){
		level[i] = 0;
		Q.push(i);
	  }
	}
	while(!Q.empty()){
      int u = Q.front();
	  Q.pop();
      for(auto to: G[u]){
		if(matchV[to] != -1 && level[matchV[to]] == -1){
		  level[matchV[to]] = level[u] + 1;
		  Q.push(matchV[to]);
		}
	  }
    }

	// dfs
	fill(ALL(finished), false);
	function<bool(int)> dfs = [&](int u){
	  finished[u] = true;
	  for(auto to: G[u]){
		int bk = matchV[to];
		if(bk == -1 || (!finished[bk] && level[bk] == level[u]+1 && dfs(bk))){
		  matchU[u] = to;
		  matchV[to] = u;
		  return true;
		}
	  }
	  return false;
	};


	REP(i,N){
	  if(matchU[i] == -1 && dfs(i)){
		up = true;
		++total;
	  }
    }
  }
  return total;
}

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

  int X, Y, E;
  cin >> X >> Y >> E;
  VVI G(X);
  REP(i,E){
	int x, y;
	cin >> x >> y;
	G[x].PB(y);
  }
  VI mu(X), mv(Y);
  cout << bipartite_matching(G, mu, mv) << endl;

  return 0;
}



Measured memory_bytes: 3304
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
from itertools import accumulate as ac
from bisect import bisect_right as bl
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
A=[0]+list(ac(a))
B=list(ac(b))
ans=0
#print(A,B)
for i in range(n+1):
    nokori=k-A[i]
    if nokori<0:
        print(ans)
        exit()
    ind=bl(B,nokori)
    ans=max(ans,i+ind)
print(ans)

Measured memory_bytes: 49016
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
void solve(){
	char c;
	cin>>c;
	if(c>='A' and c<='Z')
		cout<<"A";
	else
		cout<<"a";
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    char s;
    cin>>s;
    if(isupper(s))cout<<"A";
    if(islower(s)) cout<<"a";
    return 0;
}

Measured memory_bytes: 3064
A, B, C, X, Y = map(int, input().split())

ans = 10**18
for i in range(0, 2*max(X, Y)+2, 2):
    ans = min(ans, i * C + max(X-(i//2), 0) * A + max(Y-(i//2), 0) * B)
print(ans)

Measured memory_bytes: 8940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7,MOD=998244353;

int main() {
  int N,S;
  cin >> N >> S;
  vi A(N);
  rep(i,N) cin >> A[i];
  
  vvi dp(N+1,vi(S+1));
  dp[0][0]=1;
  rep(i,N) {
    rep(j,S+1) {
      dp[i+1][j]=dp[i][j]*2%MOD;
      if(j>=A[i]) dp[i+1][j]=(dp[i+1][j]+dp[i][j-A[i]])%MOD;
    }
  }
  
  cout << dp[N][S] << endl;
}

Measured memory_bytes: 38560
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static char[][] a;
        static int[][] ans;
        static int count = 0;
        static bool see = false;
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int h = l[0], w = l[1];
            a = new char[h][];
            ans = new int[h][];
            for (var i = 0; i < h; i++) {
                a[i] = Console.ReadLine().ToCharArray();
                ans[i] = Enumerable.Repeat(int.MaxValue, w).ToArray();
            }
            
            for (var i = 0; i < h; i++)
            {
               Initialize();
               for (var j = 0; j < w; j++)
                   JudgeFirst(i, j);
                   //Console.WriteLine(string.Join(" ", ans[i]));
               Initialize();
               for (var j = w - 2; j >= 0; j--)
                   Judge(i, j, 0, 1);
                   //Console.WriteLine(string.Join(" ", ans[i]));
            }
            
            for (var j = 0; j < w; j++)
            {
               Initialize();
               for (var i = 1; i < h; i++)
                   Judge(i, j, -1, 0);
                //Console.WriteLine(string.Join(" ", ans[j]));
               Initialize();
               for (var i = h - 2; i >= 0; i--)
                   Judge(i, j, 1, 0);
                   //Console.WriteLine(string.Join(" ", ans[j]));
            }

            var max = 0;
            for (var i = 0; i < h; i++)
            {
                //Console.WriteLine(string.Join(" ", ans[i]));
                max = Math.Max(max, ans[i].Max());
            }
            
            Console.WriteLine(max);
        }

        static void Initialize()
        {
           count = 0;
           see = false; 
        }
        
        static void JudgeFirst(int i, int j)
        {
            if (a[i][j] == '#')
            {
                see = true;
                count = 0;
                ans[i][j] = count;
            }
            else
            {
                if (see)
                    ans[i][j] = Math.Min(++count, ans[i][j]);
            }
        }
        
        static void Judge(int i, int j, int addI, int addJ)
        {
            if (ans[i+addI][j+addJ] != int.MaxValue)
            {
               ans[i][j] = Math.Min(ans[i][j], ans[i+addI][j+addJ] + 1); 
            }
        }
    }
}


Measured memory_bytes: 25156
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;cin >> str;
	string ans = "CODEFESTIVAL2016";
	int ret = 0;
	REP(i,str.size()){if(str[i]!=ans[i])ret++;}
	cout<<ret << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
pat = [0]*(N+1)
for i in range(N+1):
  if i == 0:
    pat[i] = 1
  else:
    element = a[0] if len(a) != 0 else -1
    pat[i] = pat[i-1] + pat[i-2] if i != element  else 0
    if i == element:
      a.pop(0)
print(pat[-1]%1000000007)

Measured memory_bytes: 460020
s = input()
l = [int(i) for i in s[0::2]]
r = [int(i) for i in s[1::2]]

if len(s) == 1:
    print(0)
else:
    l_count1 = l.count(1)
    l_count0 = len(l)-l_count1
    r_count1 = r.count(1)
    r_count0 = len(r)-r_count1
    l_1 = l_count0+r_count1
    l_0 = l_count1+r_count0
    if (l_count1==len(l) and r_count0==len(r)) or (l_count0==len(l) and r_count1==len(r)):
        print(0)
    elif l_1 < l_0:
        print(l_1)
    else:
        print(l_0)


Measured memory_bytes: 4032
{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace (traceShow, traceShowM)

import qualified Data.ByteString.Char8 as B
import Text.Printf (printf)
import Control.Monad.ST
import Data.Array.ST
import Data.Array
import qualified Data.IntMap.Strict as M

readi b | Just (n, _) <- B.readInt b = n

f1 xs = [(j, k, i) | (i, (j, k)) <- zip [1..] xs]

solve :: Int -> Int -> [(Int, Int)] -> IO ()
solve n m pys = forM_ pys $ \(i, j) -> do
    let m = ary ! i
    let a = m M.! j
    printf "%06d%06d\n" i (a :: Int)
  where
    ps = groupBy (\a b -> fst a == fst b) $ sort pys
    ary = runSTArray $ do
        a <- newArray (1, n) M.empty
        let qs = fmap f1 ps
        forM_ qs $ \gs -> do
            forM_ gs $ \(i, j, k) -> do
                m <- readArray a i
                writeArray a i (M.insert j k m)
        return a

main :: IO ()
main = do
    [n, m] <- fmap readi . B.words <$> B.getLine :: IO [Int]
    pys <- replicateM m $ do
        [p, y] <- fmap readi . B.words <$> B.getLine
        return (p, y) :: IO (Int, Int)
    solve n m pys

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

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

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

	vector<ll> dist(n, 0);
	for (int i = 1; i < n ;i++)
	{
		dist[i - 1] = a[i] - a[i - 1];
	}
	dist[n - 1] += k - a[n - 1] + a[0];

	auto it = max_element(dist.cbegin(), dist.cend());
	ll tot = accumulate(dist.cbegin(), dist.cend(), 0LL);
	tot -= *it;

	cout << tot << endl;

	return 0;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll x, k, d, moves, val, ans ;
    cin >> x >> k >> d ;
    x = abs(x) ;

    val = x / d ;
    moves = min(k, val) ;
    ans = x - (d * moves) ;
    k -= moves ;
    if (k % 2 == 0) cout << ans ;
    else {
        ans = min(ans + d, abs(ans - d)) ;
        cout << ans ;
    }


    return 0 ;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> table(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> table.at(i).at(j);
    }
  }
  
  vector<bool> flagH(H,false);
  vector<bool> flagW(W,false);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(table.at(i).at(j)=='#'){
        flagH.at(i)=true;
        flagW.at(j)=true;
      }
    }
  }
  
    for(int i=0;i<H;i++){
  	  for(int j=0;j<W;j++){
        if(flagH.at(i)&&flagW.at(j))
          cout << table.at(i).at(j);
        if(j==W-1)
          cout << endl;
      }
    }
   
}

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

int main() {
  int sx,sy,tx,ty,dx,dy;
  cin >> sx >> sy >> tx >> ty;
  dx = tx-sx;
  dy = ty-sy;
  for(int i = 0;i < dy;i++){
    cout << 'U';
  }
  for(int i = 0;i < dx;i++){
    cout << 'R';
  }
  for(int i = 0;i < dy;i++){
    cout << 'D';
  }
  for(int i = 0;i < dx;i++){
    cout << 'L';
  }
  cout << 'L';
  for(int i = 0;i < dy+1;i++){
    cout << 'U';
  }
  for(int i = 0;i < dx+1;i++){
    cout << 'R';
  }
  cout << 'D';
  cout << 'R';
  for(int i = 0;i < dy+1;i++){
    cout << 'D';
  }
  for(int i = 0;i < dx+1;i++){
    cout << 'L';
  }
  cout << 'U' << endl;
}


Measured memory_bytes: 256
import math
N = int(input())
all_gcd = []
for i in range(1, N+1):
  for j in range(1, N+1):
    x = math.gcd(i, j) if i != j else i
    for m in range(1, N+1):
      y = math.gcd(x, m) if x != m else x
      all_gcd.append(y)

print(sum(all_gcd))

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

#define rep(i,x) for(int i=0;i<x;i++)
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> Sm(m);
    rep(i, m){
        int k; cin >> k;
        rep(j, k) {int s; cin >> s; Sm[i].push_back(s);}
    }
    vector<int> Ps;
    rep(i, m) {
        int p; cin >> p;
        Ps.push_back(p);
    }
    int ans = 0;
    rep(i, 1 << n){
        bool allok = true;
        rep(j, m){
            int on = 0;
            for(int s : Sm[j]){
                if(i & (1 << s - 1)) on++;
            }
            if(on % 2 != Ps[j]) {allok = false; break;}
        }
        if(allok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
<?php
# 入力
fscanf(STDIN, '%d %d', $a, $b);
if ($a > $b) {
    $tmp = $a;
    $a = $b;
    $b = $tmp;
}
$diff = $b - $a;
if ($diff % 2 === 1) {
    echo 'IMPOSSIBLE';
} else {
    echo ($b - ($diff / 2)).PHP_EOL;
}
?>

Measured memory_bytes: 4604
import Data.Maybe (fromJust)
import Data.List

main = do
  k <- readLn :: IO Int
  let ans = f k 2
  case k of
    0 -> do putStrLn "2"
            putStrLn "1 1"
    1 -> do putStrLn "2"
            putStrLn "2 0"
    _ -> do let a = fromJust ans
            print $ length a
            putStrLn . unwords . map show $ a

make :: Int -> [Int]
make n = [0..n-1]

solve :: Int -> Int -> [Int] -> Maybe [Int]
solve i 0 p      = if maximum p <= 10^16 + 1000
                     then Just p
                     else Nothing
solve i k p
  | k > length p = let x = div k $ length p
                   in solve i (mod k $ length p) $ map (+x) p
  | otherwise    = let p' = map (flip (-) 1) p
                       p'' = (take i p') ++ [(+(1+length p)) $ p' !! i] ++ drop (i+1) p'
                       m = maximum p''
                       mi = fromJust $ elemIndex m p''
                   in if mi == i && elemIndex (-1) p'' == Nothing
                        then solve (i+1) (k-1) p''
                        else Nothing

f :: Int -> Int -> Maybe [Int]
f k i = let ans = solve 0 k $ make i
        in if ans /= Nothing then ans
                             else f k $ i + 1


Measured memory_bytes: 1020
n,w = map(int, input().split())

a = [list(map(int, input().split())) for i in range(n)]

x = a[0][0]

for i in range(n):
    a[i][0]-=x

dp = [[[0 for i in range(301)] for j in range(n+1)] for k in range(n+1)]

for k in range(1,n+1):
    for j in range(1,n+1):
        for i in range(301):
            if i>=a[k-1][0]:
                dp[k][j][i]=max(dp[k-1][j-1][i-a[k-1][0]] + a[k-1][1], dp[k-1][j][i])
            else:
                dp[k][j][i]=dp[k-1][j][i]

ans = 0
for j in range(n+1):
    for i in range(301):
        if i+j*x<=w:
            ans = max(ans,dp[n][j][i])

print(ans)


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

#define K 1000000
int A[K],n;

int binarysearch(int key){
  int left = 0;
  int right = n;
  int mid;
  while(left< right){
  mid = (right+left)/2;
  if(key == A[mid]) return 1;
  if(key > A[mid]) left = mid +1;
  else if(key<A[mid]) right = mid;
  }
   return 0;
}





int main(){
 
  int i,M,L,count=0;
  
  scanf("%d",&n);
 
  for(i=0;i<n;i++)
  scanf(" %d",&A[i]);
  
  scanf("%d",&M);
  for(i=0;i<M;i++){
  scanf("%d",&L);
  if(binarysearch(L) )count++;
  }

  printf("%d\n",count);  
  



  return 0;
}



Measured memory_bytes: 2128
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
H = l.shift() * 1
W = l.shift() * 1 
l = []
m = []
for (i=0; i<H; i++) {
  l.push(inp.shift().split(''))
  m[i] = []
  for (j=0; j<W; j++) {
      m[i][j] = 0 
  }
}
if (l[0][0] == "#") {
    m[0][0] = 1
}
r = 0
for (c=1; c<W; c++) {
  m[r][c] = l[r][c-1] == l[r][c] ? m[r][c - 1] : m[r][c - 1] + 1 
}
c = 0
for (r=1; r<H; r++) {
  m[r][c] = l[r-1][c] == l[r][c] ? m[r - 1][c] : m[r - 1][c] + 1 
}
for (i=1; i<H; i++) {
    r = i
    for (c=i; c<W; c++) {
      s = l[r][c-1] == l[r][c] ? m[r][c - 1] : m[r][c - 1] + 1
      t = l[r-1][c] == l[r][c] ? m[r-1][c] : m[r-1][c] + 1
      m[r][c] = Math.min(s, t)
    }
    c = i
    for (r=i; r<H; r++) {
      s = l[r-1][c] == l[r][c] ? m[r - 1][c] : m[r - 1][c] + 1
      t = l[r][c-1] == l[r][c] ? m[r][c- 1] : m[r][c-1] + 1
      m[r][c] = Math.min(s, t)
    }
}
console.log(Math.ceil(m[H-1][W-1] / 2))

Measured memory_bytes: 21448
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll X, Y, Z; cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
  return 0;
}


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

int main(void){
  int k,n;
  cin >> k >> n;
  
  vector<int> houses(n);
  for(int i=0;i<n;i++){
    cin >> houses.at(i);
  }
  
  houses.push_back(k+houses.at(0));
  
  int a=0;
  
  for(int i=0;i<n;i++){
    a = max(a,houses.at(i+1)-houses.at(i));
  }
  cout << k-a << endl;

  return 0;
  
}
    

Measured memory_bytes: 1792