akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
   int a, b, c;
   cin >> a >> b >> c;
  
   if (a <= b && b <= c)
       cout << a << " " << b << " " << c << endl; 
   else if (a <= c && c <= b)
       cout << a << " " << c << " " << b << endl;
   else if (b <= a && a <= c)
       cout << b << " " << a << " " << c << endl;
   else if (b <= c && c <= a)
       cout << b << " " << c << " " << a << endl;
   else if (c <= b && b <= a)
       cout << c << " " << b << " " << a << endl;
   else
       cout << c << " " << a << " " << b << endl;
   
   return 0;
}


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int func(int N){
  int count=0;
  while(1){
    count++;
    N=N/10;
    if(N<1){
        break;
    }
  }
  return count;
}

int main(){
  long long N;
  cin >> N;
  long long A,B;
  int answer;
  int min=N;
  for(A=1;A*A<=N;A++){
    if(N%A==0){
      B=N/A;
      int a,b;
      a=func(A);
      b=func(B);
      if(a>=b) answer = a;
      else answer = b;
      if(answer<min) min=answer;
    }
  }
  cout << answer;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h,y,k,z;
  int a,b,c,d;
  int e,f;
  scanf("%d %d",&h,&y);
  scanf("%d %d",&k,&z);
  scanf("%d %d %d %d",&a,&b,&c,&d);
  e=h*a+y*b+(h/10)*c+(y/20)*d;
  f=k*a+z*b+(k/10)*c+(z/20)*d;
  if(e>f){
    printf("hiroshi\n");
  }
  if(e<f){
    printf("kenjiro\n");
  }
  if(e==f){
    printf("even\n");
  }
}

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

