akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

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

  int R, S, P;
  cin >> R >> S >> P;

  string T;
  cin >> T;

  auto to_score = [=](char c)
  {
    if (c == 'r') return P;
    if (c == 's') return R;
    return S;
  };

  vector<bool> skipped(N, false);
  int score = 0;
  rep(i,0,N-1)
  {
    if (i < K)
      score += to_score(T[i]);
    else
    {
      if (T[i] == T[i-K] && !skipped[i-K])
        skipped[i] = true;
      else
        score += to_score(T[i]);
    }
  }

  cout << score << endl;
  return 0;
}


Measured memory_bytes: 3776
import sys
imput = sys.stdin.readline
def main():
    # input
    str_s = input()
    str_t = input()
    s_len = len(str_s)
    t_len = len(str_t)

    # loop
    dp = [[0]*(t_len+1) for _ in range((s_len+1))]
    for i, s in enumerate(str_s):
        for j, t in enumerate(str_t):
            if s==t:
                dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

    # restore
    ans = ""
    while True:
        if i<0 or j<0:
            break
        elif str_s[i]==str_t[j]:
            ans = str_s[i] + ans
            i -= 1
            j -= 1
        elif dp[i+1][j+1] == dp[i][j+1]:
            i -= 1
        elif dp[i+1][j+1] == dp[i+1][j]:
            j -= 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 111964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int K = int.Parse(str[1]);
            int[] D = new int[K];
            str = Console.ReadLine().Split(' ');
            for(int i = 0;i<K;i++)
            {
                D[i] = int.Parse(str[i]);
            }
            int count = 0;
            int kotae = 0;
            while(true)
            {
                int kotaekamo = N + count;
                count++;
                bool hukumareru = kakuKetaNiSiteisitaSuziHukumareru(D, kotaekamo);
                if(!hukumareru)
                {
                    kotae = kotaekamo;
                    break;
                }
            }
            Console.WriteLine(kotae);
            //return;
        }

        static bool kakuKetaNiSiteisitaSuziHukumareru(int[] D,int x)
        {
            int[] nbunkatu = XwoKakuketaNiBunkai(x);
            for(int i = 0;i<nbunkatu.Length;i++)
            {
                for(int j = 0;j<D.Length;j++)
                {
                    if(nbunkatu[i] == D[j])
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        static int[] XwoKakuketaNiBunkai(int X)
        {
            int syou = X;
            int amari = 0;
            int[] kotae = new int[X.ToString().Length];
            int count = 0;
            do
            {
                amari = syou % 10;
                syou = syou / 10;
                
                kotae[count] = amari;
                count++;
            }
            while (syou > 0);
            return kotae;
        }
    }
}

Measured memory_bytes: 15184
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

ll memo[200][201][201];
ll sumu=0,sumd=0;
ll acm_u[200];
ll acm_d[200];
string t="";
ll n;

ll dfs(ll pos, ll tsukatta, ll okeru) {
	if(pos==n) {
		if(tsukatta==0&&okeru==0) return 1;
		else return 0;
	}
	if(memo[pos][tsukatta][okeru]!=-1) return memo[pos][tsukatta][okeru];
	if(t[pos]=='U') {
		ll nokori_u=acm_u[pos]-(pos-((sumd-acm_d[pos])+tsukatta))-1;
		ll nokori_d=acm_d[pos]-tsukatta;
		ll ret=0;
		if(nokori_u>0) ret+=nokori_u*dfs(pos+1,tsukatta,okeru);
		if(nokori_d>0) ret+=dfs(pos+1,tsukatta+1,okeru+1);
		return memo[pos][tsukatta][okeru]=ret%MOD;
	} else {
		ll nokori_u=acm_u[pos]-(pos-((sumd-acm_d[pos])+tsukatta));
		ll nokori_d=acm_d[pos]-tsukatta;
		if(okeru==0) return 0;
		ll ret=0;
		if(nokori_u>0) ret+=nokori_u*dfs(pos+1,tsukatta-1,okeru-1);
		if(nokori_d>0) ret+=dfs(pos+1,tsukatta,okeru);
		return memo[pos][tsukatta][okeru]=(ret*okeru)%MOD;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	vector<char> c(n);
	REP(i,n) cin>>c[i];
	REP(i,n) if(c[i]!='-') t+=c[i];
	n =(ll)t.size();
	REP(i,n) {
		if(t[i]=='U') sumu++;
		if(t[i]=='D') sumd++;
	}
	REP(i,200) REP(j,201) REP(k,201) memo[i][j][k]=-1;
	REP(i,n) {
		if(t[i]=='U') acm_u[i]++;
		if(i>0) acm_u[i]+=acm_u[i-1];
	}
	for(ll i=n-1; i>=0; i--) {
		if(t[i]=='D') acm_d[i]++;
		if(i<n-1) acm_d[i]+=acm_d[i+1];
	}
	cout<<dfs(0,0,0)<<endl;
}


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

using namespace std;

long long a, b, c;

void readInput() {
    cin >> a >> b >> c;
}

int main(int argc, char const *argv[]) {
    
    readInput();

    if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        printf("0\n");
    }
    else cout << min(a * b, min(b * c, a * c));

    return 0;
}

Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if arr[i] == i + 1:
        ans += 1
        arr[i+1], arr[i] = arr[i], arr[i+1]
if arr[n-1] == n:
    ans += 1
print (ans)   

Measured memory_bytes: 20652
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int t;
  S(t);
  if(t < 1200) {
    printf("ABC\n");
  } else if(t < 2800) {
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }
  return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<int> boo(N,1);
  for(int i=0; i<M; i++){
    int A,B;
    cin >> A >> B;
    if (vec.at(A-1)<vec.at(B-1)) {boo.at(A-1)=0;}
    else if (vec.at(A-1)==vec.at(B-1)) {boo.at(A-1)=0; boo.at(B-1)=0;}
    else {boo.at(B-1)=0;}
  }

  int count=0;
  for(int i=0; i<N; i++){
    if (boo.at(i)==1) {count++;}
  }

  cout << count << endl;

}

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

