akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 100010
int main(){
  int n,t[N],x[N],y[N];
  cin>>n;
  t[0]=0,x[0]=0,y[0]=0;
  lol(i,n)cin>>t[i+1]>>x[i+1]>>y[i+1];
  bool ok=true;
  lol(i,n){
    int k=t[i+1]-t[i];
    int d=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(!(k>=d&&(d-k)%2==0))ok=false;
    //cout<<"#"<<k<<" "<<d<<endl;
  }
  cout<<(ok?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 1408
maxm = 10000
def makelist(l, n, m):
	return [[[maxm for i in range(m)] for j in range(n)] for k in range(l)]

N, Ma, Mb = map(int, input().split())
drugs = [0]*N
for i in range(N):
	a, b, c = map(int, input().split())
	drugs[i] = (a, b, c)

dp = makelist(N, 401, 401)
a0, b0, c0 = drugs[0]
dp[0][a0][b0] = c0
dp[0][0][0] = 0
for i in range(1, N):
	a, b, c = drugs[i]
	for ia in range(401):
		for ib in range(401):
			if ia - a < 0 or ib - b < 0:
				dp[i][ia][ib] = dp[i-1][ia][ib]
			else:
				dp[i][ia][ib] = \
					min(dp[i-1][ia][ib], dp[i-1][ia-a][ib-b] + c)

i = 1
ans = maxm
while Ma * i <= 400 and Mb * i <= 400:
	now = dp[N-1][Ma*i][Mb*i]
	ans = min(ans, now)
	i += 1

if ans < maxm:
	print(ans)
else:
	print(-1)


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

int main(void)
{
	int a,b = 0;
	int i;
	std::cin >> a >> b;

	for ( i = 1; i<=b; ++i){
		if(b%i == 0){
			if (a == i){
				std::cout << a+b << std::endl;
				return 0;
			}
		}
	}
	std::cout << b-a << std::endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
data = list(map(int, input().split()))
a = list(itertools.combinations(data,3))
b = []
for i in range(len(a)):
  a[i] = sorted(a[i])
  if a[i][0] != a[i][1] and a[i][1] != a[i][2] and a[i][2] != a[i][0]:
    if a[i][2] < a[i][0] + a[i][1]:
      b.append(a[i])
print(len(b))

Measured memory_bytes: 29396
from fractions import gcd
from itertools import accumulate

n, x, d = map(int, input().split())

if d == 0:
    if x == 0:
        print(1)
    else:
        print(n + 1)
    exit()
elif d < 0:
    x, d = -x, -d

g = gcd(x, d)
back_k = d // g
offset = x // g

lowers = [0] + list(accumulate(range(n)))
uppers = [0] + list(accumulate(range(n - 1, -1, -1)))
min_memo = [10 ** 18] * min(n + 1, back_k)
max_memo = [-(10 ** 18)] * min(n + 1, back_k)


ans = 0
for k in range(n + 1):
    min_acc = lowers[k]
    max_acc = uppers[k]

    if k < back_k:
        min_memo[k] = min_acc - offset
        max_memo[k] = max_acc - offset
        ans += max_acc - min_acc + 1
      
        continue

    kk = k % back_k
    back_min = min_memo[kk]
    back_max = max_memo[kk]

    if back_max < min_acc or max_acc < back_min:
        min_memo[kk] = min_acc - offset
        max_memo[kk] = max_acc - offset
        ans += max_acc - min_acc + 1
    else:
        current = max_acc - min_acc + 1
        duplicated = min(max_acc, back_max) - max(min_acc, back_min) + 1
        ans += current - duplicated
        min_memo[kk] = min(min_acc, back_min) - offset
        max_memo[kk] = max(max_acc, back_max) - offset

    

print(ans)


Measured memory_bytes: 42184
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; 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 MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    VI h(N);
    REP(i, N) cin >> h[i];
    VI dp(N, INF);
    dp[0] = 0;
    REP(i, N-1) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        if (i + 2 < N) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[N - 1] << endl;
    getchar(); getchar();
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

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

	int g = 0;
	rep(i,n) g=__gcd(g,a[i]);

	bool ok = true;
	if(k%g!=0) ok = false;
	if(*max_element(begin(a),end(a))<k) ok=false; 
	
	if(ok)
		puts("POSSIBLE");
	else
		puts("IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int x;
    cin>>x;
    int temp=x;
    int sum=0;
    while(temp!=0)
    {
        sum+=temp%10;
        temp/=10;
    }
    if(x%sum==0)
    {
        cout<<"Yes";
    }
    else
    cout<<"No";
}

Measured memory_bytes: 3652
N,M = map(int,input().split())
L,R = [],[]
for _ in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

res = min(R)-max(L)+1
if res > 0:
    print(res)
else:
    print(0)

Measured memory_bytes: 10996
#include<iostream>
int main() {
	int n;
	while (std::cin >> n){
		if (n == 0)break;
		int l[11][11];
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++)
				std::cin >> l[i][j];
			l[i][n] = 0;
			for (int j = 0; j < n; j++)
				l[i][n] += l[i][j];
		}
		for (int i = 0; i < n + 1; i++){
			l[n][i] = 0;
			for (int j = 0; j < n; j++){
				l[n][i] += l[j][i];
			}
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				std::cout.width(5);
				std::cout << l[i][j];
			}
			std::cout << std::endl;
		}
	}
}

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

