akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int	main()
{
  int		nb_min, nb_max, nb;
  int		count = 0;
  string	str, rev;
  
  cin >> nb_min >> nb_max;
  nb = nb_min;
  while (nb <= nb_max)
  {
    str = to_string(nb);
    rev = str;
    reverse(rev.begin(), rev.end());
    if (str == rev)
      count++;
    nb++;
  }
  cout << count << endl;
}

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

using namespace std;

void solve() {
  int A, B;
  cin >> A >> B;
  unordered_set<int> ans{1,2,3};
  ans.erase(A);
  ans.erase(B);
  cout << *ans.begin() << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int64_t N,S,T;
  cin >> N >> S >> T;
  vector<int64_t> X(N),W(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i) >> W.at(i);
  }
  int64_t y=0,x;
  if(W.at(0)==1){
    for(int i=1;i<N;i++){
      if(W.at(i)==2){
        if((2*T)%S<X.at(i)-X.at(0)){
          y+=(2*T)/S;
        }else{
          y+=(2*T)/S+1;
        }
      }
    }
    y%=N;
    x=(X.at(0)+T)%S;
  }else{
    for(int i=1;i<N;i++){
      if(W.at(i)==1){
        if((2*T)%S<X.at(0)-X.at(i)+S){
          y+=(2*T)/S;
        }else{
          y+=(2*T)/S+1;
        }
      }
    }
    y%=N;
    y=N-y;
    if(y>N) y-=N;
    x = (X.at(0)-T)%S;
      if(x<0){
          x+=S;
        }
  }
  
  int64_t z;
  vector<int64_t> A(N);
  for(int i=0;i<N;i++){
    if(W.at(i)==1){
      A.at(i)=(X.at(i)+T)%S;
    }else{
      z = (X.at(i)-T)%S;
      if(z<0){
          z+=S;
        }
      A.at(i)=z;
    }
  }
  sort(A.begin(), A.end());
  for(int i=0;i<N;i++){
    if(A.at(i)==x){
      if(i==N-1){
        y=(N+i-y)%N;
        break;
      }
      if(A.at(i+1)!=x){
        y=(N+i-y)%N;
        break;
      }else{
        if(W.at(0)==1){
          y=(N+i+1-y)%N;
          break;
        }else{
          y=(N+i-y)%N;
          break;
        }
      }
    }
  }
  for(int i=y;i<N+y;i++){
    cout << A.at(i%N) << endl;
  }
}
    

