akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, G, p[1010], c[1010];

signed main()
{
    cin >> N >> G;
    int bit = (1ll << N);
    for(int i = 0; i < N; i++){
        cin >> p[i] >> c[i];
    }
    int ans = INFL;
    for(int i = 0; i < bit; i++){
        int cnt = 0ll, sum = 0ll, cur = -1ll;
        for(int j = 0; j < N; j++){
            if(i & (1ll << j)){
                cnt += p[j];
                sum += p[j] * 100 * (j + 1) + c[j];
            }
            else{
                cur = j;
            }
        }
        //printf("cur:%lld i:%lld cnt:%lld sum:%lld G:%lld\n", cur, i, cnt, sum, G);
        if(cur != -1){
            if(G > sum){
                int add = (G - sum + (cur + 1) * 100 - 1) / ((cur + 1) * 100);
                //printf("%llda %lld\n", i, add);
                if(add < p[cur]){
                    //printf("%lldb\n", i);
                    cnt += add;
                    sum += add * (cur + 1) * 100;
                }
            }
        }
        if(sum >= G){
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;

    return 0;
}

/*


*/


Measured memory_bytes: 256
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


int main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
    #ifdef err
	double be = clock();
    #endif
    int flag = 0;
    int x,y;cin>>x>>y;
    _for(i,0,x+1){
        if(2*i+4*(x-i)==y){flag=1;break;}
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int q;
  list<int>L;
  list<int>::iterator it=L.begin();
  cin>>q;
  while(q--){
    int a,b;
    cin>>a;
    if(a<2)cin>>b;
    if(!a)it=L.insert(it,b);
    else if(a==1){
      r(i,abs(b)){
        if(b<0)it--;
        else it++;
      }
    }
    else it=L.erase(it);
  }
  it=L.begin();
  for(;it!=L.end();it++){
    cout<<*it<<endl;
  }
}



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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int n;
  cin >> n;
  vector<ll> h(n);
  map<ll ,int> mp;
    rep(i,n) {
      cin >> h.at(i);
     if(mp.count(i+h.at(i))){
       mp.at(i+h.at(i))++;
     }
        else{
          mp[i+h.at(i)]=1;
        }
    }
  ll sum=0;
    rep(i,n){
      if(mp.count(i-h.at(i))){
       sum+=mp.at(i-h.at(i));
      }
    }
      
  cout << sum << endl;      
}

Measured memory_bytes: 16948
n, k = map(int, input().split())
a = list(map(int,input().split()))
dict = {}
for i in a:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
dict2 = sorted(dict.items(), key=lambda x:x[1], reverse=True)
c = 0
flg = 0
d = 0
for i in dict2:
	if c >= k:
		flg = 1
	if flg == 1:
		d += i[1]
	c += 1
print (d)

Measured memory_bytes: 40092
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    while( getline( cin, s ) ) {
        if ( s == "." )
            break;

        bool b = true;
        stack<char> t;
        t.push( '\0' );
        for( auto c : string( s.cbegin(), s.cbegin() + s.find_last_of( '.' ) ) ) {
            b = [&]() mutable -> bool {
                if ( c == '(' || c == '[' )
                    t.push( c );
                else if ( c == ')' )
                    if ( t.top() == '(' )
                        t.pop();
                    else
                        return false;
                else if ( c == ']' )
                    if ( t.top() == '[' )
                        t.pop();
                    else
                        return false;
                return true;
            }();
            if ( !b )
                break;

        }
        cout << ( b && t.size() == 1 ? "yes" : "no" ) << endl;
    }
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MAX3(a, b, c) ((a) > (MAX(b, c)) ? (a) : (MAX(b, c)))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100002
int main()
{
    ll n, c;
    ll x[N]; // distance
    ll v[N]; // calorie
    ll g[N];
    ll g_id[N];
    ll sb[N];
    cin >> n >> c;

    x[0] = 0, x[n+1] = c;
    v[0] = 0, v[n+1] = 0;
    g_id[0] = 0; g[0] = 0;
    sb[n+1] = 0;
    ll sum = 0;
    ll ma = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> v[i];
        sum += v[i];
        if (ma > sum - x[i]) {
            g_id[i] = g_id[i-1];
        } else {
            ma = sum - x[i];
            g_id[i] = i;
        }
        g[i] = ma;
    }

    sum = 0, ma = 0;
    for (int i = n; i >= 1; i--) {
        sum += v[i];
        ma = max(ma, sum - c + x[i]);
        sb[i] = ma;
    }

    //rep(i, n + 1) cout << i << " " << g[i] << " " << g_id[i] << endl;
    ll bmax = 0;
    for (int b = 1; b <= n + 1; b++) {
        ll a_id = g_id[b - 1];
        //cout << x[a_id] << " " << c - x[b] << endl;
        ll total = g[b-1] + sb[b] - min(x[a_id], c - x[b]);
        bmax = max(bmax, total);
    }

    cout << bmax << endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;
    int k2 = 0;
    int k4 = 0;
    int k1 = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (t % 4 == 0) {
            k4++;
        } else if (t % 2 == 0) {
            k2++;
        } else {
            k1++;
        }
    }
    if (k4 < k1 - (int)(k2 == 0)) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	//ll N;
	//cin >> N;

	ll x, res;
	for (ll i = 0; i < 5; ++i) {
		cin >> x;
		if (x == 0) res = i + 1;
	}


	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();

		int l = s.length();
		for(int i=l-2;i>1;i-=2) {
			String a = s.substring(0, i/2);
			String b = s.substring(i/2, i);
			if(a.equals(b)) {
				System.out.println(i);
				return;
			}
		}
	}

}


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

ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}
ll min(ll a, ll b){ 
	if(a <= b) return a;
	else if(a > b) return b;
}
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
ll fact(ll n){
	ll res = 1;
	rep(i, n){
		res *= i + 1;
		res =  res%((ll)(1e9 + 7));
	}
	return res;
}
ll digit(const ll n){
	ll res = 0;
	ll i = 1;
	while(n % i != n){
		res += 1;
		i *= 10;
	}
	return res;
}

