akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		bool chk = false;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				var t = A[i]; A[i] = A[j]; A[j] = t;
				
				bool chk0 = true;
				for(int k=0;k<N-1;k++){
					chk0 &= A[k] < A[k + 1];
				}
				if(chk0) chk = true;
				
				var t2 = A[i]; A[i] = A[j]; A[j] = t2;
			}
		}
		
		Console.WriteLine(chk ? "YES" : "NO");
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11220
from sys import stdin

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

def cost(x,y):
    return pow(x-y,2)
n = I()
a = LI()

sum = 0
for i in range(n):
    sum += a[i]

ave = round(sum/n)
if ave+0.5 <= sum/n:
    ave += 1

ans = 0
for i in range(n):
    ans += cost(a[i],ave)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; cin >> n;
  if(n>=400&&n<=599) cout << 8 << endl;

  if(n>=600&&n<=799) cout << 7 << endl;

  if(n>=800&&n<=999) cout << 6 << endl;

  if(n>=1000&&n<=1199) cout << 5 << endl;

  if(n>=1200&&n<=1399) cout << 4 << endl;

  if(n>=1400&&n<=1599) cout << 3 << endl;

  if(n>=1600&&n<=1799) cout << 2 << endl;

  if(n>=1800&&n<=1999) cout << 1 << endl;
}





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



int main() {
int N;
cin >> N;
int high[200000];
for(int i = 0; i < N; i++) cin >> high[i];
int ans = 0;
for(int i = 0; i < N; i++){
int count = 0;
bool check = 1;
int now = i;
while(check == 1){
if(high[now] >= high[now+1] && high[now+1] != 0){
    count++;
    now++;
}
else{
i = now;
break;
}

}
ans = max(ans, count);
}
cout << ans << endl;
}




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

