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

int main(){
    int n ;
    cin >> n ;
    vector<int> a(n) ;
    vector<int> b(n) ;
    vector<int> c(n-1) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    for (size_t i = 0; i < n; i++)
    {
        cin >> b.at(i) ;
    }
    for (size_t i = 0; i < n-1; i++)
    {
        cin >> c.at(i) ;
    }
    int ans = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        ans += b.at(i) ;
    }
    
    for (size_t i = 0; i < n-1; i++)
    {
        if (a.at(i)+1== a.at(i+1))
        {
            ans += c.at(a.at(i)-1) ;
        }
        
    }
    cout << ans << endl ;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> Ansers(Q);
  for (int i=0; i<Q; i++){
        cin >> Ansers.at(i);
  }
  vector<int> A(N);
  for (int i=0; i < N; i++){
      A.at(i)=K;
  }
  for (int i=0; i < Q ;i++){
      A.at(Ansers.at(i)-1)++;
  }
  for(int x: A){
   if (x-Q>0){
     cout << "Yes" << endl;
   }else{
     cout << "No" << endl;
   }
  }
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Die{
	vi face; // u,r,f,d,l,b
	Die(int u,int f):face(6){
		int t[6][6]={
			{9,2,4,1,3,9},
			{3,9,0,5,9,2},
			{1,5,9,9,0,4},
			{4,0,9,9,5,1},
			{2,9,5,0,9,3},
			{9,3,1,4,2,9},
		};
		face[0]=u;
		face[1]=f;
		face[2]=t[u][f];
		repi(i,3,6)
			face[i]=5-face[i-3];
	}
	void Turn(int a,int b,int c,int d){
		int t=face[a];
		face[a]=face[b];
		face[b]=face[c];
		face[c]=face[d];
		face[d]=t;
	}
	// TurnX: X面をxy平面とみたとき，z軸を回転軸として時計回り
	void TurnF(){
		Turn(0,5,3,2);
	}
	void TurnR(){
		Turn(0,1,3,4);
	}
	void TurnB(){
		rep(i,3) TurnF();
	}
	void TurnL(){
		rep(i,3) TurnR();
	}
};

void place(vvi& height,vvi& face,Die die,int i,int j)
{
	int di[]={-1,1,0,0};
	int dj[]={0,0,-1,1};
	int df[]={4,1,5,2};
	int dir=-1;
	rep(k,4){
		int ni=i+di[k],nj=j+dj[k];
		if(height[ni][nj]>=height[i][j] || die.face[df[k]]<3)
			continue;
		if(dir==-1 || die.face[df[dir]]<die.face[df[k]])
			dir=k;
	}
	if(dir==-1){
		height[i][j]++;
		face[i][j]=die.face[0];
	}
	else{
		if(dir==0) die.TurnR();
		if(dir==1) die.TurnL();
		if(dir==2) die.TurnB();
		if(dir==3) die.TurnF();
		place(height,face,die,i+di[dir],j+dj[dir]);
	}
}