int main(){
	ll n;
	cin >> n;
	ll ans_dif = 100000000000;
	for(ll i = 1; i <= min((ll)1000000, n); i++){
		if(n%i == 0){
			ll temp_dif = max(digit(n/i), digit(i));
			if(temp_dif <= ans_dif) {
				ans_dif = temp_dif;
			}
		}
	}
	cout << ans_dif << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t; cin >>s >>t;
  vector<char> a(s.size()), b(t.size());
  for (int i=0; i<s.size(); i++) a.at(i) = s.at(i);
  for (int i=0; i<t.size(); i++) b.at(i) = t.at(i);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  bool same = true;
  for (int i=0; i<min(a.size(), b.size()); i++){
    if (a.at(i)<b.at(i)){
      cout <<"Yes" <<endl;
      same = false;
      break;
    }else if (a.at(i)>b.at(i)){
      cout <<"No" <<endl;
      same = false;
      break;
    }
  }
  if (same){
    if (a.size() < b.size()) cout <<"Yes" <<endl;
    else cout <<"No" <<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n;
ll ans;
int main(){
    cin>>n;
    rep(i,1,n){
        if(i%3==0||i%5==0)continue;
        else ans+=i;
    }
    cout<<ans<<endl;
	return 0;
}


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

const int N = 1010;
const int M = 2010;
const int mod = 1e9 + 7;

struct edge {
    int to, next, w;
} e[N * 2];

int head[N], ecnt;

inline void adde(int from, int to, int w) {
    e[++ecnt] = (edge){to, head[from], w}, head[from] = ecnt;
    e[++ecnt] = (edge){from, head[to], w}, head[to] = ecnt;
}

int fa[N][11], mx[N][11], dep[N];

void dfs(int u, int f, int w) {
    fa[u][0] = f, dep[u] = dep[f] + 1, mx[u][0] = w;
    for (int i = 1; i <= 10; i++) {
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
        mx[u][i] = max(mx[u][i - 1], mx[fa[u][i - 1]][i - 1]);
    }
    for (int i = head[u]; i; i = e[i].next)
        if (e[i].to != f) dfs(e[i].to, u, e[i].w);
}

inline int get(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b);
    int res = 0;
    for (int i = 10; i >= 0; i--) if (dep[fa[a][i]] >= dep[b]) 
        res = max(res, mx[a][i]), a = fa[a][i];
    if (a == b) return res;
    for (int i = 10; i >= 0; i--) if (fa[a][i] != fa[b][i]) {
        res = max(res, mx[a][i]), a = fa[a][i];
        res = max(res, mx[b][i]), b = fa[b][i];
    }
    return max(res, max(mx[a][0], mx[b][0]));
}

int from[M], to[M], t[M], w[M], id[M], F[N], pw2[N];

int find(int x) {
    return x == F[x] ? x : F[x] = find(F[x]);
}

typedef long long LL;

int main() {
    int n, m; LL X; scanf("%d%d%lld", &n, &m, &X); 
    for (int i = 1; i <= n; i++) F[i] = i;
    for (int i = 1; i <= m; i++) 
        scanf("%d%d%d", &from[i], &to[i], &w[i]), id[i] = i;
    sort(id + 1, id + m + 1, [](int a, int b) {
        return w[a] < w[b];
    });
    LL mn = 0;
    for (int i = 1; i <= m; i++) {
        int a = from[id[i]], b = to[id[i]];
        if (find(a) != find(b)) 
            t[id[i]] = 1, adde(a, b, w[id[i]]), F[find(a)] = find(b), mn += w[id[i]];
    }
    if (X < mn) return puts("0"), 0;
    dfs(1, 0, 0), pw2[0] = 1;
    for (int i = 1; i <= m; i++) pw2[i] = pw2[i - 1] * 2 % mod;
    if (X == mn) {
        int a = 0, b = 0;
        for (int i = 1; i <= m; i++) if (!t[i]) {
            if (w[i] == get(from[i], to[i])) a++;
            else b++;
        }
        int res = (LL)(pw2[n - 1] - 2) * pw2[m - (n - 1)] % mod;
        res = (res + (LL)2 * (pw2[a] - 1) * pw2[b]) % mod;
        printf("%d\n", res);
    } else {
        int a = 0, b = 0;
        for (int i = 1; i <= m; i++) if (!t[i]) {
            int diff = w[i] - get(from[i], to[i]);
            if (diff == X - mn) a++;
            else if (diff > X - mn) b++;
        }
        printf("%lld\n", (LL)2 * (pw2[a] - 1) * pw2[b] % mod);
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a<b && b<c){
        printf("Yes\n");
    }
    
    else{
        printf("No\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 2032
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,a;
  long int s;
  vector<long int> x(10000),m(10000);
  while(cin >>n,n){
    x[0] = m[0] = 0;
    for(int i=1; i<=n; i++){
      cin >>a;
      x[i] = x[i-1]+a;
      m[i] = min(m[i-1],x[i]);
    }
    s = x[1];
    for(int i=1; i<=n; i++) s = max(s,x[i]-m[i-1]);
    cout <<s<<endl;
  }
}

Measured memory_bytes: 1324
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;


/*==================================================*/

/*==================================================*/

int N;

int main(){

  cin>>N;
  int ans = 1, ta = 0;
  for(int i = N; 0 <= i; i--){
    int t = i;
    int cnt = 0;
    while(t % 2 == 0 && t > 0){
      cnt++;
      t /= 2;
    }
    if(ta < cnt ){
      ans = i;
      ta = cnt;
    }
  }

  cout<<ans<<endl;

  return 0;
}


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


int main()
{
	int x, n, tab[101];
	memset(tab, 1, sizeof(tab));
	cin >> x >> n;
	int p;
	while (n--) {
		cin >> p;
		tab[p] = 0;
	}
	int higher = 101;
	for (int a = x; a < 101; ++a) {
		if (tab[a]) {
			higher = a;
			break;
		}
	}
	int lower = 0;
	for (int a = x; a > 0; --a) {
		if (tab[a]) {
			lower = a;
			break;
		}
	}

	if (abs(x - higher) < abs(x - lower)) cout << higher;
	else cout << lower;

	return 0;
}

Measured memory_bytes: 3632
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/
//int i = Integer.parseInt(s);
//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static int K;
	public static void main(String[] args) {
		int N=sc.nextInt();
		double v=N/1.08;
		int a=(int)Math.ceil(v);
		int b=(int)Math.floor(v);
		//p(v);
		//p(a);
		if(Math.floor(a*1.08)==N) {
			p(a);
		}else if(Math.floor(b*1.08)==N) {
			p(b);
		}else {
			p(":(");
		}
	}
}


Measured memory_bytes: 23636
#include <stdio.h>
#include <cmath>
#include <stdlib.h>
#include <algorithm>

int main()
{
    int n;
    char a[100],b[100],c[100];
    scanf("%d", &n);
    
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);
    
    int count = 0;
    for(int i = 0;i < n;i++)
    {
        if(a[i] == b[i] && a[i] == c[i])
            continue;
        if(a[i] == b[i] || a[i] == c[i] || c[i] == b[i])
        {
            count++;
            continue;
        }
        
        count += 2;
    }

    printf("%d", count);
    return 0;
}


Measured memory_bytes: 128
import fractions
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
def main():
    N = int(input())
    A = list(map(int, input().split()))
    g = A[0]
    l = A[0]
    for i in A[1:]:
        g = fractions.gcd(g, i)
        l = l * i // fractions.gcd(l, i)
    r = 0
    mod = 10 ** 9 + 7
    n = (l // g) % mod
    for i in A:
        r += n * modinv(i//g, mod)
    print(r % mod)
main()




Measured memory_bytes: 68952
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

bool used[200001];
int c[100000];
signed main() {
	int a, b; scanf("%d%d", &a, &b);
	for (int d = 0; d < b; d++)scanf("%d", &c[d]);
	for (int d = b - 1; d >= 0; d--) {
		if (!used[c[d]]) {
			printf("%d\n", c[d]);
			used[c[d]] = true;
		}
	}
	for (int i = 1; i <= a; i++) {
		if (!used[i])printf("%d\n", i);
	}
}

Measured memory_bytes: 3776
from math import atan, degrees

a, b, x = map(int, input().split())
V = a * a * b // 2

if V >= x:
    #print('V >= x')
    l = (2 * x) / (a * b)
    theta = 90 - degrees(atan(l / b))
else:
    h = ((2 * x) / (a * a)) - b
    if b != h:
        theta = 90 - degrees(atan(a / (b - h)))
    else:
        theta = 0

print(theta)




Measured memory_bytes: 38384
N,M = (int(x) for x in input().split())
a = [[int(x) for x in input().split()] for i in range(N)] 
food = [0]*(M+1)
count = 0
for i in range(N):
    for j in range(1,a[i][0]+1):
        food[a[i][j]] = food[a[i][j]] + 1
for i in range(M+1):
    if food[i] == N:
        count = count + 1
print(count)

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

int main(){
  string n;
  cin >> n;
  rep(i,n.size()-1) {
    if (n.at(i) == n.at(i+1)) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int n;
  cin >> n;
  vector<vector<int>> p(10, vector<int>(10));
  for (int i = 1; i < n + 1; i++) {
    int e = i % 10;
    int b = i;
    while (b >= 10) {
      b /= 10;
    }
    p[b][e]++;
  }
  ll count = 0;
  for (int i = 1; i < 10; i++) {
    for (int j = i; j < 10; j++) {
      if (i == j) {
        count += (p[i][j] * p[i][j]);
      }
      else {
        count += (2 * p[i][j] * p[j][i]);
      }
    }
  }
  cout << count <<endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int sol;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; ++i)
    {
        int n = i;
        string s;
        while (n)
            s.push_back(n % 10), n /= 10;
        string z = s;
        reverse(all(z));
        if (s == z)
            ++sol;
    }
    cout << sol;
}


Measured memory_bytes: 256
L,R = [int(_) for _ in input().split()]
if L//2019 != R//2019:
    mod_min=0
else:
    mod_list=[]

    mod_min = 10**10
    for i in range(L,R):
        for j in range(i+1,R+1):
            if mod_min >= i*j%2019:
                mod_min = i*j%2019
                
            if mod_min == 0:
                break
        if mod_min == 0:
                break
#                 print(i,j,mod_min)
print(mod_min)

Measured memory_bytes: 9092
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 10, M = 1e3 + 10;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    int n, m;
    cin >> n >> m;
    ll a[n + 1], pre[n + 1] = {0};
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i) {
        if (i != 1) {
            pre[i] = pre[i - 1] + a[i];
        } else {
            pre[i] = a[i];
        }
    }
    pll q[m];
    for (ll i = 0; i < m; ++i) {
        cin >> q[i].S >> q[i].F;
    }
    sort(q, q + m, greater < pll >());
    ll ans = 0;
    int cur = 1;
    for (ll i = 0; i < m; ++i) {
        ll pos = lower_bound(a + cur, a + n + 1, q[i].F) - a - 1;
        if (pos < cur) {
            continue;
        }
        ans += q[i].F * min(q[i].S, pos - cur + 1) - pre[min(cur + q[i].S - 1, pos)] + pre[cur - 1];
        cur += q[i].S;
    }
    cout << ans + pre[n] << "\n";
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int maxm = 26;

int n;
string s;
int c[maxm];

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif // suiyuan2009
  cin>>s;
  n = s.size();
  ll ret=0;
  for(int i=n-1;i>=0;i--){
    for(int j=0;j<maxm;j++)
    if(s[i]!=j+'a')ret+=c[j];
    c[s[i]-'a']++;
  }
  cout<<ret+1<<endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    long N,T;
    cin>>N>>T;
    long bt=0,sum=0;
    for(long i = 0; i < N; i++){
        long t;
        cin>>t;
        if(t != 0){
            if(t-bt<T)
                sum+=t-bt;
            else
                sum+=T;
        }
        bt = t;
    }
    sum+=T;
    cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[100005];
	int b[100005];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[a[i]] = i + 1;
	}
	for (int i = 1; i < n + 1; i++) {
		cout << b[i];
		if(i!=n)cout << ' ';
	}
}

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

