akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    const int Inf = 1e9;
    int h,w;
    cin >> h >> w;
    int n=10;

    int dp[10][10];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> dp[i][j];
        }
    }

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }

    int x;
    int ans=0;
    for(int i=0; i<h*w; i++){
        cin >> x;
        if (x>=0) ans += dp[x][1];
    }

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

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

string divide[4] = {"dream","dreamer","erase","eraser"};

int main(){
    string s;
    cin >> s;

    reverse(s.begin(),s.end());
    for(int i=0; i<4; i++) reverse(divide[i].begin(),divide[i].end());

    bool can = true;
    for(int i=0; i<s.size();){
        bool can2 = false;
        for(int j=0; j<4; j++){
            string d = divide[j];
            if(s.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main() {
    int n, a, b;
    long long k;
    cin >> n >> k;

    map<int, long long> m;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        m[a] += b;
    }

    long long t = 0;
    for (auto i = m.begin(); i != m.end(); i++) {
        t += i->second;
        if (t >= k) {
            cout << i->first << endl;
            break;
        }
    }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

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

	int n,k;
	vector<int> sk;
	cin >> n >> k;
	FOR(i,0,k){
		int x;
		cin >> x;
		sk.push_back(x);
	}
	SORT(sk);
	FOR(i,0,(1<<k)){
		int p=0;
		vector<int> s;
		FOR(j,0,k){
			if(i&(1<<j)){
				p+=(1<<sk[j]);
				s.push_back(sk[j]);
			}
		}
		cout << p << ":";
		FOR(j,0,s.size()){
			cout << " " << s[j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3212
#include<cstdio>
#include<set>
using namespace std;

long a, b;
set<long> sa, sb;

int main() {
    scanf("%ld %ld", &a, &b);
    sa.emplace(1);
    sb.emplace(1);
    long x = a;
    for (int i = 2; static_cast<long>(i) * i <= a; i++) {
        if (x % i == 0) {
            sa.emplace(i);
            while (x % i == 0) x /= i;
        }
    }
    if (x > 1) sa.emplace(x);
    
    x = b;
    for (int i = 2; static_cast<long>(i) * i <= b; i++) {
        if (x % i == 0) {
            sb.emplace(i);
            while (x % i == 0) x /= i;
        }
    }
    if (x > 1) sb.emplace(x);
        
    int ans = 0;
    for (auto &i : sa) {
        if (sb.find(i) != sb.end()) ans++;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
N, X, Y = map(int, input().split())


count = [0] * (N-1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        routeA = abs(j-i)
        routeB = abs(X-i) + abs(Y-j) + 1
        min_route = min(routeA, routeB)
        count[min_route - 1] += 1

print('\n'.join(map(str, count)))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	int A, B, C;
	cin >> A >> B >> C;
	Cout(A+B+C - max({A,B,C}));
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int w,h,kumo,i,j,flg;
	char s[100][101];
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<h;i++){
		flg=0;
		for(j=0;j<w;j++){
			if(j!=0){
				printf(" ");
			}
			if(s[i][j]=='c'){
				printf("0");
				kumo=j;
				flg=1;
			}
			else{
				if(flg==0){
					printf("-1");
				}
				else{
					printf("%d",j-kumo);
				}
			}
		}
		printf("\n");
	}
	return 0;
}


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

int main() {
  int a, b;

  cin >> a >> b;
  
  if (a < 1 || a > 10000) {
    cout << "error" << endl;
  }  
  else if (b < 1 || b > 10000) {
    cout << "error" << endl;
  }
  else if (a * b %2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long

ll ai[100005];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    ll  sum = 100000000000;
    for(int i=1;i<=n;i++){
        scanf("%lld",&ai[i]);
    }
    for(int i=1;i<=n-k+1;i++)
    {
        if(ai[i]>0&&ai[k-1+i]>0)
            sum = min(sum,ai[k-1+i]);
        else if(ai[i]<0&&ai[k-1+i]<0)
            sum = min(sum,-ai[i]);
        else{
            sum = min(sum,ai[k-1+i]-2*ai[i]);
            sum = min(sum,2*ai[k-1+i]-ai[i]);
        }
        //printf("%lld\n",sum);
    //    sum = min(sum,)
    }
    printf("%lld\n",sum);


    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const long long lmax=1999999999;
const long long lmx=1999999999999999999;
const long long MAXN=200003;
long long n, t[4*MAXN];
void build(long long a[], long long v, long long tl, long long tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        long long tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = max(t[v*2] , t[v*2+1]);
    }
}
long long sum(long long v, long long tl, long long tr, long long l, long long r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    long long tm = (tl + tr) / 2;
   long long summ1=sum(v*2, tl, tm, l, min(r, tm));
    long long summ2=sum(v*2+1, tm+1, tr, max(l, tm+1), r);
    return max(summ1,summ2);
}

void update(long long v, long long tl, long long tr, long long pos, long long new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        long long tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}
long long h[200003],b[200003];
long long dp[200003],ans;
int main(){std::ios::sync_with_stdio(false);
cin>>n;
for(long long i=1;i<=n;i++){
	cin>>h[i];
}
for(long long i=1;i<=n;i++){
	cin>>b[i];
	ans=max(ans,b[i]);
}
for(long long i=1;i<=n;i++){
	long long r=sum(1,0,n+1,0,h[i]);
	dp[i]=r+b[i];
	ans=max(dp[i],ans);
	update(1,0,n+1,h[i],dp[i]);
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 10496
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

// ref. https://drken1215.hatenablog.com/entry/2018/09/08/195000
int main(void) {
    int Q;
    cin >> Q;

    for (int i = 0; i < Q; i++) {
        ll a, b;
        cin >> a >> b;

        if (a > b) {
            swap(a, b);
        }

        if (a == b) {
            cout << 2 * (a - 1) << endl;
            continue;
        }

        ll left = 1, right = 1LL << 31, mid;
        while (right - left > 1) {
            mid = left + (right - left) / 2;

            // printf("left: %lld, right: %lld, mid: %lld, %lld\n",
            //         left, right, mid, ((mid + 1) - a + 1) * ((mid + 1) - b + 1));

            // this condition is simpler
            // if (((mid + 1) / 2) * ((mid + 1) - (mid + 1) / 2) < a * b) {
            ll m = (mid + 1) - a + 1;
            ll n = (mid + 1) - b + 1;
            if (((mid + 1) / 2) * ((mid + 1) - (mid + 1) / 2) < a * b
                    && (m * n < a * b || (n == a && m == b))) {
                left = mid;
            } else {
                right = mid;
            }
        }

        cout << left - 1 << endl;
    }

    return 0;
}


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

int main()
{
  int s;
  cin >> s;
  int f[1'000'000] = {};
  int m = 1;
  while (f[s] == 0) {
    f[s] = 1;
    s = s % 2 == 0 ? s / 2 : s * 3 + 1;
    m++;
  }
  cout << m << endl;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    string S[10];
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    int ans = 0;
    for (int i = 0; i < (1 << H); i++) {
        for (int j = 0; j < (1 << W); j++) {
            int r = 0;
            for (int a = 0; a < H; a++) {
                for (int b = 0; b < W; b++) {
                    if (S[a][b] == '#' && ((1 << a) & i) && ((1 << b) & j)) {
                        r++;
                    }
                }
            }
            if (r == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
use std::collections::HashSet;
use std::cmp;

fn color(c: i32) -> i32{
    c / 400
}


fn main() {
    let scan = std::io::stdin();

    let mut line1 = String::new();
    let mut line2 = String::new();

    scan.read_line(&mut line1);
    let n = line1.parse().unwrap_or(0);
    scan.read_line(&mut line2);

    let vec: Vec<&str> = line2.split_whitespace().collect();
    let mut hs = HashSet::new();

    let mut free = 0;
    for s in vec{
        let c = s.parse().unwrap_or(0);
        if c < 3200{
            hs.insert(color(c));
        }else{
            free+=1;
        }
    }
    if hs.len()==0{
        println!("{} {}",1,free);
    }else{
        println!("{} {}",hs.len(), hs.len()+free);
    }
}

Measured memory_bytes: 4352
import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        idx = bisect.bisect_right(l, l[i]+l[j]-1, j+1)
        ans+=idx-(j+1)
print(ans)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int base = b * 10;

        int ans = -1;
        for (int i = base; i < base + 10; i++) {
            int cal = i * 8 / 100;
            if (cal == a) {
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int A[101010];
int num[101010][3];
ll ans = 1;

int main()
{
    cin >> N;
    rep(i, N)
    {
        cin >> A[i + 1];
        bool flag = true;
        int var = 0;
        for (int j = 0; j < 3; j++)
        {
            if (num[i][j] == A[i + 1])
            {
                var++;
            }
            if (flag && num[i][j] == A[i + 1])
            {
                num[i + 1][j] = num[i][j] + 1;
                flag = false;
            }
            else
            {
                num[i + 1][j] = num[i][j];
            }
        }
        ans = ans * var % MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int main() {
	int a, b;
	cin >> a >> b;
	int area = a * b - a - b + 1;
	cout << area << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
typedef long long LL;
using namespace __gnu_pbds;
typedef tree<LL,null_type,less<LL>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#include <ext/pb_ds/assoc_container.hpp>
#define N 202020
LL n , a[ N ];
int main(){
  scanf( "%lld" , &n );
  for( LL i = 0 ; i < n ; i ++ )
    scanf( "%lld" , &a[ i ] );
  set_t s;
  for( LL i = 0 ; i < n ; i ++ )
    s.insert( a[ i ] * N + i );

  for( LL i = 0 ; i < n ; i ++ ){
    s.erase( a[ i ] * N + i );
    printf( "%lld\n" , *s.find_by_order( n / 2 - 1 ) / N );
    s.insert( a[ i ] * N + i );
  }
}


Measured memory_bytes: 16256
/* 
	بسم الله الرحمن الرحیم
	
	(; طلا یک جهانی
*/	

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int MAX_N = 100 * 1000 + 5;
int cnt[MAX_N];

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		cnt[l]++;
		cnt[r]--;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cnt[i + 1] += cnt[i];
		ans += cnt[i] == m;
	}
	cout << ans;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

var n, m int
var g [][]int
var color []int

func main() {
	fmt.Scan(&n, &m)
	g = make([][]int, n) // SNSの関係を表すグラフ
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		g[a] = append(g[a], b) // 無向重みなしグラフ
		g[b] = append(g[b], a)
	}
	color = make([]int, n) // 各ノードにつける色
	for i := 0; i < len(color); i++ {
		color[i] = -1 // 初期化しておく
	}
	type query struct {
		s, t int
	}
	var Q int
	fmt.Scan(&Q)
	qs := make([]query, Q)
	for i := 0; i < Q; i++ {
		fmt.Scan(&qs[i].s, &qs[i].t)
	}
	// fmt.Println("n", n, "m", m, "g", g, "Q", Q, "qs", qs)
	// 全ての頂点からdfsする
	id := 1
	for u := 0; u < n; u++ {
		if color[u] == -1 {
			dfs(u, id)
			id++
		}
	}
	// fmt.Println("color", color)
	for i := 0; i < Q; i++ {
		if color[qs[i].s] == color[qs[i].t] {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

func dfs(v, c int) {
	// fmt.Printf("dfs(v %d, c %d) en:\n", v, c)
	color[v] = c
	for _, vv := range g[v] {
		// fmt.Printf("  v %d, g[v] %v, vv %d\n", v, g[v], vv)
		if color[vv] == -1 {
			dfs(vv, c)
		}
	}
}



Measured memory_bytes: 24004
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>

#define PY "Yes\n"    // printf(PY);
#define PN "No\n"     // printf(PN);

int main()
{
    int n, a;
    scanf("%d%d", &n, &a);

    if((n%500)<=a)
        printf(PY);
    else
        printf(PN);

    return 0;
}


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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      int tmp = R*i + G*j;
      if (tmp <= N) {
        if ((N - tmp) % B == 0) ans++;
      }
      else continue;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << setprecision(n) << var << endl

//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  int v[n], c[n];
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }

  ll ans=0;
  rep(i,n){
    if(v[i]-c[i]>0){
      ans += v[i]-c[i];
    }
  }

  prt(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int k;
	string s;
	cin >> k >> s;
	if(s.size() <= k){
		cout << s << endl;
	}else{
		s = s.substr(0, k);
		cout << s << "..." << endl;
	}
}

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

#define f first
#define s second

#define pb push_back
#define mp make_pair

#define ll long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;

const int MAXN = (int) 2e5 + 10;
const int INF = (int) 2e9 + 7;



int main() {
    #ifdef sony
        freopen("input.txt", "r", stdin);
    #endif // sony
    string s;
    cin >> s;
    for (int i = 0; i < sz(s); i++) {
        if (i % 2 && (s[i] != 'L' && s[i] != 'U' && s[i] != 'D')) cout << "No", exit(0);
        if (i % 2 == 0 && (s[i] != 'R' && s[i] != 'U' && s[i] != 'D')) cout << "No", exit(0);

    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n,m;
    int sum=0,x=0;
    int cnt = 0;
    double ave = 0;
    while(scanf("%d,%d",&n,&m)!=EOF){
        sum += n*m;
        cnt++;
        x += m;
        ave = (double)x/cnt;
    }
    ave += 0.4;

    printf("%d\n%.0lf\n",sum,ave);
    return 0;
}

Measured memory_bytes: 1212
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let n = read::<i64>();
  let mut a_vec = vec![];
  for _ in 0..n {
    a_vec.push(read::<i64>())
  }

  let mut current = 0;
  let mut cost = 0;
  while current != 1 && cost <= n {
    let next = a_vec[current];
    cost += 1;
    current = next as usize - 1;
  }

  println!("{}", if cost == n + 1 { -1 } else { cost });
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args) {
		int z;
		Scanner sc = new Scanner(System.in);
		// 整数の標準入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		Integer nArray[] = new Integer[n];
		int mArray[] = new int[m];
		// nの値だけ整数の標準入力
		for(int i = 0; i < n; i++) {
			nArray[i] = sc.nextInt();
		}
		// mの値だけ整数の標準入力
		for(int j = 0; j < m; j++) {
			mArray[j] = sc.nextInt();
		}
		// ソート
		Arrays.sort(nArray, Collections.reverseOrder());
		Arrays.sort(mArray);
		// mArray配列の最小値をzに代入
		z = mArray[0];
		// 条件一致の時"No War"を出力
		if(x < z && z <= y && nArray[0] < z) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
		sc.close();
	}
}


Measured memory_bytes: 23764
N, A, B = list(map(int, input().split()))
X = list(map(int, input().split()))
now = X[0]
res = 0
for i in X[1:]:
	if(i-now)*A < B:
		res += (i-now)*A
	else:
		res += B
	now = i
	
print(res)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  string s;
  cin >> s;

  int g = 0;
  int p = 0;
  REP(i,s.size()){
    if(s.at(i)=='g'){
      g++;
    }else{
      p++;
    }
  }

  cout << (g-p)/2 << endl;
}

Measured memory_bytes: 3760
S = input()
len_S = len(S)
list_S = list(S)

if len_S % 2 ==0:
    list_S1 = list_S[0:(len_S//2)]
    list_S2 = list_S[(len_S//2):len_S]
    list_S2.reverse()
    
else:
    list_S1 = list_S[0:(len_S//2)]
    list_S2 = list_S[((len_S//2)+1):len_S]
    list_S2.reverse()
    
count = 0

for i in range(len_S//2):
    if list_S1[i] != list_S2[i]:
        count += 1

print(count)

Measured memory_bytes: 3064
object Main{
	def main(args:Array[String]){
		val n = new java.util.Scanner(System.in).nextInt
		val a = Array.fill(n + 1,4,4,4)(0L)
		val A = 0
		val C = 1
		val G = 2
		val T = 3
		a(0)(T)(T)(T) = 1
		val mod = 1000000007

		def f(a:Int,b:Int,c:Int,A:Int,B:Int,C:Int)
		= a == A && b == B && c == C

		for {
			i <- 1 to n
			j <- 0 to 3
			k <- 0 to 3
			l <- 0 to 3
			m <- 0 to 3
			if !(   f(k,l,m,A,G,C) ||
					f(k,l,m,G,A,C) ||
					f(k,l,m,A,C,G) ||

					f(j,k,m,A,G,C) ||
					f(j,l,m,A,G,C))
		} {
			a(i)(k)(l)(m) += a(i - 1)(j)(k)(l)
			a(i)(k)(l)(m) %= mod
		}
		println(a(n).flatten.flatten.sum % mod)
	}
}


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

int main() {
  int N,D,X;
  int sum = 0;
  
  cin >> N >> D >> X;
  for(int i=0;i<N;++i){
    int s; cin >> s;
    int j=0;
    while(j*s + 1 <= D){
      sum += 1;
      j++;
    }
  }
  cout << sum + X << endl;
  return 0;
}


Measured memory_bytes: 3540
C = []
for i in range(3):
    C.append(list(map(int, input().split())))

d1 = C[0][0] + C[1][1] + C[2][2]
d2 = C[1][0] + C[2][1] + C[0][2]
d3 = C[2][0] + C[0][1] + C[1][2]
if d1 == d2 == d3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 1;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
ll n, m, x = 0, y,z,w,h, sum= 0, ans = 0;
int main(void) {
    cin >> n; vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] % 2) x = 1;
    }
    if (x) cout << "first" << endl;
    else cout << "second" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

ll gcd(ll x, ll y)
{
    if (x < y)
    {
        ll tmp = x;
        x = y;
        y = tmp;
    }

    ll m = x % y;
    if (m == 0)
    {
        return y;
    }

    return gcd(y, m);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}

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

    ll e = lcm(c, d);

    a -= 1;
    ll all = b - a;

    // a-1以下
    ll ca = a / c;
    ll da = a / d;
    ll ea = a / e;

    // b以下
    ll cb = b / c;
    ll db = b / d;
    ll eb = b / e;

    cout << (all - ((cb - ca) + (db - da) - (eb - ea))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <utility>
using namespace std;
vector<pair<int,int>> G[100010];
bool used[100010];
set<int> st;
int a[100010] = {},b[100010];
pair<int,int> p[100010];
vector<int> H[100010];
void dfs(int s){
	used[s] = true;
	for(auto x:G[s]){
		int v = x.first;
		if(used[v]) continue;
		st.insert(x.second);
		H[s].push_back(v); H[v].push_back(s);
		b[s]++; b[v]++;
		dfs(v);
	}
}

void dfs2(int s,int p){
	for(int x:H[s]){
		if(x==p) continue;
		dfs2(x,s);
	}
	if(b[s]==1){
		b[s]--; b[p]--;
		if(a[s]&1){
			cout << s + 1 << " " << p + 1 << endl;
			a[s]++;
		}else{
			cout << p + 1 << " " << s + 1 << endl;
			a[p]++;
		}
	}
}
int main(){
	int i,n,m;
	cin >> n >> m;
	if(m&1){
		cout << -1 << endl;
		return 0;
	}
	for(i=0;i<m;i++){
		int a,b; cin >> a >> b; a--; b--;
		G[a].push_back({b,i}); G[b].push_back({a,i});
		p[i] = {a,b};
	}
	for(i=0;i<n;i++) used[i] = false;
	dfs(0);
	for(i=0;i<m;i++){
		if(!st.count(i)){
			cout << p[i].first + 1 << " " << p[i].second + 1 << endl;
			a[p[i].first]++;
		}
	}
	dfs2(0,-1);
}

Measured memory_bytes: 26496
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    int x, l;
    REP(i, n) {
        cin >> x >> l;
        p[i] = make_pair(x + l, x - l);
    }
    SORT(p);
    int ans = 0;
    int mn = -(INF * 2);
    REP(i, n) {
        if (p[i].second >= mn) {
            ans++;
            mn = p[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 1e5 + 10;
int h[mxn];
int dp[mxn];
bool c[mxn];
int n,k;

int f(int i)
{
	if(c[i])
		return dp[i];
	if(i == n)
		dp[i] = 0;
	else
	{
		dp[i] = 2e18;
		FOR(jump,1,k)
		{
			if(jump + i > n)
				break;
			dp[i] = min(dp[i], f(i + jump) + abs(h[i] - h[i + jump]));
		}
	}
	c[i] = 1;
	return dp[i];
}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> k;
	FOR(i,1,n)
		cin >> h[i];
	
	memset(c,0,sizeof(c));
	cout << f(1);

	return 0;
}


Measured memory_bytes: 9984
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int l=s.size();
    int won=0;
    for(uint i=0; i<s.size(); i++) {
        if(s[i]=='o')
            won++;
    }
    if(won+(15-l)>=8)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

}



Measured memory_bytes: 256
def combmod(n,k,mod):
    a = 1
    b = 1
    for i in range(k):
        a = a * (n-i) % mod
        b = b * (i+1) % mod
    return a * pow(b, mod-2, mod) % mod
n,a,b=map(int,input().split())
mod=10**9+7
cn=pow(2,n,mod)-1
ca=combmod(n,a,mod)
cb=combmod(n,b,mod)
print((cn-ca-cb)%mod)





Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  int a=0,ans=0;
  vector<int> vec;
  for(int i=1;i<=n;++i){
    vec.push_back(pow(2,i));
  }
  for(int i=0;i<vec.size();++i){
    if(vec[i]>n){
      cout<<vec[i-1]<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3992
N = int(input())
a = [int(i) for i in input().split()]

if 1 not in a:
  ans = -1
else:
  ans = 0
  counter = 1
  for i in range(N):
    if a[i] == counter:
      counter += 1
    else:
      ans +=1

print(ans)

Measured memory_bytes: 25768
/*
	"We know what we are, but know not what we may be."
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

/*
	"You never know how strong you are until being strong is the only choice you have."
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

/*
	"With self-discipline most anything is possible."
*/
	
	long long n; cin >> n;

	vector<long long> a(n + 1), pref(n + 2), suff(n + 2);	
	for(long long i = 1; i <= n; i++){
		cin >> a[i];
	}
	
	for(long long i = 1; i <= n; i++){
		pref[i] = __gcd(pref[i - 1], a[i]);
	}
	for(long long i = n; i > 0; i--){
		suff[i] = __gcd(suff[i + 1], a[i]);
	}
	
	long long ans = 0;
	for(long long i = 1; i <= n; i++){
		ans = max(ans, __gcd(pref[i - 1], suff[i + 1]));
	}
	
	cout << ans;
	return 0;
}

/*
	"Reach for it. Push yourself as far as you can."
*/


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

namespace ITP1_3_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<List<int>>();
            string input;
            while ((input = Console.ReadLine()) != "0 0")
                list.Add(input.Split(' ').Select(x => Convert.ToInt32(x)).ToList());
            foreach (var l in list)
            {
                l.Sort();
                string[] str = l.Select(x => x.ToString()).ToArray();
                Console.WriteLine(string.Join(" ", str));
            }
        }      
    }
}

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

using namespace std;

int main(void){
  int N;
  cin >> N;
  int A[N];
  rep(i, N)
    cin >> A[i];
  // 入力終了

  // A[]中の負の数の数
  int negative_num = 0;
  rep(i, N)
    if(A[i] < 0)
      negative_num++;

  long long ans = 0;

  // 負の数が偶数個なら，操作の繰り返しで全て正にできる
  if(negative_num % 2 == 0){
    rep(i, N)
      ans += abs(A[i]);
  }
  // 奇数個なら，1つを残して全て正にできる
  // 絶対値が一番小さいものを負にしておけばOK
  else{
    // 絶対値が一番小さいものを探す
    int abs_min = 1000000000;
    rep(i, N)
      if(abs(A[i]) < abs_min)
	abs_min = abs(A[i] );

    // 絶対値が最小のもの以外は正で足す
    // 絶対値が最小のものは負で足す
    rep(i, N)
      if(abs(A[i]) != abs_min)
	ans += abs(A[i] );
      else
	ans -= abs(A[i] );
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(0, b + c - a) << endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

A_list = [500*i for i in range(A+1)]
B_list = [100*i for i in range(B+1)]
C_list = [50*i for i in range(C+1)]

result = 0

for i in A_list:
    for j in B_list:
        i_j = i + j
        for k in C_list:
            if i_j + k == X:
                result += 1

print(result)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
main(){int m,d,count=0;
cin>>m>>d;
if(d>21){
for(int i=22;i<=d;i++){
if((i/10)>1&&(i%10)>1){
if((i/10)*(i%10)<=(m))
count++;
}
}
cout<<count<<endl;
}
else{
cout<<0;
}
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll c, n, w, x, y, result = 0;
char p[1001][1001];
ll d[1001][1001];
bool a[1001][1001];

bool ch(int x, int y) {
  if(d[x][y] == d[n-1-x][y] && d[x][y] == d[x][n-1-y] && d[x][y] == d[n-1-x][n-1-y]) return true;
  return false;
}

signed main() {
	cin >> c >> n;
  rep(i, n) rep(j, n) cin >> p[i][j];
  ll tmp = 0;
  rep(i, n) rep(j, n) d[i][j] = p[i][j] - '0';
  rep(i, n / 2) rep(j, n / 2) {
    if(ch(i, j)) a[i][j] = true;
    else {
      a[i][j] = false;
      tmp++;
    }
  }
  if(tmp == 0) result++;
  rep(i, c - 1) {
    cin >> w;
    rep(j, w) {
      cin >> x >> y;
      x--, y--;
      if(d[x][y] == 1) d[x][y] = 0;
      else d[x][y] = 1;
      if(x >= n / 2) x = n - 1 - x;
      if(y >= n / 2) y = n - 1 - y;
      if(ch(x, y) != a[x][y]) {
        if(ch(x, y)) tmp--;
        else tmp++;
      }
      a[x][y] = ch(x, y);
    }
    if(tmp == 0) result++;
  }
  cout << result << endl;
	return 0;
}


Measured memory_bytes: 12516
#include <iostream>
#include <cmath>


static const double EPS = 1e-9;
using namespace std;

class Vector {
private:

public:
  double x, y;
  Vector():x(0), y(0){}; //Default constructor
  //Constructor
  Vector(double x_, double y_) {
    this->x = x_;
    this->y = y_;
  }
};


int main(){
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  double W = double(w);
  double H = double(h);
  Vector p(x, y);
  Vector cent(W/2.0, H/2.0);

  double max_area = (W * H) / 2;
  int has_other = 0;

  if ((fabs(cent.x - p.x) < EPS) && (fabs(cent.y - p.y) < EPS)) {
    has_other = 1;
  }

  cout << max_area << " " << has_other << endl;

  return 0;
}


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

#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)

int main()
{

    int n, m, k;
    cin >> n >> m;
    int vals[31]{};

    REP(i, n)
    {
        cin >> k;
        REP(j, k)
        {
            int tmp;
            cin >> tmp;
            vals[tmp] += 1;
        }
    }
    int ans = 0;
    REP1(i, 30)
    {
        if (vals[i] == n)
        {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> niz(n);

	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> niz[i];
		sum += niz[i];
	}

	double ans_floor = floor((double)sum / n);
	double ans_ceil = ceil((double)sum / n);

	int sum_floor = 0, sum_ceil = 0;

	for (int i = 0; i < n; i++)
	{
		int x = niz[i];
		sum_floor += (x - ans_floor)*(x - ans_floor);
		sum_ceil += (x - ans_ceil)*(x - ans_ceil);
	}

	cout << min(sum_floor, sum_ceil);
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

int main(void)
{
	ll n;
	cin >> n;
	vector<P> ps(n);
	rep(i, n) {
		cin >> ps[i].first >> ps[i].second;
	}
	vector<int>p;
	rep(i, n) p.push_back(i);
	vector<double> sum;
	do {
		double s = 0;
		rep(i, n - 1) {
			double dx = ps[p[i+1]].first - ps[p[i]].first;
			double dy = ps[p[i + 1]].second - ps[p[i]].second;
			s += sqrt(dx * dx + dy * dy);
		}
		sum.push_back(s);
	} while (std::next_permutation(p.begin(), p.end()));
	double pp = 0;
	for (auto e : sum) {
		pp += e / sum.size();
	}
	cout << std::fixed << std::setprecision(10) << pp << endl;
	return 0;
}

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

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

  ll ans = 0;
  REP(k, K, N) {
    REP(t, 0, N + 1) if(!(k == 0 && t == 0)) {
      ll s = t == 0 ? N - k : (N - k) / t - k;
      if(s <= 0) break;
      ans += s;
    }
  }
  cout << ans << endl;
}


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int main(){
	int a, b, c;
	long long k;
	scanf("%d %d %d %lld", &a, &b, &c, &k);
	int res = a - b;
	if(k & 1){
		res = -res;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void fct(ll N,vector<int>& fcn){
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            fcn.emplace_back(i);
            if(i*i!=N) fcn.emplace_back(N/i);
        }
    }
}

class EMaxGCD {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,s=0;
        in>>n>>k;
        vector<int> a(n);
        for(auto& i:a) in>>i,s+=i;
        vector<int> fcn;
        fct(s,fcn);
        int ans=0;
        for(auto d:fcn){
            int w=0;
            vector<int> b(n);
            fr(i,n) b[i]=a[i]%d,w+=b[i];
            sort(b.begin(),b.end());
            w/=d;
            int r=0;
            fr(i,n-w) r+=b[i];
            if(r<=k) ans=max(ans,d);
        }
        out<<ans<<endl;
    }
};

int main() {
    EMaxGCD solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

      String s = sc.next();

      int lng = s.length();

      String ans = "Yes";

      char[] c = new char[lng];
      for(int i=0;i<lng;i++){
        c[i] = s.charAt(i);
        if(i%2==0 && c[i]=='L'){
          ans = "No";
        }
        if(i%2==1 && c[i]=='R'){
          ans = "No";
        }
      }

      System.out.println(ans);

    }
}


Measured memory_bytes: 22612
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    char s[105]={};
    int k;
    scanf("%s%d",s,&k);
    ll length = strlen(s);
    int beg,end;
    char keep=s[0];
    for(beg=0;s[beg]==keep&&beg<length;beg++);
    keep = s[length-1];
    for(end=length-1;s[end]==keep&&end>=0;end--);
    ll num=0;
    int pat=1;
    //printf("%d %d\n",beg,end);
    keep = s[beg];
    for(int i=beg+1;i<=end;i++){
        if(s[i]==keep){
            pat+=1;
        }
        else{
            keep=s[i];
            num+=pat/2;
            pat=1;
        }
    }
    num+=pat/2;
    if(beg>end){
        printf("%lld\n",(length*k/2));
        return 0;
    }
    ll num1 = beg/2 + (length-end-1)/2;
    ll num2 = 0;
    if(s[0]==s[length-1]){
        num2 = (beg + length - end-1)/2;
    }
    else{
        num2 = num1;
    }
    ll ans = num * k + num1 + num2*(k-1);
    //printf("%ld %lld %lld\n",num,num1,num2);
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
  string N;
  cin >> N;
  if((N.at(3) == N.at(2)) && (N.at(4) == N.at(5))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

using namespace std;

int main() {
   int x;
   cin >> x;
   cout << (x<1200 ? "ABC" : "ARC") << endl;
 }

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

using ll = long long;

const string YES = "Yes";
const string NO = "No";

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int group(int x) {
  if (x == 2)
    return 1;
  else if (x == 4 || x == 6 || x == 9 || x == 11)
    return 2;
  else
    return 3;
}

void solve(ll x, ll y) {
  int xGroup = group(x);
  int yGroup = group(y);
  if (xGroup == yGroup) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll x;
  scanf("%lld", &x);
  ll y;
  scanf("%lld", &y);
  solve(x, y);
  return 0;
}


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

#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define reg register
#define ll long long

using namespace std;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int main() {
    string s, t;
    cin >> s >> t;
    reg int Ans = 0;
    rep (i, 0, s.size() - 1) if (s[i] == t[i]) Ans++;
    cout << Ans << endl;
    return 0;
}


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

//Okamoto Naohiro : J4-180084
//Rectangle http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C
//(中央, 奥)

long long int a, b;

int main(){
    scanf("%lld%lld", &a, &b);
    printf("%lld %lld\n", a * b, 2*(a + b));
    return 0;
}



Measured memory_bytes: 2600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF (ll)1e18+4
#define md 1000000007
#define mx 10000000
#define mk make_pair
#define __builtin_popcountll(x) one(x)
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
//const int md=1e9+7;
bool ab[22][22];
void solve(){
	int n;
	cin>>n;
	rep(i,0,n)rep(j,0,n)cin>>ab[i][j];
    vl dp(1<<n);
    dp[0] = 1;
    for(int mask = 0; mask < (1 << n) - 1; ++mask) {
        int a = __builtin_popcount(mask);
        for(int b = 0; b < n; ++b) {
            if(ab[a][b] && !(mask & (1 << b))) {
                int m2 = mask|(1 << b);
                dp[m2]=(dp[m2]+dp[mask])%md;
            }
        }
    }
	cout<<dp[(1<<n)-1]<<"\n";
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
   int t=1;
   //cin>>t;
     while(t--){
     	solve();
	 }
     return 0;
}

Measured memory_bytes: 19524
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main() {

ll N;
cin>>N;
cout<<N*(N-1)/2<<endl;






return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int calc(int a, int b, int op)
{
	switch (op) {
		case 0: return a + b;
		case 1: return a - b;
		case 2: return a * b;
	}
	return -1;
}
char itoc(int x)
{
	switch (x) {
		case 0: return '+';
		case 1: return '-';
		case 2: return '*';
	}
	return 0;
}
int main()
{
	int a[4];
	while (true) {
		for (int i=0; i<4; ++i) scanf("%d", a+i);
		if (!a[0]) break;
		sort(a, a+4);
		bool found = false;
		do {
			for (int i=0; i<27; ++i) {
				int o1 = i / 9;
				int o2 = i % 9 / 3;
				int o3 = i % 3;
				int ans = calc(calc(calc(a[0], a[1], o1), a[2], o2), a[3], o3);
				if (ans == 10) {
					printf("((%d %c %d) %c %d) %c %d\n",
						a[0], itoc(o1), a[1], itoc(o2),
						a[2], itoc(o3), a[3]);
					found = true;
					break;
				}

				ans = calc(calc(a[0], a[1], o1), calc(a[2], a[3], o3), o2);
				if (ans == 10) {
					printf("(%d %c %d) %c (%d %c %d)\n",
						a[0], itoc(o1), a[1], itoc(o2),
						a[2], itoc(o3), a[3]);
					found = true;
					break;
				}

				ans = calc(a[0], calc(a[1], calc(a[2], a[3], o3), o2), o1);
				if (ans == 10) {
					printf("%d %c (%d %c (%d %c %d))\n",
						a[0], itoc(o1), a[1], itoc(o2),
						a[2], itoc(o3), a[3]);
					found = true;
					break;
				}

				ans = calc(a[0], calc(calc(a[1], a[2], o2), a[3], o3), o1);
				if (ans == 10) {
					printf("%d %c ((%d %c %d) %c %d)\n",
						a[0], itoc(o1), a[1], itoc(o2),
						a[2], itoc(o3), a[3]);
					found = true;
					break;
				}

				ans = calc(calc(a[0], calc(a[1], a[2], o2), o1), a[3], o3);
				if (ans == 10) {
					printf("(%d %c (%d %c %d)) %c %d\n",
						a[0], itoc(o1), a[1], itoc(o2),
						a[2], itoc(o3), a[3]);
					found = true;
					break;
				}
			}
		} while (!found && next_permutation(a, a+4));
		if (!found) puts("0");
	}
	return 0;
}

Measured memory_bytes: 0
s = input()
t = input()

result = 10 ** 9
for i in range(len(s) - len(t) + 1):
  tmp = 0
  for i, c in enumerate(s[i:i+len(t)]):
    if c != t[i]:
      tmp += 1
  result = min(result, tmp)

print(result)

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

long long h[256];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        ++h[(int)s[0]];
    }
    long long ans = 0;
    const char z[] = "MARCH";
    for (int i = 0; i < 5; ++i) {
        for (int j = i+1; j < 5; ++j) {
            for (int k = j+1; k < 5; ++k) {
                ans += h[(int)z[i]]*h[(int)z[j]]*h[(int)z[k]];
            }
        }
    }
    cout << ans;
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
from fractions import gcd
lcm=(c*d)//gcd(c,d)
n=(b//c)-((a-1)//c)
n+=(b//d)-((a-1)//d)
print(b-a+1-n+((b//lcm)-((a-1)//lcm)))


Measured memory_bytes: 5048