akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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; }

void add(ll& a, ll b){a = (a+b) % MOD;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int sum=0,o_sum=0;
    REP(i,n){
        if(s[i]=='a'){
            if(sum+o_sum<a+b) cout<<"Yes"<<endl,sum++;
            else cout<<"No"<<endl;
        }
        else if(s[i]=='b'){
            if(sum+o_sum<a+b&&o_sum<b){
                cout<<"Yes"<<endl;
                o_sum++;
            }
            else cout<<"No"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, num=0;
  cin >> n;
  vl a(n);
  rep(i, n) {cin >> a[i]; num ^= a[i];}
  rep(i, n) cout << (num^a[i]) << (i<n-1 ? ' ' : newl);
  return 0;
}

Measured memory_bytes: 4640
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;
 
signed main()
{
    fast;
    int n;
    cin>>n;

    string s;
    cin>>s;

    string str = "ABC";
    int count = 0;
    for ( int i = 0 ; i <= s.length()-3 ; i++ )
    {
        string a = s.substr(i,3);

        if ( a == str )
        {
            count++;
        }
    }

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

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;
    n *= 2;
    
    string s;
    cin>>s;
    
    vector<int> a(n, 0);
    for (int i=0; i<n; i++) {
	if (s[i]=='B') a[i]=1;
    }


    ll open = 0;
    ll ans = 1;

    for (int i=0; i<n; i++) {
	if ((a[i]+open)%2==0) {
	    ans=ans*open%mod;
	    open--;
	} else {
	    open++;
	}
	if (open<0 || open>n) out(0);
    }


    if (open != 0) out(0);


    // order of the operations
    n /= 2;
    for (int i=1; i<=n; i++) {
	ans=ans*i%mod;
    }

    cout<<ans<<endl;    
    return 0;
}


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

int w,h;
bool walked[50][50];
int map[50][50];

// top t-r right r-d down l-d left t-l
const int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void dfs(int x, int y) {
  walked[y][x] = true;
  for (int i = 0; i < 8; i += 1) {
    int tx = x + dx[i];
    int ty = y + dy[i];
    if (tx < 0 || tx >= w) continue;
    if (ty < 0 || ty >= h) continue;
    if (map[ty][tx]==1 && !walked[ty][tx])
    dfs(tx, ty);
  }
}

int main(int argc, char const* argv[]) {
  while (true) {
    cin>>w>>h;
    if (w == 0 && h == 0) break;
    int res = 0;
    memset(walked, false, sizeof walked);
    memset(map, 0, sizeof map);
    for (int i = 0; i < h; i += 1) {
      for (int j = 0; j < w; j += 1) {
        cin>>map[i][j];
      }
    }    
    for (int i = 0; i < h; i += 1) {
      for (int j = 0; j < w; j += 1) {
        if (map[i][j]==1 && !walked[i][j]) {
          dfs(j,i);
          res++;
        }
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
data = {
        'S': [int(x) for x in range(1,14)],
        'H': [int(x) for x in range(1,14)],
        'C': [int(x) for x in range(1,14)],
        'D': [int(x) for x in range(1,14)]
        }

count = int(input())

for c in range(count):
    (s, r) = input().split()
    r = int(r)

    del data[s][data[s].index(r)]


for i in ('S', 'H', 'C', 'D'):
    for v in data[i]:
        print(i, v)

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

using namespace std;
typedef long long Int;

const int BIT_SIZE = 410000;

int bit[BIT_SIZE + 1];

void add(int pos, int val)
{
  for (pos += 1; pos <= BIT_SIZE; pos += pos & -pos) {
    bit[pos] += val;
  }
}

int get_sum(int pos)
{
  int ret = 0;
  for (pos += 1; pos; pos -= pos & -pos) {
    ret += bit[pos];
  }
  return ret;
}

int main()
{
  int n, k;
  Int a[200000];
  
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    a[i] -= k;
  }
  
  vector<Int> v;
  Int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    v.push_back(a[i] - sum);
    v.push_back(-sum);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  
  sum = 0;
  Int ans = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    int pos = lower_bound(v.begin(), v.end(), a[i] - sum) - v.begin();
    add(pos, 1);
    pos = lower_bound(v.begin(), v.end(), -sum) - v.begin();
    ans += get_sum(BIT_SIZE - 1) - get_sum(pos - 1);
  }
  
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 7920
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    double a,c,d=0,e=0,z=0,x=0;
    int b=0;
    cin>>a;
    for(int i=0;i<a;i++){
        b++;
        if(b%2!=0){x++;}
    }
    cout<<x/a;
    return 0;
}


Measured memory_bytes: 3720
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    vi ss(s.size()+1), tt(t.size()+1);
    rep(i, s.size()) {
        ss[i+1] = ss[i] + (s[i] == 'A');
        ss[i+1] -= (s[i] == 'B');
    }
    rep(i, t.size()) {
        tt[i+1] = tt[i] + (t[i] == 'A');
        tt[i+1] -= (t[i] == 'B');
    }

    int q;
    cin >> q;
    while(q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a; --c;
        //cout << tt[d]-tt[c] << ' ' << ss[a]-ss[b] << '\n';
        cout << ((tt[d]-tt[c]+ss[a]-ss[b])%3 == 0?"YES":"NO") << '\n';
    }
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define fast ios_base::sync_with_stdio(false)
#define cintie cin.tie(NULL)
int main()
{
	ll n,i,ans,t;
	cin>>n;
	ll a[n+10];
	ll b[n+10];
	for(i=0;i<=n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	cin>>b[i];
	ans=0;
	for(i=0;i<n;i++)
	{
		t=min(a[i],b[i]);
		ans=ans+t;
		a[i]=a[i]-t;
		b[i]=b[i]-t;
		t=min(a[i+1],b[i]);
		ans=ans+t;
		a[i+1]=a[i+1]-t;
		b[i]=b[i]-t;
	}
	cout<<ans<<endl;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int K;
  cin >> K;

  vector<string> Ans;
  for (uint i = 0; i < S.size(); i++) {
    for (uint j = i; j < i + K; j++) {
      Ans.push_back(S.substr(i, j - i + 1));
    }
  }
  sort(Ans.begin(), Ans.end());
  unique(Ans.begin(), Ans.end());
  cout << Ans[K - 1] << endl;
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int a[5];
    REP(i,5){
        cin >> a[i];
        if(a[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  int x;
  cin>>N>>x;

  int a[N];
  rep(i,N){
    cin>>a[i];
  }

  ll ct=0;

  rep(i,N-1){
    if(a[i]+a[i+1]<=x) continue;
    if(a[i]>x){
      ct+=a[i+1]+a[i]-x;
      a[i+1]=0;
      a[i]=x;
    }
    else{
      ct+=a[i+1]+a[i]-x;
      a[i+1]=x-a[i];
    }
  }

  cout << ct <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 640
def solve(arr):
    cost = [0, abs(arr[0] - arr[1])]
    for i in range(2, len(arr)):
        curr = min(cost[i-1] + abs(arr[i]- arr[i-1]), cost[i-2] + abs(arr[i]- arr[i-2]))
        cost.append(curr)
    return cost[-1]

def main():
    _ = int(input())
    arr = list(map(int, input().split()))
    print(solve(arr))

if __name__ == "__main__":
    main()


Measured memory_bytes: 13980
#include <iostream>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {
    stack<int> S;
    int a, b, x;
    string s;

    while (cin >> s) {
        if (s[0] == '*') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            x = a * b;
            S.push(x);
        } else if (s[0] == '+') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            x = a + b;
            S.push(x);
        } else if (s[0] == '-') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            x = b - a;
            S.push(x);
        } else {
            S.push(atoi(s.c_str()));
        }
    }
    cout << S.top() << endl;
}



Measured memory_bytes: 3204
import itertools
import os
import sys
from collections import defaultdict

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))
N += 1
P = [0] + P

def test(A):
    N = len(A)
    ret = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            b = A[i: j + 1].copy()
            b.sort()
            ret += b[-2]
    return ret


#
# ans = defaultdict(list)
# for a in itertools.permutations(range(1, 5)):
#     t = test(list(a))
#     ans[t].append(a)
#
# for k in sorted(ans.keys()):
#     print('--- {} ---'.format(k))
#     for v in ans[k]:
#         print(v)


# ans = test(P)
# print(ans)


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * size
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


def bisect_left_callable(fn, x, lo, hi):
    """
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


def argsort(li):
    return [i for _, i in sorted([(a, i) for i, a in enumerate(li)], reverse=True)]


bit = BinaryIndexedTree(size=N)

idx = argsort(P)
ans = 0
for i in idx[:-1]:
    cnt = bit.sum(i)
    # cnt が 1 減る場所
    l1 = bisect_left_callable(lambda k: bit.sum(k), cnt, lo=0, hi=i)
    l2 = bisect_left_callable(lambda k: bit.sum(k), cnt - 1, lo=0, hi=i)
    # 1 増える場所
    r1 = bisect_left_callable(lambda k: bit.sum(k), cnt + 1, lo=i + 1, hi=N)
    r2 = bisect_left_callable(lambda k: bit.sum(k), cnt + 2, lo=i + 1, hi=N)

    a = (r1 - i) * (l1 - l2)
    b = (i - l1) * (r2 - r1)
    # print(P[i], l1, l2, r1, r2, a, b)
    # print(P[i], a + b)

    ans += P[i] * (a + b)
    bit.add(i, 1)
print(ans)


Measured memory_bytes: 65440
#include <iostream>
#include <vector>
#include <algorithm>

const int MOD = 998244353;

struct FenwickTree {
    int n;
    std::vector<int> v;

    FenwickTree(int n) : v(n + 1) {
        this->n = n;
    }

    void add(int a, int x) {
        for (int i = a; i <= n; i += i & -i) v[i] += x;
    }

    int sum(int a) {
        int res = 0;
        for (int i = a; i > 0; i -= i & -i) res += v[i];
        return res;
    }
};

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

    std::vector<std::pair<int, int>> v(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        std::cin >> x >> y;
        v[i] = std::make_pair(x, y);
    }

    std::sort(v.begin(), v.end(), [](auto p1, auto p2) {
        return p1.second < p2.second;
    });
    for (int i = 0; i < N; i++)
        v[i].second = i;

    std::sort(v.begin(), v.end());
    for (int i = 0; i < N; i++)
        v[i].first = i;

    std::vector<int> p(N + 1);
    p[0] = 1;
    for (int i = 0; i < N; i++) p[i + 1] = p[i] * 2 % MOD;

    FenwickTree ft(N);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int ld = ft.sum(v[i].second);
        int lu = i - ld;
        int rd = v[i].second - ld;
        int ru = N - ld - lu - rd - 1;

        ans = (ans + (p[N] - 1)) % MOD;

        ans = (ans - (p[ld + lu] - 1) + MOD) % MOD;
        ans = (ans - (p[lu + ru] - 1) + MOD) % MOD;
        ans = (ans - (p[ru + rd] - 1) + MOD) % MOD;
        ans = (ans - (p[ld + rd] - 1) + MOD) % MOD;

        ans = (ans + (p[ld] - 1)) % MOD;
        ans = (ans + (p[lu] - 1)) % MOD;
        ans = (ans + (p[rd] - 1)) % MOD;
        ans = (ans + (p[ru] - 1)) % MOD;

        ft.add(v[i].second + 1, 1);
    }
    std::cout << ans << "\n";
}

Measured memory_bytes: 3328
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;
unsigned long long luca(int n) {
	static vector<unsigned long long>m(100, -1);
	if (n == 0) return 2;
	else if (n == 1) return 1;
	else if (m[n] != -1) return m[n];
	{
		m[n] = luca(n - 1) + luca(n - 2);
		return m[n];
	}
}
int main() {
	int n;
	cin >> n;
	cout << luca(n);

	return 0;
}





Measured memory_bytes: 256
H,W = map(int,input().split())
s = [["."]*(W+2)]+[["."]+list(input())+["."] for _ in range(H)]+[["."]*(W+2)]
#print(*s, sep="\n")
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "#":
            if s[i-1][j]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i][j+1]==".":
                print("No")
                exit()
print("Yes")


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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using 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<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

int main(){
	int n=read();
	vector<pii> x;
	int k[2]={0,0};
	REP(i,n)
		x.PB(MP(read(),0));
	REP(i,n)
		x.PB(MP(read(),1));
	sort(ALL(x));
	ll ans=1;
	const int mod=1000000007;
	for(auto p:x){
		int v=p.second;
		if(k[1-v]>0){
			ans=ans*k[1-v]%mod;
			k[1-v]--;
		}else
			k[v]++;
	}
	cout<<ans<<endl;
}


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

int main()
{
  
  int n,k; 
  
  cin>>n>>k; 
  
  int a[n]; 
  
  for(int i=0 ;i<n;i++ )
  {
    cin>>a[i]; 
  }
  
  sort(a, a + n) ; 
  
  int sum= 0; 
  
  for(int i=0 ;i<k; i++) 
  {
    sum+= a[i]; 
  }
  
  cout<<sum; 
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), rend()
#define PB pushback
#define SORT(c) sort((c).begin(),(c).end())

const LL INF = 1LL << 60;

//priority_queue<int> p;

int i, j, k, tmp, ans, cnt, N, M;
string s;

//scanf("%d",&N);

//printf("%d", ans);

//cout <<  << endl;


int main(void) {
	scanf("%d %d", &N, &M);
	int l, r;
	int L = 1, R = N;
	REP(i, M) {
		scanf("%d %d", &l, &r);
		if (l > L) {
			L = l;
		}
		if (r < R) {
			R = r;
		}
	}
	ans = R - L + 1;
	if (ans < 0) {
		ans = 0;
	}

	printf("%d", ans);


	return 0;
}

Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 6e5 + 111;
     
using namespace std;

int n, k, a[maxn], dp[maxn], t, q;

void solve(){    
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	dp[2] = abs(a[2] - a[1]);

	for (int i = 3; i <= n; i++){
		dp[i] = dp[i - 1] + abs(a[i - 1] - a[i]);
		for (int j = 2; j <= k && i - j > 0; j++)
			dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));
	}
	cout << dp[n];
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int m[26][55];
int N;
int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        string s;
        cin>>s;
        for(char c:s){
            m[c-'a'][i]++;
        }
    }
    for(int i=0;i<26;i++){
       int me = *min_element(m[i],m[i]+N);
       while(me--)cout<<(char)(i+'a');
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int ans = 33;
    for(int i = 0; i < N; ++i)
    {
        int ai;
        cin >> ai;
        int tmp = 0;
        while(!(ai & (1 << tmp)))
            tmp++;
        ans = min(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	vector<ll> v;
	rep(i,0,5){
		ll a;
		cin>>a;
		v.pb(a);
	}
	ll l = v[v.sz-1]-v[0];
	ll k;
	cin>>k;
	if(l<=k){
		cout << "Yay!" << endl;
	}
	else{
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
Ps = list(map(int, input().split()))

count = 0
for i in range(1, n - 1):
  if (Ps[i-1] < Ps[i]) and (Ps[i] < Ps[i+1]):
    count += 1
  elif (Ps[i-1] > Ps[i]) and (Ps[i] > Ps[i+1]):
    count += 1

print(count)

Measured memory_bytes: 3060
p = 10**9+7
n = int(input().rstrip())
a_ls = list(map(int, input().rstrip().split(" ")))
a_ls = [a%p for a in a_ls]
a2_ls = [(a**2)%p for a in a_ls]
a_sum_sq = ((sum(a_ls))**2)%p
a2_sum = sum(a2_ls)%p
ans = (a_sum_sq-a2_sum)%p
if ans%2 != 0:
  ans += p
ans //= 2
print(ans)

Measured memory_bytes: 31556
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
using namespace std;

void Solution()
{
    bool flag = false;
    
    string s;
    string ans[10] =
    {
        "* = ****",
        "* =* ***",
        "* =** **",
        "* =*** *",
        "* =**** ",
        " *= ****",
        " *=* ***",
        " *=** **",
        " *=*** *",
        " *=**** "
    };
    
    while(cin>>s)
    {
        if(flag)
        {
            cout << endl;
        }
        else
        {
            flag = true;
        }
        
        while(s.size() < 5)
        {
            s = '0' + s;
        }
        
        for(int i = 0; i < 8; i++)
        {
            for(int j = 0; j < 5; j++)
            {
                cout << ans[s[j] - '0'].at(i);
            }
            
            cout << endl;
        }
    }
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    string s ;
    cin >> s ;
    int f = 0 ; 
    rep(i, 0, 2) {
        if(s[i]=='A' && s[i+1]=='B' || s[i]=='B' && s[i+1]=='A') f = 1 ;
    }
    if(f == 1) cout << "Yes" << endl ;
    else cout << "No" << endl ;
}
 
int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main (){
    let n = read::<i64>();
    let ans = (1..n+1).fold(1,|y,x|{
        (y * x )% (1e9 as i64 + 7)
    });
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

struct UnionFind {
    vector<int> par;
    vector<int> rnk;

    UnionFind(int n) {
        par.assign(n, 0);
        rnk.assign(n, 1);
        for(int i=0; i<n; i++) {
            par[i] = i;
        }
    }

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if(rnk[x] < rnk[y]) swap(x, y);
        rnk[x] += rnk[y];
        par[y] = x;
    }

    int find(int x) {
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return rnk[find(x)];
    }
};



signed main() {
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind road(N+1), rail(N+1);

    rep(i, K) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        road.unite(p, q);
    }
    rep(i, L) {
        int r, s;
        cin >> r >> s;
        r--; s--;
        rail.unite(r, s);
    }

    map<P, int> mp;
    rep(i, N) {
        mp[P(road.find(i), rail.find(i))]++;
    }

    rep(i, N) {
        cout << mp[P(road.find(i), rail.find(i))] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 18048
temp = input().rstrip().split(" ")
A = int(temp[0])
B = int(temp[1])
C = int(temp[2])
flag = 0
if A == B and C > 0:
    print("NO")
elif A == 1:
    print("YES")
elif A + C == B:
    print("YES")
else:
    for i in range(1,10000):
        if (A * i) % B == C:
            print("YES")
            flag = 1
            break
    if flag == 0:
        print("NO")

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>

using namespace std;

#define MAX_V (10010)
vector<int> G[MAX_V];
int I[MAX_V];			// ??\?¬???°
bool arrived[MAX_V];
vector<int> ans;
void dfs( int s ) {
    ans.push_back( s );
    arrived[s] = true;
    for ( int i = 0; i < G[s].size(); i++ ) {
	int t = G[s][i];
	I[t]--;
	if ( I[t] == 0 ) {
	    dfs( t );
	}
    }
}

int main()
{
    int V, E;
    scanf("%d %d", &V, &E);
    
    for ( int i = 0; i < E; i++ ) {
	int s, t;
	scanf("%d %d", &s, &t);
	G[s].push_back( t );
        I[t]++;
    }

    for ( int i = 0; i < V; i++ ) {
	if ( !arrived[i] && I[i] == 0 ) dfs( i );
    }

    for ( int i = 0; i < ans.size(); i++ ) {
	printf("%d\n", ans[i] );
    }
    
    return 0;
}

Measured memory_bytes: 1836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0)
				break;
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++)
					if((i+j)%2 == 0)
						System.out.printf("#");
					else
						System.out.printf(".");
				System.out.println();
			}
			System.out.println();
		}
	}
}	


Measured memory_bytes: 61404
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, map) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M, Q; cin >> N >> M >> Q;
    vvl p(N + 1, vl(N + 1, 0));
    REP(i, M){
        ll l, r; cin >> l >> r; p[l][r]++;
    }
    vl ps(Q, 0), qs(Q, 0);
    REP(i, Q) cin >> ps[i] >> qs[i];
    
    vvl c(N + 1, vl(N + 1, 0));
    FOR(i, 1, N+1){
        ll sum = 0;
        FOR(j, i, N+1){
            sum += p[i][j]; c[i][j] = sum;
        }
    }
    
    map<ll, vp> lg, rs;
    REP(i, Q){
        ll pl = ps[i], qr = qs[i], ret = 0;
        FOR(j, pl, qr + 1){
            ret += c[j][qr];
        }
        cout << ret << endstr;
    }
    
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n; cin>>w>>h>>n;
    int x1=0,x2=w,y1=0,y2=h;
    rep(i,n){
        int x,y,a; cin>>x>>y>>a;
        if (a==1) chmax(x1,x);
        if (a==2) chmin(x2,x);
        if (a==3) chmax(y1,y);
        if (a==4) chmin(y2,y);
    }
    int dx = max(0,x2-x1);
    int dy = max(0,y2-y1);
    cout<<dx*dy<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int store[200007];
int n, k;

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

    for (int i = 1; i <= n; i++) scanf("%d", &store[i]);
    sort(store+1, store+n+1);

    int small = inf;
    for (int i = 1; i + k - 1 <= n; i++) {
        small = min(small, store[i+k-1] - store[i]);
    }

    cout << small << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
    ll ans = 0;
    ll b = 0;
    
    for (auto p : res) {
        b = p.second;
        int i = 0;

        while(b >= i*(i+1)/2) {
            ++i;
        }
        --i;
        // if (b == i*(i+1)/2) i;
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

typedef struct{
  int from,to;
  ll cost;
}edge;
const int V_MAX = 2510,E_MAX = 5010;
int V,E;
ll P;
vector<edge>es(E_MAX);
vector<vector<int> >G1(V_MAX);
vector<vector<int> >G2(V_MAX);
vector<bool> canmove1(V_MAX,false);
vector<bool> canmove2(V_MAX,false);
vector<ll> d(V_MAX,MAX_I);

//ゴールまで行ける場所
int dfs(int g,vector<vector<int> > &G, vector<bool> &canmove){
  if(canmove[g]) return 0;
  canmove[g] = true;
  for(const int & e : G[g]){
    dfs(e,G,canmove);
  }
  return 0;
}

int bellmanford(int s){
  rep(i,V)d[i] = MAX_I;
  d[s] = 0;
  while(true){
    bool update = false;
    for(const edge &e : es){
      if(!canmove1[e.from] || !canmove2[e.from])continue;
      if(d[e.from] != MAX_I && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from]+e.cost;
        update = true;
      }
    }
    if(!update)break;
  }
  return 1;
}

bool find_negative_loop(){
  rep(i,V)d[i] = 0;
  rep(i,V){
    for(const edge &e : es){
      if(!canmove1[e.from] || !canmove2[e.from])continue;
      if(d[e.from] != MAX_I && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from]+e.cost;
        if(i==V-1)return true;
      }
    }
  }
  return false;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V >> E >> P;
  rep(i,E){
    int A,B;
    ll C;cin >> A >> B >> C;
    --A;--B;
    es.push_back({A,B,P-C});
    G1[B].push_back(A);
    G2[A].push_back(B);
  }
  dfs(V-1,G1,canmove1);
  dfs(0,G2,canmove2);
  if(find_negative_loop()){
    cout << -1 << endl;
    return 0;
  }
  bellmanford(0);
  cout << max(0ll,-d[V-1]) << endl;
  return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n, m; cin >> n >> m;
  int res = 0, pen = 0;
  vector <bool> mark(n + 1, 0);
  vector <int> cnt(n + 1, 0);
  for (int i = 1; i <= m; i++){
    int x; string ver;
    cin >> x >> ver;
    if (ver == "WA"){
      if (mark[x]) continue;
      else {
        pen++; cnt[x]++;
      }
    }
    else{
      if (mark[x]) continue;
      else {
        mark[x] = true;
        res++;
      }
    }
  }
  for (int i = 1; i <= n; i++) if (!mark[i]) pen -= cnt[i];
  cout << res << ' ' << pen;
  return 0;
}

Measured memory_bytes: 640
import itertools

def main():
    n, m = map(int, input().split())
    g = set([tuple(map(int, input().split())) for _ in range(m)])

    ans = 0
    for path in itertools.permutations(list(range(1, n+1)), n):
        if path[0] != 1:
            continue
        flag = True
        for i in range(n-1):
            if ((path[i], path[i+1]) not in g) and ((path[i+1], path[i]) not in g):
                flag = False
        if flag is True:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
	return 0; 
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()

ans = [s for s in S]
end = len(S)

if S.rfind('?'*len(T)) != -1:
	j = S.rfind('?'*len(T))
	for i in range(len(T)):
		ans[i+j] = T[i]
	print(''.join(ans).replace('?','a'))
	sys.exit()
else:
	for x in range(len(T)-1, -1, -1):
		while S.rfind(T[x],0,end) != -1:
			for i in range(len(T)-1, -1, -1):
				if S.rfind(T[i],0,end) != -1 and S.rfind(T[i],0,end)+len(T)-i<=len(S):
					j = S.rfind(T[i],0,end)
					flag = True
					for k in range(len(T)):
						#print(S[j+k-i], T[k])
						if S[j+k-i] == T[k] or S[j+k-i] == '?':
							continue
						else:
							flag = False
							break
					else:
						if flag:
							for k in range(len(T)): ans[j+k-i] = T[k]
							print(''.join(ans).replace('?','a'))
							sys.exit()
			end -= 1
	print('UNRESTORABLE')

Measured memory_bytes: 3064
import sys


#https://note.nkmk.me/python-union-find/
class AlgUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    t = n * (n - 1) // 2
    uf = AlgUnionFind(n)
    pt = []
    for i in range(m):
        pt.append(t)
        a, b = ab[-i-1]
        if not uf.same(a-1, b-1):
            t -= (uf.size(a-1) * uf.size(b-1))
        uf.union(a-1, b-1)
    pt.reverse()
    print(*pt, sep="\n")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 107356
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

ll INF = 10000000;
ll mod = 1000000007;//10^9+7



//番号ズレ注意！！
int main() {
    int N, X, L[110];
    cin >> N >> X;
    int D[110] = {0};
    int ans = 1;
    REP(i, N) {
        cin >> L[i];
        D[i + 1] = D[i] + L[i];
        if (D[i + 1] <= X) { ans += 1; }
        else { break; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
using namespace std;
 
int main() {
    int N, Q; cin >> N >> Q;
    vector<pair<int, string> > data;
    data.push_back(make_pair(1, "kogakubu10gokan"));
    for(int i = 0; i < N; i++) {
        int year; string name;
        cin >> year >> name;
        data.push_back(make_pair(year, name));
    }
    sort(data.begin(), data.end());
    int r = 0;
    for(int i = 0; i < N + 1; i++) {
        if(Q >= data[i].first) r = i;
    }
    cout << data[r].second << endl;
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
using namespace std;

int main(void){
  int A, B;
  cin >> A >> B;
  if(A%2 ==1 && B%2 == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define ff first
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
inline void fastio(){ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);}

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



int main(){
	fastio();

	ll n; cin>>n;
	mll index;
	ll a[n+1]; f(i,1,n) cin>>a[i], index[a[i]]=i;

	ll ans[n+1];
	f(i,1,n) ans[i]=index[i], cout<<ans[i]<<" ";

	return 0;
}

Measured memory_bytes: 8704
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
							`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	m := nextInt()

	ans := "IMPOSSIBLE"

	la := make([]int, n)
	lb := make([]int, n)

	for c := 0; c < m; c++ {
		a := nextInt() - 1
		b := nextInt() - 1
		if ans == "POSSIBLE" {
			continue
		}
		if a == 0 {
			if lb[b] == 1 {
				ans = "POSSIBLE"
				break
			}
			la[b] = 1
		}
		if b == n-1 {
			if la[a] == 1 {
				ans = "POSSIBLE"
				break
			}
			lb[a] = 1
		}
	}

	//fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


Measured memory_bytes: 7296