int main()
{
    int n,a,b,aq;
    string str,line;
    cin >> str >> n ;
    aq=(int)str.size();
    char s[aq];
    for(int i=0;i<n;i++){
        cin >> line >> a >> b;
        if(line=="print"){
            for(int j=0;j<b-a+1;j++){
                cout << str[a+j];
            }
            cout << endl;
        }
        else if(line=="reverse"){
            for(int j=0;j<aq;j++) s[j]=str[j];
            str.erase(str.begin(),str.begin()+(int)str.size());
            for(int j=0;j<a;j++) str.push_back(s[j]);
            for(int j=b;j>=a;j--) str.push_back(s[j]);
            for(int j=b+1;j<=aq;j++) str.push_back(s[j]);
        }
        else{
            string p;
            cin >> p;
            for(int j=0;j<(int)str.size();j++) s[j]=str[j];
            str.erase(str.begin(),str.begin()+(int)str.size());
            for(int j=0;j<a;j++) str.push_back(s[j]);
            for(int j=0;j<(int)p.size();j++)str.push_back(p[j]);
            for(int j=b+1;j<=aq;j++) str.push_back(s[j]);
        }
    }
    return 0;
}



Measured memory_bytes: 3180
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int s, m, h;
  cin >> s;
  h = s / 3600;
  m = s % 3600 / 60;
  s = s % 60;
  cout << h << ':' << m << ':' << s << endl;

  return 0;
}


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

