akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 1000000000
#define endl '\n'
ll arr[105];
ll dp[105][100005];
ll dpp[105][100005];
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,k;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=0;i<=k;i++)
	{
		if(i<=arr[1])
			dp[1][i]=1;
		if(i==0)
			dpp[1][i]=dp[1][i];
		else
			dpp[1][i]=dpp[1][i-1]+dp[1][i];
	}
	for(ll i=2;i<=n;i++)
	{
		for(ll j=0;j<=k;j++)
		{
			if(j>arr[i])
				dp[i][j]=(dpp[i-1][j]-dpp[i-1][j-arr[i]-1])%mod;
			else
				dp[i][j]=dpp[i-1][j];
			if(j==0)
				dpp[i][j]=dp[i][j];
			else
				dpp[i][j]=(dpp[i][j-1]+dp[i][j])%mod;
		}
	}
	cout<<((dp[n][k]%mod)+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 159232
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int > 
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 3e5 + 10 ;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 

 
int main(){
	string s ; 
	cin>>s ; 
	s = "." + s ; 
	for (int i = 1 ; i < s.size() ; i++){
		if (s[i]!='?'){
			cout<<s[i];
			continue ; 
		}
		if (s[i+1]=='D' and s[i-1]!='P')
			cout<<"P" ; 
		else
			cout<<"D" ; 
	}
}



Measured memory_bytes: 3920
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n == 0) printf("1\n");
    else if(n == 1) printf("2\n");
    else if(n == 2) printf("1\n");
    else printf("0\n");
  }
}

Measured memory_bytes: 1168
// Last Change: 01/20/2019 21:55:36.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}

class Cal {
private:
  int N;
  vector<int> h;
  void Input();
  ll Solve();

public:
  void Main();
};


void Cal::Input() {
  cin >> N;
  h.resize(N);
  // for (int i = 0; i < N; ++i) {
  //  cin >> h.at(i);
  //}
}


ll Cal::Solve() {
  ll count = 0;
  int ipt;
  int last;
  stack<int> st;
  st.push(-1);

  //一個目
  cin >> ipt;
  st.push(ipt);

  //それ以降
  for (int i = 1; i < N; ++i) {
    cin >> ipt;
    last = st.top();

    // \ ということ
    if (last > ipt) {
      count += last - ipt;
      while (st.top() >= ipt) {
        st.pop();
      }
      st.push(ipt);
    }

    // / ということ
    else if (last < ipt) {
      st.push(ipt);
    }

    // - ということ
    else {
      //何もしない
    }
  }

  if (st.top() != -1) {
    count += st.top();
  }

  return count;
}


void Cal::Main() {
  Input();
  ll ans = Solve();
  cout << ans << endl;
}

int main() {
  unique_ptr<Cal> cal(new Cal);
  cal->Main();

  //LoopUntilZeroInpput();
}


Measured memory_bytes: 256
from collections import deque
N = int(input())

Q = deque([1,2,3,4,5,6,7,8,9])
a = 0
for i in range(N):
  a = Q.popleft()
  if a%10 > 0:
    Q.append(a*10 + (a%10 -1))
  Q.append(a*10 + a%10)
  if a%10 < 9:
    Q.append(a*10 + (a%10 +1))

print(a)

Measured memory_bytes: 73596
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999
#define MOD 1000000007
 
void func()
{
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    loop(i,0,n){
        ll a,b;
        cin>>a>>b;
        if(a*a+b*b-d*d<=0){
            ++ans;
        }
    }
    cout<<ans<<"\n";

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }

}

Measured memory_bytes: 3648
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def matrixChainMultiplication(n,p):
    dp = [[0]*(n+1) for _ in range(n + 1)]
    for l in range(2, n + 1):
        for i in range(1, n - l + 2):
            j = i + l - 1
            dp[i][j] = INF
            for k in range(i, j):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j])
    return dp[1][n]


def main():
    N = int(readline())
    P = []

    for _ in range(N):
        r, c = map(int, readline().split())
        P.append(r)
    P.append(c)

    print(matrixChainMultiplication(N,P))

    


if __name__ == '__main__':
    main()




