akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)

int sum(vector<int> scores, int g) {
  int x = 0;
  rep(i, g)
    x += scores.at(i);
  return x;
}

int sum2(vector<int> scores, int h,int j) {
  int x = 0;
  rep2(i, h,j)
    x += scores.at(i);
  return x;
}

int minm(vector<int> scores, int from, int to) {
  int x = 0;
  rep2(i,from, to){
    if(x > scores.at(i))
      x = scores.at(i);
  }
  return x;
}

int main() {
int N,ans;
  cin >> N;
  ans = 10000000;
  vector<int> w(N);
  rep(i,N)
    cin >> w.at(i);
  rep(i, N-1){
  if(ans > abs(sum(w,i+1)-sum2(w, i+1, N)))
    ans = abs(sum(w,i+1)-sum2(w, i+1, N));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll h ,a;
    cin >> h >> a;

    ll cnt(0);
    while(true)
    {
        h -= a;
        cnt++;
        if (h <= 0) break;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int a[N];
    int first = 0;
    int second = 0;
    for(int i = 0;i < N;i++){
        cin >> a[i];
        if(a[i] > first){
            first = a[i];
        }else if(a[i] > second){
            second = a[i];
        }
    }
    
    for(int i = 0;i < N;i++){
        if(a[i] == first){
            cout << second << endl;
        }else{
            cout << first << endl;
        }
    }
    
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    

  int main(){
      string s;
      lint n,q;
      cin>>n;
      s=to_string(n);
      rep(i,s.size()){
          if(s[i]=='7'){
              cout<<"Yes";
              return 0;
          }
      }
      cout<<"No";
  }
  
     


Measured memory_bytes: 3788
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll n, a, b;

ll f(ll l, ll r) {
	ll d = r - l;
	if (d & 1) {
		ll s1 = l + f(1, r - l);
		ll s2 = n - r + 1 + f(l + n - r + 1, n);
		return min(s1, s2);
	} else {
		return (r - l) / 2;
	}
}

int main() {
	cin >> n >> a >> b;
	cout << f(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3600
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],4)[0];
  var M = myconv(input[0],4)[1];
  var gakusei = new Array(N);
  var checkpoint = new Array(M);
  input.shift();
  for(var i = 0; i < N; i++){
    gakusei[i] = input[0];
    input.shift();
  }
  for(var i = 0; i < M; i++){
    checkpoint[i] = input[0];
    input.shift();
  }
  var output = new Array(N);
  for(var i = 0; i < N; i++){
    var tmp = 4294967297;
    var gx = myconv(gakusei[i],4)[0];
    var gy = myconv(gakusei[i],4)[1];
    for(var j = 0; j < M; j++){
      var cx = myconv(checkpoint[j],4)[0];
      var cy = myconv(checkpoint[j],4)[1];
      var kyori = Math.abs(gx - cx) + Math.abs(gy - cy);
      if(tmp > kyori){
      	tmp = kyori;
        output[i] = j+1;
      }
    }
  }
  myout(output.join("\n"));
}
Main(myin());

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

int main(){
	int y,m,d;
	scanf("%d/%d/%d",&y,&m,&d);
	//cout << y << "/" << m << "/" << d <<endl;
	if(y<2019) cout << "Heisei" << endl;
	else if(y==2019&&m<4) cout << "Heisei" << endl;
	else if(y==2019&&m==4&&d<=30) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
MOD = 10**9+7
n = max(N, M)
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
perm = lambda a,b:(fac[a]*rev[a-b])%MOD

ans = 0
for k in range(N+1):
    ans += comb(N, k)*((-1)**k)*perm(M, k)*(perm(M-k, N-k)**2)
    ans %= MOD
print(ans)


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

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

int f(int x){
    int t = 0;
    while(x%2 ==0){
        t++;
        x /= 2;
    }
    return t;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n){
        if(a[i]%2 == 1){
            cout << 0 << endl;
            break;
        }
        a[i] /= 2;
    }
    int t = f(a[0]);
    rep(i, n){
        if(f(a[i]) != t){
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;
    int l = 1;
    rep(i, n){
        l = lcm(l, a[i]);
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = (m /l + 1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 3788
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    ll N, D;
    io.read(N, D);

    vector<ll> X(N);
    vector<ll> Y(N);

    for(int i = 0; i < N; i++){
        io.read(X[i], Y[i]);
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        if(X[i] * X[i] + Y[i] * Y[i] <= D * D) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6416
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    long n,x,m;
    cin >> n >> x >> m;

    int k = log2(n) + 1;
    vector tb(k+1, vector(m, -1LL));
    vector sum(k+1, vector(m, 0LL));
    unordered_map<long,bool> mp;

    for (long i=0; i<m; i++) {
        tb[0][i] = i*i % m;
        sum[0][i] = i;
    }

    for (int i=0; i<k; i++) {
        for (int j=0; j<m; j++) {
            if (tb[i][j] == -1) tb[i+1][j] = -1;
            else {
                sum[i+1][j] = sum[i][j] + sum[i][tb[i][j]];
                tb[i+1][j] = tb[i][tb[i][j]];
            }
        }
    }

    long ans = 0;
    for (int i=0; i<=k; i++) {
        if ((n>>i) & 1) {
            ans += sum[i][x];
            x = tb[i][x];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 58548
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define SZ 100001

int N;
ll arr[51], p[51], X;

ll func(ll N, ll X) {
	if (N == 0) return (X > 0 ? 1 : 0);
	if (X <= 1 + arr[N - 1]) return func(N - 1, X - 1);
	return p[N - 1] + 1 + func(N - 1, X - 2 - arr[N - 1]);

}

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

	cin >> N >> X;

	arr[0] = p[0] = 1;
	for (int i = 1; i <= N; ++i) {
		arr[i] = arr[i - 1] * 2 + 3;
		p[i] = p[i - 1] * 2 + 1;
	}

	cout << func(N, X);

}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  int two = 0;
  int four = 0;
  int odd = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % 4 == 0) {
      four++;
    } else if (a[i] % 2 == 0) {
      two++;
    } else {
      odd++;
    }
  }

  bool ans;
  if (two == 0) {
    if (four + 1 >= odd) {
      ans = true;
    } else {
      ans = false;
    }
  } else {
    if (four >= odd) {
      ans = true;
    } else {
      ans = false;
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 4000
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		int K=sc.nextInt();
		int[] A=new int[N];
		for (int i=0;i<N;++i) {
			A[i]=sc.nextInt();
		}
		Arrays.sort(A);
		long ans=0;
		for (int i=0;i<K;++i) {
			ans+=A[i];
		}
		System.out.println(ans);
	}

	void tr(Object...o) {System.out.println(Arrays.deepToString(o));}
}

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: 32624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }   
    vector<int> graph[100010];
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    int ret = 0;
    for(int i = 0;i < N;i++) {
        bool cnt = true;
        for(int j = 0;j < graph[i].size();j++) {
            if(vec.at(i) <= vec.at(graph[i].at(j))) {
                cnt = false;
            }
        }
        if(cnt == true) {
            ret++;
        }
    }
    cout << ret << endl;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    int ki = (w + 1) / 2;
    int gu = w / 2;

    if (h == 1 or w == 1) {
        print(1);
        return 0;
    }

    if (h % 2 == 0) {
        print(h / 2 * (ki + gu));
    } else {
        print(h / 2 * gu + (h + 1) / 2 * ki);
    }

    return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
#define SpaceNewLine(a) Rep(i,a.size())cout<<a[i]<<(i==a.size()-1?'\n':' ')
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {
    // setup {{{ 1
    cin.tie(0);
    ios::sync_with_stdio(false);
    // }}}

    int N;
    Scd(N);

    vi A(N);
    vi B(N);

    Rep(i,N){
        Scd(A[i]);
        B[i] = A[i];
    }

    sort( B.begin(), B.end() );


    Rep(i,N){
        printf ("%d\n", B[A[i] == B[N-1] ? N-2 : N-1] );
    }

    return 0;
}



Measured memory_bytes: 3200
line = gets.chomp.split(" ").map{|n| n.to_i}
price_a = line[0]
price_b = line[1]
price_c = line[2]
req_x = line[3]
req_y = line[4]

# plan1. 総当たり
lower = price_a*req_x + price_b * req_y
[req_x, req_y].max.times do |num|
  num += 1
  c = 2 * num
  a = req_x - num
  a = a>0 ? a : 0
  b = req_y - num
  b = b>0 ? b : 0

  price = price_a*a + price_b*b + price_c * c
  lower = price if lower > price
end
puts lower


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long ll;
ll n, mn, ans, a[500005], s[500005], v[500005];
string b;
queue<int> q1, q2;
void pu(int p, int q) {
	if (p < 0 || p > n || v[p]) return;
	s[p]--;
	if (s[p] <= 0) {
		v[p] = 1;
		q1.push(p);
		q2.push(q);
	}
}
void f(int p, int q) {
//	if (p < 0 || p > n || v[p]) return;
//	s[p]--;
//	if (s[p] <= 0) {
//		v[p] = 1;
		ans += q;
		if (p > 0 && b[p - 1] == '>') pu(p - 1, q + 1);
		if (b[p] == '<') pu(p + 1, q + 1);
//	}
}
int main()
{
	ll i, t1, t2;
	cin >> b;
	n = b.size();
	for (i = 0; i <= n; i++) {
		if (i > 0 && b[i - 1] == '<') s[i]++;
		if (b[i] == '>') s[i]++;
	}
	for (i = 0; i <= n; i++) if (s[i] == 0) pu(i, 0);
	while (!q1.empty()) {
		t1 = q1.front(); q1.pop();
		t2 = q2.front(); q2.pop();
		f(t1, t2);
	}
	cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 10244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main(){
    int x;
    int n;
    int a=10000;
    int ans;
    cin >> x >> n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int p_now=0;
    
    rep(i,102){
        if(i == p[p_now]){
            p_now++;
            continue;
        }
        int sa = abs(x - i);
        if(sa<a){
        a = min(a,sa);
        ans = i;
    }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 3628
S=input()
Y=int(S[:2])
M=int(S[2:])
if Y==0 or Y>12:
    #Y!=MANTH
    if M==0 or M>12:
        print("NA")
    else:
        print("YYMM")
else:
    if M==0 or M>12:
        print("MMYY")
    else:
        print("AMBIGUOUS")


Measured memory_bytes: 9156
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    int ab[26]={};
    int i;
    while(getline(cin,str)){
        for(i=0;i<str.size();i++){
            if(str[i]>='a'&&str[i]<='z') ab[str[i]-'a']++;
            else if(str[i]>='A'&&str[i]<='Z') ab[str[i]-'A']++;
        }
    //cout << str << endl;
    }
    for(i=0;i<26;i++){
        cout << (char)('a'+i) << " : " << ab[i] << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    string str;
    cin>>str;
    int len=str.size();

    stack<int>stk;
    int Ans=0;
    stk.push(str[0]-48);
    for(int i=1 ; i<len ; i++){
        if(stk.top()==(str[i]-48)){
            Ans++;
            stk.push(!(str[i]-48));
        }
        else stk.push(str[i]-48);
    }

    cout<<Ans<<endl;

    return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;
    return 0;
}


Measured memory_bytes: 256
"""
最小値で置き換えるなら全ての要素が等しくなったら全て最小値
8 3
k-1づつ隣に影響を及ぼせる
1の位置がiだとしたら(i-1)/(k-1)の切り上げと(N-i)/(k-1)の切り上げ
"""
import math

n , k = map(int, input().split())
b = list(map(int,input().split()))
cnt = 1
i = 0
for t in b:
    if t == 1:
        i = cnt
        break
    cnt += 1

result = math.ceil((i-1)/(k-1)) + math.ceil((n-i)/(k-1))
if ((i-1)/(k-1) - math.floor((i-1)/(k-1))) != 0 and ((n-i)/(k-1) - math.floor((n-i)/(k-1))) != 0 and (((i-1)/(k-1) - math.floor((i-1)/(k-1))) + ((n-i)/(k-1) - math.floor((n-i)/(k-1)))) <= 1:
    result -= 1

print(result)


Measured memory_bytes: 13812
S = input()

clear = True
l = list()
for n in range(4):
    if S[n] not in S[n+1:]:
        l.append(S[n])
    if len(l) > 2:
        clear = False
for x in l:
    if [y for y in S].count(x) > 2:
        clear = False
if clear:
    print("Yes")
else:
    print("No")


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

using namespace std;


int main() {
    int a[3][3];
    int n;
    int board[3][3];

    rep(i,3) rep(j,3) cin >> a[i][j];
    cin >> n;
    int b[n];
    rep(i,n) cin >> b[i];
    rep(i,3) rep(j,3) board[i][j]=0;

    rep(i,n) {
        rep(j,3) {
            rep(k,3) {
                if(b[i] == a[j][k]) {
                    board[j][k]=1;
                }
            }
        }
    }

    bool can = false;
    rep(i,3) {
        if(board[i][0] == 1 && board[i][1] == 1 && board[i][2] == 1) {
            can = true;
        }
    }

    rep(i,3) {
        if(board[0][i] == 1 && board[1][i] == 1 && board[2][i] == 1) {
            can = true;
        }
    }

    if(board[0][0] == 1 && board[1][1] == 1 && board[2][2] == 1) {
        can = true;
    }
    
    if(board[0][2] == 1 && board[1][1] == 1 && board[2][0] == 1) {
        can = true;
    }

    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int main(void){
    int N, K;
    scanf("%d %d", &N, &K);

    if(K == 1){
        printf("0\n");
    }else{
        printf("%d\n", N - K);
    }
    return 0;
}


Measured memory_bytes: 256
S=list(input())
T=input()
start=-1
ans=[]
for i in range(len(S)):
    flag=0
    for j in range(len(T)):
        if i+j>=len(S):
            flag=1
            break
        if S[i+j]==T[j] or S[i+j]=="?":
            continue
        else:
            flag=1
            break
    if flag==0:
        start=max(start,i)
for i in range(start,start+len(T)):
    S[i]=T[i-start]
for i in range(len(S)):
    if S[i]=="?":
        ans.append("a")
    else:
        ans.append(S[i])
if start==-1:
    print("UNRESTORABLE")
else:
    print("".join(ans))

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

int d[15],n,k;

bool judge()
{
	int digit,nn=n;
	if(n==0 && d[1]==0)return false;
	while(nn>0)
	{
		digit=nn%10;
		for(int i=1;i<=k;i++)
			if(digit==d[i])return false;
		nn/=10;
	}
	return true;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&d[i]);
	}
	while(!judge())n++;
	printf("%d",n);
}


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

constexpr int mod = 1e9 + 7;

ll comb[2010][2010];

void init(int n) {
  comb[0][0] = 1;
  rep(i, n) {
    rep(j, i+1) {
      comb[i+1][j] += comb[i][j];
      comb[i+1][j] %= mod;
      comb[i+1][j+1] += comb[i][j];
      comb[i+1][j+1] %= mod;
    }
  }
}

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

  int n, k;
  cin >> n >> k;
  init(2005);
  const int num_red = n - k;
  for (int i = 1; i <= k; ++i) {
    ll c_blue = comb[k-1][i-1];
    ll c_red = comb[num_red+1][i]; 
    ll ans = c_blue * c_red;
    ans %= mod;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 30336
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
res = 0
for i in range(N):
  res += B[A[i] - 1]
  if i != 0:
    if A[i - 1] + 1 == A[i]:
      res += C[A[i - 1] - 1]
print(res)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n;


    //合計の高さ
    long int result = 0;
    //前の人の高さ
    long int height = 0;

    int i;

    scanf("%d", &n);


    for(i = 0; i < n; i++){
        long int this_height;
        scanf("%ld", &this_height);
        if(height > this_height)
            result += (height - this_height);

        else
            height = this_height;

    }

    printf("%ld\n", result);



    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int n,x,y;
	cin>>n>>x>>y;
	int a[n];
	for(int i=1;i<n;i++)a[i]=0;
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int ans=0;
			ans=min(min(j-i,abs(i-x)+1+abs(j-y)),abs(i-y)+1+abs(j-x));
			a[ans]++;
		}
	}
	for(int i=1;i<n;i++)
		cout<<a[i]<<endl;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int mod = 1000000007;
int n, m, a[20], dp[17][1 << 16], U, F[100000], I[100000];
void up(int &x, int y) { if ((x += y) >= mod) x -= mod; }
int C(int x, int y) { if (x < y) return 0; return static_cast<long long> (F[x]) * I[y] % mod * I[x - y] % mod; }
int main() {
	std::scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) std::scanf("%d", &a[m - i - 1]);
	U = 1 << n;
	F[0] = I[0] = F[1] = I[1] = 1;
	for (int i = 2; i < U; i++) 
		F[i] = static_cast<long long> (F[i - 1]) * i % mod,
		I[i] = static_cast<long long> (I[mod % i]) * (mod - mod / i) % mod;
	for (int i = 2; i < U; i++)
		I[i] = static_cast<long long> (I[i - 1]) * I[i] % mod;
	dp[0][0] = 1;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < U; j++) {
			up(dp[i + 1][j], dp[i][j]);
			for (int k = 0; k < n; k++)
				if (!(j & 1 << k))
					up(dp[i + 1][j | 1 << k], static_cast<long long> (dp[i][j]) * F[1 << k] % mod * C(U - j - a[i], (1 << k) - 1) % mod);
		}
	}
	int ans = 0;
	for (int i = 0; i < U; i++) {
		int t = static_cast<long long> (dp[m][i]) * F[U - i - 1] % mod;
		if (__builtin_parity(i)) up(ans, mod - t); else up(ans, t);
	}
	ans = static_cast<long long> (ans) * U % mod; 
	std::printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4736
N, K = map(int, input().split())
S = input().rstrip()
s0 = S[0]
cnt = 1
d = []
for s in S[1:]+"2":
    if s == s0:
        cnt += 1
    else:
        d.append(cnt)
        cnt = 1
    s0 = s
if S[0] == "0":
    d = [0] + d
if S[-1] == "0":
    d += [0]
L = len(d)
if L//2 < K:
    print(sum(d))
else:
    S = sum(d[:2*K+1])
    res = S
    for i in range(2,L-2*K+1,2):
        S = S - d[i-2] - d[i-1] + d[2*K+i-1] + d[2*K+i]
        res = max(S,res)
    print(res)

Measured memory_bytes: 79404
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

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

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

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

void solve();

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

    solve();
}

void solve() {
    ll h, w, k;
    std::cin >> h >> w >> k;

    vstr c(h);
    for (ll i = 0; i < h; i++)
        std::cin >> c[i];

    auto f = [=](vstr a) -> ll {
        ll res = 0;
        for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++)
            res += a[i][j] == '#';

        return res;
    };

    ll ans = 0;
    for (ll s = 0; s < 1LL << h; s++) {
        for (ll t = 0; t < 1LL << w; t++) {
            vstr tmp = c;
            for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++)
                if ((s >> i & 1) || (t >> j & 1))
                    tmp[i][j] = 'x';
            ans += f(tmp) == k;
        }
    }

    std::cout << ans << '\n';
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
#define MAX_N 200010
using namespace std;
int n,k,q,ans[MAX_N];
int main()
{
    ios::sync_with_stdio(0);
	cin>>n>>k>>q;
	for(int i=1;i<=q;++i)
	{
		int p;
		cin>>p;
		ans[p]++;
	}
	for(int i=1;i<=n;++i)
	{
		if(ans[i]+k-q<=0)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
#include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
  int A,B,C;
  cin >> A >>B>>C;
  if((A!=B&&B==C)||(B!=C&&C==A)||(C!=A&&A==B))cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 256
i,o,t,j,l,s,z = map(int,input().split())
a = 0
b = 0
if i > 0 and j > 0 and l > 0:
    a += 3
    for k in [i-1,j-1,l-1]:
        if k % 2 == 1:
            a += k-1
        else:
            a += k

for k in [i,j,l]:
        if k % 2 == 1:
            b += k-1
        else:
            b += k
print(o + max(a,b))

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

using namespace std;

int main() {
  string ABCD;
  cin >> ABCD;
  int A = ABCD[0] - '0';
  int B = ABCD[1] - '0';
  int C = ABCD[2] - '0';
  int D = ABCD[3] - '0';

  if (A + B + C + D == 7) {
    cout << to_string(A) + "+" + to_string(B) + "+" + to_string(C) + "+" +
                to_string(D) + "=7";
    return 0;
  }
  if (A + B + C - D == 7) {
    cout << to_string(A) + "+" + to_string(B) + "+" + to_string(C) + "-" +
                to_string(D) + "=7";
    return 0;
  }
  if (A + B - C + D == 7) {
    cout << to_string(A) + "+" + to_string(B) + "-" + to_string(C) + "+" +
                to_string(D) + "=7";
    return 0;
  }
  if (A + B - C - D == 7) {
    cout << to_string(A) + "+" + to_string(B) + "-" + to_string(C) + "-" +
                to_string(D) + "=7";
    return 0;
  }
  if (A - B + C + D == 7) {
    cout << to_string(A) + "-" + to_string(B) + "+" + to_string(C) + "+" +
                to_string(D) + "=7";
    return 0;
  }
  if (A - B + C - D == 7) {
    cout << to_string(A) + "-" + to_string(B) + "+" + to_string(C) + "-" +
                to_string(D) + "=7";
    return 0;
  }
  if (A - B - C + D == 7) {
    cout << to_string(A) + "-" + to_string(B) + "-" + to_string(C) + "+" +
                to_string(D) + "=7";
    return 0;
  }
  if (A - B - C - D == 7) {
    cout << to_string(A) + "-" + to_string(B) + "-" + to_string(C) + "-" +
                to_string(D) + "=7";
    return 0;
  }
  return 0;
}


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

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> grid(h);
    rep(i, h) cin >> grid[i];

    vector<string> ans1(h, string(w,'.')), ans2(h, string(w,'.'));
    rep(i, h) {
        rep(j, w) {
            if (grid[i][j] == '#') {
                ans1[i][j] = ans2[i][j] = '#';
            }
        }
    }
    ans1[0] = string(w, '#');
    ans2[h-1] = string(w, '#');
    for (int i = 1; i < h - 1; i++) {
        rep(j, w) {
            if (j & 1) {
                ans1[i][j] = '#';
            } else {
                ans2[i][j] = '#';
            }
        }
    }
    rep(i, h) cout << ans1[i] << endl;
    cout << endl;
    rep(i, h) cout << ans2[i] << endl;
}

Measured memory_bytes: 4652
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	long long int c;
	cin >> n >> c;
	long long int x[100001] = {}, v[100001] = {};
	x[n + 1] = c;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> v[i];
	}
	long long int getcal[100010] = {}, getcal_rev[100010] = {};
	for(int i = 1; i <= n; i++){
		getcal[i] = getcal[i - 1] + v[i];
	}
	for(int i = n; i >= 1; i--){
		getcal_rev[i] = getcal_rev[i + 1] + v[i];
	}
	long long int result[100010][2], result_rev[100010][2];
	result[0][0] = result[0][1] = 0;
	result_rev[n + 1][0] = result_rev[n + 1][1] = 0;
	for(int j = 0; j < 2; j++){
		for(int i = 1; i <= n; i++){
			result[i][j] = max(result[i - 1][j], getcal[i] - (j + 1) * x[i]);
		}
		for(int i = n; i >= 1; i--){
			result_rev[i][j] = max(result_rev[i + 1][j], getcal_rev[i] - (j + 1) * (c - x[i]));\
		}
	}
	long long int ans = 0;
	for(int i = 1; i <= n; i++){
		ans = max(ans, max(result[i - 1][1] + result_rev[i][0], result_rev[i + 1][1] + result[i][0]));
		// cout << result[i - 1].first + result_rev[i].first + c - x[result_rev[i].second] << " " << result_rev[i + 1].first + result[i].first + x[result[i].second] << endl;
		// cout << i << " " << result[i].first << " " << result[i].second << " : " << result_rev[i].first << " " << result_rev[i].second << endl;
		// cout << i << " " << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
/* ex3_3
    riverstone*/

#include <stdio.h>
 
int main(void){
    // 数値number、進数baseをintで定義し入力する。
    int number,base; 
    scanf("%d%d", &number, &base);
    
    // 桁数
    int digit = 1; 

    //numberをbaseで何回割れるかを数える。
    //while文によりbaseで割った商が0より大きい間繰り返す
    while (number / base > 0)
    {
        number /= base;     //numberにnumberをbaseで割った商を代入
        digit += 1;
    }

    // digitを出力
    printf("%d\n", digit);
 
    return 0;
    
}

Measured memory_bytes: 128
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid (l+r>>1)

using namespace std;
char s[10];
typedef long long LL;

bool query(LL x)
{
	printf("? %lld\n",x);
	fflush(stdout);
	scanf("%s",s);
	return s[0]=='Y';
}

void solve1()
{
	int x=1;
	rep(i,0,9)
	{
		if(query(x*9ll))
		{
			printf("! %d\n",x);
			fflush(stdout);
			break;
		}
		x*=10;
	}
}

void solve3(int l,int r)
{
	while(l<=r) query(mid*10ll)?r=mid-1:l=mid+1;
	printf("! %d\n",r+1);
	fflush(stdout);
}

void solve2()
{
	int x=1;
	rep(i,0,9)
	{
		if(!query(x))
		{
			solve3(x/10,x-1);
			break;
		}
		x*=10;
	}
}

int main()
{
	if(query(1000000000)) solve1();
	else solve2();
	return 0;
}

Measured memory_bytes: 504
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
    for j in range(1, min(K + 1, N - i)):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Measured memory_bytes: 57056
#include<bits/stdc++.h>
using namespace std;
const int maxn =  1e6 + 10;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
#define int long long
#define pb(a) push_back(a)
#define debug(a) cout << "a : " << a << '\n'
#define mp(a , b) make_pair(a ,b)
const int mod = 1e9 + 7;
const double eps = 1e-6;
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
template<typename T>void Out(T x){if(x<0)putchar('-'),x=-x;if(x>9)Out(x/10);putchar(x%10+'0');}
int nex[maxn];
int a[maxn];
signed main()
{
    ios,cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i ++) cin >> a[i] , a[i] %= mod;
    for(int i = n ; i >= 1 ; i --) nex[i] = nex[i + 1] + a[i] , nex[i] %= mod;
    int ans = 0;
    for(int i = 1 ; i <= n ; i ++){
        ans += (nex[i + 1] * a[i]) % mod;
        ans %= mod;
    }
    cout << ans << '\n';
    return 0;
}

/*
1
12
LLLLRRLRRRLL
*/


Measured memory_bytes: 6816
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int a, b, i, k;
	cin >> k;
	cin >> a >> b;
	bool can = false;
	for (i = a; i <= b; i++) {
		if (i % k == 0) {
			can = true;
			break;
		}
	}

	if (can)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;
	
	return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int n,m,f=0,x,y,d[100005],fail[100005];
vector<int>v;
pair<int,int>e[100005];
int get(int x)
{
    return fail[x]==x?x:fail[x]=get(fail[x]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        d[x]++;
        d[y]++;
        e[i]=make_pair(x,y);
    }
    bool flag=false;
    for(int i=1;i<=n;i++)
        if(d[i]%2)
        {flag=false;break;}
        else if(d[i]>=6) flag=true;
        else if(d[i]>=4)
        {
            f++;
            v.push_back(i);
            if(f>=3) flag=true;
        }
    if(f==2&&!flag)
    {
        for(int i=1;i<=n;i++)
            fail[i]=i;
        for(int i=1;i<=m;i++)
        {
            int x=e[i].first,y=e[i].second;
            if(x==v[0]||y==v[0]) continue;
            fail[get(x)]=fail[get(y)];
        }
        for(int i=1;i<=n;i++)
            f+=fail[i]==i;
        if(f>=5) flag=true;
    }
    printf(flag?"Yes":"No");
}


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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

//2値の最小公倍数
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    ll n; cin >> n;
    ll cnt = 0;
    ll buf;

    for(int i=1;i*i<=n-1;i++){
        buf = (n-1)/i;
        if(buf>=i) buf = 2*(buf-(i-1))-1;
        else buf *= 2;
        
        cnt += buf;
    }
    cout << cnt;
}

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

const int N = 3030;

int n, a[N];
bool dp[N];
vector<int> nei[N];

void dfs(int v, int par = -1) {
	dp[v] = false;
	for (int u: nei[v])
		if ((u ^ par) && a[u] < a[v]) {
			dfs(u, v);
			dp[v] |= !dp[u];
		}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		nei[--u].push_back(--v);
		nei[v].push_back(u);
	}
	for (int i = 0; i < n; i++) {
		dfs(i);
		if (dp[i])
			cout << i + 1 << ' ';
	}
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define ed end
#define bg begin
#define fr first
#define sc second
#define il inline
#define LL long long
#define pb push_back
#define mk make_pair
#define to(k) E[k].to
#define val(k) E[k].val
#define next(k) E[k].next
#define pint pair<int, int>

#define MAXN 400010
#define MAXS 400100
#define Inf 998244353

using namespace std ;
struct Edge{
	int to, next, val ;
}E[MAXN << 1] ; int head[MAXN], cnt, sz[MAXS] ; 
int N, vals[MAXN], dp[MAXN], ctn[MAXN], now_st, ans ; 

void add(int u, int v, int w){
	E[++ cnt].to = v, E[cnt].val = w,
	E[cnt].next = head[u], head[u] = cnt ;
	E[++ cnt].to = u, E[cnt].val = w,
	E[cnt].next = head[v], head[v] = cnt ;
}
int do_do(int stt){
	if (!stt) return 0 ;
	if (dp[stt] != -1) return dp[stt] ;
	int ret = Inf ;
	for (int i = 1 ; i <= 15 ; ++ i){
		if (!(stt >> i & 1)) continue ;
		for (int j = 1 ; j <= 15 ; ++ j){
			if (i == j || !(stt >> j & 1)) continue ;
			int now_st = stt ^ (1 << i) ^ (1 << j) ;
			int q = i ^ j ; now_st ^= (1 << q) ; 
			if (sz[now_st] < sz[stt]) ret = min(ret, do_do(now_st) + 1 + (~now_st >> (q) & 1)) ; 
		}
	}
	return dp[stt] = ret ; 
}
int main(){
	cin >> N ; 
	int u, v, w, i ; 
	memset(dp, -1, sizeof(dp)) ;
	for (i = 1 ; i < N ; ++ i) 
		scanf("%d%d%d", &u, &v, &w), 
		add(u + 1, v + 1, w), vals[u + 1] ^= w, vals[v + 1] ^= w ;  
	for (i = 1 ; i <= N ; ++ i) if (vals[i]) ctn[vals[i]] ++ ; 
	for (i = 0 ; i <= 15 ; ++ i) ans += ctn[i] / 2, now_st |= (ctn[i] & 1) << i ;
	for (i = 1 ; i < MAXS ; ++ i) sz[i] = sz[i - (i & -i)] + 1 ; 
	ans += do_do(now_st) ; cout << ans << endl ; return 0 ; 
}

Measured memory_bytes: 9088