int main(){
    int n, count = 0;
    cin >> n;
    int a[n+1];
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++){
        if(a[a[i]] == i) count++;
    }

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

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
int solveMeFirst(int a, int b) {
 // Hint: Type return a+b; below:
  
}
 
int main() {
  int a1, a2, a3;
  int sum = 0;
  cin>>a1>>a2>>a3;
  sum += a1;
  sum += a2;
  sum += a3;
  if(sum >= 22) cout<<"bust";
  else cout<<"win";
  return 0;
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    string S, T;
    cin >> S >> T;
    bool h = true;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == T[i]){

        } else {
            h = false;
            break;
        }
    }
    if(h){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main(){
  vector<string> alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  string A;
  cin >> A;
  for(int I=0;I<alphabet.size();I++){
    if(A == alphabet.at(I) ){
      cout << alphabet.at(I+1) << endl;
    }
  }
  
}
  

Measured memory_bytes: 256
N, M = map(int, input().split())
min, max = 0, N
ans = 0

for i in range(M):
  L, R = map(int, input().split())
  min = L if min < L else min
  max = R if max > R else max
  
for i in range(min, max+1):
  ans += 1
  
print(ans)

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int mn(vector<int> &x, int n, int b){
    
  if(b == 100) return 100000000;
  
  int y = 0;
  REP(i,n){
      y += (x[i] - b) * (x[i] - b);
  }

  
  return min(mn(x,n,b+1),y);
}
  

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  REP(i,n) cin >> x[i];
  
  int b = 0;


  
  cout << mn(x,n,b) << endl;
  
}