Measured memory_bytes: 5660
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,A,B;
    int Max=0, Min=0;
    scanf("%d%d%d", &N, &A, &B);
    Max = min(A,B);
    if(A+B>=N){
        Min = A+B-N;
    }
    printf("%d %d" , Max, Min);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    int n;
    int ans;
    while(cin >> n){
        ans = 2;
        rep(i,n){
            ans += (i + 1);
        }
        cout << ans - 1 << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  
  int i,sum,l,r;
  sum=0;
  
  for (i=0; i<N; i++){
    cin >> l >> r;
    sum+=r-l+1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int X = sc.nextInt();
		int Y = 0;;
		for(int i = 1; i <= 1000; i++) {
			if(X - 100 * i >= 0) {
				Y = i;
			}
		}
		if(X - 100 * Y <= 5 * Y) {
			System.out.println("1");
		}else {
			System.out.println("0");
		}
	}

}


Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

#define MAX 99999999

typedef pair<int,int> E;

int t[502][502];

int trans(string s,map<string,int> &name){
  if(name.find(s) != name.end()){
    return name[s];
  }

  int size = name.size();
  name[s] = size;
  return size;
}

int main(void){
  int n,m;

  while(cin>>n>>m,n||m){
    rep(i,n) rep(j,n) t[i][j] = MAX;

    map<string,int> name;
    int s,p,g;
    string S,P,G;
    cin>>S>>P>>G;

    s = trans(S,name);
    p = trans(P,name);
    g = trans(G,name);

    rep(i,m){
      int a,b;
      string A,B;
      int d,l;
      cin>>A>>B>>d>>l;
      a = trans(A,name);
      b = trans(B,name);
      t[a][b] = t[b][a] = d/40+l;
    }

    rep(k,n){
      rep(i,n){
        rep(j,n){
          if(i == j) continue;
          t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
        }
      }
    }

    cout<<t[s][p]+t[p][g]<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define deb(x) cerr << #x <<": " << x << '\n';
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    fast_io();
    int n; cin >> n;
    string s;
    map<string,int> A;
    rep(i,n){
    cin >> s;
    A[s] = 1;
    }
    ll ans = 0;
    for(auto it : A) ans += it.second;
    cout << ans;
    return 0;
}


Measured memory_bytes: 19232
#include <iostream>
#include <stack>
using namespace std;
int v[20000];
int main() {
	stack<int> s;
	stack<pair<int, int> > t;
	char ch;
	int sum = 0, a;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\')
			s.push(i);
		else if (ch == '/' && s.size() > 0) {
			int j = s.top(); s.pop();
			sum += i - j;
			a = i - j;
			while (t.size() > 0 && j < t.top().first) {
				a += t.top().second; t.pop();
			}
			t.push(make_pair(j, a));
		}
	}
	cout << sum << endl;
	cout << t.size();
	for (int i = t.size() - 1; i >= 0; i--) {
		v[i] = t.top().second;
		t.pop();
	}
	for (int i = 0; v[i] != 0; i++) {
		 cout << " ";
		cout << v[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void solve(){
   int n , k;
   cin >> n >> k ;
   int ans = 0 ;
   for( int i = 0 ; i < n ; i++){
    int x ;
    cin >> x ;
    if(x>=k) ans++;
   }
   cout << ans ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t ;
    t = 1 ;
   //cin >> t ;
    while(t--){
        solve( );
    }
}
// number of subset having xor in 2ki ow


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

char *reverse(char *s)
{
    int i;
    char tmp;
    for(i = 0; i < strlen(s)/2; i++){
        tmp = s[i];
        s[i] = s[strlen(s)-1-i];
        s[strlen(s)-1-i] = tmp;
    }
    return s;
}

int main()
{

    char str[21];

    fgets(str, sizeof(str), stdin);
    printf("%s\n", reverse(str));

    return 0;
}

Measured memory_bytes: 524
/**
    @Author:Monk78
    @Topic:OptimalGameStrategy->D-p31(geeks)
        ->Both chooses maximum element optimally
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
//#define S second;
//#define F first;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end));i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mod 1000000009
#define MAX 100005
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define rf(i,a,b) for(int i=(a);i>=b;i--)
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
#define vpshVar() int main()

struct Game{
    ll F,S;
    ll pick=0;
};
Game vec[3020][3020];
void fxn(ll arr[],ll N){

    for(ll i=0;i<N;i++){
        vec[i][i].F=arr[i];
        vec[i][i].pick=i;
    }
    for(ll l=2;l<=N;l++){
        for(ll i=0;i<=N-l;i++){
            ll j=i+l-1;
            if(arr[i]+vec[i+1][j].S > vec[i][j-1].S+arr[j]){
                vec[i][j].F=arr[i]+vec[i+1][j].S;
                vec[i][j].S=vec[i+1][j].F;
                vec[i][j].pick=i;
            }
            else{
                vec[i][j].F=arr[j]+vec[i][j-1].S;
                vec[i][j].S=vec[i][j-1].F;
                vec[i][j].pick=j;
            }

        }
    }
}

vpshVar(){
       ll N,sum=0;
       sl(N);
       ll arr[N];
       for(ll i=0;i<N;i++){
            sl(arr[i]);
       }
       for(ll i=0;i<N+5;i++){
        for(ll j=0;j<N+5;j++){
            vec[i][j].F=vec[i][j].S=vec[i][j].pick=0;
        }
       }
       fxn(arr,N);
       cout<<vec[0][N-1].F-vec[0][N-1].S<<endl;
return 0;
}


Measured memory_bytes: 214144
#include<iostream>
#include <stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#include <vector>
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(abs(a-c)<=d)printf("Yes");
    else if(abs(a-b)<=d&&abs(b-c)<=d)printf("Yes");
    else printf("No");
}




Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = list(input())
B = list(input())
C = list(input())

ans = 0
for i in range(n):
    num = len(set([A[i],B[i],C[i]]))
    if num == 2:
        ans += 1
    elif num == 3:
        ans += 2
print(ans)

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(std::string S) {
  if(S=="AAA" || S=="BBB") cout << "No" << endl;
  else cout <<"Yes"<<endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	int n;
	cin>>str>>n;
	string adj;
	int at = 0;
	while(at < str.size())
	{
		adj.push_back(str[at]);
		at+=n;
	}
	cout<<adj<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ABC141
{
    class D
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');

            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);

            input = Console.ReadLine().Split(' ');
            double[] A = new double[N];

            PriorityQueue<double> pq = new PriorityQueue<double>();
            for (int i = 0; i < N; i++)
            {
                pq.Enqueue(double.Parse(input[i]));
            }

            double now = 0;
            for (int i = 0; i < M; i++)
            {
                now = Math.Floor(pq.Top * (0.5));
                pq.Dequeue();
                pq.Enqueue(now);
            }

            double sum = 0;
            while (0 < pq.Count)
            {
                sum += pq.Top;
                pq.Dequeue();
            }
            Console.WriteLine(sum);
        }
    }

    class PriorityQueue<T> where T : IComparable<T>
    {
        List<T> buffer;

        public PriorityQueue() { this.buffer = new List<T>(); }
        public PriorityQueue(int capacity) { this.buffer = new List<T>(capacity); }

        static void PushHeap(List<T> array, T elem)
        {
            int n = array.Count;
            array.Add(elem);

            while (n != 0)
            {
                int i = (n - 1) / 2;
                if (array[n].CompareTo(array[i]) > 0)
                {
                    T tmp = array[n]; array[n] = array[i]; array[i] = tmp;
                }
                n = i;
            }
        }

        static void PopHeap(List<T> array)
        {
            int n = array.Count - 1;
            array[0] = array[n];
            array.RemoveAt(array.Count - 1);

            for (int i = 0, j; (j = 2 * i + 1) < n;)
            {
                if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) < 0))
                    j++;
                if (array[i].CompareTo(array[j]) < 0)
                {
                    T tmp = array[j]; array[j] = array[i]; array[i] = tmp;
                }
                i = j;
            }
        }

        public void Enqueue(T elem)
        {
            PushHeap(this.buffer, elem);
        }

        public void Dequeue()
        {
            PopHeap(this.buffer);
        }

        public T Top
        {
            get { return this.buffer[0]; }
        }

        public int Count
        {
            get { return this.buffer.Count; }
        }

    }
}


Measured memory_bytes: 29276
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	vector<ll> l(n);
	for(ll i=0;i<n;i++){
		cin>>l[i];
	}
	ll res=0;
	sort(l.begin(),l.end());
	for(ll i=n-1;i>=0;i--){
		for(ll j=i-1;j>=0;j--){
			ll p=l[i]-l[j];
			auto x=upper_bound(l.begin(),l.end(),p)-l.begin();
			if(x>=j){
				continue;
			}
			res+=(j-x);
		}
	}
	cout<<res;
}

Measured memory_bytes: 256
n,y = map(int, input().split())
ans = -1, -1, -1
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000+j*5000+(n-i-j)*1000==y:
            ans = i, j, (n-i-j)
            break
    else:
        continue
    break
print(*ans)


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

namespace ProconLib{
    template<typename T>
    class SegmentTree{
        std::vector<T> dat;
        int N;
        T E;
        std::function<T(T,T)> merge;
        T query_impl(int a,int b,int k,int l,int r);
        public:
        SegmentTree(int N,std::function<T(T,T)> merge,T E);
        void update(int pos,T val);        
        void updateALL(std::vector<T> x);
        T query(int a,int b);
    };

    template<typename T>
    SegmentTree<T>::SegmentTree(int N,std::function<T(T,T)> merge,T E):E(E),merge(merge){
        assert(N>=0);
        this->N=1;
        while(this->N<N){
            (this->N)*=2;
        }
        dat.assign(this->N*2-1,E);
    }

    template<typename T>
    void SegmentTree<T>::update(int pos,T val){
        pos+=N-1;
        dat[pos]=val;
        while(pos!=0){
            int par=(pos-1)/2;
            dat[par]=merge(dat[par*2+1],dat[par*2+2]);
            pos=par;
        }
    }

    template<typename T>
    void SegmentTree<T>::updateALL(std::vector<T> x){
        assert(x.size()<=N);
        for(int i=0;i<x.size();i++) dat[N-1+i]=x[i];
        for(int i=N-2;i>=0;i--) dat[i]=merge(dat[i*2+1],dat[i*2+2]);
    }

    template<typename T>
    T SegmentTree<T>::query(int a,int b){
        assert(a<=b);
        return query_impl(a,b,0,0,N);
    }

    template<typename T>
    T SegmentTree<T>::query_impl(int a,int b,int k,int l,int r){
        if(a<=l && r<=b) return dat[k];
        if(r<=a || b<=l) return E;
        int mid=(l+r)/2;
        T c1v=query_impl(a,b,k*2+1,l,mid);
        T c2v=query_impl(a,b,k*2+2,mid,r);
        return merge(c1v,c2v);
    }
}

/*verfy(AOJ DSL_2/A)*/
using namespace ProconLib;
int mymin(int a,int b){return std::min(a,b);}
int main(){
    int n,q;
    std::cin>>n>>q;
    SegmentTree<int> seg(n,mymin,int((1u<<31)-1));
    for(int i=0;i<q;i++){
        int com,x,y;
        std::cin>>com>>x>>y;
        if(com){
            y++;
            std::cout<<seg.query(x,y)<<std::endl;
        }
        else{
            seg.update(x,y);
        }
    }
    return 0;
}



Measured memory_bytes: 3896
N,K,Q = input().split()
N=int(N)
K=int(K)
Q=int(Q)

seikai_list = [K - Q] * N
for i in range(Q):
  num = int(input()) -1
  seikai_list[num] = seikai_list[num] +1

for n in seikai_list:
  if n > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 6584
N, Q = map(int, input().split())
S = list(input())
ac = [0] * N
j = 0
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        j += 1
    ac[i + 1] += j

for i in range(Q):
    l, r = map(int, input().split())
    print(ac[r - 1] - ac[l - 1])

Measured memory_bytes: 54520
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=201;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

int main(){
  boost;
  string S;
  cin>>S;
  int n=0,w=0,e=0,s=0;
  for(int i=0;i<sz(S);i++){
    if(S[i]=='N')n++;
    else if(S[i]=='W')w++;
    else if(S[i]=='E')e++;
    else s++;
  }
  bool b1=1;
  if(n>0&&s==0)b1=0;
  if(n==0&&s>0)b1=0;
  bool b2=1;
  if(e>0&&w==0)b2=0;
  if(e==0&&w>0)b2=0;
  if(b1&&b2)cout<<"Yes";
  else cout<<"No";
  return 0;
}


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

using namespace std;
typedef long long ll;

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

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

  int c[110][110];
  int y = 0, x = 0, r = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i]; j++) {
      c[y][x] = i + 1;
      if (r) {
        if (x + 1 == w) {
          y++;
          r = 0;
        } else {
          x++;
        }
      } else {
        if (x == 0) {
          y++;
          r = 1;
        } else {
          x--;
        }
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << c[i][j] << (j + 1 == w ? '\n' : ' ');
    }
  }

  return 0;
}

