akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin >>s;
  bool flag=true;
  for (int i=0;i<s.size();i++){
  if ((i+1)%2==1){
  if (s.at(i)=='L'){
  flag=false;
  }  
  }
   if ((i+1)%2==0){
     if  (s.at(i)=='R'){
       flag=false;
     }
   }
  }
  if(flag){
  cout <<"Yes"<<endl;
  }
  else{
  cout <<"No"<<endl;
  }
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
map<ll, ll> dp;
int A[3], D;
int p[3] = {2, 3, 5};
const ll INF = 1e18;
ll get(ll x){
	if(x == 0) return 0;
	auto it = dp.find(x);
	if(it != dp.end()) return it->second;
	ll ret = x >= INF / D ? INF : D * x;
	for(int i = 0; i < 3; i++){
		ll q = x % p[i];
		ret = min(ret, q * D + A[i] + get(x / p[i]));
		if(q!=0) q = p[i] - q;
		ll nxt = (x - 1) / p[i] + 1;
		if(nxt != x) ret = min(ret, q * D + A[i] + get(nxt));
	}
	return dp[x] = ret;
}
int main(){
	int t; cin >> t;
	while(t--){
		dp.clear();
		ll n; cin >> n;
		cin >> A[0] >> A[1] >> A[2] >> D;
		cout << get(n) << endl;
	}
}

Measured memory_bytes: 4396
I=lambda:map(int,input().split())
h,w,d=I()
H={}
W={}
for i in range(1,h+1):
  for j,k in enumerate(I(),1):
    H[k],W[k]=i,j
x=1+h*w
s=[0 for _ in [0]*x]
for i in range(d+1,x):
  s[i]=s[i-d]+abs(H[i]-H[i-d])+abs(W[i]-W[i-d])

for _ in [0]*int(input()):
  a,b=I()
  print(s[b]-s[a])

Measured memory_bytes: 26012
#include <iostream>
#include <string>
#include <vector>
#include <vector>

using namespace std;