Measured memory_bytes: 3576
import scala.io.StdIn.{readLine, readInt};
object Main {
    def main(args: Array[String]): Unit = {
        val size = readInt;
        val am = new AdjacencyMatrices(size);
        (0 until size).foreach { i =>
            readLine.split(" ").map(_.toInt).toList match {
                case src :: num :: dsts => am.build(src, dsts);
                case _ => ();
            }
        }
        am.dump();
    }
}
class AdjacencyMatrices(size: Int) {
    val matrix = Array.ofDim[Int](size + 1, size + 1);
    def build(src: Int, dst: Seq[Int]): Unit = dst.foreach { i => matrix(src)(i) = 1 };
    def dump(): Unit = matrix.tail.foreach { dsts => println(dsts.tail.mkString(" "))};
}


Measured memory_bytes: 46680
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;
 
int main () {
	int n,i;
	int a,b,c,d,f,g;
	string s;
	cin >> a >> b >> c >> d >> f >> g ;
	cin >> s;
	n=s.size();
	int a1[n+1],a2[n+1],a3[n+1],a4[n+1],a5[n+1],a6[n+1];
	a1[0]=a; a2[0]=b; a3[0]=c; a4[0]=d; a5[0]=f; a6[0]=g;
	for(i=0;i<n;i++){
		if(s[i]=='S'){
			a1[i+1]=a5[i]; a2[i+1]=a1[i]; a3[i+1]=a3[i]; a4[i+1]=a4[i]; a5[i+1]=a6[i]; a6[i+1]=a2[i];
		}
		else if(s[i]=='N'){
			a1[i+1]=a2[i]; a2[i+1]=a6[i]; a3[i+1]=a3[i]; a4[i+1]=a4[i]; a5[i+1]=a1[i]; a6[i+1]=a5[i];
		}
		else if(s[i]=='W'){
			a1[i+1]=a3[i]; a2[i+1]=a2[i]; a3[i+1]=a6[i]; a4[i+1]=a1[i]; a5[i+1]=a5[i]; a6[i+1]=a4[i];
		}
		else if(s[i]=='E'){
			a1[i+1]=a4[i]; a2[i+1]=a2[i]; a3[i+1]=a1[i]; a4[i+1]=a6[i]; a5[i+1]=a5[i]; a6[i+1]=a3[i];
		}
	}
	cout << a1[n] << endl;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
speed_up;
string s;
cin>>s;
int a[200] = {};
int i, n;
n = s.length();
for(i = 0; i<n; i++)
{
    a[s[i]]++;
}
sort(a, a + 200);
for(i = 0; i<200; i++)
{
    if(a[i]%2 != 0)
    {
        cout<<"No"<<endl;
        return 0;
    }
}
cout<<"Yes"<<endl;

return 0;
}