void Print(int A[], int N)
{
	for (int i = 0; i < N-1 ; i++)
	{
		cout << A[i] << " ";
	}
	cout << A[N-1]<<endl;
}

int main()
{
	int A[100];
	int N;
	cin >> N;
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = N - 1; j > i; j--)
		{
			if (A[j] < A[j - 1])
			{
				swap(A[j], A[j - 1]);
				sum++;
			}
		}

	}
	Print(A, N);
	cout << sum<<endl;
	return 0;
}


Measured memory_bytes: 3068
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hope the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 5010;

int mod;

inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }

int f[MAXN][MAXN];
int g[MAXN][MAXN];
int S[MAXN * 2];

int main() {
	int n = ri; mod = ri;
	int N = (n + 1) / 2;

	f[0][0] = 1;
	for(int i = 1; i <= N; i++)
		for(int j = 0; j <= n; j++)
			for(int k = j; k <= n; k += i)
				Add(f[i][k], f[i - 1][j]);

	g[0][0] = 1;
	for(int i = N - 1; i >= 1; i--) {
		for(int j = 0; j <= n; j++) {
			if(i * j >= n) break;
			for(int k = i * j; i + k <= n; k++)
				if(i + k <= n)
					Add(g[j + 1][k + i], g[j][k]);
		}
	}

	for(int i = 0; i <= n; i++)
		for(int j = 1; j <= n; j++)
			Add(g[i][j], g[i][j - 1]);
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= n; j++)
			Add(g[i][j], g[i - 1][j]);

	int n1 = N, n2 = N - 1;
	int res = 0;
	if(!(n & 1)) {
		for(int x = 1; x <= n; x++)
			for(int i = 0; i < x; i++)
				res = (res + 1LL * f[n1][i] * g[n - x][x - i - 1]) % mod;
	} else {
		for(int x = 1; x <= n; x++)
			for(int i = 0; i < x; i++)
				res = (res + 1LL * f[n1 - 1][i] * g[n - x][x - i - 1]) % mod;
	}
	printf("%d\n", res);
	return 0;
}

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

int main(){
  int p[3];
  cin >> p[0] >> p[1] >> p[2];
  
  sort(p, p + 3, greater<int>());
  
  if (p[0] == p[1]+p[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

void Main()
{
	int K, X; cin >> K >> X;
	int l = X - (K - 1);
	int r = X + (K - 1);
	for (int i = l; i <= r; ++i) {
		cout << i;
		if (i == r) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

using namespace std;

#define run_forrest_run ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define fi first
#define se second
#define si set <int>
#define all(x) (x).begin(),(x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);} 

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

const int N = 205000;
vector <int> g[N];
vector <bool> visited(N);
vector <int> color(N);
double dp[3010][3010];

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

	dp[1][1] = p[1];
	dp[1][0] = 1 - p[1];
	for (int i = 2; i <= n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (j == 0)
				dp[i][j] = dp[i-1][j] * (1 - p[i]);
			
			else dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * (p[i]);
		}
	}
	double ans = 0;
	for (int i = (n+1)/2; i <= n; i++)
		ans+=dp[n][i];
	cout << setprecision(10) << fixed  << ans;
}


Measured memory_bytes: 75008
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            if(N == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                var A = int.Parse(Console.ReadLine());
                var B = int.Parse(Console.ReadLine());
                Console.WriteLine(A + B);
            }
        }
    }
}


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