int
main()
{
    int n;
    vector<int64_t> a;
    cin >> n;

    for(int i=0;i<n;i++){
        int64_t x;
        cin >> x;
        a.push_back(x);
    }

    vector<int64_t> b;
    vector<int64_t> c(n);
    c[0] = a[0];
    b.push_back(0);
    for(int i=1;i<n;i++){
        int64_t d;
        c[i] = a[i];
        d = c[i-1] - a[i];
        if(d > 0) {
            c[i] += d;
            b.push_back(d);
        } else {
            b.push_back(0);
        }
    }

    uint64_t ans = 0;
    for(auto &i : b){
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9564
#include <bits/stdc++.h>
#define sz size
#define pb push_back
#define mper make_pair
#define PI 3.14159
#define fe first
#define se second
#define ll long long
//#define forik(i, a, b) for(ll i = a; i <= b; ++i)
//#define vl vector<ll>
//#define pll pair<ll, ll>
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken stringusing namespace std;

using namespace std;

int n, k, dis[2010][2010], mx;
vector < int > g[2010];

bool used[2010][2010];

bitset <2010> t[2100];

vector < pair <int, int> > pos_ans;

void dfs(int orig, int v, int ct = 0) {

    used[orig][v] = 1;

    for(auto to : g[v]) {

        if(!used[orig][to]) {

            dis[orig][to] = ct + 1;

            t[orig][to] = (dis[orig][to] > k);

            mx = max(mx, ct + 1);



            if(ct + 1 == k) {pos_ans.pb(mper(orig, to));}


            dfs(orig, to, ct + 1);

        }

    }

}

int main(){

cin >> n >> k;

for(int i = 1, l, r; i < n; ++i) {

    cin >> l >> r;

    g[l].pb(r);
    g[r].pb(l);

}

for(int i = 1; i <= n; ++i) {
    dfs(i, i);
}


if(mx <= k) {cout << 0;return 0;}


int ans = (int)1e8;

for(auto to : pos_ans) {

    int a = to.fe;
    int b = to.se;
    int ct = (t[a] | t[b]).count();
    ans = min(ans, ct);

}

cout << ans;

return 0;
}

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

int main() {
        int a, b;
        cin >> a >> b;
        int cnt=0;

        for (int i=a; i<=b; i++) {
                int dig1, dig2, dig4, dig5;
                dig1 = i%10;
                dig2 = (i%100 - dig1)/10;
                dig5 = i/10000; 
                dig4 = i/1000 -10*dig5;
                if ((dig1 == dig5) && (dig2 == dig4)) {
                        cnt++;
                }
        }

        cout << cnt << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>
#include <utility>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int64;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<vector<int>, int> count;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    vector<int> a(26, 0);
    for (int j = 0; j < s.length(); ++j) {
      a[s[j] - 'a']++;
    }
    count[a] += 1;
  }
  int64 res = 0;
  for (auto &p : count) {
    res += ((int64) (p.second) * (p.second - 1)) / 2;
  }
  cout << res << '\n';
  return 0;
}



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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pub push_back
#define pob pop_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(fmt, ...) printf(fmt, __VA_ARGS__); printf("\n")
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  string S; cin >> S;
  int n = S.size();

  int ans = n;
  for (int i = 1; i < n; i++) {
    if (S[i-1] != S[i]) {
      de(i << ":" << n-i);
      ans = min(ans, max(i, n-i));
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();
            var cc = s.ToCharArray().Distinct().ToArray();
            Array.Sort(cc);
            cc = cc.Concat(new char[10]).ToArray();
            var i = 0;
            for (char c = 'a'; c < 'a'+26; c++)
            {
                if (c != cc[i])
                {
                    Console.WriteLine(c);
                    return;
                }
                i++;
            }
            Console.WriteLine("None");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int sum = 0;
  for(int i=A;i<=B;i++) {
    if(i/10000==i%10) {
      if((i%10000)/1000==(i/10)%10) {
        sum++;
        continue;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, 0, n)
        cin >> v[i];
    sort(rbegin(v), rend(v));
    vector<pair<int, int>> mp;
    int res = 0;
    mp.push_back({v[0], 1});
    int it = 0;
    for (int i = 1; i < n; i++)
    {
        mp.push_back({v[i], 2});
        res += mp[it].first;
        mp[it].second--;
        if (mp[it].second == 0)
            it++;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 8948
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string t;
    cin >> t;
    int n = t.size();
    for (char &c: t) if (c == '?') c = 'D';
    cout << t << endl;
}

signed main() {
    solve();
    
    return 0;
}

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

//累積和の問題
//R-L % D == 0であるから，R%D ≡ L%D = xとおく
//クエリは，（xからRに行くためにかかるコスト）-（xからLに行くためにかかるコスト）に単純化される
//即ち，y = 0~D-1において，xからyまでDずつ移動するのにかかるコストをtableで保持し，table[x][y]をもとにクエリ処理する
//計算量は，(D*(H*W) + Q)で，十分間に合う

int H, W, D;
vector<pair<int, int>> idx;
vector<int> memo;

int f(int x) {
    if (0 < memo[x]) return memo[x];
    if (x < D) return 0;
 
    int y = x - D;
    int cost = abs(idx[x].first - idx[y].first) + abs(idx[x].second - idx[y].second);
    int res = cost + f(y);
    return memo[x] = res;
}

int main() {
    cin >> H >> W >> D;
    idx.resize(H*W);
    memo.assign(H*W, -1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int a; cin >> a; a--;
            idx[a] = make_pair(i, j);
        }
    }
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        int L, R; cin >> L >> R; L--; R--;
        int dist = f(R)-f(L);
        cout << dist << endl;
    }
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int left = 0;
    int pointer = 0;
    for(int i = 0;i < N;i++) {
        if(S.at(i) == '(') {
            pointer++;
        }
        else if(pointer == 0) {
            left++;
        }
        else {
            pointer--;
        }
    }
    for(int i = 0;i < left;i++) {
        cout << "(";
    }
    cout << S;
    for(int i = 0;i < pointer;i++) {
        cout << ")";
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[][] board = new char[n + 1][];
		for(int i = 0; i < n + 1; i++) {
			board[i] = sc.next().toCharArray();
		}
		int sum = 0; //print
		for(int i = 1; i <= n; i++) {//?????????????????£????????????
			out: for(int j = 0; j < board[i].length; j++) {//1??????????????¢?´¢
				if(board[i][j] == board[0][0]) {
					for(int k = j + 1; k < board[i].length; k++) {//2??????????????¢?´¢
						if(board[i][k] == board[0][1]) {
							int interval = k - j;//1???????????¨2??????????????????
							int cnt = 2;//?????????????????¢?´¢???????????????
							for(int m = k + interval; m < board[i].length; m = m + interval) {//3???????????\????????¢?´¢
								if(board[i][m] == board[0][cnt]) {
									cnt = cnt + 1;
									if(cnt == board[0].length) {
										sum = sum + 1;
										break out;
									}
								} else {
									break;
								}
							}
						}
					}
				}
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 27708
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll n,m;cin>>n>>m;
  ll a;
  priority_queue<ll> q;
  rep(i,n){
    cin>>a;
    q.push(a);
  }
  
  rep(i,m){
    ll now=q.top();
    q.pop();
    now/=2;
    q.push(now);
  }
  ll ans=0;
  
  
  rep(i,n){
    ll now=q.top();
    q.pop();
    ans+=now;
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=30000020;
const ll INF=0x3f3f3f3f3f3f3f3fLL;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("C.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);\
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
int x[100002],y[100002];
int a[100002];
int main(){
	init();
	int n=readint(),m=readint();
	for(int i=1;i<=n;i++)
		a[i]=readint();
	int cnt=0;
	ll now=0,ans=INF;
	for(int i=1;i<n;i++){
		x[a[i]==m?1:a[i]+1]++,x[a[i+1]]--;
		int t=(a[i+1]-a[i]+m)%m;
		y[a[i+1]]+=t-1;
		now+=t;
		if (a[i]>a[i+1] && a[i]!=m)
			cnt++,now-=m-a[i]-1;
	}
	for(int i=1;i<=m;i++){
		now-=cnt;
		//printf("%lld\n",now);
		ans=min(ans,now);
		now+=y[i];
		cnt+=x[i];
	}
	printf("%lld",ans);
}

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

int main(){
  string S;
  cin >> S;
  
  string Y = "";
  string M = "";
  string D = "";
  
  for (int i = 0; i < S.size(); i++) {
    if (i < 4) 
      Y += S.at(i);
    else if (5 <= i && i < 7) 
      M += S.at(i);
    else if (8 <= i) 
      D += S.at(i);
  }
  
  if (Y < "2019")
    cout << "Heisei" << endl;
  else if (Y == "2019" && M <= "04")
    cout << "Heisei" << endl;
  else 
    cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N,A,B,sum,i,c;
  scanf("%d %d %d",&N,&A,&B);
  
  int ans=0;
  for(i=1;i<=N;i++){
    sum=0;
    c=i;
    while(c>0){
      sum+=c%10;
      c=(c-(c%10))/10;
    }
    if(sum>=A&&sum<=B) ans+=i;
  }
  
  printf("%d",ans);
  return 0;
}

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

int N, M, Q;
int buildSum(vector<int>, vector<int>);
int getSum(int, int);
vector<vector<int>> LRmap;
int main()
{
	//cin >> N >> M >> Q;
	scanf("%d %d %d", &N, &M, &Q);
	vector<int> L(M);
	vector<int> R(M);
	for (int i = 0; i < M; i++)
	{
		//cin >> L[i] >> R[i];
		scanf("%d %d", &L[i], &R[i]);
	}

	vector<int> p(Q);
	vector<int> q(Q);
	for (int i = 0; i < Q; i++)
	{
		//cin >> p[i] >> q[i];
		scanf("%d %d", &p[i], &q[i]);
	}


	buildSum(L, R);

	for (int i = 0; i < Q; i++)
	{
		int ans = getSum(p[i], q[i]);
		cout << ans << endl;
	}

	return 0;
}

int buildSum(vector<int> L, vector<int> R) {
	LRmap = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
	for (int i = 0; i < M; i++)
	{
		LRmap[L[i]][R[i]]++;
	}

	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			LRmap[i][j] += LRmap[i][j - 1];
			LRmap[i][j] += LRmap[i - 1][j];
			LRmap[i][j] -= LRmap[i - 1][j - 1];
		}
	}
}
int getSum(int p, int q) {
	int a = LRmap[q][q] - LRmap[p - 1][q] - LRmap[q][p - 1] + LRmap[p - 1][p - 1];
	return a;
}

Measured memory_bytes: 5120
# 14:53
n = int(input())
h = list(map(int,input().split()))
for i in range(n-1):
    if h[i] > h[i+1]:
        print("No")
        exit(0)
    elif h[i] < h[i+1]:
        h[i+1] = h[i+1] - 1
print("Yes")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

bool is_prime(int x){
    for(int div=2;div*div<=x;div++){
        if(x%div==0)return false;
    }
    return true;
}
long long INF = 1LL<<60;
int main( ){
    int num;
    cin>>num;
    int cnt=0;
    rep(i,0,num){
        int in;
        cin>>in;
        if(is_prime(in))cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}





Measured memory_bytes: 3084
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

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

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

	int count = 0;
	for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
		if (iter->first < iter->second) {
			count += iter->second - iter->first;
		}
		else if(iter->second < iter->first){
			count += iter->second;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 8096
# vim: ft=ruby

class Solver
  def prepare
    @d = gets.to_i
    @cs = gets.split(" ").map(&:to_i)
    @mans = []  # mans[date][contest]

    @last = [0] * 26

    @d.times do
      @mans << gets.split(" ").map(&:to_i)
    end
  end

  # ----------- #

  def score(contest_id, date)
    @mans[date][contest_id]
  end

  def decrease_per_contest(contest_id, date)
    @cs[contest_id] * (date - @last[contest_id])
  end

  def decrease_all(date)
    (0..25).map do |contest_id|
      decrease_per_contest(contest_id, date)
    end.sum
  end


  # TOOLS

  def evaluate(ts)
    res = 0
    ts.each.with_index do |t, d|  # d = date
      t -= 1
      res += score(t, d)
      @last[t] = d+1
      res -= decrease_all(d+1)
    end
    res
  end

  def random_contest
    (0..25).to_a.sample
  end

  def random_pattern
    @d.times.map { random_contest }
  end

  def uniform_pattern
    ((0..25).to_a * 20)[0, @d]
  end

  def pretty_good_pattern
    @d.times.map do |d|
      @mans[d].each_with_index.max[1]
    end
  end

  def print_result(pattern)
    pattern.each do |p|
      puts p+1
    end
  end

  def elapsed_time
    # time_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    time_now = Time.now
    time_now - $time_start
  end

  ALPHA = 0.6
  MAX_TIME = 2
  def temperature
    r = elapsed_time / MAX_TIME
    ALPHA ** r
  end

  def probability(e_prev, e_next)
    t = temperature

    if e_next > e_prev
      # if e_next is better, always move
      1
    else
      # temperature
      remaining_time = MAX_TIME - elapsed_time
      (remaining_time / MAX_TIME) ** 2
      # Math.exp((e_prev - e_next) / t)
    end
  end

  # TOOLS END

  def change_randomly(pattern)
    pattern = pattern.dup
    pos = random_contest
    pattern[pos] = random_contest
    pattern
  end

  def swap_randomly(pattern)
    pattern = pattern.dup
    pos = rand(@d-1)
    c = pattern[pos]
    pattern[pos] = pattern[pos+1]
    pattern[pos+1] = c
    pattern
  end

  def solve
    pattern = pretty_good_pattern
    e = evaluate(pattern)

    count = 0
    movecount = 0

    # namasu
    loop do
      count += 1
      break if elapsed_time > 1.87
      new_pattern = swap_randomly(pattern)
      e_next = evaluate(new_pattern)

      r = rand
      if r < probability(e, e_next)
        movecount += 1
        pattern = new_pattern
        e = e_next
      end
    end

    # end namasu

    if ENV['DEBUG']
      STDERR.puts movecount
      STDERR.puts count
    end

    print_result(pattern)
  end

end

# $time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
$time_start = Time.now
solver = Solver.new
solver.prepare
solver.solve


Measured memory_bytes: 15756
s = input()

aaa = 0
ans = 0
i = 0
while i < len(s) - 1:
    if s[i] == 'A':
        aaa += 1
    elif s[i:i+2] == 'BC':
        ans += aaa
        i += 1
    else:
        aaa = 0
    i += 1
print(ans)


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

int main(){
  ll n,ans=0;
  cin >> n;
  string s;
  vector<char> t(n);
  cin >> s;
  ll cR=0;
  for(ll i=0;i<n;i++){
    if(s.at(i) == 'R') cR++;
  }
  for(ll i=0;i<n;i++){
    if(i < cR) t.at(i) = 'R';
    else t.at(i) = 'W';
  }
  for(ll i=0;i<n;i++){
    if(t.at(i) != s.at(i)) ans++;
  }
  
  if(ans%2 == 2) ans /= 2;
  else ans = (ans+1)/2;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    map<int, int> m;
    repp(i, 0, N) {
        int A; cin >> A;
        ++m[A];
    }
    int count = 0;
    for(auto x: m) {
        count += x.second - 1;
    }
    cout << m.size() - count % 2 << endl;
}


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

int main(){
    int N, K;
    int sum=0;
    cin >> N;
    cin >> K;
    int x[N];
    for(int i=0; i<N;i++){
        cin >> x[i];
        if(x[i] > (K-x[i]))
            sum += 2*(K-x[i]);
        else
            sum += 2*x[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

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

int cmp(const void *x, const void *y);
int cmp_(const void *x, const void *y);

long long n, m;
long long x[100005];
long long sub[100005];

int main()
{
	long long i;
	scanf("%lld %lld", &n, &m);
	for (i = 1; i <= m; i++) {
		scanf("%lld", &x[i]);
	}


	qsort(x + 1, m, sizeof(long long), cmp);
	for (i = 1; i < m; i++) {
		sub[i] = llabs(x[i + 1] - x[i]);
	}

	qsort(sub + 1, m - 1, sizeof(long long), cmp_);

	for (i = 1; i <= m; i++) {
		sub[i] += sub[i - 1];
	}

	if (n < m) {
		printf("%lld\n", sub[m - 1] - sub[n - 1]);
	} else {
		printf("0\n");
	}

	return 0;
}

int cmp(const void *x, const void *y)
{
	if (*(long long *)x > *(long long *)y) {
		return 1;
	} else if (*(long long *)x == *(long long *)y) {
		return 0;
	} else {
		return -1;
	}
}

int cmp_(const void *x, const void *y)
{
	return cmp(x, y) * -1;
}


Measured memory_bytes: 2284
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s = "CODEFESTIVAL2016";
  string in;
  int cnt = 0;

  cin >> in;
  
  for(int i = 0 ; i < (int)s.length() ; i++){
    if(in[i]!=s[i]) cnt++;
  }

  cout << cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	if (n == 0) {
		cout << 0 << endl; return 0;
	}
	int i = 1;
	string s = "";
	while (n != 0) {
		if (n % (i * (-2)) != 0) {
			s += '1'; n -= i;
		}
		else s += '0';
		i *= (-2);
	}
	reverse(ALL(s));
	cout << s << endl;
	return 0;
}

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

int n, k, p[1000];
int ans = 0, low, temp;

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < k; i++) {
        low = 1001;
        for (int j = 0; j < n; j++) {
            if (low > p[j]) {
                temp = low;
                low = p[j];
                p[j] = temp;
            }
        }
        ans += low;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
n = int(input())
h = list(map(int, input().split()))
h.insert(0,0) #index調整

dp = [0] * (n+1)
dp[2] = abs(h[2]-h[1])


for i in range(3,n+1):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n])

Measured memory_bytes: 13928
#include<stdio.h>
int main(void)
{
    int a=0;
    
    scanf("%d", &a);
    if(a%2==0){
    printf("%d",(a*a)/4);
    }
    if(a%2==1){
    printf("%d",((a*a)-1)/4);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    vector<LP> AB(N);FOR(i,0,N) cin>>AB[i].first>>AB[i].second;
    
    vector<LP> ab_sum(N);
    FOR(i,0,N){
        ab_sum[i]=make_pair(AB[i].first+AB[i].second,i);
    }
    
    sort(ab_sum.begin(), ab_sum.end(),greater<LP>());
    
    ll a=0;
    ll b=0;
    FOR(i,0,N){
        if(i%2==0)a+=AB[ab_sum[i].second].first;
        else b+=AB[ab_sum[i].second].second;
    }

    cout<<a-b<<endl;  

    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define M (ll)1000000007
#define MM (ll)1e8
#define INF (ll)1e18
#define arep(i, x, n) for (long long i = x; i < n; i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
// using ll = long long;

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

    char a[h][w];
    bool b[h][w];

    rep(i, h) {
        string text;
        cin >> text;
        rep(j, w) {
            a[i][j] = text.at(j);
            b[i][j] = true;
        }
    }

    ll cnt = 0;

    rep(i, h) {
        bool toRemove = true;
        rep(j, w) {
            if (a[i][j] == '#') {
                toRemove = false;
                break;
            }
        }

        if (toRemove) {
            rep(j, w) { b[i][j] = false; }
        }
    }

    rep(j, w) {
        bool toRemove = true;
        rep(i, h) {
            if (a[i][j] == '#') {
                toRemove = false;
                break;
            }
        }

        if (toRemove) {
            rep(i, h) { b[i][j] = false; }
        }
    }

    rep(i, h) {
        bool rowRemoved = true;
        rep(j, w) {
            if (b[i][j] == true) {
                cout << a[i][j];
                rowRemoved = false;
            }
        }

        if (rowRemoved == false) cout << endl;
    }
}

Measured memory_bytes: 3584
#!/usr/bin/env python3
import sys


def solve(X: int):
    if 400 <= X < 600:
        print(8)
    elif 600 <= X < 800:
        print(7)
    elif 800 <= X < 1000:
        print(6)
    elif 1000 <= X < 1200:
        print(5)
    elif 1200 <= X < 1400:
        print(4)
    elif 1400 <= X <1600:
        print(3)
    elif 1600 <= X < 1800:
        print(2)
    elif 1800 <= X < 2000:
        print(1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mi;

#define rep(i,a,b) for (int i = a; i < b; i++)




int main(){
	int n;
	cin >> n;
	
	while (n){
		int temp = n % 10;
		if (temp == 7){
			cout << "Yes";
			return 0;
		}
		n /= 10;
	}
	cout << "No";








	return 0;
}


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

int main(void){
  long long n,a[300000], cnt[300000]={0}, sum;
  
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> a[i];
    a[i]--;
    cnt[a[i]]++;
  }
  sum=0;
  for (int i=0; i<n; i++){
    sum += cnt[i]*(cnt[i]-1)/2;
  }
  for (int i=0; i<n; i++){
    long long t;
    //t = sum - cnt[a[i]]*cnt[a[i]-1];
    //t += cnt[a[i-1]] * cnt[a[i-2]];
    t = sum - (cnt[a[i]] - 1);
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
int main() {
	int m, n;
	while (cin >> m >> n, m) {
		int used[7368792] = {}; int cnt = 0;
		for (int i = m; i < 7368792; i++) {
			if (!used[i]) {
				cnt++;
				if (cnt > n) {
					cout << i << endl; break;
				}
				for (int j = 2 * i; j < 7368792; j += i) {
					used[j] = 1;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 31868
// https://atcoder.jp/contests/abc143/tasks/abc143_e

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll N, M, L;
  cin >> N >> M >> L;

  ll INF = 1 << 30;

  auto ds = VVL(N, VL(N, INF));

  rep(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;

    if (c > L) continue;

    ds[a][b] = c;
    ds[b][a] = c;
  }

  // ワーシャルフロイド
  rep(k, N) rep(i, N) rep(j, N) {
    ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
  }

  auto cts = VVL(N, VL(N, INF));

  rep(i, N) rep(j, N) {
    if (i == j) continue;

    if (ds[i][j] <= L) {
      cts[i][j] = 1;
    }
  }

  rep(k, N) rep(i, N) rep(j, N) {
    cts[i][j] = min(cts[i][j], cts[i][k] + cts[k][j]);
  }

  ll Q;
  cin >> Q;
  rep(i, Q) {
    ll s, t;
    cin >> s >> t;
    s--;
    t--;

    ll res = cts[s][t] == INF ? -1 : cts[s][t] - 1;
    cout << res << endl;
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 2048
import heapq

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

A = list(map(int, input().split()))


dis = [-abs(A[i + 1] - A[i]) for i in range(N - 1)] + [-abs(abs(A[0]) + abs(K - A[N - 1]))]


heapq.heapify(dis)

heapq.heappop(dis)

print(-sum(dis))



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

int main(){
    int K;
    int N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
    int M = K - A.at(N-1) + A.at(0);
    for(int i=0;i<N-1;i++){
        M = max(M, A.at(i+1)-A.at(i));
    }

    cout << K - M << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in) ;
		int n = Integer.parseInt(sc.next());
		System.out.println(calculate(n));
	}
	static int calculate(int n){
		if(n%2 == 0) return n/2;
		return (n/2) + 1;
	}
 
}

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

int main() {
  string s;
  cin >> s;
  int mn = 1000;
  for ( int i = 0; i+2 < s.length(); i++ ) {
    if ( abs(stoi(s.substr(i, 3))-753) < mn ) { mn = abs(stoi(s.substr(i, 3))-753); }
  }
  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 256
const fs = require("fs");

function main(input) {
  const tmp = input.split(" ").map(v => parseInt(v));
  const n = tmp[0];
  const k = tmp[1];
  console.log(process(n, k));
}

function process(n, k) {
  return n.toString(k).length;
}

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


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(){
  int n,ans=0;
  cin>>n;
  int a[n];
  r(i,n)cin>>a[i];
  for(int i=1;i<n;i++){
    if(a[i-1]==a[i]){
      a[i]=-1;
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <climits>
#include <bitset>
#include <fstream>
#include <algorithm>
#include <functional>
#include <stack>
#include <string>
#include <cmath>
#define fi first
#define se second
#define re register
#define ls i << 1
#define rs i << 1 | 1
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

#define int long long

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
int tt;
inline int rd(){
  int x = 0, f = 1; char ch = getchar();
  while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
  while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}

void out(int a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) out(a / 10);
  putchar(a % 10 + '0');
}
const int maxn = 2e5+10;
int a[maxn], sum[maxn];
void solve() {
  int n = rd();
  for (int i = 1; i <= n; i++) a[i] = rd();
  for (int i = n; i >= 1; i--) sum[i] = (sum[i+1] + a[i]) % mod;
  int ans = 0;
  for (int i = 1; i < n; i++) ans = (ans + a[i] * sum[i+1] % mod + mod) % mod;
  cout << ans << '\n';
}

signed main(){
//  for (tt = rd(); tt--; )
  solve();
  return 0;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  vector<int> v, w;
  rep(i,N){
    int a;
    cin >> a;
    if(i%2==0) v.push_back(a);
    else w.push_back(a);
  }

  vector<int> ret;
  if(N%2==0){
    reverse(ALLOF(w));
    rep(i,w.size()) ret.push_back(w[i]);
    rep(i,v.size()) ret.push_back(v[i]);
  }else{
    reverse(ALLOF(v));
    rep(i,v.size()) ret.push_back(v[i]);
    rep(i,w.size()) ret.push_back(w[i]);
  }

  rep(i,ret.size()){
    if(i>0) cout << " ";
    cout << ret[i];
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3824
def read_input():
    acard = [x for x in input().strip()]
    bcard = [x for x in input().strip()]
    ccard = [x for x in input().strip()]
    return acard, bcard, ccard


def submit():
    acard, bcard, ccard = read_input()

    board = {}
    board['a'] = acard
    board['b'] = bcard
    board['c'] = ccard

    turn = 'a'
    while True:
        # turnの人がカードを持っていないなら勝利
        if not board[turn]:
            print(turn.upper())
            break

        top = board[turn][0]
        board[turn] = board[turn][1:]
        turn = top


if __name__ == '__main__':
    submit()


Measured memory_bytes: 38384
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>

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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int W; cin >> W;
	vector<int> a(W); for (int i = 0; i < W; i++) cin >> a[i];
	vector<int> dpl(W + 1, inf), dpr(W + 1, inf);
	dpl[0] = -inf;
	dpr[W] = -inf;
	for (int i = 0; i < W; i++) {
		chmin(dpl[i + 1], dpl[i] - 1);
		if (a[i] < 0) {
			int t = -a[i];
			chmin(dpl[i + 1], t);
		}
		if (a[i] == 0) {
			dpl[i + 1] = inf;
		}
	}
	for (int i = W - 1; i >= 0; i--) {
		chmin(dpr[i], dpr[i + 1] - 1);
		if (a[i] < 0) {
			int t = -a[i];
			chmin(dpr[i], t);
		}
		if (a[i] == 0) {
			dpr[i] = inf;
		}
	}
	int res = 0;
	for (int i = 0; i < W; i++) {
		if (a[i] > 0) {
			int t = max({ dpl[i + 1], dpr[i], 0 });
			res += min(t, a[i]);
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 4152