Measured memory_bytes: 3584
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String query = sc.next();
        String target;
        int count = 0;
        while (sc.hasNext()) {
            target = sc.next().toLowerCase();
            if (target.equals("END_OF_TEXT")) break;
            if (target.equals(query)) count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26100
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 20
char pat[LEN+1];
char str[10][LEN+1];
int lp, count;
int check(char *s, int k){
    int i,j;
    char w[LEN+1]; strcpy(w,s);
    for(i=1; i<=25; i++){
        for(j=0; j<k; j++){
            if(w[j] == 'z'+1) return 0;
            if(w[j] == 'a'+i){
                w[j]--;
                break;
            }
        }
    }
    for(j=0; j<k; j++)
        if(w[j] != pat[j]) return 0;
    return 1;
}
void search(char *s, int d){
    int ret;
    ret=check(s,d);
    if(ret==0) return;
    if(s[d]=='\0'){
        if(count<10){
            strcpy(str[count],s);
        }
        else{
            strcpy(str[lp++],s);
            if(lp>=10) lp=5;
        }
        count++;
    }
    else{
        search(s,d+1);
        if(s[d]!='z'){
            s[d]++;
            search(s,d+1);
            s[d]--;
        }
    }
}
int main(void){
    int i,j,k;
    char work[LEN+1];
    while(1){
        scanf("%s",pat);
        if(strcmp(pat,"#")==0) break;
        count=0;
        lp=5;
        strcpy(work,pat);
        search(work,0);
        printf("%d\n",count);
        if(count<=10)
            for(i=0;i<count;i++)
                printf("%s\n",str[i]);
        else{
            for(i=0;i<5;i++)
                printf("%s\n",str[i]);
            for(i=0;i<5;i++){
                printf("%s\n",str[lp++]);
                if(lp>=10) lp=5;
            }
        }
    }
    return 0;
}



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

int main() {
	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  
  	string s; cin>>s;
  	cout << (s == "AAA" || s == "BBB" ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
# kleene Inversion

n, k = map(int, input().split())
a = list(map(int, input().split()))
_mod = 10**9+7

ca = 0
cb = 0

for i in range(0, n):
    for j in range(i, n):
        if a[i] > a[j]:
            ca += 1
    for l in range(0, n):
        if a[i] > a[l]:
            cb += 1

count = ca * k + cb * (k*(k-1))//2
print(count % _mod)


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

int main()
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    int* sequence = new int[n];
    for (int i=0; i<n; i++)
    {
      cin >> sequence[i];
    }
    int* result_sequence = new int[n];
    int result_num = 0;

    while (true)
    {
      for (int i=0; i<n; i++)
      {
        result_sequence[i] = 0;
      }
      for (int i=0; i<n; i++)   //  出現頻度操作
      {
        for (int j=0; j<n; j++)
        {
          if ( sequence[i] == sequence[j] )
          {
            result_sequence[i]++;
          }
        }
      }
      result_num++;

      bool flag = true;
      for (int i=0; i<n && flag; i++)
      {
        if ( sequence[i] != result_sequence[i] )
        {
          flag = false;
        }
      }
      if ( flag )   //不動点になっていれば
      {
        break;
      }
      else
      {
        for (int i=0; i<n; i++)
        {
          sequence[i] = result_sequence[i];
        }
      }
    }

    cout << result_num-1 << endl;
    for (int i=0; i<n; i++)
    {
      cout << result_sequence[i] << flush;
      if ( i == n-1 )
      {
        cout << endl;
      }
      else
      {
        cout << ' ' << flush;
      }
    }

    delete[] result_sequence;
    delete[] sequence;
  } //  データセット毎
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ban[100][10];;
ll rui[100][10];
ll kazu[6];
ll i,j,h;
ll ans,bans;
string S;
bool solve(){
	cin >> h;
	if(h == 0)return false;
	ans = 0;
	bans = 0;
	h += 5;
	for(i=5;i<h;i++){
		for(j=0;j<5;j++){
			cin >> ban[i][j];
		}
	}
	for(i=h;i<=h+10;i++){
		for(j=0;j<5;j++){
			ban[i][j] = 0;
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			ban[i][j] = 0;
		}
	}
	bool flag = false;
	while(1){
		//cout << "-----" << endl;
		for(i=0;i<h;i++){
			for(j=0;j<5;j++){
				//cout << ban[i][j] << " ";
			}
			//cout << endl;
		}

		//cout << "-----" << endl;
		for(i=h-1;i>=0;i--){
			if(ban[i][0] == ban[i][1] && ban[i][1] == ban[i][2] && ban[i][0] != 0){
				if(ban[i][0] == ban[i][3]){
					if(ban[i][0] == ban[i][4]){
						ans += ban[i][0] + ban[i][1] + ban[i][2] + ban[i][3] + ban[i][4];
						ban[i][0] = 0;
						ban[i][1] = 0;
						ban[i][2] = 0;
						ban[i][3] = 0;
						ban[i][4] = 0;
					}else{

						ans += ban[i][0] + ban[i][1] + ban[i][2] + ban[i][3];
						ban[i][0] = 0;
						ban[i][1] = 0;
						ban[i][2] = 0;
						ban[i][3] = 0;
					}
				}else{
					ans += ban[i][0] + ban[i][1] + ban[i][2];
					ban[i][0] = 0;
					ban[i][1] = 0;
					ban[i][2] = 0;
				}
			}else if(ban[i][1] == ban[i][2] && ban[i][2] == ban[i][3] && ban[i][1] != 0){
				if(ban[i][1] == ban[i][4]){

					ans += ban[i][1] + ban[i][2] + ban[i][3] + ban[i][4];
					ban[i][1] = 0;
					ban[i][2] = 0;
					ban[i][3] = 0;
					ban[i][4] = 0;
				}else{

					ans += ban[i][1] + ban[i][2] + ban[i][3];
					ban[i][1] = 0;
					ban[i][2] = 0;
					ban[i][3] = 0;
				}	
			}else if(ban[i][2] == ban[i][3] && ban[i][3] == ban[i][4] && ban[i][2] != 0){

				ans += ban[i][2] + ban[i][3] + ban[i][4];
				ban[i][2] = 0;
				ban[i][3] = 0;
				ban[i][4] = 0;
			}
		}
		if(bans == ans)break;
		for(int num = 0; num <= 15; num ++){
		for(i=h-1;i>=1;i--){
			for(j=0;j<5;j++){
				if(ban[i][j] == 0){
					swap(ban[i][j],ban[i-1][j]);
				}
			}
		}}
		bans = ans;
	}
	cout << ans << endl;
	return true;
}

int main(){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 3148
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>


using namespace std;


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>=b && c>=d)
    cout<<b+d;
    else if(a>=b && c<d)
    cout<<b+c;
    else if(a<b && c>=d)
    cout<<a+d;
    else if(a<b && c<d)
    cout<<a+c;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z;
    cin>>x>>y>>z;
    int temp=x;
    x=y;
    y=temp;
    temp=x;
    x=z;
    z=temp;
    cout << x << " "<< y <<" " << z << endl;
    return 0;
}


Measured memory_bytes: 3556
//
//  main.cpp
//  AOJ0558
//
//  Created by aki33524 on 2014/04/22.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;

typedef pair<int, int> pii;
int H, W, N;
char fields[1001][1001];

int dh[] = {0, 0, 1, -1};
int dw[] = {1, -1, 0, 0};
pii cheese[10];

const int INF = 100000000;

int bfs(int sh, int sw, int gh, int gw){
    int d[H][W];
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            d[i][j] = INF;
    queue<pii> que;
    que.push(make_pair(sh, sw));
    d[sh][sw] = 0;
    
    while(!que.empty()){
        pii p = que.front();
        que.pop();
        
        for(int i=0; i<4; i++){
            int nh = p.first + dh[i];
            int nw = p.second + dw[i];
            if(0<=nh && nh<H && 0<=nw && nw<W && fields[nh][nw] != 'X' && d[nh][nw] == INF){
                que.push(make_pair(nh, nw));
                d[nh][nw] = d[p.first][p.second] + 1;
            }
            if(nh == gh && nw == gw)
                return d[nh][nw];
            
        }
    }
    return -1;
}

int main(int argc, const char * argv[])
{
    cin >> H >> W >> N;
    
    for(int i=0; i<H; i++)
        cin >> fields[i];
    
    for(int i=0; i<=N; i++){
        if(i==0){
            for(int j=0; j<H; j++)
                for(int k=0; k<W; k++)
                    if(fields[j][k] == 'S')
                        cheese[i] = make_pair(j, k);
        }else{
            for(int j=0; j<H; j++)
                for(int k=0; k<W; k++)
                    if(fields[j][k] == '0'+i)
                        cheese[i] = make_pair(j, k);
        }
    }
    
    int ans = 0;
    for(int i=0; i<N; i++){
        pii s = cheese[i];
        pii g = cheese[i+1];
        ans += bfs(s.first, s.second, g.first, g.second);
    }
    
    cout << ans << endl;
    
    return 0;
}

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

struct UnionFind {
	vector<ll> d;
	UnionFind(int n): d(n, -1){};

	// find
	ll find(int x) {
		if (d[x] < 0) return x;

		return d[x] = find(d[x]);
	}	

	int unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return false;
		}

		if (d[x] > d[y]) {
			swap(x, y);
		}

		d[x] += d[y];
		d[y] = x;

		return true;
	}

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

	// size
	ll size(int x) {
		return abs(d[find(x)]);
	}





};