Measured memory_bytes: 384
from collections import deque
SA=deque(input())
SB=deque(input())
SC=deque(input())

ans=""
turn="a"
for i in range(500):
    if turn=="a":
        if len(SA)<1:
            ans="A"
            break
        else:
            turn=SA.popleft()
    elif turn=="b":
        if len(SB)<1:
            ans="B"
            break
        else:
            turn=SB.popleft()
    else:
        if len(SC)<1:
            ans="C"
            break
        else:
            turn=SC.popleft()
    
print(ans)

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

int main() {
    int N;cin>>N;
    vector<vector<int>> X(N),Y(N);
    vector<int> A(N);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        A[i]=a;
        for(int j=0;j<a;j++){
            int x,y;cin>>x>>y;x--;
            X[i].push_back(x);
            Y[i].push_back(y);

        }
    }
    int saidai=0;
    for(int bit=0;bit<(1<<N);bit++){
      bool ok=true;
      for(int i=0;i<N;i++){
          for(int j=0;j<A[i];j++){
              if(!(bit&(1<<i))){
              continue;
              }else{
              if(bit&(1<<X[i][j])&&Y[i][j]!=1)ok=false;
              if(!(bit&(1<<X[i][j]))&&Y[i][j]==1)ok=false;
          }
          }
      }  
      if(ok){
          int honest=0;
          for(int i=0;i<N;i++){
              if(bit&(1<<i))honest++;
          }
          saidai=max(saidai,honest);

    }

    }
    cout<<saidai<<endl;


}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int N, p[100010];
int main()
{
	cin >> N;
	REP(i, 0, N) cin >> p[i];

	int cnt = 0;
	REP(i, 0, N - 1) {
		if (p[i] == i + 1) {
			int tmp = p[i];
			p[i] = p[i + 1];
			p[i + 1] = tmp;

			cnt++;
		}
	}
	if (p[N - 1] == N) cnt++;
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a[3] = {1, 0, 0};
  string s;
  while (cin >> s) {
    swap(a[s[0] - 'A'], a[s[2] - 'A']);
  }
  for (int i = 0; i < 3; i++) {
    if (a[i]) cout << (char)(i + 'A') << endl;
  }

  return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[] arr = new int[count];
        for (int i = 0; i < count; ++i) {
            arr[i] = scanner.nextInt();
        }

        int beforePrev = 0;
        int prev = Math.abs(arr[1] - arr[0]);
        for (int i = 2; i < count; ++i) {
            int cur = Math.min(
                    Math.abs(arr[i] - arr[i - 1]) + prev,
                    Math.abs(arr[i] - arr[i - 2]) + beforePrev);
            beforePrev = prev;
            prev = cur;
        }
        System.out.println(prev);
    }
}