int main()
{
	for(int n;cin>>n,n;){
		vvi height(30,vi(30));
		vvi face(30,vi(30));
		rep(_,n){
			int u,f; cin>>u>>f; u--; f--;
			Die die(u,f);
			place(height,face,die,15,15);
		}
		
		vi cs(6);
		rep(i,30) rep(j,30)
			if(height[i][j]>0)
				cs[face[i][j]]++;
		printf("%d %d %d %d %d %d\n",cs[0],cs[1],cs[2],cs[3],cs[4],cs[5]);
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,sum=0;
  cin>>N;
  vector<ll> A(N);
  REP(i,N){
    cin>>A[i];
    sum+=A[i];
  }
  
  bitset<MAX> DP;
  DP[0]=1;
  REP(i,N) DP|=(DP<<A[i]);
  
  ll ans;
  for(ans=(sum+1)/2; ans<MAX; ++ans){
    if(DP[ans]) break;
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 2176
import sys

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())

flag = False
s = rr()
q = ri()
front = ''
end = ''
for _ in range(q):
    query = list(rs())
    if query[0] == '1':
        flag = not flag
        continue
    else:
        f = int(query[1])
        c = query[-1]
        if flag == True:
            if f == 1:
                end += c
            else:
                front = c+front
        else:
            if f == 1:
                front = c+front
            else:
                end += c
if flag:
    print((front+s+end)[::-1])
else:
    print(front+s+end)            

Measured memory_bytes: 10076
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    s = tuple(map(int, input()))
    lens = len(s)

    d1 = defaultdict(int)
    ss = 0
    num10 = 1
    for i1 in range(1, lens+1):
        ss += (int(s[-i1]) * num10) % 2019
        ss = ss % 2019
        d1[ss] += 1
        num10 = (num10 * 10) % 2019
    r = d1[0]
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

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

int main() {
    string S, T;
    cin >> S >> T;
    ll N = S.length();
    vector<vector<int>> next(N, vector<int>(26, -1));
    map<int, int> first;
    for (int c = 0; c < 26; c++) {
        first[c] = -1;
    }
    for (int i = N - 1; i >= 0; i--) {
        first[S[i] - 'a'] = i;
    }
    map<int, int> last;
    for (int c = 0; c < 26; c++) {
        last[c] = -1;
    }
    for (int i = N - 1; i >= 0; i--) {
        for (int c = 0; c < 26; c++) {
            next[i][c] = max(last[c], first[c]);
        }
        last[S[i] - 'a'] = i;
    }

    ll cnt = 0;
    ll M = T.length();
    ll idx = first[T[0] - 'a'];
    if (idx == -1) {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 1; i < M; i++) {
        if (next[idx][T[i] - 'a'] == -1) {
            cout << -1 << endl;
            return 0;
        }
        if (next[idx][T[i] - 'a'] <= idx) {
            cnt++;
        }

        idx = next[idx][T[i] - 'a'];
    }

    cout << N * cnt + idx + 1 << endl;
}


Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '.') ++count; 
    } 
    int mincount = count;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '.') --count;
        else ++count;
        mincount = min(count, mincount);  
    } 
    cout << mincount<< endl;
    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    H = list(map(int, input().split()))
    C = [0 for _ in range(N)]
    cost = 0
    for i in range(max(H)):
        is_open = True
        for j in range(N):
            if C[j] < H[j]:
                C[j] += 1
                if is_open:
                    cost += 1
                    is_open = False
            else:
                is_open = True
    print(cost)