#define fastio  ios::sync_with_stdio(false); cin.tie(0);
ll maxLL(ll a, ll b){
    return a>b?a:b;
}
class BeingZero{
    public:
        ll maxHappiness(int n){
            ll dp[n][3];
            ll mxAns = LLONG_MIN;
            for(int j=0;j<3;j++){
                cin>>dp[0][j];
                mxAns = maxLL(mxAns, dp[0][j]);
            }
            int a, b, c;
            for(int i=1;i<n;i++){
                for(int j=0;j<3;j++){
                    cin>>dp[i][j];
                    dp[i][j] += maxLL(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
                    mxAns = maxLL(mxAns, dp[i][j]);
                }
            }
            return mxAns;
        }
};

int main() {
    fastio;
    BeingZero bz;
    int n;
    while(cin>>n)
        cout<<bz.maxHappiness(n)<<"\n";
    return 0;
}



Measured memory_bytes: 6048
# ABC129D - Lamp
def main():
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = max(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 177240
#include <iostream>
#include <cmath>
using namespace std;
int main() {
  int n, cnt=0;
  double x=0, y=0;
  double trX=0, trY=0;
  double dx, dy;
  double ret = 0;

  cin>>n;
  while(cin>>dx>>dy) {
    x+=dx, y+=dy;
    double temp = max(ret, sqrt(x*x+y*y));
    if(temp == sqrt(x*x+y*y)) {
      if(ret < temp) {
	ret = temp;
	trX = x, trY = y;
	// cout << "cX:" << x << " cY:" << y << endl;
      }else if(trX<=x) {
	trX = x, trY = y;
	// cout << "trX:" << trX << " trY:" << trY << endl;
      }
    }
    if(dx==0 && dy == 0) {
      cout << trX << " " << trY << endl;
      cnt++;
      if(cnt == n) break;
      x=0, y=0;
      trX=0, trY=0;
      ret = 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	for ( int n, q; cin >> n >> q, n | q; )
	{
		VS names;
		VI begins, ends;
		REP( i, 0, n )
		{
			string name;
			int b, w;
			cin >> name >> b >> w;

			names.PB( name );
			begins.PB( w - b + 1 );
			ends.PB( w );
		}

		REP( i, 0, q )
		{
			int y;
			cin >> y;

			string name;
			int res = -1;
			REP( i, 0, n )
			{
				if ( begins[i] <= y && y <= ends[i] )
				{
					name = names[i];
					res = y - begins[i] + 1;
				}
			}

			if ( res == -1 )
			{
				cout << "Unknown" << endl;
			}
			else
			{
				cout << name << ' ' << res << endl;
			}
		}
	}

	return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int max = 0;
    int count = 0;
    int before = 0;
    for(int i = 0; i < 3; i++) {
        if(S[i] == 'R') {
            if(before == 1) {
                count += 1;
            } else {
                count = 1;
            }
            before = 1;
            if(max < count) {
                max = count;
            }
        } else if(S[i] == 'S') {
            before = 0;
        }
    }
    cout << max << endl;
    return 0;
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &v : a) cin >> v;
    sort(a.begin(), a.end());
    cout << a.back() - a[0] << '\n';
}

Measured memory_bytes: 256
import math
a,b,x = map(int,input().split())
if 2*x <= a*a*b:
    print(math.degrees(math.atan(((b*b*a)/(2*x)))))
else:
    print(math.degrees(math.atan((2*(a*a*b-x))/(a*a*a)))) 

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

string a = "CODEFESTIVAL2016";
int ans;

int main(){
    string s;cin>>s;
    for(int i=0;i<16;i++){
        if(a[i]!=s[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    cout << a.at(a.size()-1) - a.at(0) << endl;
}


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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N = 1e6 + 69, mod = 1e9 + 7, INF = 1e9;

const ll INFLL = 1e18;

ll n, k, D, x, m, answer;
ll dp[10006][101], sum[N];
string s;

int main(){

        cin >> s >> D;


        int n = s.size();

        s = '*' + s;

        for(int i = 1; i <= n; i++) sum[i] = sum[i-1], sum[i] += s[i] - '0';

        dp[n+1][0] = 1;
        for(int i = n+1; i >= 2; i--){
                for(int d = 0; d < D; d++){
                        if(!dp[i][d]) continue;
                        //cout << dp[i][d] << " " << i << " " << d << endl;
                        for(int j = 0; j <= 9; j++){
                                if(j < (s[i-1] - '0') && ((d+j) + sum[i-2])%D == 0) answer += dp[i][d], answer %= mod;
                                dp[i-1][(d+j)%D] += dp[i][d];
                                dp[i-1][(d+j)%D] %= mod;
                        }
                }
        }

        answer --; answer += mod ; answer %= mod;

        if(sum[n] % D == 0) answer++;

        answer %= mod;

        cout << answer << endl;

}


Measured memory_bytes: 9984
A = list(map(int,input().split()))
H = A[1]
N = A[0]

a = [0]
b = [0]

for i in range(0,N):
    A = list(map(int,input().split()))
    a.append(A[0])
    b.append(A[1])

a.sort(reverse = True)
b.sort(reverse = True)

countb = 0

while(H > 0):
    if (b[countb] > a[0]):
        H -= b[countb]
        countb += 1
        continue
    else:
        break

if(H<0):
    print(countb)
    exit()
print(countb + int(H/a[0]) + (0!=(H%a[0])))

    


Measured memory_bytes: 11356
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[200005],b[200005],o;
bool cmp(int x,int y){
	return x>y;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n,cmp);
	for(int i=0;i<n;i++){
		if(a[i]<b[0]){
			cout<<b[0]<<endl;
		}
		else{
			cout<<b[1]<<endl;
		}
	}
}

Measured memory_bytes: 3200
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        int n = sc.nextInt();
        int k = sc.nextInt();

        if(n * 500 >= k) System.out.println("Yes");
        else System.out.println("No");

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

    boolean is_prime(long a){
        if(a <= 1) return false;
        for(int i = 2; i*i <= a; i++){
            if(a % i == 0) return false;
        }
        return true;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


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

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

fn main() {
    let n = read::<usize>();
    let ts = read_vec::<i64>();
    let vs = read_vec::<i64>();

    let mut v_limits = vec![0; n];
    for i in (0..n - 1).rev() {
        v_limits[i] = std::cmp::min(vs[i], vs[i + 1]);
        v_limits[i] = std::cmp::min(v_limits[i], v_limits[i + 1] + ts[i + 1]);
    }
    let ts = ts.iter().map(|&x| x as f64).collect::<Vec<_>>();
    let vs = vs.iter().map(|&x| x as f64).collect::<Vec<_>>();
    let v_limits = v_limits.iter().map(|&x| x as f64).collect::<Vec<_>>();
    let mut cur_v = 0.0;
    let mut ans = 0.0;
    for i in 0..n {
        // accel whole span
        if cur_v + ts[i] <= v_limits[i] {
            ans += cur_v * ts[i] + 0.5 * ts[i] * ts[i];
            cur_v += ts[i];
        } else {
            // we need decel
            let cross_t = 0.5 * (v_limits[i] - cur_v + ts[i]);
            let cross_v = cur_v + cross_t;
            if cross_v <= vs[i] as f64 {
                ans += cur_v * cross_t;
                ans += 0.5 * cross_t * cross_t;
                ans += v_limits[i] * (ts[i] - cross_t);
                ans += 0.5 * (ts[i] - cross_t) * (ts[i] - cross_t);
            } else {
                let cross_t1 = vs[i] - cur_v;
                let cross_t2 = ts[i] - (vs[i] - v_limits[i]);
                ans += cross_t1 * cur_v;
                ans += 0.5 * cross_t1 * cross_t1;
                ans += (cross_t2 - cross_t1) * vs[i];
                ans += v_limits[i] * (ts[i] - cross_t2);
                ans += 0.5 * (ts[i] - cross_t2) * (ts[i] - cross_t2);
            }
            cur_v = v_limits[i];
        }
        // println!("{} {}", ans, cur_v);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  int cnt = 0;
  REPI (i, 1, n + 1) {
    int a; cin >> a;
    if (a != i) cnt++;
  }
  cout << (cnt <= 2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 16:41:33 2019
DP_H
@author: maezawa
"""

mod = 10**9+7
h, w = list(map(int, input().split()))
a = [['#']*(w+2) for _ in range(h+2)]
for i in range(1, h+1):
    ahi = input()
    ahi = '#' + ahi + '#'
    a[i] = list(ahi)
    
#print(*a, sep='\n')

b = [[0]*(w+1) for _ in range(h+1)]
b[1][1] = 1

for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            continue
        else:
            b[i][j] += b[i][j-1] + b[i-1][j]
            b[i][j] = b[i][j] % mod

print(b[h][w])

Measured memory_bytes: 51572
from math import ceil
N = int(input())
C = [0] * N
S = [0] * N
F = [0] * N
for i in range(N-1):
  C[i], S[i], F[i] = map(int, input().split())

for i in range(N-1):
  t = 0
  for j in range(i,N-1):
    if S[j] >= t:
      t = S[j] + C[j]
    else:
      t = ceil(t / F[j]) * F[j] + C[j]

  print(t)

print(0)

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    string S;
    cin >> S;
    
    int k = S.size();

    for (int i = 1; i < k; ++i) {
        if ((k - i) % 2 == 0) {
            if (S.substr(0, (k - i) / 2) == S.substr((k - i) / 2, (k - i) / 2)) {
                cout << k - i << endl;
                break;
            }
        }
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n;
	cin >> n;
	vector<tuple<int, int, int> >s(n-1);
	for(int i=0; i<n-1; i++)
		cin >> get<0>(s[i]) >> get<1>(s[i]) >> get<2>(s[i]);
	for(int i=0; i<n-1; i++){
		int t=0;
		for(int j=i; j<n-1; j++){
			if(t < get<1>(s[j]))
				t = get<1>(s[j]);
			else
				t = (t+get<2>(s[j])-1)/get<2>(s[j])*get<2>(s[j]);
			t += get<0>(s[j]);
		}
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}

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

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define len(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for (auto &ch : s) {
        if (ch == '?') ch = 'D';
    }
    cout << s;
    return 0;
}


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

int main() {
  
  char a;
  cin >> a;
  
   //char ch = ‘c’;
   //printf("%c = %d\n", ch, ch);  //c = 99
  
  int b = 1;
  printf("%c\n", a + b);
  
 
  
  
  
  
  
  
}

Measured memory_bytes: 3600
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main(){
    int n; cin >>n;
    ll a[101000];
    rep(i, n) cin >> a[i];

    bool up_flag=false;
    bool down_flag=false;
    int count = 0;
    rep(i, n){
        if (up_flag==true){
            if(a[i]<=a[i+1]) continue;
            else {
                up_flag=false;
                // count++;
            }
        }
        else if(down_flag==true){
            if(a[i]>=a[i+1]) continue;
            else {
                down_flag=false;
                // count++;
            }
        }
        else if(up_flag==false&&down_flag==false){
            if (a[i]==a[i+1]) continue;
            else if (a[i]<=a[i+1]){
                up_flag=true;
                count++;
            }
            else if(a[i]>=a[i+1]){
                down_flag=true;
                count++;
            }
        }
    }

    out(count);
}

Measured memory_bytes: 1024
#include <stdio.h>

#define N 500000
#define Nil -1

int n;
void maxheapify(int);
int A[N];

int main(){
  int i;

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d", &A[i]);

  for(i = n/2;i>=1;i--)
    maxheapify(i);

  for(i=1;i<=n;i++)
    printf(" %d", A[i]);

  printf("\n");

  return 0;
}

void maxheapify(int i){
  int l,r,largest,tmp;

  l = 2*i;
  r = 2*i +1;

  if(l<=n && A[l]>A[i]) largest = l;
  else                 largest = i;

  if(r<=n && A[r]>A[largest]) largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxheapify(largest);
  }

}

Measured memory_bytes: 2552
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: String = sc.get();
    if S == "AAA" || S == "BBB" {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <regex>
using namespace std;

int main(){
    string str1,str2;
    cin >> str1;
    int num = 0;
    regex re("^" + str1 + "$" , regex_constants::icase);
    smatch m;
    
    while(1){
        cin >> str2;
        if(str2.find("END_OF_TEXT") != string::npos){
            break;
        }
        if(std::regex_search(str2, m, re)){
            ++num;
        }
    }
    cout << num << endl;
    return 0;
}



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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

using pl = pair<LL, LL>;

int main() {
    int N;
    cin >> N;
    vector<pair<LL, LL>> A(N + 1, pair<LL, LL>(LINF, 0));
    FOR(i, 1, N + 1) {
        LL a;
        cin >> a;
        A[i] = make_pair(a, i);
    }
    /*
    int N = 4;
    vector<pair<LL, LL>> A = {pl(LINF, 0), pl(1, 1), pl(3, 2), pl(4, 3), pl(2, 4)};
    */

    sort(ALL(A), greater<pair<LL, int>>());
    // dp[i][j] 左にi人,右にj人移動させたときの最大値
    vector<vector<LL>> dp(N + 1, vector<LL>(N + 1, 0));

    FOR(i, 1, N + 1) {
        LL act = A[i].first;
        LL index = A[i].second;

        dp[i][0] = dp[i - 1][0] + abs(act*(index - i));
        dp[0][i] = dp[0][i - 1] + abs(act*(N - i + 1 - index));
    }

    FOR(i, 2, N + 1) {
        LL act = A[i].first;
        LL index = A[i].second;
        FOR(j, 1, i) {
            LL x = act*abs(index - (i - j));
            LL y = act*abs(N - j + 1 - index);
            LL sl = dp[i - j - 1][j] + x;
            LL sr = dp[i - j][j - 1] + y;
            dp[i - j][j] = max(sl, sr);
        }
    }

    LL res = 0;
    REP(i, N + 1) {
        res = max(res, dp[i][N - i]);
    }
    cout << res << endl;

    /*
    REP(i, N + 1) {
        REP(j, N + 1 - i) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    return 0;
}


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

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

    int64_t x;
    cin >> x;
    int64_t ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}

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

const int xm = 1e5;
bool b[xm + 1];

int main() {
	b[0] = 1;
	for (int i = 0; i <= 1e5; i++)
		if (b[i])
			for (int j = 100; i + j <= 1e5 && j < 106; j++)
				b[i + j] = 1;
	int x;
	cin >> x;
	cout << b[x] << endl;
}


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

int main() {
    //
    int num, x, y;

    cin >> num >> x >> y;
    x--;
    y--;

    // マスの状況を入れる配列
    vector<vector<int>> d(num, vector<int>(num, -1));

    // 1辺ずつ調べる
    for (int i = 0; i < num; i++) {
        // キュー
        queue<int> q;
        q.push(i);
        // 自分自身を0
        d.at(i).at(i) = 0;

        while (!q.empty()) {
            // キューの先頭の要素取り出し
            auto j = q.front();
            q.pop();  // ※先頭の要素削除

            vector<int> vec2;
            if (j > 0) vec2.push_back(j - 1);
            if (j < num - 1) vec2.push_back(j + 1);
            if (j == x) vec2.push_back(y);
            if (j == y) vec2.push_back(x);

            for (auto k : vec2) {
                if (d.at(i).at(k) == -1) {
                    d.at(i).at(k) = d.at(i).at(j) + 1;
                    q.push(k);
                }
            }
        }
    }

    vector<int> vecCnt(num, 0);
    for (int i = 0; i < num; i++) {
        for (int j = i + 1; j < num; j++) {
            //
            vecCnt.at(d.at(i).at(j))++;
        }
    }

    for (int i = 1; i < num; i++) cout << vecCnt.at(i) << endl;
    //
}


Measured memory_bytes: 19088
ans=1
c=[0]*10001
for i in range(1,int(input())+1):
    for j in range(2,int(i**.5)+1):
        while i%j==0:
            c[j]+=1
            i//=j
    if i!=1:c[i]+=1  
for i in c:
    ans*=i+1
    ans%=10**9+7
print(ans)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int x_num = CountChar(s, 'x');
            if (x_num > 7) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll ans = 0;
    if((a % 2 == 0 && b % 2 == 0)
       || (a %2 == 1 && b % 2 == 1)){
        ans = b-a;
        ans /= 2;
    } else {
        ll x = a - 1;
        ll y = n - b;
        ll near = min(x, y);
        ans += near + 1;
//        cout << ans << endl;
        ans += (b - a) / 2;

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


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


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



int main() {

  cout<<fixed<<setprecision(10);

  string s;
  cin >> s;
  string p;
  cin >> p;

  s += s;

  rep(i, s.size() - p.size() + 1){
    if(s.substr(i, p.size()) == p){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;

  return 0;
}




//






Measured memory_bytes: 3220
def spaceinput():
    return list(map(int,input().split(" ")))

H,W=spaceinput()

a=[]
for i in range(H):
    a.append(spaceinput())


ress=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2!=0:
            a[i][j+1]+=1
            a[i][j]-=1
            res=' '.join(map(str,[i+1,j+1]))
            res+=" "
            res+=" ".join(map(str,[i+1,j+2]))
            ress.append(res)

for i in range(H-1):
    if a[i][-1]%2!=0:
        a[i+1][-1]+=1
        a[i][-1]-=1
        res=' '.join(map(str,[i+1,W]))
        res+=" "
        res+=" ".join(map(str,[i+2,W]))
        ress.append(res)

print(len(ress))
for sres in ress:
    print(sres)

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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);
#define debug(x , y) cerr << #x << " = " << x << y ;

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

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

int n ;

int main(){
 vector < int > a , b ;
 cin >> n ;
 a.resize( n + 1 ) ;
 b.resize( n ) ;
 forn( int , i , 0 , n + 1 ){
     cin >> a[ i ] ;
 }

 forn( int , i , 0 , n ){
     cin >> b[ i ] ;
 }

 ll con = 0 ;
 forn( int , i , 0 , n ){
    if( b[ i ] - a[ i ] >= 0 ){
        con += a[ i ] ;
        b[ i ] -= a[ i ] ;
    } else con += b[ i ] , a[ i ] -= b[ i ] , b[ i ] = 0 ;


    if( b[ i ] - a[ i + 1 ] >= 0 ){
        con += a[ i + 1 ] ;
        b[ i ] -= a[ i + 1 ] ;
        a[ i + 1 ] = 0 ;
    } else con += b[ i ] , a[ i + 1 ] -= b[ i ] , b[ i ] = 0 ;


 }

 cout << con ;

 return 0 ;
}


/*
A B C D
try to solve A , B in 30 min as possible
If their is subtask try to solve the second one first if the constraints are only differ
Read all Problem so you could find an ex that you can solve fast
A -- don't write big code focus again
B -- greedy , math , bit mask , tricks , DP
C -- solve A , B first then solve C but fast as possible
greedy
DP
binary search
DFS , BFS , DSU
bit mask
number theory , math
meet in the middle
focus on the problem and constraints.
*/



Measured memory_bytes: 1024
#include<stdio.h>
int main() {
	int a, b,k;
	int i = 0;
	int sum;
	while (scanf("%d %d",&a,&b)!=EOF) {
		k = 0;
		sum = a + b;
		while (sum > 0) {
			sum = sum / 10;
			k++;
		}
		printf("%d\n", k);
		i++;
	}	
}

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

int main() {
    int h, w, n; cin >> h >> w >> n;
    int sr, sc; cin >> sr >> sc;
    string s, t; cin >> s >> t;

    bool ans = false;
    { // to R
        int cur = sc;
        for(int i = 0; i < n; ++i) {
            if(s[i] == 'R') cur += 1;
            ans |= cur > w;
            if(t[i] == 'L') cur = max(cur - 1, 1);
        }
    }
    { // to L
        int cur = sc;
        for(int i = 0; i < n; ++i) {
            if(s[i] == 'L') cur -= 1;
            ans |= cur <= 0;
            if(t[i] == 'R') cur = min(cur + 1, w);
        }
    }
    { // to U
        int cur = sr;
        for(int i = 0; i < n; ++i) {
            if(s[i] == 'U') cur -= 1;
            ans |= cur <= 0;
            if(t[i] == 'D') cur = min(cur + 1, h);
        }
    }
    { // to R
        int cur = sr;
        for(int i = 0; i < n; ++i) {
            if(s[i] == 'D') cur += 1;
            ans |= cur > h;
            if(t[i] == 'U') cur = max(1, cur - 1);
        }
    }

    if(!ans) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class RandomAccessIterator>
auto medianOfMedians(RandomAccessIterator first, RandomAccessIterator last, int k) {
    auto _first = *first;
    using T = decltype(_first);

    int len = last - first;
    if (len == 1 && k == 0) return *first;

    int ms = (len + 4) / 5;
    T *medians = new T[ms];
    for (int i=0; i<ms; ++i) {
        auto iter = first + 5*i;
        if (5*i + 4 < len) {
            for (int j=0; j<3; ++j) {
                int minInd = j;
                for (int k=j+1; k<5; ++k) {
                    if (*(iter+k) < *(iter+minInd)) minInd = k;
                }
                swap(*(iter+j), *(iter+minInd));
            }
            medians[i] = *(iter+2);
        } else {
            medians[i] = *iter;
        }
    }

    T pivot = medianOfMedians(medians, medians + ms, ms/2);
    delete [] medians;

    int store = 0, same = 0;
    for (int i=0; i<len; ++i) {
        if (*(first+i) < pivot) {
            if (i != store + same) swap(*(first+store), *(first+store+same));
            swap(*(first+i), *(first+store));
            ++store;
        } else if (*(first+i) == pivot) {
            swap(*(first+i), *(first+store+same));
            ++same;
        }
    }

    if (store <= k && k < store + same) {
        return pivot;
    } else if (k < store) {
        return medianOfMedians(first, first+store, k);
    } else {
        return medianOfMedians(first+store+same, last, k-store-same);
    }
}

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    int maxi = -INF;
    for (int x : a) chmax(maxi, x);
    int medi = medianOfMedians(a.begin(), a.end(), N/2);
    ll res = 0;
    int cnt = -1;
    for (int x : a) {
        if (medi < x) {
            res += 2 * x;
            cnt += 2;
        }
    }
    res -= maxi;
    res += (ll)medi * (N - 1 - cnt);
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}
const int N = 100005;

ll val[N];
ll idx[N];
ll pre[N];

int _runtimeTerror_()
{
    ll n,x,m;
    cin>>n>>x>>m;
    val[0] = 1;
    val[1] = x;
    for(int i=2;i<=m+1;++i)
        val[i] = val[i-1]*val[i-1]%m;
    pre[1] = val[1];
    for(int i=2;i<=m+1;++i)
        pre[i] = pre[i-1] +val[i];
    if(n<=m+1)
    {
        ll ans = 0;
        for(int i=1;i<=n;++i)
        {
            ans += val[i];
        }
        cout<<ans<<"\n";
        return 0;
    }
    ll sum =0,period = 0;
    ll ans = 0;
    for(int i=1;i<=m+1;++i)
    {
        if(idx[val[i]]!=0)
        {
            ll j = idx[val[i]];
            sum = pre[i]-pre[j];
            period = i-j;
            ans += pre[j-1];
            ll xx = n;
            xx -= j-1;
            ans += (xx/period)*sum;
            xx %= period;
            int cur = j;
            while(xx--)
                ans += val[j++];
            break;
        }
        idx[val[i]] = i;
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 5880
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;


template<typename T>
std::map<T, int> prime_factorize(T x) {
  std::map<T, int> primes;
  for (T factor = 2; factor * factor <= x; factor++) {
    if (x % factor == 0) {
      T count = 0;
      while (x % factor == 0) {
          count++;
          x /= factor;
      }
      primes[factor] = count;
    }
  }
  if (x != 1) primes[x] = 1;
  return primes;
}
template<typename T1, typename T2>
ostream& operator << (ostream& os, const map<T1, T2>& m){
  for (const auto [k, v] : m) os << "{" << k << "," << v << "} ";
  return os;
}

int count(const map<int, int>& m, int x) {
  int cnt = 0;
  for (const auto& [k, v] : m) {
    if (v + 1 >= x) ++cnt;
  }
  return cnt;
}

int main() {
  int N; cin >> N;
  map<int, int> base;
  for (int i = 1; i <= N; ++i) {
    auto m = prime_factorize(i);
    for (auto [k, v] : m) {
      base[k] += v;
    }
  }

  int c3  = count(base, 3);
  int c5  = count(base, 5);
  int c15 = count(base, 15);
  int c25 = count(base, 25);
  int c75 = count(base, 75);

  int cnt = (c5 * (c5 - 1) / 2) * (c3 - 2) +
            (c15 * (c5 - 1)) +
            (c25 * (c3 - 1)) +
            c75;
  cout << cnt << endl;
}


Measured memory_bytes: 3616
#include <cstdio>
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=200001;
int n,m,v,a[N],b[N],pl[19][N],pr[19][N],fl[1<<18],fr[1<<18];
void updmax(int&a,int b){if(b>a)a=b;}
void updmin(int&a,int b){if(b<a)a=b;}
int main(){
	scanf("%d%d",&n,&v);
	ref(i,1,n)scanf("%d",&a[i]);
	ref(i,0,18){
		pl[i][1]=1;pr[i][n]=n;
		pl[i][0]=1;pr[i][n+1]=n;
		ref(j,1+1,n)if(a[j]-a[j-1]<=v)pl[i][j]=pl[i][j-1];else pl[i][j]=j;
		def(j,n-1,1)if(a[j+1]-a[j]<=v)pr[i][j]=pr[i][j+1];else pr[i][j]=j;
		if(!v){m=i;break;}
		v>>=1;
	}
	ref(i,0,(1<<m)-1)fl[i]=0,fr[i]=n+1;
	ref(i,0,(1<<m)-1)ref(j,1,m)if(!(i>>j-1&1)){
		int I=i|(1<<j-1);
		updmax(fl[I],pr[j][fl[i]+1]);
		updmin(fr[I],pl[j][fr[i]-1]);
	}
	ref(i,0,(1<<m)-1)if(pr[0][fl[i]+1]>=fr[((1<<m)-1)^i]-1)
		b[pr[0][fl[i]+1]]=1;
	ref(i,1,n)if(b[pr[0][i]])printf("Possible\n");
		else printf("Impossible\n");
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    ll n;
    cin >> n;
    ll ans = LONG_MAX;

    for(ll i=1; i*i <= n; ++i){
        if(n%i==0){
            if(i != n/i)
                ans = min(ans, (i)+(n/i));
            else
                ans = min(ans, i+i);
        }
    }
    cout << ans-2;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n,k;

    cin >> n >> k;

    int left = k - (n - 1);
    int right = k + (n - 1);

    for(int i=left; i<=right; i++){
       cout << i << " ";
       }
    cout << endl;
}


Measured memory_bytes: 256