Measured memory_bytes: 52108
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  cout << max(0, a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<deque>
#include<stack>
#include<ctime>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
using namespace std;
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
char S[MAXN+5];
int main(){
	int n=read(),cnt=0;
	scanf("%s",S+1);
	for(int i=1;i<=n;i++)
		if(S[i]!=S[i-1])
			cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
int i;
#define rep2(i, a, b) for(i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
using namespace std;
// _________コーディングはここから！！___________
template <const int sz = 5 * 10000000, typename T = long long> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO io;
inline int read() { return io.read(); }
inline void write(int x) { io.write(x); }
inline void write(int x, char c) { io.write(x, c); }
constexpr int N = 500010;
int c[N];
struct T {
    int l, r, idx;
    constexpr bool operator<(const T &rhs) const noexcept { return r < rhs.r; }
} q[N];
int ans[N];
int last[N];
int dat[N];

inline void add(int k) {
    for(++k; k < N; k += k & -k) dat[k]++;
}
inline void dec(int k) {
    for(++k; k < N; k += k & -k) dat[k]--;
}
inline int sum(int k) {
    int res = 0;
    for(++k; k > 0; k -= k & -k) res += dat[k];
    return res;
}
int n, Q, now = 1;

// 頑張れ！！
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
// 頑張れ！！

main() {
    n = read(), Q = read();
    rep2(i, 1, n) c[i] = read();
    rep(i, Q) q[i].l = read(), q[i].r = read() + 1, q[i].idx = i;
    sort(q, q + Q);
    int now = 1;
    rep(i, Q) {
        for(; now < q[i].r; ++now) {
            if(last[c[now]]) dec(last[c[now]]);
            last[c[now]] = now;
        }
        ans[q[i].idx] = sum(q[i].r - 1) - sum(q[i].l - 1) + q[i].r - q[i].l;
    }
    rep(i, Q) write(ans[i], '\n');
}

Measured memory_bytes: 26764
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int a = 0, b = 0, c = 0;
    string s;
    cin >> s;
    rep(i,3)
    {
        if(s[i]=='a')++a;
        else if(s[i]=='b')++b;
        else if(s[i]=='c')++c;
    }
    if(a==1&&b==1&&c==1)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string.h>
using namespace std;
int pNum;
bool IsPrime[1000010];
int Prime[1000010];
int GetPrime(int n){
    memset(IsPrime,true,sizeof(IsPrime));
    IsPrime[0]=IsPrime[1]=false;
    pNum=0;
    for(int i=2;i<=n;i++){
        if(IsPrime[i])Prime[++pNum]=i;
        for(int j=1;j<=pNum&&Prime[j]*i<=n;j++){
            IsPrime[Prime[j]*i]=false;
            if(i%Prime[j]==0)break;
        }
    }
    return pNum;
}
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",GetPrime(n));
    }
    return 0;
}