Measured memory_bytes: 3568
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int[] b=cin.ArrayInt(N-1,0);
        int ans=b[0];
        for(int i=0;i<N-2;i++)
        {
            ans+=Math.Min(b[i],b[i+1]);
        }
        ans+=b[N-2];
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)
using ipair = pair<int,int>;

int main(){
    int X,N;
    cin >> X >> N;
    vector<int> p(N,0);
    vector<ipair> ip(N,make_pair(0,0));
    rep(i,0,N) cin >> p[i];
    sort(p.begin(),p.end());
    auto iter = upper_bound(p.begin(),p.end(),X);
    
    int add1=0;
    while(1){
        auto iter = find(p.begin(),p.end(),X+add1);
        if(iter==p.end()){break;};
        add1 ++;
    }
    int add2 = 0;
    while(1){
        auto iter = find(p.begin(),p.end(),X-add2);
        if(iter==p.end()){break;};
        add2 ++;
    }
    if(add1>=add2) cout << X-add2 << endl;
    else cout << X+add1 << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int main()
{
    ll n;
    cin>>n;
    ll xx=1,yy=1,zz=1,res=0;
    for(int i=0;i<n;i++)
    {
        xx*=10;
        xx%=mod;
        yy*=9;
        yy%=mod;
        zz*=8;
        zz%=mod;
    }
    res=xx-2*yy+zz;
    res%=mod;
    if(res<0)
    res+=mod;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void printArr(int[] arr) {
        String[] ss = new String[arr.length];
        for (int i = 0; i < arr.length; i++) {
            ss[i] = String.valueOf(arr[i]);
        }
        System.out.println(String.join(" ", ss));
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] inputs = new int[n];
        for (int i = 0; i < n; i++) {
            inputs[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = n - 1; j > i ; j--) {
                if(inputs[j - 1] > inputs[j]) {
                    int tmp = inputs[j];
                    inputs[j] = inputs[j - 1];
                    inputs[j - 1] = tmp;
                    cnt++;
                }
            }
        }
        printArr(inputs);
        System.out.println(cnt);
    }

}


Measured memory_bytes: 26308
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int fact(int n)
{
    return (n==1 || n==0) ? 1: n * fact(n - 1);
}
int main()
{
   int n;
   double sum(0);
   cin>>n;
   vpii vp(n);
   rep(i,n)
   {
       cin>>vp[i].F>>vp[i].S;
   }
   sort(all(vp));
   do{
      rep(i,n-1)
      sum+=hypot(vp[i+1].F - vp[i].F , vp[i+1].S - vp[i].S  );
   }while(next_permutation(all(vp)));
   cout<<fixed<<setprecision(10)<<sum/fact(n);

go;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int> a(n);
  for (auto& x : a) {std::cin >> x;}
  auto yes = [&] {
    std::cout << "Yes" << std::endl;
    exit(0);
  };
  auto no = [&] {
    std::cout << "No" << std::endl;
    exit(0);
  };
  if (std::none_of(a.begin(), a.end(), [](auto x){return x;})) yes();
  if (n % 3 != 0) no();
  int m = n / 3;
  std::sort(a.begin(), a.end());
  std::vector<std::vector<int>> b(3);
  for (int i = 0; i < 3; i++) {
    auto& c = b.at(i);
    c = std::vector<int>(a.begin() + i * m, a.begin() + (i + 1) * m);
    assert((int)c.size() == m);
    c.resize(std::unique(c.begin(), c.end()) - c.begin());
    if (c.size() != 1) no();
  }
  if (std::accumulate(b.begin(), b.end(), 0,
    [](auto x, auto c){return x ^ c.front();}) == 0) yes();
  else no(); 
  return 0;
}