int main() {
	vector<int> array, num(101, 0), out;
	int inp, MAX = 0;
	int flag = 0;
	
	while (cin >> inp) {
		array.push_back(inp);
	}

	for (int i = 0; i < array.size(); i++) {
		MAX = max(++num[array[i]], MAX);		
	}

	for (int i = 1; i < num.size(); i++) {
		if (MAX == num[i])cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
import static java.util.Arrays.sort;
import java.util.Scanner;

public class Main {

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

        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();

        int num[] = {P, Q, R};
        sort(num);
        
        System.out.println(num[0] + num[1]);
    }
}


Measured memory_bytes: 23636
#include <queue>
#include <string>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <vector>
#define clr(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f

using namespace std;

typedef long long ll;
const int maxn = 200005;

ll res;
int n;
int main() {
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    cin >> n;
    
    for (int i = 1; i <= n; i++) {
        int t = n / i;
        res += 1ll * t * (t + 1) / 2 * i;
    }
    cout << res << endl;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int P,Q,R;
  cin >> P >> Q >> R;
  if(P+Q <= P+R){
  	if(P+Q <= Q+R){
    	cout << P+Q << endl;
    }else{
    	cout << Q+R << endl;
    }
  }else{
  	if(P+R <= Q+R){
    	cout << P+R << endl;
    }else{
    	cout << Q+R << endl;
    }
  }
}

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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;
const long long mod = 1000000007;


int main(void){
    string s;cin >> s;
    ll k; cin >> k;
    char p='A';ll n=0;
    bool even = false; 
    for(int i=0;i<s.length();i++){
	if(p == s[i] && !even){
	    n++;
	    even = true;
	}else{
	    even = false;
	    p = s[i];
	}
    }
    int a=1,b=1; char c=s[0],d=s[s.size()-1];
    if(c != d){
	cout << n*k << endl;
	return 0;
    }
    for(int i=1;i<s.size();i++){
	if(c==s[i])a = 1-a;
	else break;
    }
    for(int i=s.size()-2;i>=0;i--){
	if(d==s[i])b = 1-b;
	else break;
    }
    int q;
    for(q=0;q<s.size()-1;q++){
	if(s[q]!=s[q+1]) break;
    }
    if(q==s.size()-1 && s.size()%2==1){
	cout << (s.size()*k)/2 << endl;
	return 0;	
    }
    if(a==1 && b==1)cout << n*k + k - 1 << endl; 
    else cout << n*k << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int x;
  cin >> x;
  if(x == 25)
    cout << "Christmas";
  if(x == 24)
    cout << "Christmas Eve";
  if(x == 23)
    cout << "Christmas Eve Eve";
  if(x == 22)
    cout << "Christmas Eve Eve Eve";
  return 0;
}

Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[i][j] = X-Y value, between i and j
    OPT[i][j] = max(A[i]-OPT[i+1][j], A[j]-OPT[i][j-1])
    OPT[i][i] = A[i]
    """
    N = read_int()
    A = read_ints()
    OPT = [
        [0]*N for _ in range(N)
    ]
    for i in range(N):
        OPT[i][i] = A[i]
    for length in range(1, N):
        for i in range(N-length):
            OPT[i][i+length] = max(A[i]-OPT[i+1][i+length],
                                   A[i+length]-OPT[i][i+length-1])
    return OPT[0][-1]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 112860
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int f(int a,int b,int c){return  a+b+c-MAX(MAX(a,b),c)-MIN(MIN(a,b),c);}
int main(){
  int n,i,c=0,d[100],b[100]={};
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=1;i<n-1;i++){
    if(d[i]==f(d[i-1],d[i],d[i+1]))c++;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n,m;
	char a[51][51],b[51][51];

	cin>>n>>m;

	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
		}
	}
	rep(i,m){
		rep(j,m){
			cin>>b[i][j];
		}
	}

	rep(i,n-m+1){
		rep(j,n-m+1){
			int f=0;
			rep(k,m){
				rep(l,m){
					if(a[i+k][j+l]!=b[k][l])f=1;
				}
				if(f==1)break;
			}
			if(f==0){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  string s, t;
  cin >> s >> t;
  int ls = s.length();
  int lt = t.length();
  int ans = 0;
  for(int i = 0; i <= ls - lt; ++i)
  {
    int score = 0;
    for(int j = 0; j < lt; ++j)
    {
      if (s[i + j] == t[j]) score++;
    }
    ans = max(ans, score);
  }
  cout << lt - ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>
#include <climits>
#include <iomanip>

constexpr long long MOD = 1000000007;

int main()
{
  int A, B;
  std::cin >> A >> B;
  if (13 <= A)
    std::cout << B;
  else if (6 <= A)
    std::cout << B/2;
  else
    std::cout << 0;
  std::cout << std::endl;
  return 0;
}



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

int main(){
  int N;
  int a;
  int t=0;
  cin >> N;
  a = N/4;
  for(int i=0; i<a+1; i++){
  if((N-4*i)%7==0){
    t = 1;
  }
}
if(t==0)cout << "No" << endl;
else{cout << "Yes" << endl;}
}

Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

#pragma region GCD
ll gcd(ll a, ll b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return (a*b) / gcd(a, b);
}
#pragma endregion

int main()
{
	int n; cin >> n;
	ll m; cin >> m;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	rep(i, n)a[i] /= 2;
	int cnt = 0;
	int tmp = a[0];
	while (tmp % 2 == 0)
	{
		++cnt;
		tmp /= 2;
	}
	bool ok = true;
	rep(i, n)
	{
		tmp = a[i];
		int check = 0;
		while (tmp % 2 == 0)
		{
			++check;
			tmp /= 2;
		}
		if (cnt != check)ok = false;
	}
	if (!ok)
	{
		cout << 0 << endl;
		return 0;
	}
	ll x = 1;
	rep(i, n)
	{
		x = lcm(x, a[i]);
		if (x > m)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	ll res = (m / x + 1) / 2;
	cout << res << endl;
}

Measured memory_bytes: 1024
N, K = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

counter = 0
arr.each_with_index do |num, index|
  a = 0
  (0..(index - 1)).each do |index_2|
    a += 1 if num > arr[index_2]
  end
  counter += (a * K - a) * K / 2

  a = 0
  ((index + 1)..(N-1)).each do |index_2|
    a += 1 if num > arr[index_2]
  end
  counter += (a * K + a) * K / 2
end

puts counter % (10 ** 9 + 7)

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int L = -1, R = N;
    for(int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        L = max(l, L);
        R = min(R, r);

    }
    cout << max(0, R - L + 1) << endl;

    return 0;
}


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

int n, a[100000];

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++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[r]);
    return i + 1;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    int p = partition(a, 0, n -1);
    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        if(i == p) cout << "[" <<  a[i] << "]";
        else cout << a[i];
    }
    cout << endl;
    return 0;
}

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

int h,w;
string s[600];
int dy[]={0,1,0,-1};
int dx[]={1,0,-1,0};
int sum=0;

bool ng[555][555];

void knock(int Y,int X){
  
  map<char,vector<P> >M;
  r(i,4){
    int y=Y;
    int x=X;

    while(!isalpha(s[y][x])){
      y+=dy[i];
      x+=dx[i];
      if(y<0||x<0||y>=h||x>=w)break;
    }

    if(y<0||x<0||y>=h||x>=w)continue;
    M[s[y][x]].push_back(P(y,x));
  }

  int TX=0;
  for(auto &e:M){
    if(e.second.size()!=2)continue;
    sum+=2;
    s[e.second[0].first][e.second[0].second] = '.';
    s[e.second[1].first][e.second[1].second] = '.';
    TX++;
  }

  if(!M.size())ng[Y][X]=1;

}

signed main(){
  cin>>h>>w;
  r(i,h)cin>>s[i];

  r(tim,26)r(i,h)r(j,w)if(!isalpha(s[i][j])&&!ng[i][j]){
    knock(i,j);
  }

  cout<<sum<<endl;
}


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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T> inline bool chkmax(T &x, const T &y){ return y > x ? x = y, 1 : 0; }
template <typename T> inline bool chkmin(T &x, const T &y){ return y < x ? x = y, 1 : 0; }

#ifdef ONLINE_JUDGE
#define debug(...) ;
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG
#endif

//---------------------------------------------------------head----------------------------------------------------

LL n, a,  b;

int main()
{
	scf(n, a, b);
	if(n == 1)
	{
		if(a != b) puts("0");
		else puts("1");
		return 0;
	}

	if(a > b)
	{
		puts("0");
		return 0;
	}

	LL mn = (n - 1) * a + b;
	LL mx = (n - 1) * b + a;
	printf("%lld\n", mx - mn + 1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()
using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (v.empty()) return os << "vector{}";
  os << "vector{" << *v.begin();
  for (auto it = ++v.begin(); it != v.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
  if (s.empty()) return os << "set{}";
  os << "set{" << *s.begin();
  for (auto it = ++s.begin(); it != s.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const map<S, T> &m) {
  if (m.empty()) return os << "map{}";
  os << "map{" << (*m.begin()).first << ": " << (*m.begin()).second;
  for (auto it = ++m.begin(); it != m.end(); ++it)
    os << ", " << (*it).first << ": " << (*it).second;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "pair{" << p.first << ", " << p.second << "}";
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (getenv("LOCAL") != nullptr) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N, A;
  cin >> N >> A;
  vector<ll> X(N);
  rep (i, N) {
    cin >> X[i];
  }

  vector<map<ll, ll>> dp(N + 1);
  dp[0][0] = 1;
  rep (i, N) {
    ll d = X[i] - A;
    each (p, dp[i]) {
      dp[i + 1][p.first] += p.second;
      dp[i + 1][p.first + d] += p.second;
    }
  }
  cout << dp[N][0] - 1 << "\n";

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, a[MAXN], b[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n+1) cin >> a[i];
    FOR(i,1,n) cin >> b[i];
    ll res = 0;
    FOR(i,1,n) {
        if (a[i] >= b[i]) {
            res += b[i];
        }
        else {
            res += a[i];
            b[i] -= a[i];
            if (a[i+1] >= b[i]) {
                res += b[i];
                a[i+1] -= b[i];
            }
            else {
                res += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h;
        int w;
        while(true){
            h = sc.nextInt();
            w = sc.nextInt();
            if(h==0&&w==0){
                break;
            }
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(i%2==0){
                        if(j%2==0){
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    } else {
                        if(j%2==0){
                            System.out.print(".");
                        } else {
                            System.out.print("#");
                        }
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 34636
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		String T = stdIn.next();
		char[] s = S.toCharArray();
		char[] t = T.toCharArray();
		int count = 0;
		
		for(int i = 0 ; i < 3; i++) {
			if(s[i] == t[i]) {
				count++;
			}
		}
		
		System.out.println(count);

	}

}

Measured memory_bytes: 22228
N = int(input())
X = [str(input()) for i in range(N)]
ans = 'Yes'
for i in range(1,N):
    if X[i][0] == X[i-1][-1]:
        pass
    else:
        ans = 'No'
count = set(X)
if len(count) != len(X):
    ans = 'No'
print(ans)

Measured memory_bytes: 38256
#include <cstdio>
#include <algorithm>

int  n, s;
long long dp[10][101][1001];

long long solve(int cnt, int sum, int num){
    if(cnt < 0 || sum < 0) return 0;
    if(num < 0) return cnt == 0 && sum == 0;

    if(dp[cnt][num][sum] != -1) return dp[cnt][num][sum];

    return dp[cnt][num][sum] = solve(cnt - 1, sum - num, num - 1) + solve(cnt, sum, num - 1);
}

int main(){
    std::fill(dp[0][0], dp[10][0], -1);

    while(scanf("%d %d", &n, &s) != EOF){
        if(n == 0 && s == 0) break;

        printf("%lld\n", solve(n, s, 100));
    }

    return 0;
}

Measured memory_bytes: 10636
//Dream your Code, Code your Dream [Siriuslight -Subham Pal]
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;    typedef long long ll;    typedef long double ld;
const int inf = 1e9, N = 1e6+5;
const ll INF = 1e18, MOD = 1e9+7;;
ll power(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll gcd(ll a,ll b){if(b>a)swap(a,b);if(!b)return a;return gcd(b,a%b);}

string s;
int k;
set<pair<string,int> > st1;
set<string>  st2;
int main(){
    FIO;
    cout << setprecision(10) << fixed;
    cin >> s >> k;
    for(int i = 0; i < s.size(); ++i){
        string x;
        x.clear();
        x += s[i];
        st1.insert({x, i});
    }

    while(st2.size() < k){
        auto x = *st1.begin();
        st2.insert(x.first);
        st1.erase(st1.begin());
        string str = x.first;
        if(x.second < s.size() - 1){
            ++x.second;
            x.first += s[x.second];
            st1.insert(x);
        }
    }
    //while()
    cout << *st2.rbegin();
    return 0;
}


Measured memory_bytes: 768
class Node:
    def __init__(self, id):
        self.id = id
        self.parent = -1
        self.left = -1
        self.right = -1
    
    def get_depth(self):
        if self.parent == -1:
            return 0
        else:
            return nodes[self.parent].get_depth() + 1

    def get_degree(self):
        degree = 0
        if self.left != -1:
            degree += 1
        if self.right != -1:
            degree += 1
        return degree

    def get_height(self):
        # if self.parent != -1:
        #     return 0
        max_height = 0
        if self.left != -1:
            max_height = nodes[self.left].get_height() + 1
            # print("left", max_height)
        if self.right != -1:
            max_height = max(max_height, nodes[self.right].get_height() + 1)
            # print("right", max_height)
        return max_height
    
    def get_sibling(self):
        if self.parent == -1:
            return -1
        
        if nodes[self.parent].left == self.id:
            return nodes[self.parent].right
        else:
            return nodes[self.parent].left

    def get_type(self):
        if self.parent == -1:
            return 'root'
        elif self.left == -1 and self.right == -1:
            return 'leaf'
        else:
            return 'internal node'

n = int(input())
nodes = []
for i in range(n):
    nodes.append(Node(i))


for i in range(n):
    # node
    i, left, right = map(int, input().split())
    nodes[i].left = left
    nodes[i].right = right

    # parent
    if left != -1:
        nodes[left].parent = i
    if right != -1:
        nodes[right].parent = i

    # if i == 4:
    #     print("----------")
    #     print(left, nodes[left].parent, right, nodes[right].parent)
    #     print("----------")
    # for j in range(n):
    #     if j == 8:
    #         print('----------')
    #         print(i, nodes[j].parent)
    #         print('----------')


# 出力
for i in range(n):
    print('node {id}: parent = {p}, sibling = {s}, degree = {degree}, depth = {depth}, height = {height}, {type}'.format(
        id=i,
        p=nodes[i].parent,
        s=nodes[i].get_sibling(),
        degree=nodes[i].get_degree(),
        depth=nodes[i].get_depth(),
        height=nodes[i].get_height(),
        type=nodes[i].get_type(),
    ))


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
#define int long long
vector<vector<int>> a(3,vector<int>(10e5+1,0));
vector<vector<int>> dp(3,vector<int>(10e5+1,0));
int32_t main() {
    int n;
    cin >> n;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 3; j++) {
                cin >> a[j][i];
            }
        }
    dp[0][0]=a[0][0];
    dp[1][0]=a[1][0];
    dp[2][0]=a[2][0];
    //cout << dp[0][0] << "\n";
    for(int i = 1; i < n;++i){ // это позиция
        for(int j = 0; j < 3; j++){ // а это добавляем
            for(int k = 0; k < 3;++k){ // а это прошлые
                if(j!=k){
                    dp[j][i]=max(dp[j][i],dp[k][i-1]+a[j][i]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 3; ++i)
        ans=max(ans,dp[i][n-1]);
    cout << ans << "\n";
    return 0;
}


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

#define ll long long int

using namespace std;

template<class V,ll NV> class SegTree_Pair {
public:
	vector<pair<V,ll>> val;
	static V const def=1<<30;
	pair<V,ll> comp(pair<V,ll> l,pair<V,ll> r){ return min(l,r);}
	SegTree_Pair(){
		val.resize(NV*2);
		for(ll i = 0; i < NV; ++ i) val[i+NV]=make_pair(def,i);
		for(ll i=NV-1;i>=1;i--) val[i]=comp(val[2*i],val[2*i+1]);
	};
	pair<V,ll> getval(ll x,ll y,ll l=0,ll r=NV,ll k=1) {
		if(r<=x || y<=l) return make_pair(def,NV);
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(ll entry, V v) {
		entry += NV;
		val[entry]=make_pair(v,entry-NV);
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};


ll inf = 1e9;

int main() {
    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    
    SegTree_Pair<ll,1<<20> st;
    vector<ll> dp(n+1, 1<<30);
    vector<ll> from(n+1);
    dp[n] = 0;
    st.update(n, 0);
    for (ll i = n-1; i >= 0; --i) if (s[i] == '0') {
        auto p = st.getval(i+1,min(i+m+1,n+1));
        from[i] = p.second;
        dp[i] = p.first+1;
        st.update(i,dp[i]);
    }
    if (dp[0] >= 1<<30) {
        cout << -1 << endl;
        return 0;
    }
    
    vector<ll> res;
    ll cur = 0;
    while (cur != n) {
        cout << from[cur] - cur << " ";
        cur = from[cur];
    }
    cout << endl;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  auto * const a = &A[0];
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  vector<int> B(N + 1);
  auto * const b = &B[0];
  for (int i = 1; i <= N; ++i)
    cin >> b[i];
  vector<int> C(N);
  auto * const c = &C[0];
  for (int i = 1; i < N; ++i)
    cin >> c[i];
  int sum = b[a[0]];
  for (int i = 1; i < N; ++i)
  {
    sum += b[a[i]];
    if (a[i - 1] + 1 == a[i])
      sum += c[a[i - 1]];
  }
  cout << sum;
  return 0;
}


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

for i in range(0,n):
    datas = input()
    dic = dict()
    sIndex = inIndex = isMove = 0

    while sIndex < len(datas):
        if not isMove:
            dic[datas[sIndex]] = inIndex
            sIndex += 2
        else:
            if datas[sIndex] == '>':
                inIndex += 1
            else:
                inIndex -= 1
            sIndex += 1
        isMove = not isMove

    dic = {k: v for k, v in sorted(dic.items(), key=lambda item: item[1])}
    for k in dic.keys():
        print(k,end="")
    print()


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;


const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);
    COMinit();
    int n,p; cin >> n>> p;
    int o=0,e=0;
    rep(i,n){
        int a; cin >> a;
        if(a%2==0)e++;
        else o++;
    }

    if(o==0){
      int res=1;
      rep(i,e)res*=2;
      cout<<(p?0:res)<<endl;
      return 0;
        //cout<<(p?0:(1<<e))<<endl; return 0;
    }

    int res=(1<<e);
    int t=0;
    if(p==1){    
        for(int i=1; i<=o; i+=2) t+=COM(o,i);
    }else{
        for(int i=0; i<=o; i+=2) t+=COM(o,i);
    }   
    cout<<res*t<<endl;


}

Measured memory_bytes: 15568
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int a[3];

  cin>>a[0]>>a[1]>>a[2];

  sort(a,a+3);

  if(a[0]==5 && a[1]==5 && a[2]==7)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, p[25], ans;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", p+i);
	for(int i = 1; i < n-1; i++){
		if((p[i-1]-p[i]) * (p[i+1]-p[i]) < 0) ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<stack> 
using namespace std;
const int N=6666;



int n;
long long a,b,c;
int main()
{
cin>>a>>b>>c;
long long  ab=a*b,ac=a*c,bc=b*c;
long long maxx=2e18;
if(a%2!=0&&bc<=maxx)maxx=bc;
 if(b%2!=0&&ac<=maxx)maxx=ac;
 if(c%2!=0&&ab<=maxx)maxx=ab;
if(a%2!=0&&b%2!=0&&c%2!=0)
cout<<maxx<<endl;
else cout<<0<<endl;
}

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

int main() {
    int K, Ans = 1;
    cin >> K;
    if (K == 32) Ans = 51;
    if (K == 24) Ans = 15;
    if (K == 16) Ans = 14;
    if (K == 27 || K == 20 || K == 18 || K == 12 || K == 8) Ans = 5;
    if (K == 30 || K == 28) Ans = 4;
    if (K == 4 || K == 6 || K == 9 || K == 10 || K == 14 || K == 21 || K == 22 || K == 25 || K == 26) Ans = 2;

    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
  import bisect
  import sys
  from itertools import accumulate
  input = sys.stdin.readline
  def hsnum(x):
    num = 0
    for i in a:
      y = x-i
      num += n-bisect.bisect_left(a,y)
    return num
  n,m = map(int, input().split())
  a = list(map(int, input().split()))
  a.sort()
  suma = [0]+list(accumulate(a))
  lx = 0
  rx = 2*10**5+2
  error = 0
  while lx+1 < rx:
    mx = (lx+rx)//2
    if hsnum(mx) < m:
      rx = mx
    elif hsnum(mx) > m:
      lx = mx + 1
    else:
      lx = mx
      break
  if hsnum(lx)<m:
    lx -= 1
  error = hsnum(lx)-m
  ans = 0
  for i in a:
    rema = lx - i
    j = bisect.bisect_left(a,rema)
    ans += (n-j)*i-suma[j]
  ans += suma[n]*n
  print(ans-error*lx)
if __name__ == "__main__":
    main()

Measured memory_bytes: 14924
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;

	vector<pair<long long,int>> v;
	for(int i=0; i<n; ++i){
		int a;
		cin >> a;
		v.push_back(make_pair(a,1));
	}
	for(int i=0; i<m; ++i){
		int b, c;
		cin >> b >> c;
		v.push_back(make_pair(c,b));
	}
	sort(v.begin(),v.end(),greater<>());

	long long ans=0;
	int cnt=0;
	for(int i=0; i<n+m && cnt<n; ++i){
		if(cnt+v[i].second>=n){
			ans += v[i].first*(n-cnt);
			break;
		}
		ans += v[i].first*v[i].second;
		cnt += v[i].second;
	}
	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
  cin >> vec.at(i);
  }
  int count = 0;
  int ans = 0;
  for(int i = 0; i < N-1; i++){
  if(vec.at(i) >= vec.at(i+1)){
  count += 1;
  }else{
  count = 0;
  }
    ans = max(count,ans);
  }
  cout <<ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 1;
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (ans > 1000000000000000000 / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	int ans=min(N*A, B);
	cout << ans;
	/*
	if (N*A<B)
	{
		cout << N * A << endl;
	}
	else
	{
		cout << B << endl;
	}
	*/
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d%d',$a,$b);
$count = 0;
for ($i=$a; $i <= $b ; $i++) {
  // code...
  $i1 = substr($i,0,1);
  $i2 = substr($i,1,1);
  $i3 = substr($i,2,1);
  $i4 = substr($i,3,1);
  $i5 = substr($i,4,1);
  if($i1 == $i5 && $i2 == $i4){
    $count++;
  }
}
echo $count;
 ?>


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,i=1;
  int A,B;
  
  cin >> A >> B;
	
  N = A;
  if( B == 1){
  	i = 0;
  }else{
    while(1){
      if(N < B){
        N += A-1;
        i++;
      }else{
        break;
      }
    }
  }

  cout << i << endl;
  

  return 0;
}


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

A = list(map(int, input().split()))
count = 0

for i in range(0, num):
        minID = i
        for j in range(i, num):
                if A[j] < A[minID]:
                        minID = j
        if i != minID:
                A[i],  A[minID] = A[minID], A[i]
                count += 1

tempA = map(str, A)
print(' '.join(tempA))
print(count)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
ll N;
int main()
{
    scanf("%lld",&N);
        ll n=sqrt(N);
        ll m;
        ans=0;
        for(int i=1;i<=n;i++)
        {
            if(N%i==0)
            {
                m=N/i-1;
                if(m==0)
                {
                    continue;
                }
                if(N/m==N%m)
                {
                    ans+=m;
                }
            }
        }
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 764
import numpy as np
import itertools
N,M,X=map(int,input().split())
CA=[]
D=[]

for n in range(N):
  arr=list(map(int,input().split()))
  CA.append(arr)
CA=np.array(CA)

v=list(itertools.product([0,1], repeat=N))

for v_ in v:
  SUM=np.zeros(M+1)
  for n in range(N):
    if v_[n]==1:
      SUM = SUM+CA[n]
  D.append(list(SUM))

key=[]
value=[]
  
for d in D:
  key.append(d[0])
  value.append(d[1:])
  
dict = dict(zip(key,value))
dict_sorted = sorted(dict.items(), key=lambda x:x[0])


for d in dict_sorted:
  if all([i>=X  for i in d[1]]):
    print(int(d[0]))
    exit()

print(-1)
 

Measured memory_bytes: 30836
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int len = sc.nextInt();
    String s = sc.next();
    if (len % 2 != 0) {
      System.out.println("No");
      return;
    }
    for (int i = 0, j = len/2; j < len; i++, j++) {
      if (s.charAt(i) != s.charAt(j)) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 20692
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cassert>

using namespace std;
using ll = long long;

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);

		if (A == B) return false;
		if (size (A) < size(B)) swap(A, B);

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}
};

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

	vector<ll> ans(M);
	ans[M-1] = (ll)N * (N-1) / 2;

	UnionFind Uni(N);

	for (int i = M-1; i >= 1; i--) {
		ans[i-1] = ans[i];
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i-1] = ans[i] - (ll)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

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

//int main()
//{
//	ll n, m;
//	cin >> n >> m;
//	struct edge {ll from; ll to;};
//	vector<edge> d(m);
//	for (ll i = 0; i < m; i++) {
//		cin >> d[i].from >> d[i].to;
//	}
//
//	vector<ll> ans;
//	ll count = n * (n-1) / 2;
//	ans.push_back(count);
//
//	UnionFind tree(n+1);
//	for (ll i = m - 1; i >= 0; i--) {
//		edge e = d[i];
//		ll x = e.from;
//		ll y = e.to;
//
//		if (!tree.same(x, y)) {
//			ll px = tree.size(x);
//			ll py = tree.size(y);
//			tree.unite(x, y);
//
//			count = count - (px + py) * (px + py - 1) / 2 +
//				px * (px - 1) / 2 + py * (py - 1) / 2;
//
//		}
//		ans.push_back(count);
//	}
//
//}
//


Measured memory_bytes: 3328
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;
	
	static final long MOD = 1_000_000_007;

	static void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		long[] x = new long[n];
		long[] y = new long[m];
		long sumX = 0, sumY = 0;
		for (int i=0; i<n; i++) {
			x[i] = in.nextInt();
			if (i != 0)
				sumX = (sumX + (x[i]-x[i-1])*i%MOD*(n-i)%MOD)%MOD;
		}
		for (int i=0; i<m; i++) {
			y[i] = in.nextInt();
			if (i != 0)
				sumY = (sumY + (y[i]-y[i-1])*i%MOD*(m-i)%MOD)%MOD;
		}
		out.println(sumX*sumY%MOD);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 93980
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    string s;
    cin >> s;
    int q;
    cin >> q;

    int rev = 0;
    vector<char> front, back;

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

        if(t==1) rev = 1 - rev;
        else{
            int f;
            char c;
            cin >> f >> c;

            if((f==1 && rev==0) || (f==2 && rev==1)) front.push_back(c);
            if((f==2 && rev==0) || (f==1 && rev==1)) back.push_back(c);
        }
    }

    if(rev==0){
        for(int i = front.size()-1; i >= 0; --i) cout << front[i];
        cout << s;
        rep(i, back.size()) cout << back[i];
    }
    else{
        reverse(s.begin(), s.end());

        for(int i = back.size()-1; i >= 0; --i) cout << back[i];
        cout << s;
        rep(i, front.size()) cout << front[i];
    }

    cout << endl;

    return 0;
}

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

using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr.begin(),arr.end());
    long long ans=1e9;
    for(int i=1;i<=100;i++){
        long long val=0;
        for(int j=0;j<n;j++){
            val+=(arr[j]-i)*(arr[j]-i);
        }
        if(val<ans)
            ans=val;
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, A, B;
    scan(N, A, B);
    auto X = aryread();
    long ans;
    foreach (i; 0 .. N - 1)
    {
        ans += min(A * (X[i + 1] - X[i]), B);
    }
    writeln(ans);
}

/// 素因数分解
long[long] factorize(long x)
{
    assert(0 < x, "x is negative");
    long[long] ps;
    while ((x & 1) == 0)
    {
        x /= 2;
        ps[2] = (2 in ps) ? ps[2] + 1 : 1;
    }
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
        {
            x /= i;
            ps[i] = (i in ps) ? ps[i] + 1 : 1;
        }
    if (x != 1)
        ps[x] = (x in ps) ? ps[x] + 1 : 1;
    return ps;
}


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

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

  string ans;
  do{
    if(N%2==0){
      ans.push_back('0');
      N/= -2;
    }
    else{
      ans.push_back('1');
      N= -(N-1)/2;
    }
  } while(max(N,-N)>0);
  
  reverse(ans.begin(), ans.end());

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,x,i;
  scanf("%d", &n);
  for(i=1; i <= n; i++){
    if( i % 3 == 0){
      printf(" %d", i);
    }
    else{
      x=i;
      while(1){
        if( x % 10 == 3 ){
          printf(" %d", i);
          break;
        }
        x/=10;
        if(x==0) break;
      }
    }
  }
  printf("\n");
  return 0;
}


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

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const auto INF = static_cast<ll>(1e15);
const auto MOD = static_cast<ll>(1e9 + 7);

/*********** Variables ***********/
ll N, K;
ll fac[2001], finv[2001], inv[2001];

/*********** Functions ***********/
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 2001; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll comb(ll n, ll r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main() {
    COMinit();
    cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        ll ret = comb(K - 1, i - 1);
        if (N - K < i - 1) {
            cout << 0 << endl;
            continue;
        }
        ret *= comb(N - K + 1, i) % MOD;
        cout << ret % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import fractions
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a,b=map(int,input().split())
ans=0
c=fractions.gcd(a,b)
d=prime_factorize(c)
d=set(d)
print(len(d)+1)


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int dp[500][500];

void solve(long long N, long long M_a, long long M_b, std::vector<long long> a,
           std::vector<long long> b, std::vector<long long> c) {

    for (int j = 0; j < 500; j++)
        for (int k = 0; k < 500; k++)
            dp[j][k] = 1e9;

    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 499 - a[i]; j >= 0; j--) {
            for (int k = 499 - b[i]; k >= 0; k--) {
                dp[j + a[i]][k + b[i]] = min<int>(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
            }
        }
    }
    int ans = 1e9;
    for (int i = 1; i < 500; i++) {
        for (int j = 1; j < 500; j++) {
            if (M_a * j == i * M_b) {
                ans = min(ans, dp[i][j]);
            }
        }
    }
    if( ans == 1e9 ){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;
}


int main() {
    long long N;
    scanf("%lld", &N);
    long long M_a;
    scanf("%lld", &M_a);
    long long M_b;
    scanf("%lld", &M_b);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
        scanf("%lld", &c[i]);
    }
    solve(N, M_a, M_b, std::move(a), std::move(b), std::move(c));
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

int main(void)
{
    ll K;
    cin >> K;

    ll mod = 7;

    int ans = -1;
    FOR(i,1,K){
        if(mod % K == 0){
            ans = i;
            break;
        }
        mod = (mod*10 + 7) % K;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612