Measured memory_bytes: 3960
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m=map(int,input().split())\n"
"d=[[10**18]*n for i in range(n)]\n"
"e=[]\n"
"for _ in range(m):\n"
"    a,b,c=map(int,input().split())\n"
"    d[a-1][b-1]=c\n"
"    d[b-1][a-1]=c\n"
"    e.append([a-1,b-1,c])\n"
"for i in range(n):\n"
"    d[i][i]=0\n"
"for k in range(n):\n"
"    for i in range(n):\n"
"        for j in range(n):\n"
"            d[i][j]=min(d[i][j],d[i][k]+d[k][j])\n"
"print(sum(c>d[a][b]for a,b,c in e))\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3788
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);

		int N = sc.nextInt();

		int[] scoreList = new int[N];
		String[] cityList = new String[101];
		String[] city = new String[N];

		for (int index=0; index<N; index++) {
			String name = sc.next();
			int score = sc.nextInt();

			scoreList[index]=score;
			cityList[score]=name;
			city[index]=name;
		}

		Arrays.sort(city);

		for (int index=0; index<N; index++) {

			int temp = find(city[index],cityList,N);
			System.out.println(get(scoreList,temp,N)+1);
		}
	}

	private static int get (int[] scoreList, int temp, int N) {
		int a = 0;
		for (int index=0; index<N; index++) {
			if (scoreList[index]==temp) {
				a = index;
				break;
			}
		}
		return a;
	}
	private static int find (String city, String[] cityList,int N) {

		int max=0;
		for (int index=0; index<101; index++) {

			try {
				if (cityList[index].equals(city)) {
					if (index>max) {
						max=index;
					}
				}
			} catch (Exception e) {

			}
		}
		cityList[max]=null;
		return max;
	}
}

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