Measured memory_bytes: 1024
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import math
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()

i = 0
a = 100

while True:
    i += 1
    a = math.floor(a * 1.01)
    if a >= X:
        print(i)
        break


Measured memory_bytes: 10632
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static int w=sc.nextInt();
	private static int first=sc.nextInt();
	private static int second=sc.nextInt();
	private static int dist;
	public static void main(String[] args){
		if(first>second){
			int t=first;
			first=second;
			second=t;
		}
		if(first+w<second) dist=second-first-w;
		else dist=0;
		System.out.println(dist);
	}
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vb = vector<bool>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second

#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

#define rv(type,name,count) vector<type> name(count); FOR(_i,0,count) cin >> name[_i];
#define grid(type,name,c1,c2) vector<vector<type>> name(c1, vector<type>(c2)); FOR(_i,0,c1)FOR(_j,0,c2)cin >> name[_i][_j];

int main() {
	string a, b;
	cin >> a >> b;
	vvl v(sz(b) + 1, vl(sz(a)+1));
	FOR(i, 1, sz(b)+1) {
		FOR(k,1,sz(a)+1) {
			if (a[k-1] == b[i-1]) {
				v[i][k] = 1 + v[i-1][k-1];
			} else {
				v[i][k] = max(v[i-1][k], v[i][k-1]);
			}
			//cout << v[i][k] << " ";
		}
		//cout << endl;
	}
	string res = "";
	ll row = sz(b), col = sz(a);
	while (row > 0 && col > 0) {
		//cerr << row << " " << col << endl;
		if (a[col-1] == b[row-1]) {
			res = a[col-1] + res;
			row--;
			col--;
		} else if (v[row-1][col] > v[row][col-1]) {
			row--;
		} else {
			col--;
		}
	}
	cout << res << endl;
	//cout << v[sz(b)][sz(a)] << endl;
}


Measured memory_bytes: 70784
n,k = map(int, raw_input().split())
from fractions import gcd

if n % k== 0:
  print 0
else:
  mini = n
  s = set()
  while True:
    if n > k:
      n = n % k
    else:
      n = abs(n-k)
    mini = min(n, mini)
    if n in s:
      print mini
      break
    s.add(n)
    


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

int main()
{
  int A,B,C,X;
  cin >> A >> B >> C >>X;
  cout << endl;
  
  int res=0;
  
  for(int i=0; i<=A; ++i)
  {
    for(int j=0; j<=B; ++j)
    {
      for(int k=0; k<=C; ++k)
      {
        int total = 500*i + 100*j + 50*k;
        if(total==X) ++res;
      }
    }
  }
  
  cout << res << endl;
  
  return 0;
}

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


using namespace std;


using ll = long long;
mt19937 mt(736);


class dsu
{
	vector<int> par, siz;

public:
	dsu(int n) : par(n, -1), siz(n, 1)
	{}

	int get_class(int v)
	{
		return par[v] == -1 ? v : par[v] = get_class(par[v]);
	}