using namespace std;

typedef long long ll;

#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"


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

    string s, t; cin>>s>>t;
    bool flag = true;

    for(int i=0; i<s.length(); i++){
        if(s[i]!=t[i]){
            flag = false;
        }
    }

    if(flag){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }


    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    rep(i,3){
        if(s[i]=='1')s[i]='9';
        else s[i]='1';
    }
    cout<<s<<endl;
}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 28;

int dp[10][10001];
map< int, int > vv;
vector< pair< int, int > > latte;

int rec(int idx, int v) {
  if(idx == latte.size()) return v == 0 ? 0 : -INF;
  if(~dp[idx][v]) return dp[idx][v];
  int ret = -INF;
  if(v - latte[idx].second >= 0) ret = max(ret, rec(idx, v - latte[idx].second) + 1);
  ret = max(ret, rec(idx + 1, v));
  return dp[idx][v] = ret;
}

void rec2(int idx, int v) {
  if(idx == latte.size()) return;
  int ret = dp[idx][v];
  if(v - latte[idx].second >= 0 && rec(idx, v - latte[idx].second) + 1 == ret) {
    cout << latte[idx].first;
    rec2(idx, v - latte[idx].second);
  } else {
    rec2(idx + 1, v);
  }
}


int main() {
  int N, M, X[9];
  int t[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    cin >> X[i];
    latte.emplace_back(X[i], t[X[i]]);
  }
  memset(dp, -1, sizeof(dp));
  sort(latte.rbegin(), latte.rend());
  rec(0, N);
  rec2(0, N);
}





Measured memory_bytes: 768
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    if(k<a){
      System.out.println(k);
      return ;
    }else if(a<=k&&k<=a+b){
      System.out.println(a);
    }else{
      System.out.println(a - (k-a-b));
    }


  }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);