int main() {
    string str;
    string key="keyence";
    int i, j;
    cin >> str;
    for(i=0;i<key.size();i++){
        if(str[i]!=key[i]){
            break;
        }
    }
    for(;i<key.size();i++){
        if(str[str.size()-key.size()+i]!=key[i]){
            break;
        }
    }
    if(i==7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void loop (i64 *a, i32 n, i32 k, i64 *res, i32 *len) {
  static i64 val = 0;
  if (k == 0) {
    res[(*len)++] = val;
    return;
  }
  if (n < k) return;
  val += a[0];
  loop (a + 1, n - 1, k - 1, res, len);
  val -= a[0];
  loop (a + 1, n - 1, k, res, len);
  return;
}

int cmp (const void *a, const void *b) {
  i64 d = *(i64 *)a - *(i64 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

i64 calc (i64 *a, i32 alen, i64 *b, i32 blen, i64 lim) {
  i64 res = 0;
  i32 j = 0;
  for (i32 i = alen - 1; i >= 0; --i) {
    while (j < blen && a[i] + b[j] <= lim) j++;
    res += j;
  }
  return res;
}

void run (void) {
  i32 n, k;
  i64 l, r;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi64 "%" SCNi64, &n, &k, &l, &r);
  i64 *a = (i64 *) calloc (n, sizeof (i64));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi64,a + i);
  }
  i64 ans = 0;
  i32 m = n / 2;
  i64 *front = (i64 *) calloc (184756, sizeof (i64));
  i64 *back = (i64 *) calloc (184756, sizeof (i64));
  for (i32 i = 0; i <= k; ++i) {
    i32 front_len = 0;
    loop (a, m, i, front, &front_len);
    i32 back_len = 0;
    loop (a + m, n - m, k - i, back, &back_len);
    qsort (front, front_len, sizeof (i64), cmp);
    qsort (back, back_len, sizeof (i64), cmp);
    ans += calc (front, front_len, back, back_len, r);
    ans -= calc (front, front_len, back, back_len, l - 1);
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run ();
  return 0;
}



Measured memory_bytes: 6308
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int m,f,r;
		int sum;
		Scanner scan = new Scanner(System.in);
		while(true){
			m=scan.nextInt();
			f=scan.nextInt();
			r=scan.nextInt();
			if((m == -1)&&(f == -1)&&(r == -1))
				break;
			sum=m+f;
			if((m == -1)||(f == -1)||sum<30)
				System.out.println("F");
			else if(sum>=80)
				System.out.println("A");
			else if(sum>=65)
				System.out.println("B");
			else if(sum>=50||r>=50)
				System.out.println("C");
			else
				System.out.println("D");
		}
	}

}


Measured memory_bytes: 26312
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};