	bool unite(int a, int b)
	{
		a = get_class(a);
		b = get_class(b);

		if (a == b)
			return false;

		siz[a] += siz[b];
		par[b] = a;

		return true;
	}
};


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n, m;

	cin >> n >> m;

	vector<pair<int, int>> edges(m);

	for (auto &it : edges)
	{
		cin >> it.first >> it.second;
		it.first--;
		it.second--;
	}

	if (m % 2 == 1)
	{
		cout << -1 << endl;

		return;
	}

	vector<set<int>> gr(n), tree(n);
	vector<bool> num(n);

	dsu Kr(n);

	vector<pair<int, int>> ord;

	for (auto it : edges)
	{
		gr[it.first].insert(it.second);
		gr[it.second].insert(it.first);

		if (Kr.unite(it.first, it.second))
		{
			tree[it.first].insert(it.second);
			tree[it.second].insert(it.first);
		}
		else
			ord.push_back(it);
	}

	set<int> leaves, alive;

	for (int i = 0; i < n; i++)
		if (!gr[i].empty())
		{
			alive.insert(i);

			if (gr[i].size() == 1)
				leaves.insert(i);
		}

	vector<vector<int>> ans(n);

	while (!alive.empty())
	{
		int q, w;

		if (ord.empty())
		{
			assert (!leaves.empty());

			q = *leaves.begin();
			w = *gr[q].begin();
		}
		else
		{
			q = ord.back().first;
			w = ord.back().second;

			ord.pop_back ();
		}

		if (num[q])
		{
			ans[q].push_back(w);
			num[q] = !num[q];
		}
		else
		{
			ans[w].push_back(q);
			num[w] = !num[w];
		}

		gr[q].erase(w);

		if (gr[q].size() == 1)
			leaves.insert(q);
		if (gr[q].empty())
		{
			leaves.erase(q);
			alive.erase(q);
		}

		gr[w].erase(q);

		if (gr[w].size() == 1)
			leaves.insert(w);
		if (gr[w].empty())
		{
			leaves.erase(w);
			alive.erase(w);
		}
	}

	if (count(num.begin(), num.end(), true) != 0)
	{
		cout << -1 << endl;

		return;
	}

	for (int i = 0; i < n; i++)
		for (auto j : ans[i])
			cout << i + 1 << ' ' << j + 1 << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4);
	cout << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 40192
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	ll n;
	cin >> n;
	vl v(3*n);
	rep(i, 3 * n) cin >> v[i];
	vl s1(3 * n), s2(3 * n);
	{
		priority_queue<ll> q;
		ll sum = 0LL;

		q.push(-v[0]);
		sum = v[0];
		s1[0] = sum;

		for(int i = 1; i < 3*n; i++) {
			if(q.size() == n) {
				ll tmp = -q.top();
				if(tmp < v[i]) {
					sum -= tmp;
					sum += v[i];
					q.pop();
					q.push(-v[i]);
				}
			}
			else q.push(-v[i]), sum += v[i];
			s1[i] = max(sum, s1[i-1]);
		}
	}
	{
		priority_queue<ll> q;
		ll sum = 0LL;

		q.push(v[3*n-1]);
		sum = v[3*n-1];
		s2[3*n-1] = sum;

		for(int i = 3*n-2; i >= 0; i--) {
			if(q.size() == n) {
				ll tmp = q.top();
				if(tmp > v[i]) {
					sum -= tmp;
					sum += v[i];
					q.pop();
					q.push(v[i]);
				}
			}
			else q.push(v[i]), sum += v[i];
			s2[i] = sum;
			if(i < 2*n-1) s2[i] = min(s2[i], s2[i+1]);
		}
	}
	ll ans = -1e18;
	for(int i = n-1; i < 2*n; i++) ans = max(ans, s1[i] - s2[i+1]);
	cout << ans << endl;
	// rep(i, 3*n) cout << s1[i] <<" ";
	// cout << endl;
	// rep(i, 3*n) cout << s2[i] <<" ";
	// cout << endl;
}


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

cnt = a.pop()
tmp = a.pop()
l = 0
for i in range(n - 2):
    if l == 2:
        l = 0
        tmp = a.pop()
    cnt += tmp
    l += 1
print(cnt)

Measured memory_bytes: 31392
# coding: utf-8
# Your code here!
n=input().rstrip().split(" ")
n[1]=int(n[1])
n[0]=int(n[0])
i=0
l=""
seter=n[1]
d=0
ans=1
l=input().rstrip().split(" ")
for i in range(len(l)):
    l[i]=int(l[i])
    d=d+l[i]
    if(seter >=d):
        ans=ans+1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int N;
  cin >> N;
  int sum;
  for(int i=1; i<=N; ++i) sum += i;
  cout << sum << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, C;
    cin >> A >> B >> C;

    if(A == B){
        cout << C << endl;
    }else if(A == C){
        cout << B << endl;
    }else if(B == C){
        cout << A << endl;
    }

}

Measured memory_bytes: 256
import collections
N = int(input())
S = []
for i in range(N):
    st = str(input())
    S.append(st[0])
    
#print(S)

c = collections.Counter(S)
#print(c)
count = []
for i in c.items():
    if i[0] in 'MARCH':
        count.append(i[1])
#print(count)
ans = 0
for i in range(len(count)):
    for j in range(i+1,len(count)):
        for k in range(j+1,len(count)):
            #print(i,j,k)
            ans += count[i]*count[j]*count[k]
            
if len(count) != 0:
    print(ans)
else:
    print(0)


Measured memory_bytes: 10232