akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	M := readInt()

	W := make([][]int, N+1)
	for i := range W {
		W[i] = make([]int, N+1)
		for j := range W[i] {
			W[i][j] = -1
		}
	}

	as := make([]int, M)
	bs := make([]int, M)
	cs := make([]int, M)
	for i := 0; i < M; i++ {
		a := readInt()
		b := readInt()
		c := readInt()
		W[a][b] = c
		W[b][a] = c
		as[i] = a
		bs[i] = b
		cs[i] = c
	}

	for k := 1; k <= N; k++ {
		for i := 1; i <= N; i++ {
			for j := 1; j <= N; j++ {
				if W[i][k] == -1 || W[k][j] == -1 {
					continue
				}
				d := W[i][k] + W[k][j]
				if W[i][j] == -1 || d < W[i][j] {
					W[i][j] = d
				}
			}
		}
	}

	var ans int
	for i := range as {
		a := as[i]
		b := bs[i]
		c := cs[i]
		if W[a][b] < c {
			ans++
		}
	}
	println(ans)

}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    vector<pair<int,int>> X(N);
    REP(i,N)
    {
        int tmp; cin >> tmp;
        X[i] = make_pair(tmp, i);
    }
    sort(X.begin(), X.end());

    VI ans(N);

    REP(i,N)
    {
        if(i < N/2) 
        {
            ans[X[i].second] = X[N/2].first;
        }
        else ans[X[i].second] = X[N/2 - 1].first;
    }
    REP(i,N)
    {
        cout << ans[i] << endl;
    }

}


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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;
typedef int64_t ll;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);
  int x, a, b;
  cin >> x >> a  >> b;
  cout << (x - a)%b  << endl;

  return 0;
}



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

using namespace std;

long long gcd(long long a, long long b) {
    if(b>a) {
        long long c=b; b=a; a=c;
    }
    if(b==0) return a;
    else return gcd(b, a%b);
}

int main(int argc, char const *argv[])
{
    long long n, m; cin >> n >> m;
    string s, t;
    cin >> s; cin >> t;
    long long g = gcd(n, m);
    long long a, b;
    for(long long k=0;k<g;++k) {
        a = k*(n/g); b = k*(m/g);
        if (s[a]!=t[b]) {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << m*(n/g) << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    
    System.out.println((H-h) * (W-w));
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k,sum=0;
        cin>>n>>k;
        vector<ll>v(k);
        for(int i=0;i<k;i++)
        {
            ll a;
            cin>>a;
            sum+=a;
        }
        if(n-sum>=0)
        {
            cout<<n-sum<<"\n";
        }
        else
        {
            cout<<-1<<"\n";
        }
    }
}



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

int main(){
  long long int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  vector<int> b(0);
  vector<int> kanri(n,-1);
  int y=0;//現在地-1
  
  while(kanri.at(y)==-1){
    kanri.at(y)=b.size();
    b.push_back(y+1);
    y=a.at(y)-1;
  }
  y=kanri.at(y);//yは例外の数
  
  if(k<=y) cout << b.at(k) << endl;
  else cout << b.at((k-y)%(b.size()-y)+y) << endl;
}


Measured memory_bytes: 5884
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int len = Integer.parseInt(scanner.nextLine());

        int inputs[] = new int[len];
        for (int i = 0; i < len; i++) {
            inputs[i] = Integer.parseInt(scanner.nextLine());
        }

        int maxProfit = new Main().maxProfit(inputs);
        System.out.println(maxProfit);
    }

    private static int maxProfit(int numbers[]) {
        Integer maxProfit = null;
        Integer minStart = null;
        for (int n : numbers) {
            if (minStart == null) {
                minStart = n;
                continue;
            }

            int profit = n - minStart.intValue();
            if (maxProfit == null || maxProfit < profit) {
                maxProfit = profit;
            }
            if (n < minStart.intValue()) {
                minStart = n;
            }
        }
        return maxProfit.intValue();
    }
}



