akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.r = [-1 for _ in range(n)]

    def root(self, x):
        if self.r[x] < 0:
            return x
        self.r[x] = self.root(self.r[x])
        return self.r[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.r[x] > self.r[y]:
            x, y = y, x
        self.r[x] += self.r[y]
        self.r[y] = x
        return True

    def size(self, x):
        return -self.r[self.root(x)]


n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.unite(a - 1, b - 1)

max_friend = -min(uf.r)

print(max_friend)

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

const int DIM = 1e5 + 5;

int arr[DIM];

int main(void) {
    ios::sync_with_stdio(false);
    
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    
    if (x1 <= x2 && x2 <= y1)
        cout << min(y1 - x2, y2 - x2) << endl;
    else
    if (x2 <= x1 && x1 <= y2)
        cout << min(y1 - x1, y2 - x1) << endl;
    else
        cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 256
import math

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = [False]*(max(A)+10)

    for i in range(N):
        divi =  make_divisors(A[i])
        for j in range(len(divi)):
            if L[divi[j]]==False:
                L[divi[j]] = True
            elif divi[j] != 1:
                gc = A[0]
                for k in range(1,N):
                    gc = math.gcd(gc,A[k])
                if gc == 1:
                    print('setwise coprime')
                    return
                else:
                    print('not coprime')
                    return


    print('pairwise coprime')
    return





if __name__ == '__main__':
    main()


Measured memory_bytes: 205204
N = int(input())

AB = [[[] for _ in range(10)] for _ in range(10)]
for i in range(1, N+1):
    if int(str(i)[0]) != 0 and int(str(i)[-1]) != 0:
        AB[int(str(i)[0])][int(str(i)[-1])].append(i)

ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += len(AB[i][j]) * len(AB[j][i])

print(ans)

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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front

typedef long long ll;

using namespace std;

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

int main(){
    ll N,T;
    cin>>N>>T;
    vector <ll> t(N);
    rep(i,0,N)cin>>t[i];
    ll prev,now=t[0]+T;
    prev=t[0];
    ll ans =0;
    rep(i,1,N){
        if(now > t[i])now =t[i]+T;
        else{
            ans += now-prev;
            prev =t[i];
            now =t[i]+T;
        }
    }
    ans += now-prev;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;
int n;
int dfs(int seven, int five, int three, ll cur) {
  if(cur > n) return 0;
  int res = 0;
  if(seven > 0 && five > 0 && three) ++res;
  ll next = cur * 10;
  res += dfs(seven + 1, five, three, next + 7);
  res += dfs(seven, five + 1, three, next + 5);
  res += dfs(seven, five, three + 1, next + 3);
  return res;
}

int main(){
  cin >> n;
  int ans = dfs(0, 0, 0, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9;
#define LINF = 1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << = << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

int main(){

   int n;
   cin >> n;
   int house[4][3][10] = {};

   rep(i, n){
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    house[b-1][f-1][r-1] += v;
   }

   rep(i, 4){
       rep(j, 3){
           rep(k, 10){
               cout << " " << house[i][j][k];
           }
           putchar('\n');
       }
       if(i < 3)puts("####################");
   }

}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

int main()
{
  IOS;
  int n;
  cin >> n;
  int arr[n];
  for (int i=0; i<n; i++)
    {
      cin >> arr[i];
    }
  int ans=1;
  int q=arr[0];
  for (int i=1; i<n; i++)
    {
      if (arr[i]<q)
	{
	  q=arr[i];
	  ans++;
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4372
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
	string s;
	cin >> s;
	int x1=0,x2=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1') x1++;
		if(s[i]=='0') x2++;
	}
	cout << min(x1,x2)*2;
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  long long int x=0;
  cin >> n >> k;
  vector<long int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  for (int i = 0; i < n-k; i++) {
    x+=h[i];
  }
  cout << x << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    long long a, b, c, d, max;
    vector<long long> ans(4);
    cin >> a >> b >> c >> d;
    /*
    for (i = a; i <= b; i++)
    {
        for (j = c; j <= d; j++)
        {
            tmp = i * j;
            if (tmp >= max)
            {
                max = tmp;
            }
        }
    }
    */
    ans[0] = a * c;
    ans[1] = a * d;
    ans[2] = b * c;
    ans[3] = b * d;
    max = ans[0];
    for (int i = 0; i < 4; i++)
    {
        if (ans[i] >= max)
            max = ans[i];
    }
    cout << max << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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; }

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main() {
    string s;
    ll k;

    cin >> s;
    cin >> k;

    char ans = '1';
    int cursor = 0;
    rep(i, s.size()) {
        if (s[i] == '1') {
            cursor++;
            if (cursor == k) break;
        } else {
            ans = s[i]; 
            break;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
  int ans=0;

  for(int bit=0;bit<8;bit++){
    vector<int> v(n,0);
    for(int i=0;i<n;i++){
      if(bit&(1<<0))v[i]+=a[i];
      else v[i]-=a[i];
      if(bit&(1<<1))v[i]+=b[i];
      else v[i]-=b[i];
      if(bit&(1<<2))v[i]+=c[i];
      else v[i]-=c[i];
    }
    sort(v.begin(),v.end(),greater<int>());
    int tmp=0;
    for(int i=0;i<m;i++)tmp+=v[i];
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int solve(int a[],int n,int k,int dp[]){
   
    if(n==0){
        return dp[n]=0;
    }
    if(n==1){
        return dp[n]=abs(a[n]-a[n-1]);
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    int ans=INT_MAX;
    for(int i=1;i<=k;i++){
        if(n-i>=0){
            ans=min(abs(a[n]-a[n-i])+solve(a,n-i,k,dp),ans);
        }
    }
    
    return dp[n]=ans;
    
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n];
    for(int i=0;i<n;i++){
        dp[i]=-1;
    }
    cout<<solve(a,n-1,k,dp)<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 10368
s = input()
t = input()
t_length = len(t)

temp = s[:]
count = 0
ans = 0

for i in range(len(t)):
    a = s.find(t[i])
    if a == -1:
        print(-1)
        exit()

while count < t_length:
    value = temp.find(t[count])
    if value == -1:
        ans += len(temp)
        temp = s[:]
    
    else:
        ans += value + 1
        count += 1
        temp = temp[value + 1:]

print(ans)

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


int main() {
    ll N,K; cin >> N >> K;
    ll A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    } // {6,5,2,5,3,2}
    int cnt[N] = {0};
    int next = 0;
    for (int i = 0; i < N; i++)
    {
        cnt[next]++;
        if(cnt[next] == 2) break;
        else next = A[next]-1;
    } // nextはループの最初
    /*
        cnt[0]=1,next=5,
        cnt[5]=1,next=1,
        cnt[1]=1,next=4,
        cnt[4]=1,next=2,
        cnt[2]=1,next=1
        cnt[1]=2,break,
    */
    int start = next; //start=1
    next = 0;
    int notloop = 0;
    int root[N];
    int loop = -1;
    for (int i = 0; i < N; i++)
    {
        loop += cnt[i]; //loop = 5
    }
    for (int i = 0; i < N; i++)
    {
        if(next == start){
            loop -= notloop;
            for (int j = 0; j < loop; j++)
            {
                root[j] = next;
                next = A[next]-1;
            }
            break;
        }
        notloop++;
        next = A[next]-1;
    }
    /*
    notloop=1,next=5,
    notloop=2,next=1
    loop = 5-2 = 3,
    root[0]=1, next=4,
    root[1]=4,next=2,
    root[2]=2,next=1,
    */
    if(K<=notloop){
        next = 0;
        for (int i = 0; i < K; i++)
        {
            next = A[next]-1;
        }
        cout << next+1 << endl;
        /*
        K=1
        next=5 cout<<6,
        */
    }else{
        K -= notloop;
        K %= loop;
        cout << root[K]+1 << endl;
        /*
        K=7
        K=7-2=5 K%loop=5%3=2
        root[2]=2
        cout<<3
        */
    }
}

Measured memory_bytes: 6604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N; 
    cin >> N;
    int A[N+1];
    int B[N+1];
    int C[N+1];

    for ( int i = 1; i <= N; i ++ ) {
        cin >> A[i];
    }
    for ( int i = 1; i <= N; i ++ ) {
        cin >> B[i];
    }
    for ( int i = 1; i <= N-1; i ++ ) {
        cin >> C[i];
    }

    int total = 0;
    for ( int i = 1; i <= N; i ++ ) {
        total += B[ A[i] ];
        
        if ( i > 0 ) {
            if ( A[i-1]+1 == A[i] ) total += C[A[i-1]];
        }
    }
    
    cout << total << endl;

    
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n = INT()
    while n >= 0:
    	if n%4==0 or n%7==0:
    		print('Yes')
    		sys.exit()
    	n -= 11
    print('No')


if  __name__=='__main__':
    main()


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

using namespace std;

const int P = 1000000007;

int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;

	vector<vector<long long> > dp;
	dp.resize(n + 1);
	for(int i = 0; i < n + 1; ++i) {
		dp[i].resize(n + 1);
	}

	dp[0][0] = 1;

	auto power = [&] (long long x, long long t) {
		long long ret = 1;
		
		for(; t; t >>= 1, x = x * x % P) {
			if(t & 1) {
				ret = ret * x % P;
			}
		}

		return ret;
	};

	vector<long long> fac;
	fac.resize(n + 1);
	
	fac[0] = 1;
	for(int i = 1; i < n + 1; ++i) {
		fac[i] = fac[i - 1] * i % P;
	}

	vector<vector<long long> > pow;
	pow.resize(n + 1);
	
	for(int i = 0; i < n + 1; ++i) {
		pow[i].resize(n + 1);
	}
	
	vector<long long> inv;
	inv.resize(n + 1);

	inv[0] = 1;
	for(int i = 1; i < n + 1; ++i) {
		inv[i] = power(i, P - 2);
	}

	for(int i = 0; i < n + 1; ++i) {
		pow[i][0] = 1;

		fac[i] = power(fac[i], P - 2);

		for(int j = 1; j < n + 1; ++j) {
			pow[i][j] = pow[i][j - 1] * fac[i] % P;
		}

	}

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j <= n; ++j) {
			for(int k = 0; j + k * (i + 1) <= n; ++k) {
				if(k == 0 || (a <= i + 1 && i + 1 <= b && c <= k && k <= d)) {
					dp[i + 1][j + k * (i + 1)] = (dp[i + 1][j + k * (i + 1)] + dp[i][j] * pow[i + 1][k] % P * fac[k] % P) % P;
				}
			}
		}
	}

	for(int i = 1; i <= n; ++i) {
		dp[n][n] = dp[n][n] * i % P;
	}

	cout << dp[n][n] << '\n';

	return 0;

}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if (b <= a) PRINT("delicious");
    else if (b <= a+x) PRINT("safe");
    else PRINT("dangerous");
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    i32 N;
    cin >> N;
    Vec<pair<i32, i32>> A(N);
    for (i32 i = 1; i <= N; i++) {
        i32 a;
        cin >> a;
        A[i - 1] = make_pair(a, i);
    }
    sort(ALL(A));
    for (i32 i = 0; i < N; i++) {
        cout << A[i].second;
        if (i != N - 1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3912
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

x,y = get_nums_l()

for a in range(x+1):
    b = x-a
    if a*2 + b*4 == y:
        print("Yes")
        exit()
print("No")


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

#define ll long long

using namespace std;

main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (s[i] != t[i]);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3856
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 100002;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int num[maxn], cnt[100001];
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0 ; i < n ; i++){
        cin >> num[i];
        cnt[num[i]]++;
    }
    int MAX = -1;
    for (int i = 0 ; i < n ; i++){
        if (num[i] == 0)
            MAX = max(MAX, cnt[num[i]+1] + cnt[num[i]]);
        else if (num[i] == 99999)
            MAX = max(MAX,cnt[num[i]] + cnt[num[i]-1]);
        else
            MAX = max(MAX,cnt[num[i]+1] + cnt[num[i]] + cnt[num[i]-1]);
    }
    cout << MAX << '\n';
 
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int a, b; cin >> a >> b;
	if (a % 2 != b % 2)cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[128];
	char str2[128];
	int ans;
	int i, j;
	
	ans = 0;
	while (scanf("%s", str) != EOF){
		j = 0;
		for (i = strlen(str) - 1; i >= 0; i--){
			str2[j] = str[i];
			j++;
		}
		str2[j] = '\0';
		if (strcmp(str, str2) == 0){
			ans++;
		}
	}
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 976
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll num=1e9+7;
ll mod(ll n)
{
    return (n%num+num)%num;
}
ll add(ll x,ll y)
{
    return mod(mod(x)+mod(y));
}
ll mult(ll x,ll y)
{
    return mod(mod(x)*mod(y));
}
ll sub(ll x,ll y)
 {
     return mod(mod(x)-mod(y));
 }
 ll pt(ll n,ll p)
 {
      if(p==0)
       return 1;
       if(p==1)
        return n%num;
        ll t=pt(n,p/2);
        if(p%2==0)
         return mult(t,t);
         else
          return mult(n,mult(t,t));
 }
 void solve()
 {
     ll n;
     cin>>n;
     if(n==1)
     {
         cout<<0<<endl;
         return;
     }
     if(n==2)
     {
         cout<<2<<endl;
         return;
     }
    
     cout<<sub(add(pt(10,n),pt(8,n)),mult(2,pt(9,n)))<<endl;
      
 }
int main(){
   ll t;
   t=1;
   while(t--)
   {
       solve();
   }
    
}


Measured memory_bytes: 3608
#define e(i,n)for(i=0;i<n;i++)
#define s(a,b){a^=b;b^=a;a^=b;}
char p[8][9];i,j;r(o){e(i,8)e(j,i)s(p[i][j],p[j][i])e(i,8)e(j,4)s(p[i][j],p[i][7-j])printf("%d\n",o);e(i,8)puts(p[i]);}main(){e(i,8)scanf("%s",p[i]);r(90);r(180);r(270);exit(0);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int sum=0,p=0,g=0;
int main()
{
	scanf("%s", s);
	int len=strlen(s);
	for(int i=0;i<len;i++)
	{
		if(s[i]=='g')
		{
			if(g>p)
			{
				sum++;
				p++;
			}else 
		    {
			    g++;
		    }
		} 
		else 
		{
			if(g>p)
			{
				p++;
			}
			else
			{
				sum--;
				g++;
			}
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
AB = [[int(i) for i in input().split()]for j in range(N)]
sortsecond = lambda val: val[0]
AB.sort(key=sortsecond)
ans = 0
c = 0
for ab in AB:
    if c+ab[1] <= M:
        ans += (ab[0] *ab[1])
        c += ab[1]
        continue
    else:
        while c != M:
            c += 1
            ans += ab[0] 
        break

print(ans)

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

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

	int ans = 0;
	for (int i = 0; i < N; i++){
		if (i < K){
			ans += X;
		} else {
			ans += Y;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from math import gcd 
 
n = int(input())
maxA = 10**6+5
A = list(map(int, input().split()))
c = [0]*maxA
for a in A:
    c[a] += 1

for i in range(2, maxA):
    cnt = 0
    for j in range(i, maxA, i):
        cnt += c[j]
    if cnt >= 2:
        break
else:
    print('pairwise coprime')
    exit()

g = A[0]
for a in A[1:]:
    g = gcd(g, a)
if g == 1:
    print('setwise coprime')
else:
    print('not coprime')

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

int main()
{
  int a, b;
  cin >> a >> b;
  int tak = 0;
  for (int m = 1; m <= a; m++) {
    if (m < a) {
      for (int d = 1; d <= 31; d++) {
        if (m == d) tak++;
      }
    } else {
      for (int d = 1; d <= b; d++) {
        if (m == d) tak++;
      }
    }
  }
  cout << tak << endl;
  return 0;
}


Measured memory_bytes: 256
while true
    m, f, r = gets.chomp.split.map(&:to_i)
    break if m == -1 && f == -1 && r == -1

    grade = "F"
    if m == -1 || f == -1
        grade = "F"
    elsif m + f >= 80
        grade = "A"
    elsif m + f >= 65
        grade = "B"
    elsif m + f >= 50
        grade = "C"
    elsif m + f >= 30
        if r >= 50
            grade = "C"
        else
            grade = "D"
        end
    end
    puts grade
end

Measured memory_bytes: 8620
use std::vec::Vec;
use std::cmp::*;
use std::collections::VecDeque;
use std::collections::BinaryHeap;


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut g = vec![vec![]; n];
    for _ in 0..n-1 {
      let t: Vec<(usize)> = read_vec();
      g[t[0] - 1].push((t[1] - 1, 1));
      g[t[1] - 1].push((t[0] - 1, 1));
    }

    let f_list = dijkstra(n, &g, 0);
    let s_list = dijkstra(n, &g, n-1);

    let mut fennec = 0;
    let mut snuke = 0;

    for i in 0..n {
      if s_list[i] >= f_list[i] {
        fennec += 1;
      } else {
        snuke += 1;
      }
    }

    if fennec > snuke {
      println!("Fennec");
    } else {
      println!("Snuke")
    }
}


// 単一始点から全てのノードへの最短経路超を探索
fn dijkstra(n: usize, adj_list: &Vec<Vec<(usize, u64)>>, start: usize) -> Vec<u64> {
  let mut dist = vec![std::u64::MAX; n];
  let mut p_queue: BinaryHeap<(i64, usize)> = BinaryHeap::new();

  //init
  dist[start] = 0;
  p_queue.push((0, start));

  while !p_queue.is_empty() {
    // 起点となるノード
    let (cost, now)
      = match p_queue.pop() {
        None => break,
        Some(e) => (-e.0 as u64, e.1),
      };

    // 繋がっているノードを探索
    for &edge in &adj_list[now] {
      let next = edge.0;
      let weight = edge.1;

      if dist[next] > weight + cost {
        p_queue.push((-((weight + cost) as i64), next));
        dist[next] = weight + cost;
      }
    }

  }

  dist
}


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

int main(){
  int a, b;
  cin >> a >> b;
  int min, cnt;
  if (a>=b) {
    min = b;
    cnt = a;
  }
  else{
    min = a;
    cnt = b;
  }
  rep(i,cnt){
    cout << min;
  }
 }
  

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = input().rstrip()
    B = input().rstrip()
    C = input().rstrip()

    res = 0
    for a, b, c in zip(A, B, C):
        res += 1 if len(set(a + b + c)) == 2 else 2 if len(set(a + b + c)) == 3 else 0

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
ans=1

if K%2==1 and A[-1]<0:
    for i in range(K):
        ans=ans*A[N-(i+1)]%mod
    print(ans)
    exit()

l=0
r=N-1
if K%2==1:
    ans=ans*A[r]
    r-=1

for _ in range(K//2):
    ml=A[l]*A[l+1]
    mr=A[r]*A[r-1]
    if ml>mr:
        ans=ans*ml%mod
        l+=2
    else:
        ans=ans*mr%mod
        r-=2

print(ans)

Measured memory_bytes: 31552
/*
 * atcoder/abc127/e.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}
template<class T> struct BiCoef {
    vector<T> fact_, inv_, finv_;
    constexpr BiCoef() {}
    constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
        init(n);
    }
    constexpr void init(int n) noexcept {
        fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
        for(int i = 2; i < n; i++){
            fact_[i] = fact_[i-1] * i;
            inv_[i] = -inv_[MOD%i] * (MOD/i);
            finv_[i] = finv_[i-1] * inv_[i];
        }
    }
    constexpr T com(int n, int k) const noexcept {
        if (n < k || n < 0 || k < 0) return 0;
        return fact_[n] * finv_[k] * finv_[n-k];
    }
    constexpr T fact(int n) const noexcept {
        if (n < 0) return 0;
        return fact_[n];
    }
    constexpr T inv(int n) const noexcept {
        if (n < 0) return 0;
        return inv_[n];
    }
    constexpr T finv(int n) const noexcept {
        if (n < 0) return 0;
        return finv_[n];
    }
};

ll H, W, K, S;
BiCoef<mint> bc;
void solve() {
  cin >> H >> W >> K;
  S = H*W;
  bc.init(S);

  mint total = 0;
  for (int d=1; d<H; d++) {
    total += d * (H-d) * W * W;
  }
  for (int d=1; d<W; d++) {
    total += d * (W-d) * H * H;
  }

  total *= bc.com(S-2, K-2);
  cout << total << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define INF 10000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main()
{
	int n;
	cin >> n;
	int ans = 0;
	int A[] = {500, 1000, 5000, 10000};
	int i = 3;
	while(1)
	{
		if(i < 0)
			break;
		if(n - A[i] < 0)
		{
			i--;
		}
		else
		{
			n -= A[i];
			ans += A[i];
		}
	}
	cout << ans << endl;
	return 0;
}




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

int main() {
  int N;
  int Y;
  cin >> N >> Y;
  for (int i=0; i<=N; i++) {
    if(i*1000 > Y) break;
    for (int j=0; j<=N-i; j++) {
      if(i*1000 + j*5000 > Y) break;
      int k = N - (i+j);
      if(i*1000 + j*5000 + k*10000 == Y) {
          cout << k << " " << j << " " << i;
          return 0;
      }
    }	
  }
  cout << "-1 -1 -1";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int n;
int a[maxn],b[maxn],c[maxn];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    for(int i=1;i<=n-1;i++)
        cin>>c[i];
    int ans = b[a[1]];
    for(int i=2;i<=n;i++)
    {
        ans += b[a[i]];
        if(a[i]==a[i-1]+1)
            ans += c[a[i-1]];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    N, *M = (int(input()) for _ in range(6))

    mi = min(M)

    ans = 5 + (N - 1) // mi + 1 - 1
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
 
using namespace std;
 
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	
	int a;
	while(cin>>a){
		if(a==-1)break;
		
		double q = a;
		double x = q/2;
		rep(i,20000){
			x = x-(x*x*x-q)/(3*x*x);
			if(fabs(x*x*x-q)<0.00001*q)break;
		}
		
		printf("%.9lf\n",x);
	}
	
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,K;
ll arr[100*1000+5];
ll dp[100*1000+5];

ll solve(ll arr[], ll i){
	if (i >= N-1) return 0;
	
	if(dp[i] != -1) return dp[i];
	
	dp[i] = 1e18;
	for(ll k = 1;k<=K;k++){
		if (i+k<N)
			dp[i] = min(dp[i], solve(arr, i+k) + abs(arr[i+k]-arr[i]));
	}
	
	return dp[i];
}

int main(){
	cin>>N; cin>>K;
	for(int i = 0;i<N;i++)cin>>arr[i];
	memset(dp, -1, sizeof dp);
	cout<<solve(arr, 0)<<endl;
}

Measured memory_bytes: 6528
#include <stdio.h>
int gcd(int a,int b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
int main()
{
    int a, b;
    while(scanf("%d%d", &a, &b) != EOF)
        printf("%d %d\n", gcd(a, b), a / gcd(a, b) * b);
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
X = [int(x) for x in input().split()]

ans = 100 ** 2 * N
for i in range(min(X), max(X)+1):
  a = 0
  for j in range(N):
    a += (X[j] - i) ** 2
  if ans > a:
    ans = a
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	ll x,a,b;
  	cin>>x>>a>>b;
  	
  	if(a+x<b) cout<<"dangerous"<<endl;
  	else if(a<b && b<=a+x) cout<<"safe"<<endl;
  	else cout<<"delicious"<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

ll modpower(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n)
{
    return modpower(n, MOD - 2, MOD);
}
void COMinit(vector<ll> &fact, vector<ll> &invfact, ll k)
{ //空っぽの配列を二つ
    fact.resize(k, 0);
    invfact.resize(k, 0);
    fact[0] = 1;
    repi(i, k, 1)
    {
        fact[i] = fact[i - 1] * i % MOD;
    }
    invfact[k - 1] = inv(fact[k - 1]);
    repd(i, k - 2, -1)
    {
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
    return;
}
ll nCk(vector<ll> &fact, vector<ll> &invfact, ll n, ll k)
{ //この関数を使う前にCOMinit
    if (k < 0 || n < k)
        return 0LL;
    return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}

//---------main function----------

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> node[n];
    repi(i, m, 0)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }

    queue<ll> q;
    vector<ll> dist(n, INF);
    dist[0] = 0;
    q.push(0);
    while (!q.empty())
    {
        ll p = q.front(); //parent
        q.pop();
        for (ll child : node[p])
        {
            if (dist[child] > dist[p] + 1LL)
            {
                dist[child] = dist[p] + 1LL;
                q.push(child);
            }
        }
    }
    cout << "Yes" << endl;
    repi(i,n,1){
        ll dst = dist[i];
        ll ans = i + 1;
        for(int child : node[i]){
            if(dst > dist[child]){
                ans = child + 1;
                dst = dist[child];
            }
        }
        if(ans == 0)ans = 1;
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 12932
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <math.h>
#include <iomanip>
using namespace std;
int main() {
    int n,m,x,y;cin>>n;
    m=1;
    long double r;
    for(int i=1;i<=n;i++){
        m*=i;
    }
    vector<pair<int,int>> xy(n);
    for(int i=0;i<n;i++){
        cin>>x>>y;
        xy[i]=make_pair(x,y);
    }
    sort(xy.begin(),xy.end());
    do{
        for(int i=0;i<n-1;i++){//こういう書き方もあります
            r+=sqrtl(powl(xy[i].first-xy[i+1].first,2)+powl(xy[i].second-xy[i+1].second,2));
        }
    }while(next_permutation(xy.begin(),xy.end()));
    //do-while文というものです。whileの中身を実行してから()内を評価します。
    cout<<fixed << setprecision(10)<<r/m<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

string S[13];
string ansS[13];

int main()
{
	int H, W;
	cin >> H >> W;
	REP(i, H)
	{
		cin >> S[i];
	}

	bool us[13] = {};
	int ss = 0;
	REP(i, H - 1)
	{
		if (us[i])continue;
		string s1 = S[i];
		string s2;
		FOR(j, H, i + 1)
		{
			if (us[j])continue;
			s2 = S[j];
			int same = 0;
			bool uc[13] = {};
			REP(k, W - 1)
			{
				if (uc[k])continue;
				FOR(l, W, k + 1)
				{
					if (uc[l])continue;
					char c11 = s1[k], c21 = s2[l], c12 = s1[l], c22 = s2[k];
					if (c11 == c21&&c12 == c22)
					{
						same++;
						uc[l] = true;
						break;
					}
				}
			}
			if (same == W / 2)
			{
				//s1とs2はコンビ
				ansS[ss] = s1;
				ansS[H - 1 - ss] = s2;
				ss++;
				us[j] = true;
				us[i] = true;
				break;
			}
		}
	}

	if (ss != H / 2)
	{
		cout << "NO" << endl;
		return 0;
	}
	REP(i, H)
	{
		if (!us[i])
		{
			ansS[H / 2] = S[i];
		}
	}

	bool uw[13] = {};
	int sw = 0;
	REP(i, W - 1)
	{
		if (uw[i])continue;
		FOR(j, W, i + 1)
		{
			if (uw[j])continue;
			bool same = true;
			REP(k, H)
			{
				char c1 = ansS[k][i];
				char c2 = ansS[H - 1 - k][j];
				if (c1 != c2)
				{
					same = false;
					break;
				}
			}
			if (same)
			{
				uw[i] = true;
				uw[j] = true;
				sw++;
				break;
			}
		}
	}

	if (sw != W / 2)
	{
		cout << "NO" << endl;
		return 0;
	}

	//! 中央の列が回文かみる
	REP(i, W)
	{
		if (uw[i])continue;
		REP(j, H)
		{
			char c1 = ansS[j][i];
			char c2 = ansS[H - 1 - j][i];
			if (c1 != c2)
			{
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <ctime>
#include <utility>
#include <fstream>
#include <queue>
#include <deque>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("vpt")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:256000000")
#pragma warning(disable:4996)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const ld pi = 3.14159265358979323846264;
const char el = '\n';
//const int inf = 1000'000'000;
const ll llinf = 1e18, mod = 1000'000'007;
 
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define all(v) v.begin(), v.end()
#define x first
#define y second
 
template<typename T> bool uin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T> bool uax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class iterator> void output(iterator begin, iterator end, char p = ' ', ostream &out = cout) { while (begin != end) { out << (*begin) << p; begin++; } out << el; }
template<class T> void output(T x, char p = ' ', ostream &out = cout) { output(all(x), p, out); }
 
mt19937 rnd(time(NULL));
 
#define int ll


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    string s;
    cin >> s;
    int n = (int)s.size();
    int pv = 0;
    int sum = 0;
    int i = 0;
    while (i < n) {
        int cur = 0;
        if (s[i] == '>') {
            int j = i;
            while (j + 1 < n && s[j + 1] == '>') {
                ++j;
            }
            cur = j - i + 1;
            if (i) {
                if (s[i - 1] == '<') {
                    uax(cur, pv + 1);
                }
            }
            while (i <= j) {
                sum += cur;
                pv = cur;
                // cout << cur << ' ';
                cur = min(cur - 1, j - i);
                ++i;
            }
        } else {
            cur = 0;
            if (i) {
                if (s[i - 1] == '<') {
                    cur = pv + 1;
                } else {
                    cur = 0;
                }
            } else {
                cur = 0;
            }
            pv = cur;
            sum += cur;
            ++i;
            // cout << cur << ' ';
        }
        // cout << cur << ' ';
    }
    if (s[n - 1] == '<') {
        sum += pv + 1;
        // cout << pv + 1 << ' ';
    } else {
        sum += pv - 1;
        // cout << pv - 1 << ' ';
    }
    cout << endl;
    cout << sum << '\n';
    return 0;
}
/*
<>>><<><<<<<>>><
0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1
0 3 2 1 0 1 2 0 1 2 3 4 5 3 2 0 1 

*/

Measured memory_bytes: 1172
class Dice
    def initialize(n)
        @up = n[0]
        @front = n[1]
        @right = n[2]
        @left = n[3]
        @back = n[4]
        @down = n[5]
    end

    def move(direction)
        case direction
        when 'S'
            tmp = @up
            @up = @back
            @back = @down
            @down = @front
            @front = tmp
        when 'W'
            tmp = @up
            @up = @right
            @right = @down
            @down = @left
            @left = tmp
        when 'E'
            tmp = @up
            @up = @left
            @left = @down
            @down = @right
            @right = tmp
        when 'N'
            tmp = @up
            @up = @front
            @front = @down
            @down = @back
            @back = tmp
        end
    end
    def getUp
        @up
    end
    def getDown
        @down
    end
    def getFront
        @front
    end
    def getBack
        @back
    end
    def getRight
        @right
    end
    def getLeft
        @left
    end
    def display
        puts "#{@up} #{@front} #{@right} #{@down} #{@back} #{@left}"
    end
    def displayUp
        puts @up
    end
    def rotation(up,front)
        if @right == front then
            move('W')
            move('S')
        elsif @left == front then
            move('E')
            move('S')
        else
            while @front != front do
                move('S')
            end
        end
        if @back != up then
            while @up != up do
                move('W')
            end
        end
    end
    def problem1
        displayUp
    end
    def problem2(up,front)
        rotation(up,front)
        puts @right
    end
    def same?(other_dice)
        rotation(other_dice.getUp,other_dice.getFront)
        @up == other_dice.getUp && @down == other_dice.getDown && @front == other_dice.getFront && @back == other_dice.getBack && @right == other_dice.getRight && @left == other_dice.getLeft
    end
    def problem3(other_dice)
        puts same?(other_dice) ? "Yes" : 'No'
    end
end

n = gets.to_i
x = gets.split.map(&:to_i)
dice = Dice.new(x)
(n-1).times do |i|
    y = gets.split.map(&:to_i)
    unless x.sort == y.sort then
        next
    end
    other_dice = Dice.new(y)
    if dice.same?(other_dice) then
        puts 'No'
        exit
    end
end
puts "Yes"


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()  
#define sz(x) int(x.size()) 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=2e5+5;
bool DEBUG=0;
vi primes;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int k; cin >> k;
    map<int,bool>vis;
    int val = 7%k;
    int cnt = 1;
    while(1){
		int mod = val;
		if(mod==0){
			cout << cnt << endl;
			return 0;
		}else{
			if(vis[mod])break;
			vis[mod]=1;
		}
		val = val*10+7;
		val%=k;
		cnt++;
	}
	cout << -1 << endl;
	return 0;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 50484
#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;
  string s;
  cin >> s;
  int ans = 0;
  rep(i,n-1) {
    if (s[i] != s[i+1]) ++ans;
  }
  ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=1e7;
int is_prime[MAXN],prime[10000];
int sieve(int n){
	memset(is_prime,-1,sizeof(is_prime));
	int index=0;
	prime[0]=prime[1]=0;
	for(int i=2;i<=n;i++){
		if(is_prime[i])prime[index++]=i;
		for(int j=2*i;j<=n;j+=i)
		is_prime[j]=0;
	}
	return index;
}
int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",sieve(n));
	}
	return 0;
}

Measured memory_bytes: 41712
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define re register
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
ll a,b;
ll work(ll n){
	ll ans=0;
    if(!(n&1)) n++,ans=n;
    ll num=(n+1ll)/2ll;
    if(num&1) ans^=1;
    return ans;
}
int main(){
    readl(a);
    readl(b);
    a--;
    printf("%lld",work(a) xor work(b));
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

void out(V<int> vec) {
	int sz = vec.size();
	rep(i, sz) printf("%d%c", vec[i], i==sz-1?'\n':' ');
}

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

	if (K % 2 == 0) {
		V<int> ans(N, K);
		ans[0] = K / 2;
		out(ans);
	} else {
		V<int> ans(N, (K + 1) / 2);
		rep(_, N/2) {
			if (ans.back() == 1) {
				ans.pop_back();
			} else {
				--ans.back();
				while (ans.size() < N) ans.pb(K);
			}
		}
		out(ans);
	}
	return 0;
}

Measured memory_bytes: 4608