int main() {
	int Q; cin >> Q;
	auto f = [](LL A, LL B) {
		if (A == B)return 2 * A - 2;
		if (B < A)swap(A, B);
		LL L = A, R =2e9;
		while (R - L > 1) {
			LL mid = (L + R) / 2;
			LL a = (mid + 1) / 2;
			LL b = mid / 2 + 1;
			if (a*b < A*B)L = mid;
			else R = mid;
		}
		return L - 1;
	};
	FOR(_, 0, Q) {
		LL A, B; cin >> A >> B;
		LL ans = f(A, B);
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a, int b){
	return a%b?gcd(b,a%b):b;
}
int main(){
	int A,B,K;
	scanf("%d %d %d",&A,&B,&K);
	int g=gcd(A,B),i,cnt;
	for(i=1,cnt=0;cnt<K;i++) if(g%i==0) cnt++;
	i--;
	printf("%d",g/i); 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, p;
	string s;
	cin >> n >> p >> s;
	ll ans = 0;
	if (p == 2 || p == 5) {
		for (int i = n - 1; i >= 0; i--) {
			int k = s[i] - '0';
			if (k % p == 0) {
				ans += i + 1;
			}
		}
	} else {
		vector<ll> sum(n + 1);
		sum[n] = 0;
		map<ll, ll> mp;
		mp[0] = 1;
		vector<ll> ten(n);
		ten[0] = 1;
		for (int i = 1; i < n ; i++) {
			ten[i] = ten[i - 1] * 10 % p;
		}
		for (int i = n - 1; i >= 0; i--) {
			sum[i] = (sum[i + 1] + ll(s[i] - '0') * ten[n - 1 - i] % p) % p;
			ans += mp[sum[i]];
			mp[sum[i]]++;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4116
def getD(graph):
    # search edge
    origin=1
    d = 0
    queue = Queue()
    for it in graph[origin]:
        queue.enqueue((it, origin, d+1)) # next, coming from, depth

    while queue.size() > 0:
        leaf, origin, d = queue.dequeue()
        for it in graph[leaf]:
            if it != origin:
                queue.enqueue((it, leaf, d+1)) # next, coming from, depth
    # print(d, leaf)

    # search D
    origin=leaf
    d = 0
    queue = Queue()
    for it in graph[origin]:
        queue.enqueue((it, origin, d+1)) # next, coming from, depth

    while queue.size() > 0:
        leaf, origin, d = queue.dequeue()
        for it in graph[leaf]:
            if it != origin:
                queue.enqueue((it, leaf, d+1)) # next, coming from, depth
    # print(d, leaf)
    return d

class Node:
    def __init__(self, data):
        self.data = data
        self.next = None


class Queue:
    def __init__(self):
        self.head = None
        self.last = None
        self._size = 0

    def enqueue(self, data):
        if self.last is None:
            self.head = Node(data)
            self.last = self.head
        else:
            self.last.next = Node(data)
            self.last = self.last.next
            
        self._size += 1

    def dequeue(self):
        if self.head is None:
            return None
        else:
            to_return = self.head.data
            self.head = self.head.next
            self._size -= 1
            
            if self._size == 0:
                self.head = None
                self.last = None
            return to_return
        
    def size(self):
        return self._size
    
def inside(y,x,H,W):
    if 0<=y<H and 0<=x<W:
        return True
    else:
        return False
    
def addQueueIfPossible(new_y, new_x, new_val, data, queue):
    if inside(new_y, new_x, H, W) and data[new_y][new_x]==-1:
        data[new_y][new_x] = new_val
        queue.enqueue((new_y, new_x, new_val))
        return True
    else:
        return False


n = int(input())
graph = [[] for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

if n==1:
    print('First')
else:
    d = getD(graph)

    if (d+2)%3==0:
        print('Second')
    else:
        print('First')

Measured memory_bytes: 88392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vi a(n);
  vi b(n);
  rep(i,n){
    cin >> a[i];
    b[a[i] - 1] = i + 1;
  }
  rep(i,n){
    cout << b[i]<<" ";
  }
  cout << endl;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    int n;cin>>n;
    set<string>s;
    string d;
    for(int i=0;i<n;i++){
        cin>>d;
        s.insert(d);
    }
    cout<<s.size()<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
	//cout<<"Case #"<<i+1<<": ";
       	solve();
    }   
}


Measured memory_bytes: 19272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = 3.141592654;
//
//void solve()
//{
//    ll a[4][4],b[4][4];
//    for(int i=1; i<=2; i++)
//    {
//        for(int j=1; j<=2; j++)
//            cin>>a[i][j];
//    }
//    for(int i=1; i<=2; i++)
//    {
//        for(int j=1; j<=2; j++)
//            cin>>b[i][j];
//    }
//    ll a1,a2;
//
//    for(int i=1,k=2; i<=2; i++)
//    {
//        for(int j=1; j<=2; j++)
//        {
//            a1+=(a[i][j]*b[j][i]);
//            a2+=(a[i][j]*b[j][k]);
//        }
//
//        cout<<a1<<" "<<a2<<endl;
//    }
//
//
//}

void solve()
{
    ll n;
    cin>>n;
    ll arr[n+1];
    deque<ll>q;

    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        if(i%2==0)
            q.push_back(arr[i]);
        else
            q.push_front(arr[i]);
    }
    if(n%2 !=0)
        reverse(q.begin(),q.end());
    for(int i=0;i<n;i++)
        cout<<q[i]<<" ";


}

int main()
{
    ios_base :: sync_with_stdio(false);
    ll t,i=1;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 5376
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void){

    int N; cin>>N;
    map<int,int > mp;
    for (int i = 0; i < N; ++i) {
        ll tmp; cin>>tmp;
        mp[tmp]++;
    }
    ll ans = 0;
    for (auto i:mp) {
        if(i.second > i.first) ans += i.second-i.first;
        else if(i.second < i.first) ans += i.second;
    }
    cout<<ans<<endl;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int pivot = a[n-1];
    int i = -1;
    for (int j = 0; j < n-1; j++){
        if(a[j] <= pivot){
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[n-1]);

    REP(j, i+1) cout << a[j] << " ";
    cout << "[" << pivot << "]";
    for(int j = i+2; j<n; j++) cout << " " << a[j];
    cout << endl;


    return 0;
}

Measured memory_bytes: 1524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

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

    cout << 10 - x / 200 << endl;
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define si set<int>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define sq(x) ((x) * (x))
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int res = 0;
    sort(all(a));
    for (int i = 1; i <= n - 1; i++)
        res += (a[n - i / 2 - 1]);
    cout << res << endl;
    GAME_OVER;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  bool A=true;
  cin>>S;
  for(int i=0;i<S.size();i++)
  {
    if(S.at(i)=='U'||S.at(i)=='D')A&=true;
    else if(i%2==0&&S.at(i)=='R')A&=true;
    else if(i%2!=0&&S.at(i)=='L')A&=true;
    else A=false;
  }
  A?cout<<"Yes\n":cout<<"No\n";
}

Measured memory_bytes: 256
require 'pp'

MOD = 10 ** 9 + 7
n = gets.to_i
a_n = gets.split.map(&:to_i)


memo = Array.new(n, 0)
memo[n-1] = a_n[n-1]
(n-2).downto(0) do |i|
    memo[i] = (memo[i+1] + a_n[i]) % MOD
end

sum = 0
(n-2).downto(0) do |i|
    sum = (sum + (a_n[i] * memo[i+1]) % MOD) % MOD
end

puts sum


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

using namespace std;

int n, a, b;

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

    cin >> n >> a >> b;

    if (n > 1 || a <= b) {
        cout << max(0ll, (long long)(n - 2) * (long long)(b - a) + 1ll) << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, v) for (auto &&i : v)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
vector<vector<int>> graph;
vector<bool> visited;
vector<vector<int>> visitedList;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    REP(i, N)
    {
        if (A[i] == B[i] && B[i] == C[i])
        {
            ans += 0;
        }
        else if (A[i] == B[i] || B[i] == C[i] || C[i] == A[i])
        {
            ans += 1;
        }
        else
        {
            ans += 2;
        }
    }
    cout << ans << "\n";
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    int sum = 0;
    int k = 0;
    for (int i = 1; i < 1000; i++)
    {
        sum += i;
        if(sum!=n)
        {
            continue;
        }
        k = i;
        cout << "Yes" << endl;
        int size = n*2/k;
        vector<int> vc[size];
        int num = 1;
        for (int i = 0; i < size; i++)
        {
            for (int j = i+1; j < size; j++)
            {
                vc[i].push_back(num);
                vc[j].push_back(num);
                num++;
            }
        }
        cout << size << endl;
        rep(i,size)
        {
            cout << sz(vc[i]) << " ";
            for (auto &&j : vc[i])
            {
                cout << j << " ";
            }
            cout  << endl;
        }
        return 0;
    }
    cout << "No" << endl;
    

}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define pb push_back
#define vi vector<ll>
#define all(_x) _x.begin(), _x.end()
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define lb(_x, _a) (lower_bound(all(_x), _a) - _x.begin())
#define ub(_x, _a) (upper_bound(all(_x), _a) - _x.begin())
ll n, tc;

int main()
{
  	// ll is int now
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    int a,b,c;
    int dp[3] = {0};
    for(int i=0; i<n; i++)
    {
        cin>>a>>b>>c;
        a += max(dp[1], dp[2]);
        b += max(dp[0], dp[2]);
        c += max(dp[0], dp[1]);

        dp[0] = a;
        dp[1] = b;
        dp[2] = c;
    }
    cout<<max({dp[0],dp[1],dp[2]});
    
    return 0;
}


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

int main() {
  int n; cin>>n;
  vector<int64_t> vec(n);
  int64_t mad=0;
  for (int i = 0; i < n; i++) {
    cin>>vec.at(i);
  }
  for (int i = 1; i < n; i++) {
    if (vec.at(i)-vec.at(i-1) > 0) vec.at(i) = vec.at(i) - 1;
    else if (vec.at(i) < vec.at(i-1)) {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

using namespace std;

int main(){
  string s; 
  int sum = 700;
  
  cin >> s;
  
  if(s[0] == 'o') sum += 100;
  if(s[1] == 'o') sum += 100;
  if(s[2] == 'o') sum += 100;
  
  cout << sum << endl;
}

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

int main() {
  int n;
  cin>>n;
  if(n<2) {
    cout<<"1"<<endl;
  }
  else if(2<=n&&n<4) {
    cout<<"2"<<endl;
  }
  else if(4<=n&&n<8) {
    cout<<"4"<<endl;
  }
  else if(8<=n&&n<16) {
    cout<<"8"<<endl;
  }
  else if(16<=n&&n<32) {
    cout<<"16"<<endl;
  }
  else if(32<=n&&n<64) {
    cout<<"32"<<endl;
  }
  else if(64<=n) {
    cout<<"64"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
const int maxx=100100;
int f[maxx][21],n,m,ff[maxx][21],a[maxx];
int query(int x,int y)
{
    int k=log2(y-x+1);
    return std::min(f[x][k],f[y-(1<<k)+1][k]);
}
int query1(int x,int y)
{
    int k=log2(y-x+1);
    return std::max(ff[x][k],ff[y-(1<<k)+1][k]);
}
int main()
{
	int min=0x3f3f3f3f;
    std::cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        std::cin>>a[i];
    }
    std::sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        f[i][0]=a[i];
        ff[i][0]=f[i][0];
    }
    for(int j=1;j<=20;j++)
    {
        for(int i=1;i+(1<<j)-1<=n;i++)
        {
            f[i][j]=std::min(f[i][j-1],f[i+(1<<j-1)][j-1]);
            ff[i][j]=std::max(ff[i][j-1],ff[i+(1<<j-1)][j-1]);
        }
    }
    for(int i=1;i<=n-m+1;i++)
    {
        min=std::min(query1(i,i+m-1)-query(i,i+m-1),min);
    }
    std::cout<<min;
    return 0;
}

Measured memory_bytes: 17024
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scaner = new Scanner(System.in);

        String word1 = scaner.nextLine();
        String word2 = scaner.nextLine();


        if(word1.charAt(0) != word2.charAt(2)){
            System.out.println("NO");
        }else if(word1.charAt(1) != word2.charAt(1)){
            System.out.println("NO");
        }else if(word1.charAt(2) != word2.charAt(0)){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 21716
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>

#define cmax(_a, _b) (_a < (_b) ? _a = (_b), 1 : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b), 1 : 0)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))

#define maxn 1010
typedef long long ll;
typedef double ld;

ll x[maxn], y[maxn], z[maxn], v[maxn];
int main()
{
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld%lld%lld", x + i, y + i, z + i);
	ll ans = 0;
	for (int i = 0; i < 8; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			v[j] = 0;
			i & 1 ? v[j] += x[j] : v[j] -= x[j];
			i >> 1 & 1 ? v[j] += y[j] : v[j] -= y[j];
			i >> 2 & 1 ? v[j] += z[j] : v[j] -= z[j];
		}
		std::sort(v + 1, v + n + 1);
		ll ret = 0;
		for (int j = 1, k = n; j <= m; ++j, --k) ret += v[k];
		ans < ret ? ans = ret : 0;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int main(){
	string s,t;
  	cin >> s >> t;
  	int n = s.length();
  	int m = t.length();
  	int mindiff = m;
  	int diff;
  	for(int i=0;i<=n-m;i++){
      	diff = 0;
    	for(int j=i;j<i+m;j++){
        	if(t[j-i] != s[j]){
            	diff++;
            }
        }
      	if(diff < mindiff){
        	mindiff = diff;
        }
    }
  	cout << mindiff << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define int ll
bool used[100005],u2[100005];
ll cost[100005]={0};
vector<ll> node[100005];
P dfs(ll pos){
  P res;
  res.first=cost[pos];
  res.second=pos;
  for(int i=0;i<node[pos].size();i++){
    int to=node[pos][i];
    if(used[to]) continue;
    used[to]=true;
    res=min(res,dfs(to));
  }
  return res;
}
signed main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>cost[i];
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  for(int i=0;i<n;i++){
    used[i]=false;
    u2[i]=false;
  }
  int cnt=0;
  ll ans=0;
  for(int i=0;i<n;i++){
    if(!used[i]){
      used[i]=true;
      P p=dfs(i);
      ans+=p.first;
      u2[p.second]=true;
      cnt++;
    }
  }
  cnt--;
  if(cnt==0){
    cout<<0<<endl;
    return 0;
  }
  if(cnt*2>n){
    cout<<"Impossible"<<endl;
    return 0;
  }
  priority_queue<ll,vector<ll>,greater<ll>> pque;
  for(int i=0;i<n;i++){
    if(!u2[i]) pque.push(cost[i]);
  }
  for(int i=0;i<cnt-1;i++){
    ans+=pque.top();
    pque.pop();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
using namespace std;
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; }
using Graph = vector<vector<int> >;
// MOD
const int MOD = 1000000007;

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

int H, W;
int field[100][100];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];


string N[100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

void dfs(int v, vector<bool> &seen, int &res) {
    bool end = true;
    for (int i = 0; i < seen.size(); ++i) if (!seen[i] && i != v) end = false;
    if (end) {
        ++res;
        return;
    }

    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv]) continue;
        dfs(nv, seen, res);
    }
    seen[v] = false;
}
bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}

int dp[100000];

int main() {
    int s, w; cin >> s >> w;
    if(s<=w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int main()
{
	int N;
	stack<int> s;
	while(~scanf("%d",&N)){
		if(N){
			s.push(N);
		}
		else{
			printf("%d\n",s.top());
			s.pop();
		}
	}

	return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int a;

int main(){
  cin >> a;
  double ans;
  if(a % 2 == 0){
    ans = 0.5;
  }else{
    ans = (a + 1)/2;
    ans = ans / a;
  }
  cout << setprecision(10) << ans <<endl;
}

Measured memory_bytes: 256
s = list(str(input()))
n = len(s)
ans = False
s1 = s
s2 = s[:(n-1)//2]
s3 = s[(n+3)//2-1:]
if s1 == s1[::-1] and s2 == s2[::-1] and s3 == s3[::-1]:
    ans = True
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <stdio.h>
int main(){
  int n,f,p,r=0;
  char s[101];
  scanf("%d%s",&n,s);
  for(int i=1;i<n;i++){
    p=0;
    for(int j=0;j<26;j++){
      f=0;
      for(int k=0;k<i;k++)if(s[k]=='a'+j)f=1;
      for(int k=i;k<n;k++)if(s[k]=='a'+j)if(f)f=-1;
      if(f==-1)p++;
    }
    if(p>r)r=p;
  }
  printf("%d",r);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define END {cout<<ans<<'\n'; return 0;}

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

    string s; cin>>s; string ans="-1"; int a[26]={},n=s.size();
    if(n==26){
        string s1=s;
        if(!next_permutation(s.begin(),s.end()))END
        ans="";
        for (int i = 0; i < n; i++){
            ans.push_back(s[i]);
            if(s[i]!=s1[i])END
        }
    }else{
    for (int i = 0; i < n; i++)a[s[i]-'a']++;
    for (int i = 0; i < 26; i++)if(!a[i]){
        s+=i+'a'; cout<<s<<'\n'; return 0;
    }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

// Solving the maze using bfs
#define WALL '#'
#define PATH '.'
class coord{
	public:
	coord(){}
	coord(int _x,int _y):x(_x),y(_y){}
	int x,y;
};

class maze{
	public:
		maze(int _h,int _w):h(_h),w(_w){
			m = vector<vector<char>>(h,vector<char>(w));
			d = vector<vector<int>>(h,vector<int>(w,-1));
		}
		void input_map(){
			rep(i,h){
				string si; cin >> si;
				rep(j,w){
					m[i][j] = si[j];
					if(si[j]==WALL) wall_n++;
					if(si[j]==PATH) path_n++;
				}
			}
		}
		void set_start(coord _s){ s = _s; }
		void calc_distance(){
			queue<coord> q;
			q.push(s);
			d[s.x][s.y]=0;
			while(q.size()){
				coord u = q.front(); q.pop();
				int i,j;
				i = u.x-1; j = u.y;	
				if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==PATH){
					d[i][j] = d[u.x][u.y]+1;
					q.push(coord(i,j));
				}
				i = u.x+1; j = u.y;		
				if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==PATH){
					d[i][j] = d[u.x][u.y]+1;
					q.push(coord(i,j));
				}
				i = u.x; j = u.y-1;		
				if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==PATH){
					d[i][j] = d[u.x][u.y]+1;
					q.push(coord(i,j));
				}
				i = u.x; j = u.y+1;		
				if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==PATH){
					d[i][j] = d[u.x][u.y]+1;
					q.push(coord(i,j));
				}
			}				
		}
		int distance(coord g){return d[g.x][g.y];}
		int number_of_wall(){return wall_n;}
		int number_of_path(){return path_n;}
		void print_map(){
			rep(i,h){
				rep(j,w) cout << m[i][j];
				cout << endl;
			}
		}		
		void print_distance(){
			rep(i,h){
				rep(j,w) cout << d[i][j] << " ";
				cout << endl;
			}
		}
	private:
		int h,w;
		vector<vector<char>> m;
		vector<vector<int>> d;
		coord s;
		int wall_n = 0;
		int path_n = 0;
};

int main(void) {
	int h,w; cin >> h >> w;
	maze mz(h,w);
	coord s(0,0);
	mz.set_start(s);
	mz.input_map();
	mz.calc_distance();
//	mz.print_distance();
	coord g(h-1,w-1);
	int dis = mz.distance(g);
	if(dis==-1){
		cout << -1 << endl;
		return 0;
	}
	int ans = h*w-mz.number_of_wall()-(dis+1);
	cout << ans << endl;
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/dsu>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int n, q;
	cin >> n >> q;
	atcoder::dsu d(n);

	rep(i, q) {
		int t, u, v;
		cin >> t >> u >> v;

		if (t == 0) {
			d.merge(u, v);
		}
		else {
			cout << (d.same(u, v) ? 1 : 0) << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
#define M_PI  3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
// -----------------------------------------------CKMKB-----------------------------------------------------------
// -----------------------------------------------PKMKB-----------------------------------------------------------
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1;
  //cin>>t;
  while(t--)
  {
      ll x;
      cin>>x;
      ll a = x%1000;
      if( a!=0 ) a = 1000 - a ;
      cout<<a;
  }
  return 0;

}


Measured memory_bytes: 3652
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}


int main() {
	ll N;
	cin >> N;
	ll ans = 0;

	vi A(N);
	vi C(N);
	rep(i, N) {
		cin >> A[i];
		A[i]--;
	}
	rep(i, N) {
		ll b; cin >> b;
		ans += b;
	}

	rep(i, N-1) {
		cin >> C[i];
	}

	rep(i, N-1) {
		if (A[i] + 1 == A[i + 1]) {
			ans += C[A[i]];
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
const int MAXN = 1e6+20;
const long long INF = 1e16;
using namespace std;

string s,t;
int cnt;
int main()
{
 
	ios_base::sync_with_stdio(0);
 
//	freopen("longpath.in", "r", stdin);
//	freopen("longpath.out", "w", stdout);


cin>>s>>t;
for (int i=0; i<s.length(); i++) if (s[i]==t[i]) cnt++;
cout<<cnt<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;


int main(){
  
  string s,t; cin>>s>>t;
  int ans = t.size();
  for(int i=0; i<=s.size()-t.size(); i++){
    int a{};
    for(int j=0; j<t.size(); j++){
      if(t.at(j)!=s.at(i+j)) a++;
    }
    ans = min(a,ans);
  }
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans = LINF, a, b, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};
map<char, ll> aru;

//-------------------------↓↓↓↓↓↓------------------------

void dfs(string now, char cc, ll sousa)
{
    set<char> st;
    rep(i, Size(now))
    {
        st.insert(now[i]);
    }
    if (Size(st) == 1)
    {
        cnt = min(cnt, sousa);
    }
    else
    {
        string noww = "";
        rep(i, Size(now) - 1)
        {
            if (now[i] == cc || now[i + 1] == cc)
                noww += cc;
            else
                noww += now[i];
        }
        dfs(noww, cc, sousa + 1);
    }
}

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

    cin >> s;
    rep(i, Size(s)) aru[s[i]] = 1;
    for (char c = 'a'; c <= 'z'; c++)
    {
        if (aru[c] == 0)
            continue;
        cnt = LINF;
        dfs(s, c, 0LL);
        ans = min(ans, cnt);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#define REP(i, n) for(int i = 0; i < n; i++)

int main()
{
    const int INF = 999999999;
    const int MAX_N = 50;
    const int MAX_M = 50;
    int n, m;
    int a[MAX_N];
    int b[MAX_N];
    int c[MAX_M];
    int d[MAX_M];
    std::cin >> n >> m;
    REP(i, n) std::cin >> a[i] >> b[i];
    REP(i, m) std::cin >> c[i] >> d[i];
    REP(i, n)
    {
        int min = INF, point;
        REP(j, m)
        {
            int distance = std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]);
            if(min > distance)
            {
                min = distance;
                point = j + 1;
            }
        }
        std::cout << point << std::endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') { insert(key); np++; size++; }
        else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}


Measured memory_bytes: 33964
#include <iostream>
using namespace std;
int main()
{
	long long a[100000];
    long long n;
    cin >> n;
    for(int i = 0;i < n;i ++)
        {
            cin >> a[i];
        }
    for(int i = 0;i < n-1;i++)
        {
             
            for(int j = n -2; j >= i;j--)
                {
                    if(a[j] > a[j+1])
                        {
                            int t = a[j+1];
                            a[j+1] = a[j];
                            a[j] = t;
                        }
                }
        }
    long long sum1 = 0;
    long long sum2 = 0;
    if(n % 2 == 0)
        {
        	for(int i = 0;i < n-1;i += 2)
        	    {
        	    	sum1 += a[i];
				}
			for(int i = 1;i < n;i += 2)
			    {
			    	sum2 += a[i];
				}
		}
		else
		    {
		    	for(int i = 1;i < n-1;i += 2)
		    	    {
		    	    	sum1 += a[i];
					}
				for(int i = 0;i < n;i += 2)
				    {
				    	sum2 += a[i];
					}
			}
	cout << sum2 - sum1 << endl;
    return 0;
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll n;
         cin>>n;
         map<pair<ll,ll>,ll>mp;
         for(int i=1;i<=n;i++)
          {
            ll p1 = i%10;
            ll p2 = i;
            while(p2>=10)
            {
                  p2/=10;
            }
            mp[{p1,p2}]++;
          }
          ll ans =0;
          for(int i=0;i<=9;i++)
          {
            for(int j=0;j<=9;j++)
            {
              ans+=mp[{i,j}]*mp[{j,i}];
            }
          }
          cout<<ans;

      }
      






}



























Measured memory_bytes: 256
K,A,B = map(int, input().split())
if B-A<=2:
    print(K+1)
elif A-1>K:
    print(K+1)
else:
    rest = K-(A-1)
    if rest%2==0:
        print(A + (rest//2) * (B-A))
    else:
        print(A + (rest//2) * (B-A) + 1)

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

int main()
{
  int K, S;
  int count = 0;

  cin >> K >> S;
  for (int i = max(S - 2 * K, 0); i <= K; i++)
  {
    if (S < i)
      break;
    if (S - i <= 2 * K)
        count += K - abs(S - i - K) + 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int n,hoji,hoji2;
int roop;
int sum=0;
scanf("%d",&n);

for(roop=0;roop<n;roop++){
scanf("%d",&hoji);
scanf("%d",&hoji2);
sum=sum+(hoji2-hoji+1);
}
printf("%d",sum);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  string ans = "Yes";
    for(int i=n-1;i>=1;i--){
      if(v[i-1] - v[i] >= 2) {
        ans ="No";
      }
      
      else if(v[i-1] - v[i] == 1){
        v[i-1]--;
      }
    }
          cout << ans << endl;
}
    
  
    

Measured memory_bytes: 640
import numpy as np
from collections import defaultdict
from collections import Counter
from collections import OrderedDict
#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
N = int(input())
#H = (int(i) for i in input().split())
#H = (int(input().split()))
H=list(map(int, input().split()))  #リスト入力
#print(H)
cnt = 0
for i, h in enumerate(H):
    if i == 0:
        max_h = H[0]
        cnt += 1
        continue
    else:
        if max_h <= h:
            cnt += 1
            max_h = h
print(cnt)

Measured memory_bytes: 21508
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int d;
	int r;
	double c;
	double e;
	double f;
	
	scanf("%d %d", &a, &b);
	
	d = a / b;
	r = a % b;
	c = a;
	e = b;
	f = c / e;
	
	printf("%d %d %f\n", d, r, f);
	
	return (0);
}

Measured memory_bytes: 636
n, m, k = map(int,input().split())

ANS = [0] * (n*m + 1)

for i in range(n+1):
    for j in range(m+1):
        ANS[i*j + (n-i)*(m-j)] = 1
# print(ANS)
if ANS[k] == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 46704
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int cnt = 0;
    while(true){
      b -= a;
      if(cnt >= c) break;
      if( b < 0) break;
      cnt++;
    }
    System.out.println(cnt);
  }
}

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

int main(){
  string S; cin >> S;
  reverse(S.begin(), S.end());

  string divider[4] = {"maerd", "remaerd", "esare", "resare"};

  bool flag;
  for (int i=0; i<S.size(); ){
    flag = false;
    for (int j=0; j<4; j++){
      if (S.substr(i, divider[j].size()) == divider[j]){
        flag = true;
        i += divider[j].size();
      }
    }
    if (!flag) break;
  }

  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 512