Measured memory_bytes: 170812
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    string a, b;
    cin >> a >> b;
    if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int main() {

    int N;
    cin >> N;
    vl A(2e5);
    vl B(2e5);
    ll sum = 0;
    rep(i, N+1) {
        cin >> A[i];
    }
    for (int i = N; i >= 0; --i) {
        sum += A[i];
        B[i] = sum;
    }

    if (N == 0 && A[0] != 1) {
        cout << -1 << endl;
        return 0;
    }

    B[0] = 1;
    rep(i, N) {
        if (i < N && B[i] - A[i] <= 0) {
            cout << -1 << endl;
            return 0;
        }
        B[i+1] = min(B[i+1], (B[i]-A[i])*2);
        if (i == N-1 && A[i+1] != B[i+1]) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    rep(i, N+1) {
        ans += B[i];
        // cout << B[i] << " ";
    }
    // cout << endl;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    ll x;
    cin >> x;
    cout << 1000 * (x / 500) + ((x - (x / 500) * 500) / 5) * 5;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>


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



int solve(){
    int n;
    cin>>n;
    if(n==0)return 0;
    vector<int> res(5000);
    rep(i,n){
        int d,p,q;
        cin>>d>>p>>q;
        if(d==1){
            int bit = ((1<<p)-1)<<(q-1);
            int i = res.size();
            while(i>0&&(res[i-1]&bit)==0)--i;
            res[i]|=bit;
            if(res[i]==31){
                res.erase(res.begin()+i);
            }
        }
        else {
            int i = res.size();
            int bit = 1<<(q-1);
            while(i>0&&(res[i-1]&bit)==0)--i;
            rep(j,p)res[i+j]|=bit;
            for(int j=p-1;j>=0;--j){
                if(res[i+j]==31)res.erase(res.begin()+i+j);
            }
        }
    }
    int ans = 0;
    for(auto e : res){
        ans += __builtin_popcount(e);
    }
    cout<<ans<<endl;
    return 1;
}

int main(){
    while(solve());
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

template <int M> class ModInt {
    int x;

  public:
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    constexpr ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % M);
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt &p) const {
        return ModInt(*this) += p;
    }
    constexpr ModInt operator-(const ModInt &p) const {
        return ModInt(*this) -= p;
    }
    constexpr ModInt operator*(const ModInt &p) const {
        return ModInt(*this) *= p;
    }
    constexpr ModInt operator/(const ModInt &p) const {
        return ModInt(*this) /= p;
    }
    constexpr bool operator==(const ModInt &p) const { return x == p.x; }
    constexpr bool operator!=(const ModInt &p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t = 0;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    constexpr friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    constexpr friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t = 0;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using modint = ModInt<mod>;

modint solve1(const ll &h, const ll &w) {
    modint m2(2);
    return m2.pow(h) + m2.pow(w) + m2.pow(__gcd(h, w)) - 3;
}

modint solve(const ll &h, const ll &w, const ll t) {
    ll ht = __gcd(h, t), wt = __gcd(w, t);
    return solve1(h / ht, w / wt).pow(ht * wt);
}

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

    ll H, W, T;
    cin >> H >> W >> T;

    cout << solve(H, W, T) << endl;

    return 0;
}

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

using namespace std;

int main(){
  int a;
  int count=0;
  cin >> a;
  
  if(a==1 || a==10 || a==100){
    count=1;
  }else if(a==11 || a==101 || a==110){
    count=2;
  }else if(a==111){
    count=3;
  }else{
    count=0;
  }
  cout << count << endl;
}

Measured memory_bytes: 3552
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		for(char c: str.toCharArray()){
			if(Character.isUpperCase(c)){
			System.out.print(Character.toLowerCase(c));
			}else{
			System.out.print(Character.toUpperCase(c));
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 16988
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

a = set(nm())
print('YNeos'[len(a) != 2::2])


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n;
		while(true){
			n=sc.nextInt();
			if(n==-1) break;
			System.out.println(f(n));
		}
	}
	static String f(int n){
		int four[]=new int[10];
		four[0]=1;
		String str="";
		for(int i=1;i<10;i++){
			four[i]=four[i-1]*4;
		}
		for(int i=9;0<=i;i--){
			if(four[i]<=n){
				str=str+Integer.toString(n/four[i]);
				n%=four[i];
			}
			else if(!str.equals("")){
				str=str+"0";
			}
		}
		if(str.equals("")){
			return "0";
		}
		else return str;
	}
}

Measured memory_bytes: 13000
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
    static int N;
    static int[] X;
    static int[] Y;
    static double d=0;
    static double c=0;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
	    N=gi();
        X=new int[N];
        Y=new int[N];
        for (int i=0; i<N;i++) {
	        X[i]=gi();
	        Y[i]=gi();
	    }

        List<Integer> l2=new ArrayList<Integer>();
        f(l2);
	    System.out.print(d/c);
//	    if (s.contains("AC")) {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }


	}
	
	public static void f(List<Integer> l) {
		if(l.size()==N) {
			for (int i=0; i<N-1;i++) {
				d+=Math.sqrt(Math.pow(X[l.get(i+1)] - X[l.get(i)], 2) + Math.pow(Y[l.get(i+1)] - Y[l.get(i)], 2));
			}
			c++;
			return;
		}
		
		for (int i=0; i<N; i++) {
			if(!l.contains(i)) {
				List<Integer> l2=new ArrayList<Integer>();
				l2.addAll(l);
				l2.add(i);
				f(l2);
			}
		}
		
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 53464
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int mx = 0, mx2 = 0;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        if(mx < a[i]){
            mx2 = mx;
            mx = a[i];
        }
        else if(mx2 < a[i]){
            mx2 = a[i];
        }
    }
    rep(i,n){
        if(a[i] == mx) cout << mx2 << endl;
        else cout << mx << endl;
    }
    return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> l(n+1), r(n+1);
  l[1] = a[0]; r[1] = a[n-1];
  rep(i,n-1){
    l[i+2] = gcd(l[i+1],a[i+1]);
    r[i+2] = gcd(r[i+1],a[n-2-i]);
  }
  ll ans = max(l[n-1],r[n-1]);
  for(int i = 1; i<n-1; ++i){
    ans = max(ans,gcd(l[i],r[n-i-1]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    val lines: List<List<Int>> =
            System.`in`.bufferedReader()
                .readLines()
                .map { it.split(" ").map { it.toInt() } }
    val sorted = lines.drop(1)
                .sortedWith(compareBy({ it[1] }))
    var current: Long = 0
    for (task in sorted) {
        current += task[0]
        if (current > task[1]) {
            print("No")
            return
        }
    }
    print("Yes")
}


Measured memory_bytes: 141340
<?php

$n = trim(fgets(STDIN));
$numbers_str = trim(fgets(STDIN));
$numbers = explode(' ', $numbers_str);


$is_approved = true;
foreach ($numbers as $number) {
    if ($number % 2 !== 0) {
        continue;
    }

    if (! (($number % 3 === 0) || ($number % 5 === 0))) {
        $is_approved = false;
        break;
    }
}

echo $is_approved ? 'APPROVED' : 'DENIED';


Measured memory_bytes: 4728
#include <iostream>

using namespace std;

int arb[1003][1003];
int n,k;

void inc(pair<int, int> a, int V) {

    //cout << "T3 " << a.first << " " << a.second << '\n';

    for(int i = a.first; i > 0; i -= (i&-i))
        for(int j = a.second; j > 0; j -= (j&-j))
            arb[i][j] += V;

    /*for(int i = a.first; i <= 1002; i += (i&(-i)))
        for(int j = a.second; j <= 1002; j += (j&(-j))) {
            arb[i][j] += V;
        }*/

}

void upd(pair<int, int> st, pair<int, int> dr) {

    if(st.first > dr.first || st.second > dr.second)
        return;

    //cout << "T1 " << st.first << " " << st.second << " " << dr.first << " " << dr.second << '\n';

    st.first += 2;
    st.second += 2;
    dr.first += 2;
    dr.second += 2;

    //arb[2][2]++;

    inc({dr.first, dr.second}, 1);
    inc({st.first-1, dr.second}, -1);
    inc({dr.first, st.second-1}, -1);
    inc({st.first-1, st.second-1}, 1);

}

int que(pair<int, int> poz) {

    int sum = 0;

    for(int i = poz.first; i <= 1002; i += (i&(-i)))
        for(int j = poz.second; j <= 1002; j += (j&(-j))) {
            sum += arb[i][j];
        }

    /*for(int i = poz.first; i > 0; i -= (i&-i))
        for(int j = poz.second; j > 0; j -= (j&-j))
            sum += arb[i][j];*/

    return sum;

}

void magic(pair<int, int> poz, bool blk) {

    int magicI = poz.first / k;
    int magicJ = poz.second / k;

    if(!((magicI%2 == 0 && magicJ%2 == 0) || (magicI%2 == 1 && magicJ%2 == 1))) {
        blk = !blk;
    }

    pair<int, int> mod = {poz.first%k, poz.second%k};
    int addI = k-1 - mod.first;
    int addJ = k-1 - mod.second;

    //cout << "T " << k << " " << blk << " " << addI << " " << addJ << '\n';

    if(blk) {

        upd({0, 0}, {addI, addJ});
        upd({addI+1, addJ+1}, {k-1, k-1});


        //upd(poz, {poz.first + addI, poz.second + addJ});
        //upd({poz.first + addI+1, poz.second + addJ+1}, {poz.first + k-1, poz.second + k-1});

    } else {

        upd({addI+1, 0}, {k-1, addJ});
        upd({0, addJ+1}, {addI, k-1});


        //upd({poz.first + addI+1, poz.second}, {poz.first + k-1, poz.second + addJ});
        //upd({poz.first, poz.second + addJ+1}, {poz.first + addI, poz.second + k-1});

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin >> n >> k;
    int x,y;
    char C;

    for(int i = 1; i <= n; i++) {
        cin >> x >> y >> C;
        magic({x, y}, C=='B'?true:false);
    }

    int mx = 0;

    for(int i = 2; i <= k+1; i++) {
        for(int j = 2; j <= k+1; j++) {
            int T = que({i, j});
            mx = max(mx, max(T, n-T));
            //cout << "T2 " << i-2 << " " << j-2 << " " << T << " " << n-T << '\n';
        }
    }

    cout << mx;

    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 1e15
    
const int N=1e6+5;
const int M=1e9+7;
void solve()
{
	int n;
	cin>>n;
	for(int i=0;i<=1000000;i++)
	{
		int pp=floor(i*(1.08));
		if(pp==n){
			cout<<i;
			return;
		}
	}
	cout<<":(";
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;
int main() {
	int alen;
	while (scanf("%d",&alen)) {
		if (alen == 0) break;
		int a[alen];
		for (int i=0; i<alen; i++) scanf("%d",&a[i]);
		sort(a,a+alen);
		map<int, int> cnt;
		for (int i=0; i<alen; i++) {
			if (cnt.count(a[i])==0) {
				cnt[a[i]]=1;
			} else {
				cnt[a[i]]++;
			}
		}
		int res = INT_MAX;
		for (map<int, int>::iterator it=cnt.begin(); it!=cnt.end(); ++it) {
			if ((*it).second > alen/2) {
				res = (*it).first;
			}
		}
		if (res == INT_MAX) {
			printf("NO COLOR\n");
		} else {
			printf("%d\n",res);
		}
	}
}

Measured memory_bytes: 5764
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4040;
int uf[maxn];
int find(int x){
	if(x == uf[x]) return x;
	return uf[x] = find(uf[x]);
}
vector<pair<int,int> > e[maxn];
int dep[maxn], par[maxn], cost[maxn];
void dfs(int u){
	for(auto to : e[u]){
		if(to.first == par[u]) continue;
		dep[to.first] = dep[u] + 1;
		cost[to.first] = to.second;
		par[to.first] = u;
		dfs(to.first);
	}
}
int main(){
	iota(uf, uf + maxn, 0);
	int n, m; cin >> n >> m;
	vector<tuple<int,int,int> > eds;
	for(int i = 0; i < m; i++){
		int u, v, w; cin >> u >> v >> w;
		eds.push_back(make_tuple(w, u, v));
	}
	sort(eds.begin(), eds.end());
	long long mst = 0;
	for(int i = 0; i < m; i++){
		int u, v, w; tie(w, u, v) = eds[i];
		if(find(u) != find(v)){
			e[u].push_back({v, w});
			e[v].push_back({u, w});
			mst += w;
			uf[find(u)] = find(v);
		}
	}
	dfs(1);
	int q; scanf("%d", &q);
	for(int i = 0; i < q; i++){
		int s, t; cin >> s >> t;
		int big = 0;
		while(s != t){
			if(dep[s] < dep[t]) swap(s, t);
			big = max(big, cost[s]);
			s = par[s];
		}
		printf("%lld\n", mst - big);
	}
	return 0;
}


Measured memory_bytes: 8560
#include<stdio.h>

int main()
{
    int n, x, t;
    scanf("%d %d %d", &n, &x, &t);
    int d = n % x == 0 ? 0 : 1;
    int a = (n / x + d) * t;
    printf("%d\n", a);
    return 0;
}

Measured memory_bytes: 1704
N, Y = map(int, input().split())
flag = True
for x in range(N+1):
    for y in range(N+1):
        z = N-x-y
        if z>=0 and 10000*x + 5000*y + 1000*z == Y:
            print(str(x) + ' ' + str(y) + ' ' + str(z))
            flag = False
            break
            
    if not flag:
        break
    
if flag:
    print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
#define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));}
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 1e3+5;
int h,w,sr,sc,er,ec,dist[MM][MM];
char grid[MM][MM];
int main()
{
    memset(dist,0x3f,sizeof dist);
	cin.tie(0)->sync_with_stdio(0);
    cin >> h >> w;
    cin >> sr >> sc;
    cin >> er >> ec;
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
            cin >> grid[i][j];
    }
    deque<pi> q;
    dist[sr][sc] = 0;
    q.pb({sr,sc});
    while(!q.empty())
    {
        auto[x,y] =q.front(); q.pop_front();
        // do 0 weight moves
        for(auto&[ax,ay]:vector<pi>{{1,0},{-1,0},{0,1},{0,-1}})
        {
            int nx = x + ax, ny = y + ay;
            if(nx < 1 || nx > h || ny < 1 || ny > w || grid[nx][ny] == '#') continue;
            if(dist[nx][ny] <= dist[x][y] + 0) continue;
            dist[nx][ny] = dist[x][y] + 0;
            q.push_front({nx,ny});
        }

        // do 1 weight moves
        for(int i = -2; i <= 2; i++)
        {
            for(int j = -2; j <= 2; j++)
            {
                if(i == 0 && j == 0) continue;
                int nx = x + i, ny = y + j;
                if(nx < 1 || nx > h || ny < 1 || ny > w || grid[nx][ny] == '#') continue;
                if(dist[nx][ny] <= dist[x][y] + 1) continue;
                dist[nx][ny] = dist[x][y] + 1;
                q.push_back({nx,ny});
            }
        }
    }
    cout << (dist[er][ec]==INF ? -1 : dist[er][ec]) << "\n";
}


Measured memory_bytes: 8560
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
#define SEG_LEN (1 << 20)
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
  ll x,y;
  cin >> x >> y;
  if((x + y) % 3 != 0 || x == 0 || y == 0){
    cout << 0 << endl;
    return 0;
  }
  ll n = (x + y) / 3;
  x -= n;
  y -= n;
  if(x < 0 || y < 0){
    cout << 0 << endl;
    return 0;
  }
  ll a = 1,b = 1;
  REP(i,1,(x + y) + 1){
    a *= i;
    a %= INF;
  }
  REP(i,1,x + 1){
    b *= i;
    b %= INF;
  }
  REP(i,1,y + 1){
    b *= i;
    b %= INF;
  }
  cout << a * modinv(b,INF) % INF << endl;
  return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, m;
string s;
vector<int> e[200000];
pi cnt[200000];
bool dead[200000];

int main() {
    cin >> n >> m >> s;
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
        if (s[b] == 'A') cnt[a].first++;
        else cnt[a].second++;
        if (a != b) {
            if (s[a] == 'A') cnt[b].first++;
            else cnt[b].second++;
        }
    }
    while (true) {
        bool end = true;
        rep(i,n) {
            if (dead[i]) continue;
            if (cnt[i].first > 0 && cnt[i].second > 0) continue;
            end = false;
            dead[i] = true;
            queue<int> que;
            rep(j,e[i].size()) {
                if (dead[e[i][j]]) continue;
                if (s[i] == 'A') cnt[e[i][j]].first--;
                else cnt[e[i][j]].second--;
                if (cnt[e[i][j]].first == 0 || cnt[e[i][j]].second == 0) {
                    dead[e[i][j]] = true;
                    que.push(e[i][j]);
                }
            }
            while (!que.empty()) {
                int q = que.front(); que.pop();
                rep(j,e[q].size()) {
                    if (dead[e[q][j]]) continue;
                    if (s[q] == 'A') cnt[e[q][j]].first--;
                    else cnt[e[q][j]].second--;
                    if (cnt[e[q][j]].first == 0 || cnt[e[q][j]].second == 0) {
                        dead[e[q][j]] = true;
                        que.push(e[q][j]);
                    }
                }
            }
        }
        if (end) break;
    }
    rep(i,n) {
        if (!dead[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 12036
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define pb push_back

int main()
{
    lli h , aux = 1 ;
    cin >> h ;
    lli ans = 0 ;

    while (h > 0)
    {
        if (h == 1)
        {
            ans += aux ;
            break ;
        }

        ans += aux ;
        aux = aux * 2 ;
        h = h / 2 ;
    }   

    cout << ans << endl ;

    return 0 ;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    int n;
    cin >> n;

    vector<int> ans(9,0);
    int ans_max = 0, ans_min = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if((1<=a) && (a<=399)) ans[0]++;
        else if((400<=a) && (a<=799)) ans[1]++;
        else if((800<=a) && (a<=1199)) ans[2]++;
        else if((1200<=a) && (a<=1599)) ans[3]++;
        else if((1600<=a) && (a<=1999)) ans[4]++;
        else if((2000<=a) && (a<=2399)) ans[5]++;
        else if((2400<=a) && (a<=2799)) ans[6]++;
        else if((2800<=a) && (a<=3199)) ans[7]++;
        else ans[8]++;
    }

    for(int i = 0; i < 9; i++){
        if(i == 8){
            ans_max += ans[8];
            if(ans_min == 0) ans_min = 1; 
        }
        else{
            if(ans[i] != 0){
                ans_max++;
                ans_min++;
            }
        }
    }
    cout << ans_min << " " << ans_max << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
ll dp[102][100002];
ll n,w;
ll weight[100002],val[100002];
ll solve(ll r,ll idx){
    if(idx==n) return r==0? 0:INT_MAX;
    
    if(dp[idx][r]!=-1) return dp[idx][r];
    
    ll ans =solve(r,idx+1);
    if(val[idx]<=r) ans=min(ans,weight[idx] + solve(r-val[idx],idx+1));
    
    return dp[idx][r]=ans;
    
}
ll s(ll v_max){
    for(ll i=v_max;i>=0;i--){
        if(solve(i,0)<=w) return i;
        
    }
    return 0;
}
int main(){
    
    cin>>n>>w;
    ll max_value=0;
    for(ll i=0;i<n;i++) {cin>>weight[i]>>val[i];
    max_value+=val[i];}
    
	memset(dp,-1,sizeof(dp));
    cout<<s(max_value);
	return 0;
}



Measured memory_bytes: 83308
#include <stdio.h>

int main( int argc, char *argv[] )
{
    long long k, n;
    long long a[200000];
    long long max = 0;

    scanf( "%lld %lld", &k, &n );
    for( int i=0; i<n; i++ ) scanf("%lld", &a[i] );


//    for( int i=0; i<n; i++ )
//    printf( "%lld\n", a[i] );

    a[n] = k+a[0];

    for( int i=0; i<n; i++ ) {
        if( a[i+1] - a[i] > max ) max = a[i+1] - a[i];
    }
    printf( "%lld\n", k - max );
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void write(int x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
int w,h,n;
int s[105][105];
int cnt[10005];
int main()
{
	h=read();
	w=read();
	n=read();
	for(int i=1;i<=n;i++)
        cnt[i]=read();
	int k=1;
	for(int i=1;i<=h;i++)
	{
		if(i%2==1)
		{
			for(int j=1;j<=w;j++)
			{
				if(cnt[k]==0)
				k++;
				cnt[k]--;
				s[i][j]=k;
			}
		}
    else
    {
        for(int j=w;j>0;j--)
        {
            if(cnt[k]==0)
              k++;
            cnt[k]--;
            s[i][j]=k;
        }
    }
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
			printf("%d ",s[i][j]);
		printf("\n");
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int N, M;
  bool mat[100][100] = {{}};
  int deg[100] = {};
  cin >> N >> M;
  UnionFind uf(N);
  for(int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    uf.unite(x, y);
    mat[x][y] = true;
    mat[y][x] = true;
    deg[y] ^= 1;
    deg[x] ^= 1;
  }
  bool update = true;
  vector< pair< int, int > > es;
  vector< int > rots;
  for(int i = 0; i < N; i++) {
    if(uf.find(i) == i) rots.push_back(i);
  }

  for(int i = 0; i + 1 < rots.size(); i++) {
    deg[rots[i]] ^= 1;
    deg[rots[(i + 1) % rots.size()]] ^= 1;
    mat[rots[i]][rots[(i + 1) % rots.size()]] = true;
    mat[rots[(i + 1) % rots.size()]][rots[i]] = true;
    es.emplace_back(minmax(rots[i], rots[(i + 1) % rots.size()]));
  }


  while(update) {

    queue< int > que;
    vector< int > v(N, -1);
    vector< int > pv(N, -1);
    int select = -1;
    for(int i = 0; i < N; i++) {
      if(deg[i]) {
        v[i] = 0;
        deg[i] ^= 1;
        que.emplace(i);
        select = i;
        break;
      }
    }

    if(select == -1) break;

    while(que.size()) {
      int p = que.front();
      que.pop();
      for(int i = 0; i < N; i++) {
        if(p == i) continue;
        if(mat[i][p]) continue;
        if(v[i] == -1) {
          v[i] = v[p] + 1;
          pv[i] = p;
          que.emplace(i);
        }
      }
    }

    vector< pair< int, int > > ex;
    for(int i = 0; i < N; i++) {
      if(deg[i] && ~v[i]) {
        ex.emplace_back(v[i], i);
      }
    }
    sort(begin(ex), end(ex));
    if(ex.size()) {
      deg[ex[0].second] ^= 1;
      int cur = ex[0].second;
      while(cur != select) {
        es.emplace_back(minmax(cur, pv[cur]));
        mat[cur][pv[cur]] = true;
        mat[pv[cur]][cur] = true;
        cur = pv[cur];
      }
      update = true;
    } else {
      break;
    }
  }

  for(int i = 0; i < N; i++) {
    if(deg[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << es.size() << endl;
  for(auto &p : es) cout << p.first + 1 << " " << p.second + 1 << endl;
}


Measured memory_bytes: 3172
import re

s = input()
era = 'eraser'
er = 'erase'
dr = 'dream'
drm = 'dreamer'

s1 = re.sub(era,'',s)
s2 = re.sub(er,'',s1)
s3 = re.sub(drm,'',s2)
s4 = re.sub(dr,'',s3)

if s4 == '':
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3672
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

d,g=MI()
lis=[LI() for i in range(d)]
pr=[]
for x in product([0,1],repeat=d):
    #print(x)
    score=0
    pro=0
    for i in range(d):
        if x[i]==1:
            score+=100*(i+1)*lis[i][0]+lis[i][1]
            pro+=lis[i][0]
    if score>=g:
        pr.append(pro)
    else:
        rest=g-score
        #print(rest)
        for i in range(d):
            j=d-i-1
            if x[j]==0:
                pro+=min(ceil(rest/(100*(j+1))),lis[j][0]-1)
                rest-=100*(j+1)*min(ceil(rest/(100*(j+1))),lis[j][0]-1)
            if rest<=0:
                pr.append(pro)
                break
        else:
            continue
        
print(min(pr))
#print(pr)

Measured memory_bytes: 74164
H, W = map(int, input().split())
N = int(input())
an = map(int, input().split())

T = [[None for i in range(W)] for i in range(H)]

h , w = 0, 0
down = True
first = True

ha = []
reverse = False
for i in range(W):
    if reverse:
        ha += zip(range(H)[::-1],[i] * H)
    else:
        ha += zip(range(H), [i] * H)
    reverse = not reverse

wa = []
b = 0
for c, k in enumerate(an):
    c += 1
    for i in range(k):
        h,w = ha[b]
        T[h][w] = c
        b += 1

for row in T:
    print(' '.join(map(str, row)))


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a = 0;
    for (int i = 0; i < s.length() / 2; i++) {
        if (s[i] != s[s.length() - i - 1]) {
            a++;
        }
    }
    cout << a << endl;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    int Ai;
    priority_queue<int> q;
    for(int i=0;i<N;i++){
        cin >> Ai;
        q.push(Ai);
    }
    for(int i=0;i<M;i++){
        auto v = q.top(); q.pop();
        q.push(v/2);
    }
    long long res = 0;
    while(!q.empty()){
        res += q.top();
        q.pop();
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 892
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    length = len(divisors)
    if length%2 != 0:
        mov = divisors[length//2] * 2 - 2
    else:
        mov = divisors[length//2 - 1] + divisors[length//2] - 2
    return mov
n = int(input())
k = make_divisors(n)
print(k)

Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <sstream>

std::vector<std::string> split(const std::string &str, char sep)
{
	std::vector<std::string> ret;
	std::stringstream ss(str);
	std::string buf;
	while( std::getline(ss, buf, sep) ) 
	{
		ret.push_back(buf);
	}
	return ret;
}

long long calc(const std::string &s)
{
	long long sum = 0;
	std::vector<std::string> num = split(s, '+');
	for(const auto &x: num) sum += std::stoll(x);
	return sum;
}

int main()
{
	std::string S; std::cin >> S;
	int N = S.size();
	std::stack<std::vector<int> > st;
	for(int i=1; i<N; i++)
	{
		std::vector<int> tmp;
		tmp.push_back(i);
		st.push(tmp);
	}
	long long ans = 0;
	ans += std::stoll(S);
	while(!st.empty())
	{
		std::vector<int> current = st.top(); st.pop();
		std::string s = S;
		for(int i=0; i<current.size(); i++)
		{
			s.insert(current[i]+i, "+");
		}
		//std::cout << s << "=" << calc(s) << std::endl;
		ans += calc(s);
		for(int i=current.back()+1; i<N; i++)
		{
			std::vector<int> tmp = current;
			tmp.push_back(i);
			st.push(tmp);
		}

	}
	std::cout << ans << std::endl;

	return 0;
}

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

int main() {
	vector<long long> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	long long ans1 = 0;
	long long ans2 = 0;
	ans1 = (a[2] / 2) * a[1] * a[0];
	ans2 = (a[2] - (a[2] / 2)) * a[1] * a[0];
	cout << abs(ans2 - ans1) << endl;
	return 0;
}

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

int main() {
    int n, t;
    cin >> n >> t;
    int64_t ans = t;
    int pre;
    cin >> pre;
    for (int i = 0; i < n-1; i++) {
        int ti;
        cin >> ti;
        ans += min(ti - pre, t);
        pre = ti;
    }
    cout << ans << endl;
} 


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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  string S, T;
  cin >> S >> T;

  bool ans = false;
  ll len = S.size();
  rep(i, len){
    ll cnt = 0;
    rep(j, len) if(S[(i+j)%len] == T[j]) cnt++;
    if(cnt == len) ans = true;
  }
  puts(ans ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a: print("AC")
    else :print("WA")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#x = ip()                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列



print(a.count("2"))

Measured memory_bytes: 6044
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 8010
using namespace std;
char s[N];bool dp[N][N<<1];
int c[5],cnt[N],p[2][N];
int main()
{
	int a,b,n,d=1;scanf("%s",s+1);
	scanf("%d%d",&a,&b),n=strlen(s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='F') cnt[i]++;
		else d^=1,p[d][++c[d]]=i;//x->0 y->1
	d^=1,p[d][++c[d]]=n+1;
	d^=1,p[d][++c[d]]=n+2;
	for(int i=1;i<=n+2;i++) cnt[i]+=cnt[i-1];
	int o=8000;a+=o,b+=o;
	dp[1][o+cnt[p[0][1]]]=true;
	for(int i=1;i<c[0];i++)
		for(int j=0;j<=2*o;j++)
		{
			int t=cnt[p[0][i+1]]-cnt[p[1][i]];
			if(j+t<=2*o) dp[i+1][j+t]|=dp[i][j];
			if(j-t>=0) dp[i+1][j-t]|=dp[i][j];
		}
	if(!dp[c[0]][a]) return !printf("No\n");
	for(int i=0;i<=c[1];i++)
		memset(dp[i],false,sizeof(dp[i]));
	dp[0][o]=true;
	for(int i=0;i<c[1];i++)
		for(int j=0;j<=2*o;j++)
		{
			int t=cnt[p[1][i+1]]-cnt[p[0][i+1]];
			if(j+t<=2*o) dp[i+1][j+t]|=dp[i][j];
			if(j-t>=0) dp[i+1][j-t]|=dp[i][j];
		}
	if(!dp[c[1]][b]) return !printf("No\n");
	printf("Yes\n");return 0;
}

Measured memory_bytes: 63744
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

#define mod 1000000007
int n,m;
char s[1005][1005],tmp[1005][1005];
long long k;
struct Matrix{
	long long mat[5][5];
	Matrix(){memset(mat,0,sizeof(mat));}
	Matrix operator*(const Matrix &b)const{
		Matrix c;
		for(int i=1;i<=2;i++)
		for(int j=1;j<=2;j++){
			for(int k=1;k<=2;k++)
				c.mat[i][j]+=mat[i][k]*b.mat[k][j];
			c.mat[i][j]%=mod;
		}
		return c;
	}
	Matrix operator^(long long x)const{
		Matrix a(*this),ans;
		for(int i=1;i<=2;i++)ans.mat[i][i]=1;
		while(x){
			if(x&1)ans=ans*a;
			x>>=1,a=a*a;
		}
		return ans;
	}
}mat;

int qpow(int x,long long y){
	int ans=1;
	while(y){
		if(y&1)ans=1LL*ans*x%mod;
		y>>=1,x=1LL*x*x%mod;
	}
	return ans;
}

bool check(){
	for(int i=1;i<=n;i++)
		if(s[i][1]=='#'&&s[i][m]=='#')return true;
	return false;
}

void turn(){
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
		tmp[m-j+1][i]=s[i][j];
	swap(n,m);
	memcpy(s,tmp,sizeof(s));
}

int main(){
	scanf("%d%d%lld",&n,&m,&k);
	int x=0,y=0,z=0;
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)x+=s[i][j]=='#';
	}	
	bool a=check(),b=(turn(),check());turn();
	if(a&&b)return printf("1"),0;
	else if(!a&&!b)return printf("%d",qpow(x,k-1)),0;
	else if(b)turn();
	for(int i=1;i<=n;i++)
		z+=s[i][1]=='#'&&s[i][m]=='#';
	for(int i=1;i<=n;i++)
	for(int j=1;j<m;j++)y+=s[i][j]=='#'&&s[i][j+1]=='#';
	mat.mat[1][1]=x,mat.mat[1][2]=y,mat.mat[2][2]=z;
	mat=mat^(k-1);
	printf("%lld",(mat.mat[1][1]-mat.mat[1][2]+mod)%mod);
}

Measured memory_bytes: 2176