int main() {

	int N, M;

	cin >> N >> M;

	vector<int> A(M);
	vector<int> B(M);
	for (int i =0;i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		A[i] = a;
		B[i] = b;
	}

	vector<ll> ans(M);
	ans[M-1] = (ll)N * (N-1) / 2;
	
	UnionFind uf = UnionFind(N);
	for (int i = M-1; i >=1; i--) {
		int a, b;
		a = A[i];
		b = B[i];

		ans[i-1] = ans[i];
		// 同じグループであれば無視
		if (uf.find(a) != uf.find(b)) { 
			ans[i-1] -= (ll)uf.size(a) * uf.size(b);
		}
		uf.unite(a, b);
	}

	for (int i =0; i < M; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int a, sum, b[6] = { 1,5,10,50,100,500 };

int main() {
	for (int i = 0;i < 6;i++) {
		cin >> a;
		sum += a * b[i];
	}
	if (sum >= 1000)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int main()
{
    long long a, b, l;
    cin>> a>> b;
    long long n1, n2, rem;
    n1=a, n2=b;
    while(n2!=0)
    {
        rem= n1%n2;
        n1=n2;
        n2=rem;
    }
    l=a*b/n1;

    cout<< l <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;
int main()
{
	int n, d;
    string a, b, c, s;
  	cin >> a >> b;
	c = a+b;
  	n = stoi(c);
  	d = sqrt(n);
	if (d*d == n){
      	cout << "Yes" << endl;
    }else {
  		cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    char c;  cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}

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

int main() {
	cin.tie(nullptr); ios_base::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	atcoder::dsu uf(n);
	for (int i = 0; i < q; ++i) {
		int t, u, v; cin >> t >> u >> v;
		if (t == 0) uf.merge(u, v);
		else if (uf.same(u, v)) printf("1\n");
		else printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 3976
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(a,b,c,d) REP(a,0,b)REP(c,0,d)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
#define N 1000

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<vector<int>> Matrix;

int main() {

    int a,b,c;
    cin>>a>>b>>c;
    
    if(c>=min(a,b) && c<=max(a,b)) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include  <iostream>

using namespace std;

typedef long long ll;

int main()
{
	ll s;
	cin >> s;
	
	ll k = static_cast <ll> (1e9);
	ll x0 = 0;
	ll y0 = 0;
	ll x1 = k;
	ll y1 = 1;
	ll x2;
	ll y2;
	if (s != k * k) {
		y2 = s / k + 1;
		x2 = k - (s % k);
	}
	else {
		x2 = 0;
		y2 = k;
		y1 = 0;
	}
	cout << x0 << ' ' << y0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
}

Measured memory_bytes: 256
k = int(input())
power = 0
cnt = 1
if k == 1 or k == 7:
  print(1)
elif k%2 == 0 or k%5 == 0:
  print(-1)
elif k%7 == 0:
  l = 9*k/7
  a = 1
  while(True):
    a = (10*a)%l
    if a == 1:
      break
    cnt+= 1
  print(cnt)
else:
  a = 1
  l = 9*k
  while(True):
    a = (10*a)%l
    if a == 1:
      break
    cnt+=1
  print(cnt)

Measured memory_bytes: 63972
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, K;
  cin >> N >> K;
  i64 ans = 0, i;
  REP(0, N, i) {
    i64 h;
    cin >> h;
    if(h >= K) {
      ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repx(i,a,b,x) for(ll i=a;i<b;i+=x)
#define rev(i,a,b) for(ll i=a;i>b;i--)
#define revx(i,a,b,x) for(ll i=a;i>b;i-=x)
#define arep(it,v) for(auto it=v.begin();it!=v.end();it++)
#define wh1(n) rep(xy1,0,n)
#define wh2(n) rep(xy2,0,n)
#define wh3(n) rep(xy3,0,n)
#define sc(i) cin>>i
#define ssc(i,j) sc(i);sc(j)
#define sssc(i,j,k) ssc(i,j);sc(k)
#define pf(i) cout<<i<<" "
#define pfn(i) cout<<i<<endl
#define cvec(v,n) rep(abc,0,n){ll xyz;sc(xyz);v.pb(xyz);}
#define pvec(v,n) rep(abc,0,n){pf(v[abc].F);pf(v[abc].S);}pfn("")
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define spll set<pll>
#define vpll vector<pll>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define pq(a) priority_queue<a>
#define pqc(a,cmp) priority_queue<a,vector<a>,cmp>
#define F first
#define S second
#define B begin
#define E end
#define R return
#define mp make_pair
#define pb push_back
#define ln length()
#define to_s to_string
#define Sort(v) sort(v.begin(),v.end())
#define Scmp(v,cmp) sort(v.begin(),v.end(),cmp)
#define zero_arr(v) memset(v,0,sizeof(v))
#define update_map(m,i) if(m.find(i)!=m.end()){m[i]++;}else{m[i]=1;}
#define update_mapx(m,i,x) if(m.find(i)!=m.end()){m[i]+=x;}else{m[i]=x;}
#define M 1000000007
#define INF 2000000000
#define fast ios::sync_with_stdio(0); cin.tie(0)
int main(){
    fast;
    ll n;
    string s;
    ssc(n,s);
    stack<char> stack1;
    rep(i,0,n){
        if(stack1.size()){
            if(stack1.top()=='('&&s[i]==')'){
                stack1.pop();
            }else{
                stack1.push(s[i]);
            }
        } else{
            stack1.push(s[i]);
        }
    }
    while(stack1.size()){
        if(stack1.top()=='('){
            s+=')';
        }else{
            s='('+s;
        }
        stack1.pop();
    }
    pfn(s);
    R 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N;
int main(){
    LL ans=0;
    LL n,m=1; 
    cin>>N;
    for(int i=0;i<N;i++){
        int t,a;
        cin>>t>>a;
        n=(n-1)/t*t+t;
        if(n/t*a>=m){
            m=n/t*a;
        }else{
            m=(m-1)/a*a+a;
            n=m/a*t;
        }

    }
    cout<<n+m;


        
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int x;
  int ans;
  cin>>x;
  for(int i=1;i<=9;i++){
    if(i*111>=x){
       ans=i*111;
      break;
    }
  }
  cout<<ans<<endl;
}


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

const int MAX = 2100;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int S, k;
    cin >> S;
    k = S / 3;

    COMinit();

    long int ans = 0;

    for (int i = k; 0 < i; i--){
        int num = S - 3 * i;
        ans = (ans + COM(num + i - 1, i - 1)) % MOD;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

int main(){
  int N;
  while(cin >> N){
    vector<int> d(N); cin >> d;

    LLI ans = 0;

    REP(i,N){
      REP(j,N){
        if(i < j) ans += d[i] * d[j];
      }
    }


    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

int dp[3030][6060];
int N, T;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> T;
    vector<pair<int,int>> A(N);
    REP(i,N){
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(), A.end());

    REP(i,N){
        for(int j=0;j<3030;j++){
            if(j < T) chmax(dp[i+1][j+A[i].first], dp[i][j]+A[i].second);
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    int ans = 0;
    REP(i,N+1) REP(j,6060) chmax(ans, dp[i][j]);
    
    cout << ans << endl;
}

Measured memory_bytes: 71296
import sys

patterns = ( 'S', 'H', 'C', 'D' )
n = int( sys.stdin.readline() )
cards = { pattern:[False]*13 for pattern in patterns }
for i in range( n ):
	pattern, num = sys.stdin.readline().split( " " )
	cards[ pattern ][ int( num )-1 ] = True

for pattern in patterns:
	for i in range( 13 ):
		if not cards[ pattern ][ i ]:
			print( "{:s} {:d}".format( pattern, i+1 ) )

Measured memory_bytes: 4224
n = gets.chomp.to_i
h = gets.chomp.split(' ').map{ |e| e.to_i }

dp = [0, (h[0] - h[1]).abs]

(n - 2).times{|ii|
  i = ii + 2
  cand1 = dp[1] + (h[i - 1] - h[i]).abs
  cand2 = dp[0] + (h[i - 2] - h[i]).abs
  dp[0] = dp[1]
  dp[1] = cand1 < cand2 ? cand1 : cand2
}
puts dp[1]


Measured memory_bytes: 8452
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#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 rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    cout << ((N % 2 == 0 && (S.substr(0, N / 2) == S.substr(N / 2, N / 2)))
                 ? "Yes"
                 : "No")
         << endl;
}


Measured memory_bytes: 3572
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll dp[2][20][1 << 19];
int to[1 << 19][19];
int d[20][20];
int main()
{
	int num, kai, res;
	scanf("%d%d%d", &num, &kai, &res);
	for (int i = 0; i < res; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		if (zc == 0)d[za][zb] = -1;
		else d[za][zb] = 1;
	}
	num--;
	for (int p = 0; p < (1 << num); p++)
	{
		for (int i = 0; i < num; i++)
		{
			if (p&(1 << i))continue;
			int t = -1;
			for (int j = i + 1; j < num; j++)
			{
				if (p&(1 << j))
				{
					t = j;
					break;
				}
			}
			if (t == -1)to[p][i] = p + (1 << i);
			else to[p][i] = p + (1 << i) - (1 << t);
			//printf("%d %d %d\n", p, i, to[p][i]);
		}
	}
	dp[0][num][0] = 1;
	int cur = 0;
	for (int i = 0; i < kai; i++)
	{
		for (int j = 0; j < (1 << num); j++)dp[1 - cur][0][j] = dp[cur][num][j];
		for (int j = 0; j <= num; j++)for (int k = 0; k < (1 << num); k++)dp[cur][j][k] = 0;
		cur = 1 - cur;
		for (int j = 0; j < num; j++)
		{
			for (int k = 0; k < (1 << num); k++)
			{
				dp[cur][j + 1][k] += dp[cur][j][k];
				if (dp[cur][j + 1][k] >= mod)dp[cur][j + 1][k] -= mod;
				if ((k&(1 << j)) == 0)
				{
					dp[cur][j + 1][to[k][j]] += dp[cur][j][k];
					if (dp[cur][j + 1][to[k][j]] >= mod)dp[cur][j + 1][to[k][j]] -= mod;
				}
			}
		}
		for (int j = 0; j < num; j++)
		{
			for (int k = 0; k < (1 << num); k++)
			{
				if (d[i][j] == -1 && (k&(1 << j)) != 0)dp[cur][num][k] = 0;
				if (d[i][j] == 1 && (k&(1 << j)) == 0)dp[cur][num][k] = 0;
			}
		}
		//for (int j = 0; j < (1 << num); j++)printf("%lld ", dp[cur][num][j]); printf("\n");
	}
	ll ans = 0;
	for (int i = 0; i < (1 << num); i++)ans = (ans + dp[cur][num][i]) % mod;
	printf("%lld\n", ans);
}

Measured memory_bytes: 203008
def main():
    N,W = map(int, input().split())
    dp = [[0]*(W+1) for i in range(N+1)]
    weight = [0]
    value = [0]
    for i in range(N):
        w,v=map(int, input().split())
        weight.append(w)
        value.append(v)

    # dp[i][w] is the maximum value got with first i items stored in w weight of knapsack
    for i in range(1,N+1):
        for w in range(1,W+1):
            if w>=weight[i]:
                dp[i][w] = max(dp[i-1][w],dp[i-1][w-weight[i]]+value[i])
            else:
                dp[i][w] = dp[i-1][w]
    print(dp[N][W])





if __name__ == "__main__":
    main()

Measured memory_bytes: 118512
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    h = LI()[::-1]
    ans = 0
    i = 0
    while i < n:
        j = i+1
        while j < n and h[j] >= h[j-1]:
            j += 1
        m = j-i-1
        if ans < m:
            ans = m
        i = j
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 59632
# -*- coding: utf-8 -*-
import sys

N, *A = map(int, sys.stdin.buffer.read().split())

def tree(A,N):
  m = [A[i] for i in range(N+1)]
  M = [A[i] for i in range(N+1)]
  for i in range(N-1,-1,-1):
    m[i] += m[i+1]//2+m[i+1]%2
    M[i] += M[i+1]
  if m[0]>1 or M[0]==0:
    return -1
  count = 1
  vertex = 1
  for i in range(1,N+1):
    vertex = min(2*(vertex-A[i-1]), M[i])
    count += vertex
  return count
      
print(tree(A,N))

Measured memory_bytes: 22332
s = input()
t = input()

s_num = len(s)
t_num = len(t)

ans_list = []
ind_list = []

if s_num<t_num:
    ans_list.append('UNRESTORABLE')
else:
    for i in range(s_num -t_num + 1):
        flg = True
        for j in range(t_num):
            if s[i+j] == '?':
                pass
            elif s[i+j]==t[j]:
                pass
            else:
                flg=False
                break
        if flg:
            ind_list.append(i)
if len(ind_list) ==0:
    ans_list.append('UNRESTORABLE')
else:
    for i in ind_list:
        ans = ''
        j=0
        while j <s_num:
            if j==i:
               ans = ans+t
               j = j + t_num
            elif s[j] == '?':
                ans = ans + 'a'
                j = j + 1
            else:
                ans = ans + s[j]
                j = j + 1
        ans_list.append(ans)

print(min(ans_list))

Measured memory_bytes: 63376
#include <stdio.h>
   
   int main(void) {
   
     int a, b, c;
   
     scanf("%d%d%d", &a, &b, &c);
   
     if (((a == 7) && (b == 5) && (c == 5)) || ((a == 5) && (b == 7) && (c == 5)) || ((a == 5) && (b == 5) && (c == 7)))
        printf("YES\n");
   else
      printf("NO\n");
  
    return 0;
  }


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <deque>
#include <set>
using namespace std;

int main()
{
	int H, W, M;
	cin >> H >> W >> M;
	vector<pair<int, int>>point;
	set<long long>pointPos;

	vector<int>h(H);
	vector<int>w(W);
	for (int i = 0; i < M; i++) {
		int x = 0;
		int y = 0;
		cin >> y >> x;
		x--;
		y--;
		point.push_back({ x,y });
		pointPos.insert(x*(long long)H + y);
		w[x]++;
		h[y]++;
	}

	int ymax = 0;
	vector<int>ypos;
	int xmax = 0;
	vector<int>xpos;

	for (int i = 0; i < H; i++) {
		if (ymax == h[i]) {
			ypos.push_back(i);

		}
		if (ymax < h[i]) {
			ypos.clear();
			ypos.push_back(i);
			ymax = h[i];
		}
	}
	for (int i = 0; i < W; i++) {
		if (xmax == w[i]) {
			xpos.push_back(i);
		}
		if (xmax < w[i]) {
			xpos.clear();
			xpos.push_back(i);
			xmax = w[i];

		}
	}
	int a = 0;
	if (xpos.size()*ypos.size() <= M) {
		for (int x = 0; x < xpos.size(); x++) {
			for (int y = 0; y < ypos.size(); y++) {
				long long  b = xpos[x] * (long long )H +ypos[y];
				if (pointPos.erase(b) == 1) {
					a++;
				}
			}
		}
	}
	if (a == (xpos.size()*ypos.size())) {
		cout << xmax + ymax - 1;

	}
	else {
		cout << xmax + ymax;

	}
	return 0;


}

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

using namespace std;

int dp[100001];
int h[100001];

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

    int n;
    cin>> n;

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

    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    //int res = 0;

    for(int i = 2; i<n; i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        //res+=dp[i];
    }

    cout<< dp[n-1];


    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
const int INF = (1e9);

int prim(vector< vector< pair<int,int> > > &G){
  vector<bool> connected(G.size(),false);
  priority_queue< pair<int,int> > wait;
  wait.emplace(0,0);
  int ret = 0;
  while(!wait.empty()){
    int c = -wait.top().first, v = wait.top().second;
    wait.pop();
    if(connected[v]) continue;
    connected[v] = true;
    ret += c;
    for(size_t i = 0; i < G[v].size(); ++i){
      int c_ = G[v][i].first, v_ = G[v][i].second;
      if(!connected[v_]){
        connected[v] = true;
        wait.emplace(-c_,v_);
      }
    }
  }
  return ret;
}

int main(){
  int V, E;
  cin >> V >> E;
  vector< vector< pair<int,int> > > G(V);
  for(int i = 0; i < E; ++i){
    int s, t, d;
    cin >> s >> t >> d;
    G[s].emplace_back(d,t);
    G[t].emplace_back(d,s);
  }
  cout << prim(G) << endl;
  return 0;
}



Measured memory_bytes: 6828
#include<iostream>
#include<cstring>
#include<climits>
using namespace std;
int n,m;
int a[100005],b[100005],c[100005],d[3][100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
	for(int i=1;i<=n;i++){
		d[1][i]=max(d[2][i-1]+b[i],d[3][i-1]+c[i]);
		d[2][i]=max(d[1][i-1]+a[i],d[3][i-1]+c[i]);
		d[3][i]=max(d[1][i-1]+a[i],d[2][i-1]+b[i]);
	}
	cout<<max(d[1][n],max(d[2][n],d[3][n]));
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int D[7][7]={{},
{0,0,4,2,5,3,0},
{0,3,0,6,1,0,4},
{0,5,1,0,0,6,2},
{0,2,6,0,0,1,5},
{0,4,0,1,6,0,3},
{0,0,3,5,2,4,0}};

int G[7],N,i,t,f;
 
int sc(int d)
{
	int i;
	for(i=1;i<=6;i++)
		if(G[i]==d)
			return i;
}

int main()
{
	for(i=1;i<7;i++)scanf("%d",G+i);
	scanf("%d",&N);
	for(;N--;)
	{
		scanf("%d%d",&t,&f);
		printf("%d\n",G[D[sc(f)][sc(t)]]);
	}
	return 0;
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define all(con) (con).begin(),(con).end()
#define zoro ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+5;
const int mod=1e9+7;
void solve();
signed main(){
    zoro;
    int tests=1;
    // cin>>tests;
    while(tests--){
        solve();
    }
return 0;
}
void solve(){
    string s;cin>>s;
	for(char ch:s){
		if(ch=='7'){
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;
}



Measured memory_bytes: 3656
/*
  Author : lifehappy
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define endl '\n'
#define mid (l + r >> 1)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define ls rt << 1
#define rs rt << 1 | 1

using namespace std;

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

const double pi = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;

inline ll read() {
    ll f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-')    f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return f * x;
}

const int N = 1e6 + 10, mod = 998244353;

ll sum[N], c[N], n, m, all;

bool st[N];

int prime[N], mu[N], cnt;

ll quick_pow(ll a, ll n, ll mod) {
    ll ans = 1;
    while(n) {
        if(n & 1) ans = ans * a % mod;
        n >>= 1;
        a = a * a % mod;
    }
    return ans;
}

void init() {
    mu[1] = 1;
    for(int i = 2; i < N; i++) {
        if(!st[i]) {
            prime[cnt++] = i;
            mu[i] = -1;
        }
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
            mu[i * prime[j]] = -mu[i];
        }
    }
    for(int i = 1; i < N; i++) {
        for(int j = i; j < N; j += i) {
            sum[j] = (sum[j] + i * mu[i] % mod + mod) % mod;
        }
    }
}

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    init();
    n = read(), m = 0;
    for(int i = 1; i <= n; i++) {
        ll x = read();
        all = (all + x) % mod;
        m = max(x, m);
        c[x]++;
    }
    ll ans = 0;
    for(ll t = 1; t <= m; t++) {
        ll res = 0;
        for(ll i = 1; i <= m / t; i++) {
            res = (res + 1ll * i * c[i * t] % mod) % mod;
        }
        ans = (ans + t * res % mod * res % mod * sum[t] % mod) % mod;
    }
    printf("%lld\n", ((ans - all) * quick_pow(2, mod - 2, mod) % mod + mod) % mod);
	return 0;
}

Measured memory_bytes: 24588
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define abs(a) (a<0?-1*a:a)

int main()
{
    int N;
    scanf("%d", &N);
    int *W = (int *)malloc(sizeof(int)*N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &W[i]);
    }
    int left = 0, right = 0;
    int le = 0, ri = N-1;
    while(1)
    {
        if(left > right)
        {
            right += W[ri];
            ri--;
        }
        else
        {
            left += W[le];
            le++;
        }
        if(ri < le) break;
    }
    printf("%d\n", abs((left-right)));
}

Measured memory_bytes: 128
N=gets.to_i
a=gets.split.map(&:to_i)
min,max=a.minmax
r=[]
if min<0 && max>0
    if min.abs<=max
        i=a.index(max)+1
        (1 .. N).each{|n|
            r << [i, n]
        }
        min+=max
    else
        i=a.index(min)+1
        (1 .. N).each{|n|
            r << [i, n]
        }
        max+=min
    end
end
if min>=0
    (1 .. N-1).each{|n|
        r << [n, n+1]
    }
elsif max<=0
    (2 .. N).reverse_each{|n|
        r << [n, n-1]
    }
end
puts r.size
r.each{|i|
    puts i*" "
}


Measured memory_bytes: 14340
#include <iostream>
#include <algorithm>

double alch(double v[], int n);

int main() {
  int n;
  std::cin >> n;
  double v[n];
  for (int i {}; i < n; ++i) {
    std::cin >> v[i];
  }
  std::sort(v, v + n);
  std::cout << alch(v, n);
}

double alch(double v[], int n) {
  if (n == 2) {
    return (v[0] + v[1]) / 2;
  } else {
    return (alch(v, n - 1) + v[n - 1]) / 2;
  }
} 

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int mod = 998244353;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
const int maxN = (int)1e5 + 100;
ll t[4 * maxN];
const ll INF = (ll)1e18;
void build(int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = INF;
        return;
    }
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    t[v] = min(t[2 * v], t[2 * v + 1]);
}
ll get(int v, int tl, int tr, int l, int r) {
    if (l > r) return INF;
    if (tl == l && tr == r) return t[v];
    int tm = (tl + tr) / 2;
    return min(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}
void upd(int v, int tl, int tr, int pos, ll val) {
    if (tl == tr) {
        t[v] = min(val, t[v]);
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm) upd(2 * v, tl, tm, pos, val);
    else upd(2 * v + 1, tm + 1, tr, pos, val);
    t[v] = min(t[2 * v], t[2 * v + 1]);
}
int m;
int l[maxN], r[maxN], cost[maxN];
bool cmp(int i, int j) {
    return l[i] < l[j];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    vector < int > ind;
    for (int i = 1; i <= m; i++) {
        cin >> l[i] >> r[i] >> cost[i];
        ind.push_back(i);
    }
    sort(ind.begin(), ind.end(), cmp);
    build(1, 1, n);
    ll bst = INF;
    for (int v : ind) {
        if (l[v] == 1) {
            upd(1, 1, n, r[v], cost[v]);
            if (r[v] == n) bst = min(bst, (ll)cost[v]);
        }
        else {
            ll mn = get(1, 1, n, l[v], r[v]);
            if (mn == INF) continue;
            mn += cost[v];
            upd(1, 1, n, r[v], mn);
            if (r[v] == n) bst = min(bst, mn);
        }
    }
    if (bst > 1e17) {
        cout << -1;
    }
    else {
        cout << bst;
    }
    return 0;
}

Measured memory_bytes: 4856
import sys

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)
    
def lcm_array(arr):
    return reduce(lambda cur, x: lcm(cur, x), arr, arr[0])
    

    
if __name__ == '__main__':
    n = sys.stdin.readline()
    n = int(n)
    arr = sys.stdin.readline()
    arr = map(lambda x: int(x), arr.split())
    
    sys.stdout.write(str(lcm_array(arr)) + '\n')
        

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

#define all(a) (a).begin(), (a).end()

int main(){
   int a[5];

   int mm=0,sum=0;
   for (int i = 0; i < 5; ++i){
   	cin>>a[i];

   	if(a[i]%10!=0){
   		mm=max(mm,10-(a[i]%10));
   	}

   	if(a[i]%10==0){
   		sum+=a[i];
   	}else{
   		sum+=a[i]/10*10+10;
   	}

   }

   cout<<sum-mm<<endl;

}


Measured memory_bytes: 256
import sys
def primes(m):
    N = range(1,m+1,2)
    r = int(m**.5)
    h = len(N)
    N[0] = 0
    i=0
    while 1:
        x = N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x] = [0]*((h-1-i-x)/x+1)
        i += 1
    x = [2] + filter(None,N)
    return x

PRIMES = primes(50030)
for s in sys.stdin:
    n = int(s)
    for a in PRIMES:
        if a>n: break
        elif a<n: b = a
    print b,a

Measured memory_bytes: 5280
#include<stdio.h>
#define N 100

int main(){
  int i,j,n,u,v,k;
  int V[N][N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      V[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      V[u-1][v-1]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j){
	printf(" ");
      }
      printf("%d",V[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int n, q, op, x, y, res, p2[30], arb[2000002];
char ch;
string s;
int l, r, pos, val;
inline void Build(int node, int st, int dr) {
    if (st == dr) {
        arb[node] = p2[s[st-1] - 'a'];
        return;
    }
    int mid = (st + dr) / 2;
    Build(2 * node, st, mid);
    Build(2 * node + 1, mid + 1, dr);
    arb[node] = (arb[2 * node] | arb[2 * node + 1]);
}
inline void Update(int node, int st, int dr) {
    if (st == dr) {
        arb[node] = val;
        return;
    }
    int mid = (st + dr) / 2;
    if (pos <= mid)
        Update(2 * node, st, mid);
    else Update(2 * node + 1, mid + 1, dr);
    arb[node] = (arb[2 * node] | arb[2 * node + 1]);
}
inline int Query(int node, int st, int dr) {
    if (l <= st && dr <= r)
        return arb[node];
    int mid = (st + dr) / 2, r1(0), r2(0);
    if (l <= mid)
        r1 = Query(2 * node, st, mid);
    if (mid < r)
        r2 = Query(2 * node + 1, mid + 1, dr);
    return (r1 | r2);
}
int main() {
    DAU
    p2[0] = 1;
    for (int i = 1; i < 30; ++i)
        p2[i] = p2[i-1] * 2;
    cin >> n >> s >> q;
    Build(1, 1, n);
    for (int i = 1; i <= q; ++i) {
        cin >> op >> x;
        if (op == 1) {
            cin >> ch;
            pos = x, val = p2[ch - 'a'];
            Update(1, 1, n);
        }
        else {
            cin >> y;
            l = x, r = y;
            cout << __builtin_popcount(Query(1, 1, n)) << '\n';
        }
    }
    PLEC
}

Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int k,x;
    cin>>k>>x;
    if(k==x){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) std::cout << (x) << std::endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int cnt[10][10];
    REP(i, 10) {
        REP(j, 10) {
            cnt[i][j] = 0;
        }
    }
    REP(i, n + 1) {
        int tmp = i;
        int first, last;
        first = tmp % 10;
        last = tmp % 10;
        tmp /= 10;
        while (tmp > 0) {
            first = tmp % 10;
            tmp /= 10;
        }
        if (first == 0)
            continue;
        cnt[first][last]++;
    }
    int ans = 0;
    REP(i, 10) {
        REP(j, 10) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    OUT(ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  vector<llong> a(n), b(n), c(n);
  REP(i,n){
    cin >> a[i] >> b[i] >> c[i];
  }

  llong dp[100100][3];
  REP(i,100100){
    REP(j,3)
      dp[i][j] = 1 << 31;
  }

  dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0;

  REP(i,n){
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i];
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + b[i];
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c[i];

  }

  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
  return 0;
}



Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  int x, y;
  cin >> x >> y;
  int result = 0;
  if (x <= 3) result += (4 - x) * 100 * 1000;
  if (y <= 3) result += (4 - y) * 100 * 1000;
  if (x == 1 && y == 1) result += 400 * 1000;
  cout << result << endl;
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
// #define MOD 1000000007
#define MOD 998244353
#define VL vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<ll> dx8 = {-1, -1, -1,  0, 0,  1, 1, 1};
vector<ll> dy8 = {-1,  0,  1, -1, 1, -1, 0, 1};

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 A, B;
	cin >> A >> B;

	vector<vector<bool>> mat(100, vector<bool>(100, 0));
	REP(i, 50) {
		REP(j, 100) {
			mat[i][j] = true;
		}
	}
	ll cntA = 1;
	ll cntB = 1;
	if (cntA != A) {
		REP(i, 50-1) {
			REP(j, 100) {
				bool flag = true;
				REP(k, 8) {
					ll x = i + dx8[k];
					ll y = j + dy8[k];
					if (0 <= x && x < 50-1 && 0 <= y && y < 100) {
						flag &= mat[x][y];
					}
				}
				if(flag) {
					mat[i][j] = false;
					cntA ++;
				}
				if (cntA == A) {
					i = 100;
					j = 100;
				}
			}
		}
	}
	if (cntB != B) {
		FOR(i, 51, 100) {
			REP(j, 100) {
				bool flag = true;
				REP(k, 8) {
					ll x = i + dx8[k];
					ll y = j + dy8[k];
					if (51 <= x && x < 100 && 0 <= y && y < 100) {
						flag &= !mat[x][y];
					}
				}
				if(flag) {
					mat[i][j] = true;
					cntB ++;
				}
				if (cntB == B) {
					i = 100;
					j = 100;
				}
			}
		}
	}
	PRINT(100 << " " << 100);
	REP(i, 100) {
		REP(j, 100) {
			if (mat[i][j]) cout << "#";
			else cout << ".";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main
import . "fmt"
import . "strconv"
func main() {
  var a,b,s int
  var n string
  Scan(&a,&b)
  s = 0
  for i:=a;i<b+1;i++ {
    n = Itoa(i)
    if n[0:1] == n[4:5] && n[1:2] == n[3:4] { s++ }
  }
  Println(s)
}

Measured memory_bytes: 1024