int main() {
    int N,count = 0, now=1;
    cin >> N;
    vector<int> next(N);

    for (int i = 0; i < N; ++i)
    {
        cin >> next.at(i);
    }

    for (int i = 0; i < N; ++i){
        now = next.at(now - 1);
        ++count;
        if (now == 2){
            cout << count << endl;
            break;
        }
        else if(i==N-1){
                cout << -1 << endl;
                break;
        }
    }
}


Measured memory_bytes: 640
package main

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

func main() {
	n, d, an := 0, 0, 0
	fmt.Scanf("%d %d", &n, &d)
	sc := bufio.NewScanner(os.Stdin)
	d = d * d
	for i := 0; i < n; i++ {
		sc.Scan()
		tmp := strings.Split(sc.Text(), " ")
		x, _ := strconv.Atoi(tmp[0])
		y, _ := strconv.Atoi(tmp[1])
		if x*x+y*y <= d {
			an++
		}
	}
	fmt.Println(an)
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";
const ld pie = 3.14159265358979 ;

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    ll n ; 
    cin >> n ; 
    
    ll ans = round ( pow ( n , 3 ) ) ; 
    cout << ans ; 
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 384
// by syu
package main

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

var in = NewScanner(os.Stdin, 0)

func main() {
	N := in.Int()
	if N&1 != 0 {
		Pln(N * 2)
	} else {
		Pln(N)
	}
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}


Measured memory_bytes: 640
from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, M, K = map(int, readline().split())
    INF = 10**18
    E = [[-INF]*N for i in range(N)]
    for i in range(M):
        a, b, c = map(int, readline().split())
        E[a][b] = max(E[a][b], c)
    G = [[] for i in range(N)]
    for v in range(N):
        for w in range(N):
            if E[v][w] >= 0:
                G[v].append((w, E[v][w]))
    T = 100
    dist = [[0]*(T+1) for i in range(N)]
    prv = [[None]*(T+1) for i in range(N)]
    que = []
    for i in range(N):
        que.append((0, i, 0))
    t0 = T+1
    while que:
        cost, v, t = heappop(que)
        cost = -cost
        if cost >= K and t < t0:
            t0 = t
        if cost < dist[v][t] or t == T:
            continue
        for w, d in G[v]:
            if dist[w][t+1] < cost + d:
                dist[w][t+1] = cost + d
                prv[w][t+1] = v
                heappush(que, (-(cost + d), w, t+1))
    if t0 != T+1:
        v0 = 0; d = 0
        for v in range(N):
            e = dist[v][t0]
            if d < e:
                d = e
                v0 = v
        res = [v0]
        v = v0; t = t0
        while t > 0:
            v = prv[v][t]; t -= 1
            res.append(v)
        res.reverse()
        write("%d\n" % t0)
        write(" ".join(map(str, res)))
        write("\n")
        return

    for v in range(N):
        E[v][v] = 0
    E2 = [[-INF]*N for i in range(N)]
    A = (K-1).bit_length()
    RS = [E]
    for k in range(A):
        F = [[-INF]*N for i in range(N)]
        for v in range(N):
            for w in range(N):
                E2[w][v] = E[v][w]
        ok = 0
        for i in range(N):
            Ei = E[i]
            for j in range(N):
                Ej = E2[j]
                F[i][j] = r = max((a+b for a, b in zip(Ei, Ej) if a >= 0 and b >= 0), default = -INF)
                if r >= K:
                    ok = 1
        RS.append(F)
        E = F
        if ok:
            A = k
            break

    D = [0]*N
    ans = 0
    for i in range(A, -1, -1):
        E = RS[i]
        D0 = [0]*N
        ok = 0
        for v in range(N):
            D0[v] = r = max((a + e[v] for a, e in zip(D, E) if e[v]), default = -INF)
            if r >= K:
                ok = 1
        if not ok:
            ans += 1 << i
            D = D0
    ans += 1
    if ans > K:
        write("-1\n")
    else:
        write("%d\n" % ans)
solve()


Measured memory_bytes: 24200
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const int MOD = 1e9 + 7;
int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    IFOR(i, k, n+1){
        // (2n-k+1)*k/2 - k*(k-1)/2
        //0-k-1   n-k+1 - n
        ll to_add = (n-i+1) * i + 1;
        to_add %= MOD;
        ans = (ans + to_add) % MOD;
    }

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

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

s = []
for i in range(3):
    s.append(input())

ans = 0
for i in range(N):
    s1 = s[0][i]
    s2 = s[1][i]
    s3 = s[2][i]

    if s1==s2 and s2==s3 and s1==s3:
        ans += 0
    elif s1==s2 or s1==s3 or s2==s3:
        ans += 1
    else:
        ans += 2

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
int H,W,h,w;
int A[550][550];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(H,W,h,w);
  int cnt=0;
  for(int i=h;i<=H;i+=h) {
    for(int j=w;j<=W;j+=w) {
      ++cnt;
      A[i][j]=1;
    }
  }
  int a=W*H-cnt,b=cnt,c=h*w;
  int g=a-b*(c-1),t=b;
  if(g>0) {
    int v=1;
    while(g*v<=t) v<<=1;
    puts("Yes");
    for(int i=1;i<=H;++i) {
      for(int j=1;j<=W;++j) {
        printf("%d ",A[i][j]?-c*v+v-1:v);
      }
      puts("");
    }
  }
  else puts("No");
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define ll long long


using namespace std ;

const int MAXN = 101 * 1001 ;

int p[MAXN] , cnt[MAXN] ;

vector< int > won[MAXN] ;

int dp[MAXN] , d[MAXN];

int32_t main()
{
    ios::sync_with_stdio(0) ; cin.tie(0) ;
    int n ;
    cin >> n ;
    for(int i = 2 ; i <= n ; i ++ )
    {
        cin >> p[i] ;
        won[p[i]].pb(i) ;
        cnt[p[i]] ++ ;
        d[p[i]] ++ ;
    }
    queue < int > q ;
   for(int i = 1 ; i <= n ; i ++ )
        if(!d[i])
            q.push(i) ;
    while(q.size())
    {
        int i = q.front() ; q.pop() ;
        dp[i] = cnt[i] ;
        vector < int  > v ;
        for(auto u : won[i] )
        {
            v.pb(dp[u]) ;
        }
        sort(v.rbegin(),v.rend()) ;
        for(int j = 0 ; j < cnt[i] ; j ++ )
            dp[i] = max(dp[i],j+v[j]+1) ;
//      cout << i << ' ' << dp[i] << ' ' << (v.size()?v[0]:-1)<< ' ' <<cnt[i]<< endl  ; 
        d[p[i]] -- ;
        if(!d[p[i]]&&i>1)
            q.push(p[i]) ;
    }
    cout << dp[1]   << endl ;
}


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

int main() {
  string S, T;
  cin >> S >> T;

  int answer = 0;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == T.at(i)) answer++;
  }

  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    bool ok[n]={};
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a==b)ok[i] = 1;
    }
    bool pos = false;
    for(int i=2;i<n;i++){
        if(ok[i-2] && ok[i-1] && ok[i])pos=1;
    }
    if(pos)cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3648