main()


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{   long long n,m,x,y;
  double s;
	while(~scanf("%lld%lld%lld%lld",&n,&m,&x,&y))
	{    s=n*m/2.0; 
        if(n%2==0&&m%2==0&&n/2==x&&m/2==y)
        {
		printf("%.6lf 1\n",s);
		                      
        }
        else
        {
        	printf("%.6lf 0\n",s);
		
		}
		
	} 
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 2000000

int H;

int parent(int i){ return i/2; }
int left(int i){ return 2*i; }
int right(int i){ return (2*i)+1; }

void maxHeapify(int A[], int i){
  int l, r, largest, tmp;
  l = left(i);
  r = right(i);
  if( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  
  if( r <= H && A[r] > A[largest] ) largest = r;

  if( largest != i ){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int A[]){
  int i;
  for( i = H/2 ; i >= 1 ; i-- ) maxHeapify(A,i);
}

int main(){
  int i, A[MAX+1];

  scanf("%d", &H);

  for( i = 1 ; i <= H ; i++ ) scanf("%d", &A[i]);

  buildMaxHeap(A);

  //printf("%d",A[1]);
  for( i = 1 ; i <= H ; i++ ) printf(" %d",A[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 3724
#include <stdio.h>

int main(){
    int N,i,r=0,b=0;
    scanf("%d",&N);
    char str[N+1];
    scanf("%s",str);
    for(i=0;i<N;i++){
        if(str[i] == 'R') r++;
        else b++;
    }
    if(r>b) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
int N;
ll ans = 0;

int main()
{
    cin >> N;
    vector<ll> a(3 * N);
    rep(i, 0, 3 * N)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = N; i < 3 * N; i += 2)
    {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
 
 vector<int> c(500);
 vector<int> s(500);
 vector<int> f(500); 

int arrival(int i, int n){
    
    if(i == n){
        return s[i] + c[i];
    }
    int t_nmade = arrival(i - 1, n);
    if(t_nmade <= s[i]){
        return s[i] + c[i];
    }else{
        if((t_nmade - s[i]) % f[i] == 0){
            return t_nmade + c[i];
        }else{
            return t_nmade - ((t_nmade - s[i]) % f[i]) + f[i] + c[i] ;
        } 
    }
} 
 
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }
    for(int i = 0; i < n - 1; i++){
        cout << arrival(n - 2, i) << '\n';
    }
    cout << 0;

}





Measured memory_bytes: 256
#include<stdio.h>

 int main(){
     int i,n,S,GG,j;
     int Card[4][13]={0};
     char G,M[]="SHCD";

     scanf("%d",&n);

     for(i=0;i<n;i++){
             scanf(" %c %d",&G,&S);

             if(G=='S'){GG=0;}
             else if(G=='H'){GG=1;}
             else if(G=='C'){GG=2;}
             else if(G=='D'){GG=3;}

             Card[GG][S-1]=1;
             }

     for(i=0;i<4;i++){
            for(j=0;j<13;j++){
                    if(Card[i][j]==0){printf("%c %d\n",M[i],j+1);}
                    }
            }
     return 0;
     }


Measured memory_bytes: 2120
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    int a=0,i,j;
    char input[1010],ans[15];
    
    scanf("%s",ans);
    
    while(1){
        scanf("%s",input);
        if(strcmp(input,"END_OF_TEXT")==0)break;
        for(i=0;i<'\n';i++){
            input[i]=tolower(input[i]);
        }
        if(strcmp(input,ans)==0)a++;
    }
    
    printf("%d\n",a);
    return 0;
}


Measured memory_bytes: 2132
s=list(input().split())
n=int(s[0])
l=int(s[1])
apple=[]
total=[]
for i in range(n):
  taste=l+(i+1)-1
  if taste<0:
    apple.append(taste*-1)
  else:
    apple.append(taste)
  total.append(taste)
total.pop(apple.index(min(apple)))
print(sum(total))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, pii> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
int A[112345], B[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d %d", A + i, B + i);
	
	vector<pii> v;
	REP(i, N) v.push_back(pii(A[i] + B[i], i));
	sort(ALL(v), greater<pii>());
	
	ll taka = 0, ao = 0;
	REP(i, v.size()) {
		if (i % 2 == 0) taka += A[v[i].se];
		else ao += B[v[i].se];
	}
	cout << taka - ao << endl;
	return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstdlib>

using namespace std;

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


string sum(string a, string b) {
	if (a.size() > b.size()) swap(a, b);
	
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	
	string res = "";
	int c = 0;
	REP(i, a.size()) {
		c += a[i] - '0' + b[i] - '0';
		res.push_back(c % 10 + '0');
		c /= 10;
	}
	FOR(i, a.size(), b.size()) {
		c += b[i] - '0';
		res.push_back(c % 10 + '0');
		c /= 10;
	}
	if (c > 0) res.push_back(c + '0');
	
	reverse(res.begin(), res.end());
	
	return res;
}

string kake(string a, string b) {
	if (a == "0" || b == "0") return "0";
	
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	
	string res = "0";
	REP(i, a.size()) {
		string plus = "";
		int c = 0;
		REP(j, b.size()) {
			c += (a[i] - '0') * (b[j] - '0');
			plus.push_back(c % 10 + '0');
			c /= 10;
		}
		if (c > 0) plus.push_back(c % 10 + '0');
		reverse(plus.begin(), plus.end());
		REP(j, i) plus.push_back('0');
		res = sum(res, plus);
	}
	
	return res;
}

string pow(string x, int n) {
	if (n == 0) return "1";
	string res = pow(kake(x, x), n / 2);
	if (n & 1) res = kake(res, x);
	return res;
}

string jin[19] = {
	"", "Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"
};

int main() {
	string m;
	int n;
	
	while (cin >> m >> n, m != "0" || n) {
		string num = pow(m, n);
		
		int data[19] = {};
		reverse(num.begin(), num.end());
		REP(i, (num.size() - 1) / 4 + 1) {
			string now = num.substr(i * 4, min(4, (int)num.size() - i * 4));
			reverse(now.begin(), now.end());
			data[i] = atoi(now.c_str());
		}
		
		for (int i = 18; i >= 0; i--) if (data[i] != 0) {
			printf("%d%s", data[i], jin[i].c_str());
		}
		puts("");
	}
}

Measured memory_bytes: 3324
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int a, p; cin >> a >> p;
  cout << (3*a+p)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, mod = 1e9 + 7;
int a[256];
vector<int> vi;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int ans  = 0;
    for (int i = 1; i < n - 1; ++i){

        vi.push_back(a[i - 1]);
        vi.push_back(a[i]);
        vi.push_back(a[i + 1]);
        sort(vi.begin(), vi.end());
        if (a[i] > vi[0] && a[i] < vi[2]) ++ans;
        vi.clear();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for (ll i = 0, i##_len = (n); i < i##_len; i++)

int main() {

    ll n; cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];

    auto bb = b;
    sort(bb.begin(), bb.end());
    bb.erase(unique(bb.begin(), bb.end()), bb.end());
    if (bb.size() == n) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << "\n";
        vector<ll> c(n, a[0]), d(n, a[1]);
        map<ll, ll> im;
        REP(i, n) im[a[i]] = i;
        for (ll bi : b) {
            c[im[bi]] = d[im[bi]] = a[0];
        }
        REP(i, n) cout << c[i] << " \n"[i+1 == n];
        REP(i, n) cout << d[i] << " \n"[i+1 == n];
        cout << flush;
    }

}


Measured memory_bytes: 13168
n,k=map(int,input().split())
mod=10**9+7
s=[1]*(k+1)
for d in range(1,k//2+1)[::-1]:
  a=pow(k//d,n,mod)
  for i in range(2*d,k+1,d):
    a-=s[i]
  s[d]=a%mod
ans=0
for i,s_i in enumerate(s):
  ans+=i*s_i
  ans%=mod
print(ans)

Measured memory_bytes: 11204
#include<bits/stdc++.h>
#define ll long long
#define lc (id * 2)
#define rc (id * 2 + 1)
#define mid ((l + r) >> 1)
#define fi first
#define se second

using namespace std;

const int maxN = 2e5 + 5;
int p[maxN];

struct SegmentTree {
	int e, st[maxN * 4];

	void build(int id, int l, int r) {
		if (l == r){
            st[id] = l * 2 - e;
            return;
        }
		build(lc, l, mid); build(rc, mid+1, r);
		st[id] = p[st[lc]] < p[st[rc]] ? st[lc] : st[rc];
	}

	int query(int id, int l, int r, int x, int y) {
		if (l == x && y == r)
            return st[id];
		if (y <= mid)
            return query(lc, l, mid, x, y);
		if (mid < x)
            return query(rc, mid+1, r, x, y);
		int L = query(lc, l, mid, x, mid);
		int R = query(rc,  mid+1, r, mid+1, y);
		return p[L] < p[R] ? L : R;
	}
} Tree[2];

struct Node {
	int l, r, p, q, a, b;
	bool operator < (const Node &x) const {
		return a > x.a;
	}
} tmp;

priority_queue<Node> Q;
int n;

void calc(int l, int r) {
	Node res;
	res.l = l; res.r = r;
	if (l&1) {
		res.p = Tree[1].query(1, 1, n/2, (l+1)/2, (r+1)/2);
		res.q = Tree[0].query(1, 1, n/2, (res.p+2)/2, (r+1)/2);
	}
	else {
		res.p = Tree[0].query(1, 1, n/2, (l+1)/2, r/2);
		res.q = Tree[1].query(1, 1, n/2, (res.p+2)/2, (r+1)/2);
	}
	res.a = p[res.p]; res.b = p[res.q];
	Q.push(res);
}

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

	Tree[0].e = 0; Tree[1].e = 1;

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

	Tree[0].build(1, 1, n/2);
	Tree[1].build(1, 1, n/2);
	calc(1, n);

	while (!Q.empty())
    {
		tmp = Q.top();
        Q.pop();
		cout << tmp.a << " " << tmp.b << " ";
		if (tmp.l < tmp.p) calc(tmp.l, tmp.p-1);
		if (tmp.p + 1 < tmp.q) calc(tmp.p+1, tmp.q-1);
		if (tmp.q < tmp.r) calc(tmp.q+1, tmp.r);
	}
	return 0;
}


Measured memory_bytes: 7716
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
lights = [list(map(int, input().split()[1:])) for i in range(M)]
p = list(map(int, input().split()))

combi = 0
for i in range(1<<N):
    flag = True
    for j, switch in enumerate(lights):
        if sum([1 for s in switch if (i>>(s-1)) & 1 == 1])%2 != p[j]:
            flag = False
            break
    if flag:
        combi += 1

print(combi)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, m;
    cin >> n >> m;
    vector<string> v;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++) if(s[j] == '#'){
            v.pb(s);
            break;
        }
    }
    for(int i = 0; i < m; i++){
        bool q = true;
        for(int j = 0; j < v.size(); j++) if(v[j][i] == '#'){
            q = false;
            break;
        }
        if(q){
            for(int j = 0; j < v.size(); j++) v[j][i] = '0';
        }
    }
    for(int i = 0; i < v.size(); i++) {
        for(int j = 0; j < v[i].size(); j++) if(v[i][j] != '0') cout << v[i][j];
        cout << endl;
    }
}

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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    fastio();

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

    sort(all(a));
    int cnt = 0;
    for(int i=n-1;i>=0;i--)
    {
        if( 4*m*a[i] >= total )
        {
            cnt++;
        }
    }

    if( cnt >= m )
        cout<<"Yes";
    else
        cout<<"No";


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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


ans = 0


def solve(i, l):
    global ans

    if len(l) == n:
        total = 1
        for k in l:
            total *= k
        if total % 2 == 0:
            ans += 1
        return

    for j in range(-1, 2):
        l.append(a[i] + j)
        solve(i + 1, l)
        l.pop()


solve(0, [])
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
using namespace std;
typedef long long ll;
 

 
int main(){
    string wheather;
    cin>>wheather;
    if(wheather=="Sunny")cout<<"Cloudy"<<endl;
    else if(wheather=="Cloudy")cout<<"Rainy"<<endl;
    else  if(wheather=="Rainy")cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> v(0);
  int vel;
  for(int i=0;i<N;i++){
    cin >> vel;
    v.push_back(vel);
  }
  sort(v.begin(),v.end());
  double ans;
  ans = (v.at(0)+v.at(1))/2.0;
  for(int i=2; i<N;i++){
    ans = (ans+v.at(i))/2.0;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(), l.end());
    int sum = 0;
    rep(i,n-1) sum += l[i];
    if(sum > l[n-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3544
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
it = iter(AB)

d = defaultdict(int)
zeros = 0
for a, b in zip(it, it):
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)


Measured memory_bytes: 159728
// include
#include <iostream>
#include <queue>
#include <utility>

// using namespace 
using namespace std;

// typedef
typedef unsigned long long ull;
typedef unsigned int uint; 
typedef pair<int, int> PII;

// macro
#define REP(index, num) for (auto index = 0; index < num; index++)
#define FOR(index, num) for (auto index = 1; index <= num; index++)

#define MAX_HEIGHT 60
#define MAX_WIDTH 60
#define INF (int)1e9

const int CountShortestDistance();

// global
int H, W;
char s[MAX_WIDTH][MAX_HEIGHT];
int whiteCount = 0;

int main()
{
  cin >> H >> W;
  
	FOR(hId, H)
    FOR(wId, W)
  {
    cin >> s[wId][hId];
    if (s[wId][hId] == '.')
      whiteCount++;
  }

  // 幅優先探索で最短の移動コストを調べる
  int cost = CountShortestDistance();
  if (cost != INF)
    cout << whiteCount - (CountShortestDistance() + 1) << endl;
  else
    cout << -1 << endl;

}

const int CountShortestDistance()
{
  int distance[MAX_WIDTH][MAX_HEIGHT];

  FOR(hId, H)
    FOR(wId, W)
    distance[wId][hId] = INF;

  int sw = 1, sh = 1;
  int gw = W, gh = H;

  distance[sw][sh] = 0;

  queue<PII> que;
  que.push(make_pair(sw, sh));

  while (que.size())
  {
    PII curPair = que.front();
    int curX = curPair.first;
    int curY = curPair.second;
    que.pop();

    // 上下左右に移動
    const int addNextX[4] = {1, 0, -1, 0};
    const int addNextY[4] = {0, 1, 0, -1};
    for (int pId = 0; pId < 4; pId++)
    {
      int nextX = curX + addNextX[pId];
      int nextY = curY + addNextY[pId];
      PII nextPair = make_pair(nextX, nextY);
      if ((nextX < 1 || W < nextX) || (nextY < 1 || H < nextY) 
        || s[nextX][nextY] == '#' || distance[nextX][nextY] != INF)
        continue;
      que.push(nextPair);
      distance[nextX][nextY] = distance[curX][curY] + 1;
    }

  }

  return distance[gw][gh];

}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
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;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  set<char> s;
  rep(i, n) {
    char si; std::cin >> si;
    s.insert(si);
  }
  std::cout << (s.size() == 3 ? "Three" : "Four") << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

//#define ll __int64
#define ll long long
#define P pair<ll,ll>

ll q,h,s,d,n;

int main(){
	cin>>q>>h>>s>>d>>n;
	q*=4;//1l
	h*=2;//1l
	
	ll ans=0;
	ll one=1000000000000;
	ll two=one;

	one=min(one,q);
	one=min(one,h);
	one=min(one,s);
	two=min(one*2,d);
	//cout<<one<<" "<<two<<endl;
	ans=n/2*two;
	if(n%2)ans+=one;
	cout<<ans<<endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
double a, b, h, m;
const double pi = 3.141592653589793;
int main(){
	scanf("%lf%lf%lf%lf", &a, &b, &h, &m);
	h = (h*60+m)/360*pi; m = m/30*pi;
	printf("%.9f\n", hypot(a*cos(h)-b*cos(m),a*sin(h)-b*sin(m)));
}

Measured memory_bytes: 4168
#include<bits/stdc++.h>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
typedef long long int ll;
ll mod(ll x) { return x%MOD; }
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll k;
	cin>>k;
	ll sum = 0;
	for(ll i=1;i<=k;++i)
	{
		for(ll j=1;j<=k;++j)
		{
			for(ll z=1;z<=k;++z)
			{
				sum+= __gcd(__gcd(i,j),z);	
			}
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3612
/*
oruegg19 - Arundhati Bhattacharya
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<unsigned ll>
#define mp make_pair
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const unsigned ll l=1000000007;
const int MAX_=2000;
int T;

void solve(int t)
{
  ll n;
  cin >> n;

  vector<int> a(26);

  fill(a.begin(), a.end(), 60);

  for(int i=0; i<n; i++)
  {
    string s;
    cin >> s;
    for(int j=0; j<26; j++)
    {
      char c = 'a' + j;
      // cout << c << endl;
      int x = count(s.begin(), s.end(),c);
      // cout << c << " " << x << " ";
      a[j] = min(a[j],x);
    }
  }

  string s="";

  for(int i=0;i<26; i++)
  {
    char c = 'a' + i;
    s += string(a[i],c);
  }

  cout << s << endl;
}

int main()
{
  IOS
  int t,testCases;
  testCases=1;
  #ifdef DEBUG
    // freopen("input.txt","r",stdin);
    // cin >> testCases;
    // cout << "Running " << testCases << " testcases" << endl;
    // freopen("output.txt","w",stdout);
    // freopen("error.txt","w",stderr);
    clock_t t1, t2;
    t1 = clock();
  #endif

  while(testCases--)
  {
    t=1;
    // cin >> t; //comment this in case of singular test case
    T = t;
    while(t--)
    {
      // cout << "HERE" << endl;
      solve(t);
    }
  }
  #ifdef DEBUG
    t2 = clock(); cerr << "time taken: " << (t2-t1)/(long double)CLOCKS_PER_SEC;
  #endif
  return 0;

}




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

d=['3','5','7','']
k=10
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))

ans=sum([1 if x<=n else 0 for x in s])
print(ans)


Measured memory_bytes: 44568
n = int(input())
h_inputs = [int(i) for i in input().split()]

index = 0
ans = 0

for i in range(n-1):
    if h_inputs[i]<h_inputs[i+1]:
        if ans<(i-index):
            ans = i-index
        index = i+1
if ans<(n-index):
    ans = n-index-1
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int a,b, c; cin >> a>> b>> c;
    swap(a, b); swap(a, c);

    cout << a << " " << b <<" "<< c << endl;;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
int n,m,a[100],b[100],c[100],d[100],ans,ansi; 
int main()
{
  scanf("%d%d",&n,&m); 
  for(int i=1;i<=n;i++)
    scanf("%d%d",&a[i],&b[i]);
  for(int i=1;i<=m;i++)
    scanf("%d%d",&c[i],&d[i]);
  for(int i=1;i<=n;i++)
  {
    ans=10e10;
    for(int j=1;j<=m;j++)
      if(ans>abs(a[i]-c[j])+abs(b[i]-d[j]))ans=abs(a[i]-c[j])+abs(b[i]-d[j]),ansi=j;
    printf("%d\n",ansi);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
int n, m, x;
int mat[15][15];

void solve(){
    int i = 0, j = 0;
    int ans = 1e9;
    for(int mask = 0; mask < (1 << n); mask++){
        int cnt[m + 1];
        memset(cnt, 0, sizeof(cnt));
        int cost = 0;
        for(i = 0; i < n; i++){
            if(mask & (1 << i)){
                for(j = 1; j <= m; j++)
                    cnt[j] += mat[i][j];
                cost += mat[i][0];
            }
        }
        bool ok = true;
        for(i = 1; i <= m; i++)
            ok &= (cnt[i] >= x);
        if(ok)
            ans = min(ans, cost);
    }
    if(ans == 1e9)
        ans = -1;
    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> x;
    int i = 0, j = 0;
    for(i = 0; i < n; i++){
        cin >> mat[i][0];
        for(j = 1; j <= m; j++)
            cin >> mat[i][j];
    }
    solve();
    return 0;
}

Measured memory_bytes: 3644
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <array>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  std::vector<char> s(n);
  for (auto &e : s) {
    std::cin >> e;
  }
  isize x = 0;
  isize ans = 0;
  for (const auto e : s) {
    if (e == 'I') {
      x += 1;
    } else {
      x -= 1;
    }
    chmax(ans, x);
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
cnt = 0
for i in range(n):
    x = int(input())
    if x == 2:
        cnt += 1
    elif x <= 1\
    or x % 2 == 0:
        continue
    else:
        j = 3
        prime = "yes"
        while j <= math.sqrt(x):
            if x % j == 0:
                prime = "no"
                break
            else:
                j += 2
        if prime == "yes":
            cnt += 1
print(cnt)

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

using namespace std;

unsigned long long x,y;

int main()
{
	cin>>x>>y;
	
	if (x>y)
	{
		cout<<0<<endl;
		
		return 0;
	}
	
	unsigned long long tmp=x,ans=1;
	
	while (tmp*2<=y)
	{
		ans++;
		tmp*=2;
	} 
	
	cout<<ans<<endl;
	
	return 0;
} 

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

string s;
const int p = 2019;
map<int,int> rem;
signed main(){
    cin >> s;
    int ev = 0;
    int mlp = 1;
    rem[0] = 1;
    int ret = 0;
    for(auto it = s.rbegin(); it != s.rend(); it++){
        ev = (ev  + (*it - '0') * mlp) % p;
        ret += rem[ev];
        rem[ev]++;
        mlp = (mlp * 10) % p;
    }
    // int ret = 0;
    // for (auto pr: rem){
    //     int n = pr.second;
    //     ret += n * (n-1) / 2;
    // }
    cout << ret << endl;
}

Measured memory_bytes: 3744
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] div = new int[n+1];
		for(int i=1;i<=n;i++){
			for(int j=1;j*i<=n;j++){
				div[i*j]++;
			}
		}
		long ans=0;
		for(int i=1;i<=n;i++){
			ans =ans+((long)i*(long)div[i]);
		}
		System.out.println(ans);
	}
	
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll mod = 1000000007;

ll inv(ll n){
	if(n == 1)return 1;
	return inv(mod%n)*(mod - mod/n)%mod;
}

ll modPow(ll a, ll b){
	ll ret = 1;
	while(b){
		if(b&1)(ret *= a) %= mod;
		(a *= a) %= mod;
		b >>= 1;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, a, b;
	cin>>n>>a>>b;
	ll tot = modPow(2, n) - 1;
	{
		ll num = 1, den = 1;
		for(int i = 1; i <= a; i++){
			(num *= (n - i + 1)) %= mod;
			(den *= i) %= mod;
		}
		tot += mod - (num*inv(den)%mod);
	}
	{
		ll num = 1, den = 1;
		for(int i = 1; i <= b; i++){
			(num *= (n - i + 1)) %= mod;
			(den *= i) %= mod;
		}
		tot += mod - (num*inv(den)%mod);
	}
	tot %= mod;
	cout<<tot<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>
 
using namespace std;
typedef long long ll;
const ll INF = 1e12;
 
 
int main(){
        ll a,b,c,d;
        cin >> a >> b>> c >> d;
        if(labs(b-a)<=d && labs(b-c)<=d || labs(c-a)<=d)cout << "Yes";
        else cout << "No";
 
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

template <typename T>
struct BinaryIndexedTree {
  vector<T> dat;
  BinaryIndexedTree(int n) : dat(n + 1, 0) {}
  BinaryIndexedTree(int n, T a) : BinaryIndexedTree(vector<T>(n, a)) {}
  BinaryIndexedTree(vector<T> y) : dat(y.size() + 1) {
    for (int i = 0; i < y.size(); ++i) dat[i + 1] = y[i];
    for (int i = 1; i + (i & -i) < dat.size(); ++i) dat[i + (i & -i)] += dat[i];
  }
  void add(int i, T a = 1) {
    for (++i; i < (int)dat.size(); i += i & -i) dat[i] += a;
  }
  T sum(int i) {  // sum [0,i)
    T s = 0;
    for (; i > 0; i &= i - 1) s += dat[i];
    return s;
  }
  // min { i : sum(i+1) > k } -> kth element(0-indexed)
  int find(T k) const {
    int i = 0;
    for (int p = 1 << (__lg(dat.size() - 1) + 1); p > 0; p >>= 1)
      if (i + p < (int)dat.size() && dat[i + p] <= k) k -= dat[i += p];
    return i + 1 == (int)dat.size() ? -1 : i;  // -1 -> no solutions
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C;
  cin >> A >> B >> C;
  int X = max({A, B, C});
  if (((A + B + C) ^ X) & 1) X++;
  cout << (3 * X - (A + B + C)) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 3644
n = int(input())
dat_n = list(map(int, input().split()))
dp = [0] * n
dp [0]
for i in range(1, n):
    if i > 1:
        dp[i] = min(dp[i - 1] + abs(dat_n[i] - dat_n[i-1]),dp[i - 2] + abs(dat_n[i] - dat_n[i-2]) )
    else:
        dp[i] = dp[i - 1] + abs(dat_n[i] - dat_n[i-1])
print(dp[n-1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define ll long long
int n,a[200005],b[200005];
ll k;
int check(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i)
		sum+=std::max((ll)0,a[i]-(ll)x/b[i]);
	return sum<=k;
}

int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)scanf("%d",&b[i]);
	std::sort(a+1,a+n+1);std::sort(b+1,b+n+1);std::reverse(b+1,b+n+1);
	ll l=0,r=1e17,ans;
	while (l<=r){
		ll mid=(l+r)>>1;
		if (check(mid)){ans=mid;r=mid-1;}
		else l=mid+1;
	}printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import defaultdict
from itertools import permutations
from bisect import bisect_left

input()
s = input()

d = defaultdict(list)

for idx, c in enumerate(s):
    d[c].append(idx)

ans = 0

for first, second, third in permutations("RGB"):
    for v1 in d[first]:
        for v2 in d[second]:

            if v2 < v1:
                continue

            ans += len(d[third]) - bisect_left(d[third], v2)
            dist = v2 - v1

            dist_idx_check = bisect_left(d[third], v2 + dist)

            if dist_idx_check < len(d[third]) and d[third][dist_idx_check] == v2 + dist:
                ans -= 1

print(ans)


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli n,m;
vll a;
vll b;
vll imos;
lli ans,y;

lli calc(lli x){
  lli ret = 0;
  for(lli i = 1;i < n;i++) ret += min((a[i]+m-a[i-1])%m,(a[i]+m-x)%m+1);
  return ret;
}

int main(){
  cin >> n >> m;
  a = vll(n);
  for(lli i = 0;i < n;i++) cin >> a[i];
  imos = vll(2*m+1);
  for(lli i = 1;i < n;i++){
    if(a[i] < a[i-1]){
      imos[a[i]+m]--;
      imos[a[i-1]]++;
    }else{
      imos[a[i]]--;
      imos[a[i-1]]++;
    }
  }
  for(lli i = 1;i <= 2*m;i++) imos[i] += imos[i-1];
  b = vll(m+1);
  for(lli i = 1;i < n;i++){
    b[a[i]] += (a[i]+m-a[i-1])%m;
  }
  // for(lli i = 1;i <= m;i++) cout << calc(i) << " " << imos[i]+imos[i+m] << endl;
  // cout << "-" << endl;
  ans = y = calc(1);
  // cout << y << endl;
  for(lli i = 1;i < m;i++){
    y = y-imos[i-1]-imos[i+m-1]+b[i];
    // cout << y << endl;
    ans = min(ans,y);
  }
  cout << ans << endl;
  return 0;


}


Measured memory_bytes: 3328
#include <iostream>
#define SIZE 44
using namespace std;

int F[SIZE];

int Fibonacci(int n)
{
    if (n == 1 || n == 0)
    {
        return F[n] = 1;
    }
    if (F[n])
    {
        return F[n];
    }
    return F[n] = Fibonacci(n - 1) + Fibonacci(n - 2);
}

int main()
{
    int n;
    cin >> n;
    cout << Fibonacci(n) << endl;

    return 0;
}



Measured memory_bytes: 3096