akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    ll K;
    cin >> N >> K;
    vint A(N);
    rep(i, N) cin >> A[i];
    int now = 1;
    vint B;
    B.push_back(now);
    rep(i, N) {
        if (K - i <= 0) {
            cout << now << endl;
            return 0;
        }
        now = A[now - 1];
        B.push_back(now);
    }
    unordered_map<int, int> already;
    int loop_start = 0;
    int loop_end = 0;
    rep(i, B.size()) {
        if (already.count(B[i]) > 0) {
            K -= already[B[i]];
            loop_start = already[B[i]];
            loop_end = i;
            break;
        }
        already[B[i]] = i;
    }
    vint C(B.begin() + loop_start, B.begin() + loop_end);
    ll ans = C[K % C.size()];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11632
#include <stdio.h>

int main(void){
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b&&b<c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N, D, X;
	cin >> N >> D >> X;

	auto count = X;
	for (auto i = 0; i < N; ++i)
	{
		int A;
		cin >> A;
		for (auto j = 0; j < D; j += A)
		{
			++count;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define int long long
#define Graph vector<vector<int> >
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数定義や変数宣言
int N,Q;

vector<bool> seen(200005,false);
vector<int> counter(200005,0);
int p,x;
Graph G(200005);


int num=0;



void dfs(const Graph &G ,int node,int parent= -1)
{
	

	for (auto next_node:G[node])
	{

		if (next_node==parent)
		{
			continue; 
		}

		counter[next_node]+=counter[node];

		
		dfs(G,next_node,node);

	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

cin>>N>>Q;
REP(i,N-1){
	int a,b;
	cin >> a>>b;
	G[a].push_back(b);
	G[b].push_back(a);

}
REP(i,Q){
	cin>>p>>x;
	counter[p]+=x;
}
dfs(G,1);
FOR(i,1,N){
	cout<<counter[i]<<" ";
}
return 0;

}

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

int main() {
   int N, K;
   cin >> N >> K;
   vector<int> v(N);

   for(int i=0; i<N; i++) {
      cin >> v[i];
   }
   sort(v.begin(), v.end());

   int sum=0;
   for(int i=0; i<K; i++) {
      sum += v[i];
   }
   cout << sum << endl;
}

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

int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (u == s)
        cout << a - 1 << " " << b << endl;
    else
        cout << a << " " << b - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
/*
	Solved!
	Time: 05:23:26 PM
	Date: 05-04-2020
*/
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long  ll;
typedef vector<int>         vi;
typedef vector<ll>          vll;

#define ff                  first
#define sf                  scanf
#define pf                  printf
#define ss                  second
#define ppb                 pop_back
#define pb                  push_back
#define MP                  make_pair
#define MAXN                5000005
#define MOD                 100000007
#define inf                 0x3f3f3f3f
#define PI                  (2.0*acos(0.0))
#define INF                 0x3f3f3f3f3f3f3f3f
#define rev(v)              reverse(all(v))
#define all(v)              v.begin(), v.end()
#define __lcm(x, y)         (x * y) / __gcd(x, y)
#define FOR(i, x, y)        for(int i = x; i < y; i++)
#define RFOR(i, x, y)       for(int i = x; i >= y; i--)
#define MEM(arr, val)       memset(arr, val, sizeof(arr));
#define unq(v)              (v).resize(unique(all(v)) - v.begin())
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define si(n)               scanf("%d", &n)
#define sl(n)               scanf("%lld", &n)
#define sii(a, b)           scanf("%d %d", &a, &b)
#define sll(a, b)           scanf("%lld %lld", &a, &b)
#define siii(a, b, c)       scanf("%d %d %d", &a, &b, &c)
#define slll(a, b, c)       scanf("%lld %lld %lld", &a, &b, &c)
#define siiii(a, b, c, d)   scanf("%d %d %d %d", &a, &b, &c, &d)
#define sllll(a, b, c, d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define vout(v)             for(int i = 0; i < v.size(); i++) {cout << v[i]; if(i < v.size() - 1) cout << ' '; else cout << endl;}

int main(){
    /*#ifndef ONLINE_JUDGE
        double start = clock(); READ(); WRITE();
    #endif*/
        ll n, m; sll(n, m);
        --n, --m;
        ll ans = (n * (n + 1)) / 2;
        ans += (m * (m + 1)) / 2;
        cout << ans << endl;


   /* #ifndef ONLINE_JUDGE
        printf("\n>>Runtime: %.10fs\n", (double)(clock() - start) / CLOCKS_PER_SEC);
    #endif*/

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  while(cin>>n>>k,n||k) {
    int cost[n][n]; FOR(i,0,n) FOR(j,0,n) cost[i][j] = 1e9;
    FOR(i,0,k) {
      int x; cin >> x;
      if(x == 0) {
        int d[n]; FOR(i,0,n) d[i] = 1e9;
        bool used[n]; CLR(used);
        // ??????????????????
        int a, b; cin >> a >> b;
        a--;b--;
        d[a] = 0;
        while(1) {
          int v = -1;
          for(int u = 0; u < n; u++) {
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
          }
          if(v == -1) break;
          used[v] = true;
          for(int u = 0; u < n; u++) {
            d[u] = min(d[u], d[v] + cost[v][u]);
          }
        }
        if(d[b] >= 1e9) d[b] = -1;
        cout << d[b] << endl;
      } else {
        int c, d, e; cin >> c >> d >> e;
        c--;d--;
        cost[c][d] = min(cost[c][d], e);
        cost[d][c] = min(cost[d][c], e);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3028
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int start = -1, end = 0;
            for (int i = 0; i < s.Length; ++i)
            {
                if (start == -1 && s[i] == 'A')
                {
                    start = i;
                }
                if (s[i] == 'Z')
                {
                    end = i;
                }
            }
            Console.WriteLine(end - start + 1);
        }
    }
}

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

int main(){
    int a,b,d,r;
    double f;
    cin >> a >> b;
    d = a/b;
    r = a%b;
    f = (double)a/b;
    cout << d << " " << r << " " <<fixed<<setprecision(5)<<f<<endl;
}


Measured memory_bytes: 3272
#include <stdio.h>

int main(){
  int W,H,x,y,r;

  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if (x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H){
    printf("Yes\n");
  }else if (x-r < 0||x+r> W || y-r > 0 || y+r < H){
    printf("No\n");

  }
 
  return 0;

}

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

int main(int argc, char const *argv[])
{
    int n;
    int a;
    std::vector<int> input_a;

    std::cin >> n;

    for (int i = 0; i < n; i++)
    {
        std::cin >> a;
        input_a.emplace_back(a);
    }

    for (int i = n - 1; i > 0; i--)
    {
        std::cout << input_a[i] << " ";
    }
    std::cout << input_a[0] << std::endl;

    return 0;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  ll temp=1;
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(a[i]<temp) continue;
    if(a[i]==temp) {
      temp++;
      continue;
    }
    ans+=(a[i]-1)/temp;
    if(temp==1) temp++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const int infi = 2147483647;
const ll infl = 1e17;

ll powmod(ll x, ll y, ll mod)
{
    map<ll, ll> Z;
    Z[0] = 1;
    Z[1] = x;
    ll nowy = 1;
    ll nowx = x;
    while (nowy * 2 <= y)
    {
        nowy *= 2;
        nowx = nowx * nowx % mod;
        Z[nowy] = nowx;
    }
    ll nowz = nowy / 2;
    while (nowy < y)
    {
        if (nowz + nowy <= y)
        {
            nowy += nowz;
            nowx = (nowx * Z[nowz]) % mod;
        }
        nowz /= 2;
    }
    return nowx;
}

int main()
{
    ll n,m,k;
    cin >> n >> m >> k;
    ll L = n * m;
    vector<ll> kaijo(L + 1, 0);
    kaijo[0] = 1;
    repf(i, 1, L + 1)
        kaijo[i] = (kaijo[i - 1] * i) % mod;
    vector<ll> gyaku(L + 1, 0);
    gyaku[L] = powmod(kaijo[L], mod - 2, mod);
    rep(i, L)
        gyaku[L - 1 - i] = gyaku[L - i] * (L - i) % mod;
    ll ans = 0;
    repf(i,1,n+1){
        ll res = i * (n - i) % mod;
        res = (res * m % mod) * m % mod;
        res = (res * kaijo[n * m - 2]) % mod;
        res = (res * gyaku[k - 2]) % mod;
        res = (res * gyaku[n * m - k]) % mod;
        ans = (ans + res) % mod;
    }

    repf(i, 1, m + 1)
    {
        ll res = i * (m - i) % mod;
        res = (res * n % mod) * n % mod;
        res = (res * kaijo[n * m - 2]) % mod;
        res = (res * gyaku[k - 2]) % mod;
        res = (res * gyaku[n * m - k]) % mod;
        ans = (ans + res) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int x = sc.nextInt(), y = sc.nextInt();
        List<Integer> xlist = new ArrayList<>();
        List<Integer> ylist = new ArrayList<>();
        boolean xdir = true;
        int cnt = 0;
        for (int i = 0; i < s.length; i++) {
            if(s[i] == 'F'){
                cnt++;
            }else{
                if(xdir) xlist.add(cnt);
                else ylist.add(cnt);
                xdir = !xdir;
                cnt = 0;
            }
        }
        if(0 < cnt){
            if(xdir) xlist.add(cnt);
            else ylist.add(cnt);
        }
        Set<Integer> xset = new HashSet<>();
        xset.add(xlist.get(0));
        xlist.remove(0);
        for(int nx : xlist){
            Set<Integer> tset = new HashSet<>();
            for(int cx: xset){
                tset.add(cx + nx);
                tset.add(cx - nx);
            }
            xset = tset;
        }
        Set<Integer> yset = new HashSet<>();
        yset.add(0);
        for(int ny : ylist){
            Set<Integer> tset = new HashSet<>();
            for(int cy : yset){
                tset.add(cy + ny);
                tset.add(cy - ny);
            }
            yset = tset;
        }
        System.out.println(xset.contains(x) && yset.contains(y) ? "Yes" : "No");
        sc.close();

    }

}


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

int insertionSort(vector<int> &A, int N, int g, int &cnt){
  for(int i = g; i < N; i++){
    int v = A.at(i);
    int j = i - g;
    while(j >= 0 && A.at(j) > v){
      A.at(j+g) = A.at(j);
      j = j - g;
      cnt++;
    }
    A.at(j+g) = v;
  }
}

void shellSort(vector<int> &A, int N){

  int cnt = 0;
  int m;
  vector<int> G(100);

  for(int i = 0; i < 100; i++){
    if(i == 0){
      G.at(i) = N / 2 + 1;
    }
    else{
      G.at(i) = G.at(i-1) / 2 - 1;
    }
    if(G.at(i) < 0){
      G.at(i-1) = 1;
      G.at(i) = 0;
      m = i;
      break;
    }
  }
  for(int i = 0; i < m; i++){
    insertionSort(A, N, G.at(i), cnt);
  }

  cout << m << endl;
  for(int i = 0; i < m; i++){
    if(i) cout << " ";
    cout << G.at(i);
  }
  cout << endl << cnt << endl;
  for(int i = 0; i < N; i++){
    cout << A.at(i) << endl;
  }
}

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

  for(int i = 0; i < n; i++){
    cin >> R.at(i);
  }

  shellSort(R, n);

  return 0;
}



Measured memory_bytes: 6800
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll n, k;
	cin >> n >> k;
	vlli dp(k + 1, 0);
	fr(i, 0, n)
	{
		ll w, v;
		cin >> w >> v;
		for (ll j = k - w; j >= 0; --j)
		{
			dp[j + w] = max(dp[j + w], dp[j] + v);
		}

	}
	ll ans = 0;
	fr (i, 0, k + 1)
	{
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;


}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,i,a;
  double s=0;
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a;
    s+=(double)1/a;
  }
  printf("%.12lf\n",(double)1/s);
  return 0;
}

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

int n, t, a, h;

int main() {
    std::cin >> n >> t >> a;
    double  min = INT32_MAX;
    int mini;
    for (int i = 1; i <= n; ++i) {
        std::cin >> h;
        double ht = t - h * 0.006;
        if (fabs(ht - a) < min) {
            mini = i;
            min = fabs(ht - a);
        }
    }
    std::cout << mini;
}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n; cin >> n;
	vi a(n); cin >> a;
	double ans = 0;
	for (int x : a) ans += 1.0 / x;
	cout << fixed << setprecision(6) << 1.0 / ans << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

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

// vim: fdm=marker


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

int GetRandom(int min,int max){
	return min + (int)(rand()*(max-min+1.0)/(1.0+RAND_MAX));
}

int main(){
    // 入力
    int D;
    cin >> D;   // D = 365
    ll c[26];
    for(int i=0;i<26;i++)
        cin >> c[i];
    ll s[D][26];
    for(int i=0;i<D;i++)
        for(int j=0;j<26;j++)
            cin >> s[i][j];
    // 初期解t[D]
    int t[D];
    /*
    for(int i=0;i<D;i++)
        cin >> t[i];
    */
    for(int i=0;i<D;i++){
        //t[i] = GetRandom(1,26);   // 1<=, <=26
        t[i] = i%26 + 1;
    }
    // クエリ
    int M;
    // cin >> M;
    M = 100000;
    int d[M], q[M];
    /*
    for(int i=0;i<M;i++)
        cin >> d[i] >> q[i];
    */
    for(int i=0;i<M;i++){
        d[i] = GetRandom(1,D);   // 1<=, <=365
        q[i] = GetRandom(1,26);   // 1<=, <=26 
    }

    // 処理部
    ll v_best = 0;
    for(int query=0;query<M;query++){
        int last[26] = {}, q_;
        // コンテスト種別の変更
        q_ = t[d[query]-1];
        t[d[query]-1] = q[query];
        // D日分
        ll v = 0;
        for(int i=1;i<=D;i++){
            // 満足度の増加分
            v += s[i-1][t[i-1]-1];
            last[t[i-1]-1] = i;
            // 満足度の低下分（コンテスト26種分）
            for(int j=0;j<26;j++)
                v -= c[j]*(i - last[j]);
        }
        // cout << v << endl;
        if(v < v_best){
            t[d[query]-1] = q_;
        }else{
            v_best = v;
        }
    }

    // 答え出力
    for(int i=0;i<D;i++)
        cout << t[i] << endl;

}


Measured memory_bytes: 4528
import bisect
import itertools

def find_ge(a, x):
    'Find leftmost item greater than or equal to x'
    i = bisect.bisect_left(a, x)
    return i
def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bisect_right(a, x)
    return i-1

ans=0
pmax=41
N,K = [int(x) for x in raw_input().split()]
A = [int(x) for x in raw_input().split()]
B=A[:]
for i in range(1,N):
    B[i]=B[i-1]+A[i]
B = [0] + B[:]
C=[0 for x in range(N*(N+1)/2)]
i=0
for xx in itertools.combinations_with_replacement(range(N), 2):
    l,r=sorted(xx)
    r+=1
    q = B[r]-B[l]
    C[i] = q
    i+=1

while(1):
    D=[ [] for x in range(pmax)]
    for q in C:
        for j in range(pmax):
            if q & pow(2, j)==pow(2, j):
                D[j].append(q)
    for j in range(pmax-1 ,-1 ,-1):
        if len(D[j])>=K:
            ans += 2**j
            C = D[j][:]
            pmax = j
            break
    else:
        break
print ans
#C.sort()

# p=0
# while C[-1]<2**p:
#     p+=1
# for n in range(p,-1,-1):


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

typedef long long ll;

const ll MOD = 1000000007;

int main() {
    ll N, H, a;
    ll Max = 0;
    ll total = 0;
    ll ans = 0;
    cin >> N >> H;
    vector<ll>b(N);
    for (int i = 0; i < N; i++) {
        cin >> a >> b[i]; 
        Max = max(Max, a);
    }
    sort(b.begin(), b.end(), greater<ll>());

    for (int i = 0; i < N; i++) {
        if (b[i] > Max) {
            ans++;
            total += b[i];
        }
        if (total >= H) {
            break;
        }
    }

    if (total < H) {
        ans += ceil((double)(H-total)/(double)Max);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
const long long int mod=1000000007;
int main(){
	int N, M;
	int a[50], b[50], ans[50] = {};
	cin >> N >> M;
	for (int i = 1; i <= M; i++){
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= N; i++){
		for (int j = 1; j <= M; j++){
			if (a[j] == i || b[j] == i){
				ans[i]++;
			}
		}
	}
	for (int i = 1; i <= N; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A[2][101];
int n;
int main()
{

    scanf("%d",&n);
    for(int i = 0; i < 2; i++)
    {
        for(int j = 0; j < n; j++)
            scanf("%d",&A[i][j]);
    }

    int ans = 0;

    for(int i = 0; i < n; i++)
    {
        int mx = 0;
        for(int j = 0; j <= i; j++)
        {
            mx += A[0][j];
        }
        for(int j = i; j < n; j++)
        {
            mx += A[1][j];
        }
        ans = max(ans,mx);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
int main() {
	int c[30] = { 0 }, t, a, b, n, i,w;
	fscanf(stdin, "%d", &n);
	i = 0;
	while (i < n) c[i] = i+1,i++;
	i = 0;
	fscanf(stdin, "%d", &w);
	while (i < w)
		fscanf(stdin, "%d,%d", &a, &b),
		t = c[a - 1], c[a - 1] = c[b - 1], c[b - 1] = t,
		i++;
	i = 0;
	while (i < n) fprintf(stdout, "%d\n", c[i++]);
	return 0;
}

Measured memory_bytes: 600
S = gets.chomp.reverse
T = gets.chomp.reverse

wk = nil
(0..(S.size-T.size)).each{|i|
  (wk = i; break) if (0...T.size).to_a.all?{|j| S[i+j] == T[j] || S[i+j] == '?'}
}

if not wk.nil? then
  (0...T.size).each{|i| S[wk+i] = T[i]}
  S.gsub!(/\?/, 'a')
  puts S.reverse
else
  puts 'UNRESTORABLE'
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  ll k=1000;
  ll a[n];
  rep(i,n)cin >> a[i];
  rep(i,n-1){
    k+=max((ll)0,(a[i+1]-a[i])*(k/a[i]));
  }
  cout << k << endl;
}


Measured memory_bytes: 3636
import java.util.*;

 
class Main {
 
    private static Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] v = new int[n];
        int[] c = new int[n];
        for(int i = 0; i < n; i++){
            v[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            c[i] = sc.nextInt();
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            int val = v[i]-c[i];
             if(val > 0){
                ans += val;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 22740
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC164D();

#if 1
int main()
{
	ABC164D();
	fflush(stdout);
	return 0;
}
#endif

static void ABC164D()
{
	std::string orgs;
	std::cin >> orgs;

	std::vector<LLONG> counter(2019, 0);
	int sLen = orgs.length();

	int factor = 1;
	int curVal = 0;
	counter[curVal]++;
	for (int i = sLen - 1; i >= 0; i--) {
		int num = orgs[i] - '0';
		curVal = (curVal + num * factor) % 2019;
		counter[curVal]++;
		factor = (factor * 10) % 2019;
	}

	LLONG ans = 0;
	for (int i = 0; i < 2019; i++) {
		ans += (counter[i] * (counter[i] - 1LL)) / 2LL;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3744
#include <stdio.h>
using namespace std;
int main(void){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<=b&&b<=c){
printf("%d %d %d\n",a,b,c);
}else if(a<=c&&c<=b){
printf("%d %d %d\n",a,c,b);
}else if(b<=a&&a<=c){
printf("%d %d %d\n",b,a,c);
}else if(b<c&&c<a){
printf("%d %d %d\n",b,c,a);
}else if(c<=b&&b<=a){
printf("%d %d %d\n",c,b,a);
}else {
printf("%d %d %d\n",c,a,b); 
}
}


Measured memory_bytes: 2704
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int coin500 = (int)Math.floor(x/500.0);
        int coin5 = (int)Math.floor((x%500)/5.0);
        System.out.println(coin500*1000 + coin5*5);
    }
}


Measured memory_bytes: 21844
n,y = map(int,input().split())

for i in range(0,(y//10000)+1):
    for j in range(0,((y-10000*i)//5000)+1):
        if y- 10000*i - 5000*j == 1000 * (n-i-j):
            print(i,j,n-i-j)
            quit()

print(-1,-1,-1)

Measured memory_bytes: 3060
a, b = map(int, input().split())
s = input()
for i in range(len(s)):
    if i == a:
        if s[i] != '-':
            print("No")
            break
    else:
        if not s[i] in [str(i) for i in range(10)]:
            print("No")
            break
else:
    print("Yes")



Measured memory_bytes: 3060
N = int(input())
L = list(map(int,input().split()))
L.append(0)
K = [0]*(N+1)
cnt = 0
c = 0
flag = True
while flag:
  if K == L:
    flag = False
  else:
    for i in range(N+1):
      if K[i] < L[i]:
        K[i] += 1
        cnt += 1
      else:
        if cnt != 0:
          c += 1
          cnt = 0
print(c)

Measured memory_bytes: 3064
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  var params = inputs.split('\n')[0].split(' ').map(Number);
  (function(a,b) {
    if(a > b){
      console.log('a > b');
    }else if(a < b){
      console.log('a < b');
    }else{
      console.log('a == b');
    }
    //????????????????????????
  }(params[0],params[1])); 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7376
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GS(S);
  char c = S[0];
  print((c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
            ? "vowel"
            : "consonant");
  return 0;
}

Measured memory_bytes: 256
/*
 * ID: 0055
 * Problem: sum of series
 */

#include <stdio.h>

int main(void)
{
    double a;
    while (scanf("%lf", &a) != EOF) {
        double sum = a;
        double b;
        int i;
        for (i = 2; i <= 10; i++) {
            b = i % 2 ? a / 3.0 : a * 2.0;
            sum += b;
            a = b;
        }
        printf("%f\n", sum);
    }

    return 0;
}



Measured memory_bytes: 1984
#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;

using vi = vector<int>;
using pi = pair<int, int>;
using ll = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

const int mxn = 1e4+10;
const int Mod = 1e9+7;

void solve()
{
    int n, k;
    cin>>n>>k;
    int s = 0;
    for(int i=0 ; i<k ; i++){
        int x;
        cin>>x;
        s+=x;
    }
    (s > n) ? cout<<-1<<endl : cout<<(n-s)<<endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int tc = 1;
    //cin>>tc;
    while(tc--) solve();

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long T;
int gcd(T a,T b)
{
	return b==0?  a :  gcd(b,a%b);
}
int main()
{
	T x,y;
	cin>>x>>y;
	cout<<gcd(x,y)<<endl;
	return 0;
}


Measured memory_bytes: 3080
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	
	int cnt = 0;
	for (int i = 1; i < n+1; i++) {
		if (i % 2 == 1)cnt++;
	}

	double ans = (cnt) / (double)n;

	cout << fixed << setprecision(10) << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  set<int>a,b;
  cin>>n;
  while(n--){
    int x;
    cin>>x;
    a.insert(x);
  }
  cin>>n;
  while(n--){
    int x;
    cin>>x;
    b.insert(x);
  }
  vector<int>c;
  set_difference(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
  for(int i=0;i<c.size();i++)cout<<c[i]<<endl;
}


Measured memory_bytes: 22568
//20181208
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main() {

    int n;
    cin >> n;

    int p[n];
    int max = 0;
    int maxi;
    for(int i=0;i<n;i++){
        cin >> p[i];
        if(p[i]>max){
            max = p[i];
            maxi = i;
        }
    }

    int sum = 0;

    for (int i=0;i<n;i++){
        if(i!=maxi) sum+=p[i];
        else sum += p[i]/2;
    }

    cout << sum << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void func(int x,int y);
int h,w;
char a[111][111];
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int nx,ny;
int cnt=0;
int main(){
  int fx,fy;
  while(1){
    cin >> w >> h;
    if(h==0 && w==0)break;
    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
	cin >> a[i][j];
	if(a[i][j]=='@'){
	  fx=i;
	  fy=j;
	}
      }
    }
    func(fx,fy);
    cout << cnt << endl;
    cnt=0;
  }
}


void func(int x,int y){
  cnt++;
  a[x][y]='0';
  for(int i=0;i<4;i++){
    nx=dx[i]+x;
    ny=dy[i]+y;
    if(nx<=h && nx>=1 && ny<=w && ny>=1 && a[nx][ny]!='#' && a[nx][ny]!='0'){
      func(nx,ny);
    }
  }
}

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

int h,w;
int fie[51][51];
int dist[51][51];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main(void){
	scanf("%d%d",&h,&w);
	int cnt=0;
	for(int i=0;i<h;i++){
		string str;
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='#'){
				fie[i][j]=-1;
				cnt++;
			}
		}
	}
	memset(dist,-1,sizeof(dist));
	dist[0][0]=0;
	queue<P> que;
	que.push(P(0,0));
	while(que.size()){
		P p=que.front();
		que.pop();
		for(int i=0;i<4;i++){
			int nx=p.second+dx[i];
			int ny=p.first+dy[i];
			if(nx>=0 && ny>=0 && nx<w && ny<h){
				if(dist[ny][nx]==-1 && fie[ny][nx]==0){
					dist[ny][nx]=dist[p.first][p.second]+1;
					que.push(P(ny,nx));
				}
			}
		}
	}
	if(dist[h-1][w-1]==-1){
		puts("-1");
	}else{
		printf("%d\n",h*w-cnt-dist[h-1][w-1]-1);
	}
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s; cin >> s;
  int n = (int)s.size();
  int l=0,r=n;
  for(l = 0; l < n; ++l){
    if(s[l] == 'A')break;
  }
  for(r = n-1; r >= 0; --r){
    if(s[r] == 'Z')break;
  }
  cout << r - l + 1 << endl;
}


Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

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

  int N; cin >> N;
  string S; cin >> S;

  int res = 0;
  rep(i, N-2) if(S.substr(i, 3) == "ABC") ++res;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#define MAX_COUNT 8
using namespace std;

int xs[MAX_COUNT] = {0};
int ys[MAX_COUNT] = {0};
int main(int argc, char const *argv[])
{
	int count;
	cin >> count;
	for (int i = 0; i < count; ++i)
	{
		cin >> xs[i] >> ys[i];
	}
	double pathSum = 0.0;
	for (int i = 0; i < count; ++i)
	{
		for (int j = i + 1; j < count; ++j)
		{
			pathSum += sqrt(pow(xs[i] - xs[j], 2) + pow(ys[i] - ys[j], 2));
		}
	}
	printf("%.10f", 2.0 * pathSum / (double) count);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mp make_pair
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
const int N=1e6+7;
int n,m,k,t,a[N],l[N],r[N];
ll ans;

int main(){
    fast;
    cin>>n;
    for1(i,n) cin>>a[i];
    stack<int> s;
    s.push(0);
    a[0]=a[n+1]=0;
    for1(i,n){
        while(a[s.top()]>=a[i]){
            s.pop();
        }
        l[i]=s.top();
        s.push(i);
    }
    while(!s.empty()) s.pop();
    s.push(n+1);
    for(int i=n;i>=1;i--){
        while(a[s.top()]>=a[i]){
            s.pop();
        }
        r[i]=s.top();
        s.push(i);
    }
    for1(i,n){
        ans+=1LL*a[i]*(i-l[i])*(r[i]-i);
    }
    cout<<ans<<endl;
    return 0;
}


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

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(void)
{
  int n;
  int a[200000];
  int b[200000];
  int i,j;
  int p;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    b[i]=a[i];
  }
  
  /*for(i=0;i<n-1;i++)
  {
    for(j=0;j<n-i-1;j++)
    {
      if(a[i]<a[i+1])
      {
        p=a[i+1];
        a[i+1]=a[i];
        a[i]=p;
      }
    }
  }*/
  


  qsort(a, sizeof(a) / sizeof(*a), sizeof(*a), desc);
  
  for(i=0;i<n;i++)
  {
    if(b[i]==a[0])
      printf("%d\n",a[1]);
    else
      printf("%d\n",a[0]);
  }
  return 0;
}

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

using namespace std;

int main() {

	int n, is, ig, iw;
	vector< vector<int> > v, w;
	vector<int> col;
	queue<int> q;

	cin >> n;

	v.resize(n + 1);
	w.resize(n + 1);
	col.resize(n + 1, -1);

	for (int i = 0;i<n;i++) {
		cin >> is >> ig >> iw;

		v[is].push_back(ig);
		w[is].push_back(iw);
		v[ig].push_back(is);
		w[ig].push_back(iw);
	}

	col[1] = 0;
	q.push(1);
	while(!q.empty()){
		for (int i = 0;i < v[q.front()].size();i++) {
          	if(col[v[q.front()][i]]!=-1) continue;
			q.push(v[q.front()][i]);
				//cout << "push " << v[q.front()][i] << endl;
			col[v[q.front()][i]] = (w[q.front()][i] % 2) ^ col[q.front()];
				//cout << "col " << v[q.front()][i] << " = " << (w[q.front()][i] % 2) << " ^ " << col[q.front()] <<endl;
		}
			//cout << "pop " << q.front() << endl;
		q.pop();
	}

	for (int i = 1;i<=n;i++) cout << col[i] << endl;

	return 0;
}

Measured memory_bytes: 11904
from collections import defaultdict
n,k = map(int,input().split())
mod = 924844033
rng = 2010
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
if (n-k)*2 <= n:
  x = (n-k)*2
  ans = 0
  for i in range(x+1):
    if i%2 == 0:
      ans += cmb(x,i)*fctr[n-i]
    else:
      ans -= cmb(x,i)*fctr[n-i]
    ans %= mod
  print(ans)
  exit()
dc = defaultdict(int)
for j in range(1,k+1):
  a = j
  b = k+j
  cnt = 0
  while a<=n and b<=n:
    if a>b:
      b += 2*k
    else:
      a += 2*k
    cnt += 1
  dc[cnt] += 2
nn = (n-k)*2
cp = set()
cpp = 1
for i,x in dc.items():
  for j in range(x):
    cpp += i
    cp.add(cpp)
cp.add(1)
dp = [[0 for j in range(n+1)] for i in range(nn+1)]
dp[0][0] = 1
for i in range(1,nn+1):
  dp[i] = dp[i-1][:]
  if i not in cp:
    for j in range(1,min(i,n)+1):
      dp[i][j] += dp[i-2][j-1]
      dp[i][j] %= mod
  else:
    for j in range(1,min(i,n)+1):
      dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= mod
ans = 0
for i in range(n+1):
  if i%2 == 0:
    ans += fctr[n-i]*dp[nn][i]
  else:
    ans -= fctr[n-i]*dp[nn][i]
  ans %= mod
print(ans)

Measured memory_bytes: 143368
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<pair<int,int>>point1(n),point2(n);
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    point1[i]={x,y};
    point2[i]={x,y};
  }
  sort(point1.begin(),point1.end(),[&](pair<int,int>&a,pair<int,int>&b){
      return (a.first+a.second)<(b.first+b.second);
  });
  sort(point2.begin(),point2.end(),[&](pair<int,int>&a,pair<int,int>&b){
      return (a.first-a.second)<(b.first-b.second);
  });
  int m1=point1[n-1].first+point1[n-1].second-(point1[0].first+point1[0].second);
  int m2=point2[n-1].first-point2[n-1].second-(point2[0].first-point2[0].second);
    cout<<max(m1,m2)<<"\n";
 return 0;
}
  

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

int main(){

  int n;

  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    vector<int> vec(n);
    for(int i=0;i<n;i++){
      cin >> vec[i];
    }

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

    int index=0;

    while(index < vec.size() && vec[index] < 2){
      index++;
    }

    if(index==vec.size()){
      cout << "NA" << endl;
    }
    else{
      index = 0;

      while(vec[index]==0){
        index++;
      }

      if(index!=0){
        vec.erase(vec.begin(),vec.begin() + index );
      }

      cout << vec.size() + 1 << endl;
    }

  }


    return 0;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

using tup = tuple<string, int, int>;

bool comp(const tup& lhs, const tup& rhs) {
    if (get<0>(lhs) == get<0>(rhs)) {
        return get<1>(lhs) > get<1>(rhs);
    }
    return get<0>(lhs) < get<0>(rhs);
}

int main() {
    /* code */
    int n;
    cin >> n;
    vector<tup> sp;
    REP(i, n) {
        string s;
        int p;
        cin >> s >> p;
        sp.push_back(std::make_tuple(s, p, i + 1));
    }
    sort(sp.begin(), sp.end(), comp);
    for (const auto& elm : sp) {
        cout << get<2>(elm) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();
        string s = sc.NextString();
        for (int i = 0; i < n; i++)
        {
            Console.Write(i == k - 1 ? s.ToLower()[i] : s[i]);
        }
        Console.WriteLine();
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long LL;
const int mod=998244353;
const int maxn=1e5+50;
LL power(LL x,LL y)
{
	LL re=1;
	while(y)
	{
		if(y&1) re=re*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return re;
}
int n;
int D[maxn];
int cnt[maxn];
int solve()
{
	if(D[1]!=0)
	{
		return 0;
	}
	for(int i=2;i<=n;++i)
	{
		if(D[i]==0)
		{
			return 0;
		}
	}
	int m=0;
	for(int i=1;i<=n;++i)
	{
		++cnt[D[i]];
		m=max(m,D[i]);
	}
	int an=1;
	for(int i=1;i<=m;++i)
	{
		if(cnt[i]==0)
		{
			return 0;
		}
		an=an*power(cnt[i-1],cnt[i])%mod;
	}
	return an;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&D[i]);
	}
	printf("%d\n",solve());
	return 0;
}

Measured memory_bytes: 1024