from collections import deque

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

s_m = []
for _ in range(M):
    flag = True
    num = 0
    for s in input().split():
        if flag:
            flag = not flag
        else:
            s = int(s)
            num += 2**(s-1)
    s_m.append(num)

p = [int(x) for x in input().split()]

# print(s_m)

cnt = 0
for i in range(2**N):
    flag = True
    for j in range(len(s_m)):
        n = s_m[j]
        n &= i
        tf = True if p[j] == 0 else False
        # print(i, n)
        for _ in range(N):
            if n & 1 == 1:
                tf = not tf
            n >>= 1
        if not tf:
            flag = False
            break
    if flag:
        cnt += 1

print(cnt)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int p[200001], q[200001], c[200001], dp[100001];
map<int, vector<int>> vert[100001];
set<int> companies[100001];

int main()
{
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 2; i <= n; i++)
	{
		dp[i] = 1000000000;
	}
	for (int i = 1; i <= m; i++)
	{
		// cin >> p[i] >> q[i] >> c[i];
		scanf("%d %d %d", &p[i], &q[i], &c[i]);
		companies[p[i]].insert(c[i]);
		companies[q[i]].insert(c[i]);
		if (vert[p[i]].find(c[i]) == vert[p[i]].end())
		{
			vector<int> temp;
			vert[p[i]][c[i]] = temp;
		}
		vert[p[i]][c[i]].pb(q[i]);
		if (vert[q[i]].find(c[i]) == vert[q[i]].end())
		{
			vector<int> temp;
			vert[q[i]][c[i]] = temp;
		}
		vert[q[i]][c[i]].pb(p[i]);
	}
	queue<int> q1;
	q1.push(1);
	while (!q1.empty())
	{
		int start = q1.front();
		q1.pop();
		int dist = dp[start] + 1;
		for (int comp : companies[start])
		{
			queue<int> q;
			q.push(start);
			while (!q.empty())
			{
				int cur = q.front();
				q.pop();
				if (cur != start)
				{
					q1.push(cur);
				}
				for (int v : vert[cur][comp])
				{
					if (dp[v] >= dist)
					{
						dp[v] = dist;
						q.push(v);
					}
				}
				vert[cur].erase(comp);
			}
		}
		companies[start].clear();
	}
	if (dp[n] == 1000000000)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 74880