int main(){
  int n, m;
  fastScan(n);
  fastScan(m);
  for(int i = 0; i <= n; i++){
    int tot = i * 2 + (n - i) * 4;
    if(tot == m){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int Maxn=100005,maxi=100000;
int fa[2*Maxn],cnt[2*Maxn];
int get_fa(int x)
{
	return x==fa[x]?fa[x]:fa[x]=get_fa(fa[x]);
}
void merge(int x,int y)
{
	int a=get_fa(x),b=get_fa(y);
	if(a!=b)
	{
		cnt[b]+=cnt[a];
		fa[a]=b;
	}
}
int n;
long long tot,ans[2*Maxn][3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*maxi;i++)
		fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y+maxi);
		cnt[get_fa(x)]++;
	}
	for(int i=1;i<=maxi;i++)
		ans[get_fa(i)][1]++;
	for(int i=maxi+1;i<=2*maxi;i++)
		ans[get_fa(i)][2]++;
	for(int i=1;i<=2*maxi;i++)
		if(get_fa(i)==i) tot+=(ans[i][1]*ans[i][2]-cnt[i]);
	printf("%lld",tot);
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    int mx = *max_element(arr.begin(), arr.end());
    int mn = *min_element(arr.begin(), arr.end());
    cout << (mx - mn) << endl;
    return 0;
}


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

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

    ll sum = 0;
    for(int i = 1; i <= n; ++i){
        sum += i-1;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;
	   int ans = 0;
	   m = n;
	   int k = 0;
	vvint dic;
	initvv(dic,10,10,0);
	for(int a = 1;a <= n ;a++){
		int f = a%10;
		int l = a;
		while(l >= 10){l/=10;}
		dic[l][f]++;
	}
	for(int a = 1;a <= n ;a++){
		int f = a%10;
		int l = a;
		while(l >= 10){l/=10;}
		if(f!=0){ans += dic[f][l];}
	}
	/*while(m>0){m/=10;k++;}
	for(int a = 1;a <= n;a++){
		int f = a%10;
		int l = a;
		while(l >= 10){l/=10;}
		if(f==0)continue;
		if(f==l&&f<=n)ans++;
		int cou = 1;
		while(1){
			if((int)pow(10,cou)*f+l > n){
				break;
			}
			if(k==cou+1){
				if(k!=2){ans+=(n-(int)pow(10,cou)*f-l)/10;}
				else{ans+=1;}
			}else{
			ans += (int)pow(10, (cou-1));}
			cou++;
		}
		//cout << a << ' ' << ans << endl;

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


Measured memory_bytes: 256
M,D=map(int,input().split(" "))
cnt=0
for m in range(M):
    for d in range(D):
        m1=m+1
        d1=d+1
        if len(str(d1))==1:
            continue
        if int(str(d1)[0])>=2 and int(str(d1)[1])>=2 and int(str(d1)[0])*int(str(d1)[1])==m1:

            cnt+=1
print(cnt)

Measured memory_bytes: 3064
n=int(input())
l=list(map(int,input().split()))
s=[]
a=l[0]
b=-l[0]
for i in l:
    b+=i
c=a-b
s=[abs(c)]
for i in range(1,n-1):
    c+=2*l[i]
    s.append(abs(c))
print(min(s))

Measured memory_bytes: 24812
def solve(k):
    a_mod = 0
    pow_10 = 7
    for i in range(1000000):
        a_mod += pow_10
        a_mod %= k
        if a_mod == 0:
            return i + 1
        pow_10 *= 10
        pow_10 %= k
    return -1


def main():
    k = int(input())
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)
#define ll long long

int main()
{
    int a,b;
    cin >> a >> b;
    if(a%2 == 0 || b%2 == 0){
        cout << "No" <<endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}


int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
	
	int n;
	cin >> n;
	vi v;
	for(int i=0;i<n;i++)
	v.PB(i+1);
	vi p,q;
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		p.PB(a);
	}
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		q.PB(a);
	}
	int A,B;
	int i = 1;
	do{
		if(q == v)
		A = i;
		if(p == v)
		B = i;
		i++;
	}while(next_permutation(all(v)));
	cout << abs(B-A);
	return 0;
}



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

int f[100005];
int K;

typedef pair<int,int> ii;

int sum(int x) {
	int ret = 0; while(x) ret += x % 10, x /= 10; return ret;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> K;
	priority_queue < ii, vector<ii>, greater<ii> > q;
	for (int i = 1; i <= K; ++i) f[i % K] = sum(i), q.push(ii(sum(i), i % K));
	
	while(!q.empty()) {
		ii t = q.top(); q.pop();
		int mod = t.second, ff = t.first;
		if (ff != f[mod]) continue;
		if (mod == 0) {
			printf("%d\n", ff);
			return 0;
		}
		for (int dig = 0; dig < 10; ++dig) {
			int nxt = (mod * 10 + dig) % K;
			if (f[nxt] > ff + dig) {
				f[nxt] = ff + dig;
				q.push(ii(f[nxt], nxt));
			}
		}
	}
}

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


long long n,a,m,k,q,b,c,a1,a2,b1,b2;
float qq,ww,ff=2,qs;
string ss,s1,s2;
int main(){
    cin>>ss;
    for (int i=0; i<ss.size(); i++){
        cout<<'x';
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int cnt;
void insertionSort(int n, int A[], int g){
    int i,j,v;
    for (i=g;i<n;i++){
        v=A[i];
        j=i-g;
        while(j>=0&&A[j]>v){
            A[j+g]=A[j];
            j=j-g;
            cnt++;
        }
        A[j+g]=v;
    }
}

void answer(int n, int A[]){
    int i;
    for(i=0;i<n;i++) cout << A[i] << endl;
}

void shellSort(int n, int A[]){
    int m;
    cnt=0;
    m = (int)(log(n<3?3:n)/log(3));
    int G[m],g,i;
    g=n;
    for(i=0;i<m;i++){
        g = (int)g/3;
        if(i==m-1)g=1;
        G[i]=g;
        insertionSort(n,A,g);
    }
    cout << m << endl;
    for(i=0;i<m;i++) cout << (i!=0?" ":"") << G[i];
    cout << endl << cnt << endl;
    answer(n,A);
}

int main(){
    int n;
    cin >> n;
    int A[n-1],i;
    for(i=0;i<n;i++) cin >> A[i];
    shellSort(n,A);
    return 0;
}


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

int main(){
  int A,B,C;cin >> A >> B >> C;
  for(int i=1;i<=B;i++){
    if((A*i)%B==C){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int A[mn];
int n;
bool check_asc() {
    for (int i=2; i<=n; i++) if (A[i] < A[i-1]) return 0;
    return 1;
}
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    for (int i=1; i<=n; i++) {
        cin>>A[i];
    }

    if (check_asc()) {
                cout<<"YES\n";
                return;
            }

    for (int i=1; i<=n; i++) {
        for (int j=i+1; j<=n; j++) {
            int temp = A[i];
            A[i] = A[j];
            A[j] = temp;
            if (check_asc()) {
                cout<<"YES\n";
                return;
            }
            temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    cout<<"NO";
    return;

}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

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

struct StQuery
{
  StQuery() : m_nLeft(0), m_nRigt(0) { }

  int m_nLeft;
  int m_nRigt;
};

void input(string& rsStr, vector<StQuery>& rvoQuery)
{
  int nStrSiz, nQuerySiz;
  cin >> nStrSiz >> nQuerySiz;
  rvoQuery.resize(nQuerySiz);

  cin >> rsStr;
  
  for (StQuery& roQuery : rvoQuery)
    cin >> roQuery.m_nLeft >> roQuery.m_nRigt;
}

void calcSubStrACCnt(string sStr, const vector<StQuery>& cnrvoQuery)
{
  vector<int> vnCumlSum(sStr.size() + 1);      // 累積和

  //vnCumlSum_ix 0 1 2 3 4 5 6 7 8
  //sStr_pos      1 2 3 4 5 6 7 8
  //sStr          A C A C T A C G
  //sStr_ix       0 1 2 3 4 5 6 7
  for (int nBgn = 0; nBgn < vnCumlSum.size() - 1; nBgn++)
  {
    vnCumlSum[ nBgn + 2 ] = vnCumlSum[ nBgn + 1 ];
    if (sStr[nBgn] == 'A' && sStr[nBgn + 1] == 'C')
      vnCumlSum[ nBgn + 2 ]++;
  }

 for (int i = 0; i < cnrvoQuery.size(); i++)
  {
    cout << vnCumlSum[ cnrvoQuery[i].m_nRigt ] - vnCumlSum[ cnrvoQuery[i].m_nLeft ];
    cout << endl; 
  }
}
 
int main()
{
  string sStr;
  vector<StQuery> voQuery;

  input(sStr, voQuery);
  calcSubStrACCnt(sStr, voQuery);

  return 0;
}

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n,a,b;
  
  cin >>n>>a>>b;
  
  if((b-a)%2==0){
    cout<<(b-a)/2<<endl;
    return 0;
  }
  else if(a<=n+1-b){
    cout<<(b+a-1)/2<<endl;
    return 0;
  }
  else{
  cout<<(2*n+1-a-b)/2<<endl;
  }
  
  return 0;
}

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


int main (){
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    rep(i,n){
        cin >> a[i].first ;
        a[i].second = i+1;
    }
    sort(a.begin(),a.end());
    rep(i,n){
        cout << a[i].second << " ";
    }
    return 0;

}

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

int main()
{
    long long n, sum;
    string f;
    char b[10];
    map<string, int> zm;
    while (cin >> n)
    {
        sum = 0;
        zm.clear();
        for (long long i = 0; i < n; i++)
        {
            cin >> b;
            sort(b, b + 10);
            f = b;
            sum += zm[f];
            zm[f] += 1;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 8064
main(){
  int l=1000010,n,q;
  int d[l];
  long long m[l],c[l],x[l];
  char s[l];
  for(int i=0;i<l;i++)d[i]=-1;
  scanf("%d%s%d",&n,s,&q);
  int j=0;
  for(int i=1;i<=n;i++){
    m[i]=m[i-1];
    c[i]=c[i-1];
    x[i]=x[i-1];
    if(s[i-1]=='D')d[j++]=i-1;
    else if(s[i-1]=='M')m[i]++;
    else if(s[i-1]=='C'){
      c[i]++;
      x[i]+=m[i];
    }
  }
  while(q--){
    long long a=0;
    int k;
    scanf("%d",&k);
    for(int i=0;d[i]>-1;i++){
      int j=d[i];
      int l=j+k;
      if(l>n)l=n;
      a+=x[l]-x[j]-(c[l]-c[j])*m[j];
    }
    printf("%lld\n",a);
  }
}

Measured memory_bytes: 28544
def gcd(a,b):
    k=0
    while b != 0:
        r=a%b
        a=r
        a,b=b,a
        k+=1
    return[a,k]
        
while True:
    m,n=map(int,input().split())
    if m==0:break
    if m<n:m,n=n,m
    ans = gcd(m, n) #print(math.gcd(a, b)) #二つの整数を渡すと最大公約数を返す    s=0
    print(*ans)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

#define N 500
ll a[N][N];
ll now[N];
ll n,m;
ll dfs(ll p,ll cou){
    ll ma,mb;
    if(p==n){
        bool flag=true;
        rep(i,0,m-1)if(now[i]%2==1)flag=false;
        if(flag)return cou;
        else return 0;
    }
    ma=dfs(p+1,cou);
    rep(i,0,m-1){
        now[i]+=a[p][i];
    }
    mb=dfs(p+1,cou+1);
    rep(i,0,m-1){
        now[i]-=a[p][i];
    }
    return max(ma,mb);
}

bool ansproblem(){
    string str[n];rep(i,0,n-1)cin>>str[i];
    rep(i,0,n-1)rep(j,0,m-1)a[i][j]=(str[i][j]-'0');
    if(n<=m){
        memset(now,0,sizeof(now));
        cout<<dfs(0,0)<<endl;
        return 0;
    }else{
        ll xorr[n];memset(xorr,0,sizeof(xorr));
        rep(i,0,n-1){
            rep(j,0,m-1){
                if(a[i][j])xorr[i]+=(1<<j);
            }
        }
        ll dp[2][1<<m];
        rep(i,0,1)rep(j,0,(1<<m)-1)dp[i][j]=-inf;
        dp[0][0]=0;
        rep(i,0,n-1){
            rep(j,0,(1<<m)-1){
                Max(dp[(i+1)&1][j],dp[i&1][j]);
                Max(dp[(i+1)&1][j^xorr[i]],dp[i&1][j]+1);
            }
        }
        cout<<dp[n&1][0]<<endl;
        return 0;
    }
    return 0;
}

int main(){fastio
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)return 0;
        ansproblem();
    }
    return 0;
}



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

#define ll long long
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define rfo(i,n,a) for(ll i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t,n,i,j;
    cin>>t>>n;
    ll jo=(4*t-n);
    if(jo%2==0 && n>=2*t && n<=4*t && jo/2>=0 && jo/2<=t)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 3644
def idx_cmb(n, r):
    import itertools
    lst1 = [i for i in range(0, n)]
    lst = list(itertools.combinations(lst1, r))
    return lst


def main():
    n = int(input())
    s_lst = [str(input()) for _ in range(n)]

    march = [0] * 5
    for i in range(n):
        s = s_lst[i]
        if s[0] == 'M':
            march[0] += 1
        elif s[0] == 'A':
            march[1] += 1
        elif s[0] == 'R':
            march[2] += 1
        elif s[0] == 'C':
            march[3] += 1
        elif s[0] == 'H':
            march[4] += 1

    idx_lst = idx_cmb(5, 3)
    x = 0
    for i in range(len(idx_lst)):
        idx1 = idx_lst[i][0]
        idx2 = idx_lst[i][1]
        idx3 = idx_lst[i][2]
        number1 = march[idx1]
        number2 = march[idx2]
        number3 = march[idx3]
        x += number1 * number2 * number3

    print(x)


if __name__ == '__main__':
    main()

Measured memory_bytes: 16008
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	char s[52][52], t[52][52];
	for(int i=0; i<h; i++){
		scanf("%s", s[i]);
	}
	for(int j=0; j<=w+1; j++){
		t[0][j]='.';
		t[h+1][j]='.';
	}
	for(int i=1; i<=h; i++){
		for(int j=0; j<=w+1; j++){
			if(j==0 || j==w+1){
				t[i][j]='.';
			}else{
				t[i][j]=s[i-1][j-1];
			}
		}
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(t[i][j]=='#' && t[i-1][j]=='.' && t[i+1][j]=='.' && t[i][j-1]=='.' && t[i][j+1]=='.'){
				printf("%s\n", "No");
				return 0;
			}
		}
	}
	printf("%s\n", "Yes");			

	return 0;
}

Measured memory_bytes: 128
# N = gets.chomp.to_i
# A, B, C = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars

n = S.size
if (n % 2) == 1
  print "No\n"
else
  ans = true
  0.upto(n-1).each do |i|
    if (i % 2 == 0)
      if S[i] != 'h'
        ans = false
        break
      end
    else # i%2 == 1
      if S[i] != 'i'
        ans = false
        break
      end
    end
  end
  if ans
    print "Yes\n"
  else
    print "No\n"
  end
end



Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int a,i;
string s;
int main()
{
	cin>>s;
	a=10*(s[0]-'0')+(s[1]-'0');
	i=10*(s[2]-'0')+(s[3]-'0');
	if((a<1||a>12)&&(i<1||i>12))
	{
		cout<<"NA";
	}
	else if(a<=12&&a>=1&&i<=12&&i>=1)
	{
		cout<<"AMBIGUOUS";
	}
	else if(a<1||a>12)
	{
		cout<<"YYMM";
	}
	else
	{
		cout<<"MMYY";
	}
	return 0;
}

Measured memory_bytes: 256
line = input()
A = line.split()

stack = []

for c in A:
    if c == '+':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs + rhs)
    elif c == '-':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs - rhs)
    elif c == '*':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs * rhs)
    else:
        stack.append(int(c))


print(stack.pop())

Measured memory_bytes: 7684
#include <cstdio>
template<typename T>
void swap(T& a,T& b){
  T temp = a;
  a = b;
  b = temp;
}
int partition(int* A, int p, int r){
  int x = A[r];
  int i = p-1;
  for (int j = p ; j< r ; j++){
    if (A[j] <= x){
      i = i+1;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

int main(){
  int n;
  int A[100000];
  scanf("%d", &n);
  for(int i=0;i<n;i++)
    scanf("%d", &A[i]);
  int dividedIndex = partition(A, 0, n-1);
  for (int i=0;i<n;i++){
    if (i!=0)
      printf(" ");
    if (i==dividedIndex) printf("[%d]", A[i]);
    else printf("%d", A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3124
// 2020-08-16 10:52:26
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define REP(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}

bool is_palindrome(string const& s) {
  return equal(s.begin(), s.end(), s.rbegin());
}

bool is_prefix(string const& s, string const& t) {
  if(s.size() < t.size()) return false;
  return equal(s.begin(), s.begin() + t.size(), t.begin());
}

bool is_suffix(string const& s, string const& t) {
  if(s.size() < t.size()) return false;
  return equal(s.rbegin(), s.rbegin() + t.size(), t.rbegin());
}

string prefix_removed(string const& s, string const& t) {
  return string(s.begin() + t.size(), s.end());
}

string suffix_removed(string const& s, string const& t) {
  return string(s.begin(), s.end() - t.size());
}

const ll inf = 1e18;
int n;
vector<string> S;
vector<ll> C;
ll bfs(int flr, int fi) { // l = 0, r = 1
  using State = pair<string, int>; // u, lr
  using Q = pair<ll, State>; // d, state
  map<State, ll> D; // state, d
  auto update = [&](ll d, State state) {
    if(D.count(state) == 0) D[state] = inf;
    return chmin(D[state], d);
  };
  priority_queue<Q, vector<Q>, greater<Q> > que;
  que.emplace(Q(C[fi], State(S[fi], flr)));
  ll res = inf;
  while(!que.empty()) {
    ll d; State state;
    tie(d, state) = que.top(); que.pop();
    if(!update(d, state)) continue;
    string u; int lr;
    tie(u, lr) = state;
    if(is_palindrome(u)) {
      chmin(res, d);
      continue;
    }
    rep(i, n) {
      string s = u, t = S[i];
      ll nd = d + C[i];
      if(lr == 1) swap(s, t);
      {
        string rt = t;
        reverse(ALL(rt));
        if(is_prefix(s, rt)) {
          string nu(prefix_removed(s, rt));
          que.emplace(Q(nd, State(nu, 0)));
        }
      }
      {
        string rs = s;
        reverse(ALL(rs));
        if(is_suffix(t, rs)) {
          string nu(suffix_removed(t, rs));
          que.emplace(Q(nd, State(nu, 1)));
        }
      }
    }
  }
  return res;
}
void answer() {
  cin >> n;
  rep(i, n) {
    string s;
    ll c;
    cin >> s >> c;
    S.push_back(s);
    C.push_back(c);
  }
  ll ans = inf;
  rep(i, n) {
    chmin(ans, bfs(0, i));
    chmin(ans, bfs(1, i));
  }
  if(ans == inf) ans = -1;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        int P, Q, R;
        std::cin >> P >> Q >> R;
        std::cout << P + Q + R - max({P, Q, R}) << std::endl;

    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <class Q>
void clearQueue(Q & q) {
    q = Q();
}
void solve(){
	int maxx=-1;
    int len=0;
    string s;cin>>s;
    for(int i=0;i<=2;i++){
        if(s[i]=='S'){
            maxx=max(maxx,len);len=0;
        }
        else{
            len++;
        }
    }
    if(len!=0) maxx=max(maxx,len);
    cout<<maxx;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<set>

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<string> A(3);
    for(int i = 0; i < 3; i++) cin >> A[i];
    int ans = 0;
    for(int i = 0; i < N; i++){
        set<int> c;
        for(int j = 0; j < 3; j++) c.insert(A[j][i]);
        ans += c.size() - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,num;
int main()
{
	scanf("%d %d",&a,&num);
	if(num==100)num++;
	 if(a==0) printf("%d\n",num);
	else  if(a==1) printf("%d00\n",num);
	else if(a==2) printf("%d0000\n",num);
 } 

Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define SQ(x) ((x)*(x))
int main(void){
	int n;
	cin>>n;
	while(n--){
		int x=0,y=0,dx,dy,ax=0,ay=0;
		for(;;){
			cin>>dx>>dy;
			if(dx==0&&dy==0) break;
			x+=dx;y+=dy;
			if(SQ(x)+SQ(y)>=SQ(ax)+SQ(ay)){
				if(SQ(x)+SQ(y)==SQ(ax)+SQ(ay)){
					if(x>ax) ax=x;ay=y;
				}else ax=x;ay=y;
			}
		}
		cout<<ax<<" "<<ay<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
import java.lang.*;
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=new int[a];
		for(int i=0;i<b*2;i++) {
			int d = sc.nextInt();
			++c[d-1];
		}
		for(int i=0;i<a;i++){
			System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 21844
X, K, D = map(int, input().split())
X = abs(X)
if X/D >= K:
    print(abs(X-D*K))
else:
    if (K-X//D) % 2 == 0:
        print(abs(X-D*(X//D)))
    else:
        print(abs(X-D*(X//D+1)))


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

int main(){
  int n,k;
  cin >> n >> k;
  int ans = 0;
  for(int i=0; i<n; i++){
    int tmp;
    cin >> tmp;
    if(tmp>=k)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 #define GRAY 1
#define WHITE 0
#define BLACK 2
 
int de[101], f[101], col[101];
int A[101][101];
int n, time;
 
void visit(int u) {
  int v;
   col[u] = GRAY;
   de[u] = ++time;
 
  for (v = 1; v <= n; v++) {
    if (col[v] == WHITE && A[u][v] == 1) visit(v);
  }
  col[u] = BLACK;
  f[u] = ++time;
}
 
void dfs() {
  int u;
  for (u = 1; u <= n; u++) {
    col[u] = WHITE;
  }
  time = 0;
  for (u = 1; u <= n; u++) {
    if (col[u] == WHITE) {
      visit(u);
    }
  }
}
 
int main() {
  int i, j, u, k, v;
 
  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 1; j <= k; j++) {
      scanf("%d ", &v);
      A[u][v] = 1;
    }
  }
 
  dfs();
  for (i = 1; i <= n; i++) {
    printf("%d %d %d\n", i, de[i], f[i]);
  }
 
 
  return 0;
}

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

#define ll long long

using namespace std;

int main(void){
    ll N, X, M;
    cin >> N >> X >> M;
    ll period = -1, start, prefix_sum = 0, period_sum = 0, XX = X;
    vector<int> appear(M, -1);
    for(int i = 0; i < N && i < M; i++){
        if(appear[XX] > 0){
            start = XX;
            period = i - appear[start];
            break;
        }
        prefix_sum += XX;
        appear[XX] = i;
        XX *= XX;
        XX %= M;
    }
    if(period == -1){
        cout << prefix_sum << endl;
        return 0;
    }
    for(int i = 0; i < period; i++){
        period_sum += XX;
        XX *= XX;
        XX %= M;
    }
    N -= appear[start];
    ll ans = prefix_sum + period_sum * (N / period - 1);
    N %= period;
    for(int i = 0; i < N; i++){
        ans += XX;
        XX *= XX;
        XX %= M;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3752
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
using namespace std;

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	typedef pair<int, long long>P;
	vector<P> connect[100005];
	int a, b;
	long long c;
	for (int i = 0; i < n-1; i++) {
		cin >> a >> b >> c;
		connect[a].push_back(P(b, c));
		connect[b].push_back(P(a, c));
	}
	int q, k;
	cin >> q >> k;
	queue<int> que;
	long long dist[100004] = { 0 };
	for (int i = 0; i < 100004; i++) {
		dist[i] = -1;
	}
	dist[k] = 0;
	que.push(k);
	while (!que.empty()) {
		int now = que.front();
		que.pop();
		for (int i = 0; i < connect[now].size(); i++) {
			int dest = connect[now][i].first;
			if (dist[dest] == -1) {
				dist[dest] = dist[now] + connect[now][i].second;
				que.push(dest);
			}
		}
	}
	int x, y;
	for (int i = 0; i < q; i++) {
		cin >> x >> y;
		cout << dist[x] + dist[y]<<endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

template <typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return b;
	} else {
		return gcd(b, a % b);
	}
}

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	ll res = A[0];
	for (int i = 1; i < N; ++i) {
		res = gcd(res, A[i]);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

#define rep(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

int main() {
  ll a, b;
  cin >> a >> b;
  ll n = max(a,b), m = min(a,b), t;
  while(m != 0) {
    t = n % m;
    n = m;
    m = t;
  }
  cout << a * b / n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

struct{
	int g;
	int p;
} list[6]={
	{200,380},   //190
	{300,550},   //183.3
	{500,850},   //170
	{1000,1520}, //152
	{1200,1870}, //155.8
	{1500,2244}  //149.6
};

static map[51]={0};

int main(){
	int i,j,n;
	map[2]=380;map[3]=550;map[5]=850;
	map[10]=1520;map[12]=1870;map[15]=2244;
	for(i=4;i<=50;i++){
		for(j=i-2;j>=i/2;j--)
			if(!map[i] || map[j] + map[i-j] < map[i]) map[i] = map[j] + map[i-j];
	}
	while(scanf("%d ", &n), n) printf("%d\n", map[n/100]);
    return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans = max(max(a*10+b+c,a+b*10+c),a+b+c*10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256