akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int a[200000];
signed main(){
  int n, q;
  string str;
  cin >> n >> q >> str;
  str = " " + str;
  rrep(i,n-1){
    a[i] += a[i-1];
    if(str[i] == 'A' and str[i+1] == 'C')a[i]++;
  }
  rep(i,q){
    int x, y;cin >> x >> y;
    int ans = a[y-1] - a[x-1];
    cout << ans << endl;
  }
  return 0;
}





Measured memory_bytes: 1788
# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


# 最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
lcm_val = A[0]
for a in A[1:]:
    lcm_val = lcm(lcm_val, a)

ans = 0
for a in A:
    ans += lcm_val // a
print(ans % mod)

Measured memory_bytes: 4084
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	if (n < 3) {
		cout << 0 << endl;
		return 0;
	}
	int ans[11][11] = { {} };
	REP(k, 1, 11) {
		REP(i, 1, 5) {
			int sum = 0;
			rep(j, 9) {
				int y = k + (j % 3);
				int x = i + (j / 3);
				// cout << x << " " << y << endl;
				sum += y * 7 + x - 7;
			}
			ans[k - 1][sum % 11]++;
		}
	}
	//*
	rep(i, 11) {
		if (i != 0) rep(j, 11) ans[i][j] += ans[i - 1][j];
	}
	//*/
	cout << (n - 3) / 11 * 5 + ans[(n - 3) % 11][k] << endl;





    return 0;
}


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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const vector<pll> p = {{0,1},{0,-1},{-1,0},{1,0}};


int main(){
    ll H,W,K;
    cin>>H>>W>>K;
    ll x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    vector<vector<char>> c(H+10,vector<char>(W+10,'@'));
    REP(i,H) REP(j,W) cin>>c[i+1][j+1];
    //ダイクストラ
        auto dist = make_vec<ll>(H+10,W+10,5);
        REP(i,H+10) REP(j,W+10) REP(k,5) dist[i][j][k]=INF;

        //dist,x,y,方向(0:上 1:下 2:左 3:右),連続cnt
        priority_queue<tuple<ll,ll,ll,ll,ll>,vector<tuple<ll,ll,ll,ll,ll>>,greater<tuple<ll,ll,ll,ll,ll>>> que;
        
        // 初期条件 (頂点 0 を初期ノードとする)
        dist[x1][y1][4] = 0;
        que.push(make_tuple(0,x1,y1,4,0)); // 0 を橙色頂点にする
        
         // 開始 (キューが空になるまで探索を行う)
        while (!que.empty()) {
            tuple<ll,ll,ll,ll,ll> t = que.top(); // 優先度キューから先頭頂点を取り出す
            que.pop();
            ll d=get<0>(t);
            ll x=get<1>(t);
            ll y=get<2>(t);
            ll direct=get<3>(t);
            ll cnt=get<4>(t);
            
            if(dist[x][y][direct]<d) continue;
            // v から辿れる頂点をすべて調べる
            REP(i,p.size()) {
                pll next=p[i];
                ll nx = x + next.first;
                ll ny = y + next.second;
                
                if (c[nx][ny] == '@') continue; // 行けない行き先ならパス
                
                ll nd=dist[x][y][direct];
                ll ncnt=cnt;
                
                if(direct!=i){//方向転換
                    ncnt=1;
                    nd++;
                }else{//方向同じ
                    ncnt++;
                    if(ncnt>=K+1){
                        ncnt=1;
                        nd++;
                    }
                }
                
                // 新たな頂点 nv について距離が短いなら更新
                if(nd<dist[nx][ny][i]){
                    dist[nx][ny][i] = nd;
                    que.push(make_tuple(nd,nx,ny,i,ncnt));
                }
            }
        }

        ll ans=INF;
        REP(i,5) ans=min(ans,dist[x2][y2][i]);
        if(ans==INF) ans=-1;
        cout<<ans<<endl;

}

Measured memory_bytes: 857864
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

const long long InF = 1e15+7;

int main() {
  long long N,neck;
  cin>>N;
  neck = InF;
  vector<long long> capa(5);
  for (int i = 0; i < 5; i++) {
    long long capa;
    cin>>capa;
    neck = min(neck,capa);
  }
  cout<<(N-1)/neck+5<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c,e[7],d;
	for(d=0;d<7;d++){
		scanf("%d %d",&a,&b);
		e[d]=a-b;
	}
	for(d=0;d<7;d++){
		printf("%d\n",e[d]);
	}
	return 0;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = 998244353;

int add(int a, int b)
{
   int res = a + b;
   if(res >= MOD)
      return res - MOD;
   return res;
}

int mult(int a, int b)
{
   long long res = a;
   res *= b;
   if(res >= MOD)
      return res % MOD;
   return res;
}

const int N = 2e5 + 5;

int PW[N];
int ele[N];

class segmentTree {
public:
   int n;
   vector<int> t;
   vector<bool> left;
   vector<int> lazy;
 
   segmentTree() { }
   
   segmentTree(int n) {
      this->n = n;
      t.resize(4 * n + 5, 0);
      left.resize(4 * n + 5, 0);
      lazy.resize(4 * n + 5, 0);
   }
    
   void push(int v, int tl, int tr) {
      if (left[v] == false) return ;
 
      t[v] = mult(lazy[v], ele[tr - tl + 1]);
      
      if (tl != tr) {
         int tm = (tl + tr) / 2;
         lazy[2 * v] = lazy[v];
         left[2 * v] = true;
         lazy[2 * v + 1] = lazy[v];
         left[2 * v + 1] = true;
      }
 
      lazy[v] = 0;
      left[v] = false;
   }
 
   void update(int v, int tl, int tr, int l, int r, int val) {
      push(v, tl, tr);
 
      if (tl > tr || tl > r || tr < l) return ;
      if (tl >= l && tr <= r) {
         left[v] = true;
         lazy[v] = val;
         push(v, tl, tr);
         return ;
      }
      
      int tm = (tl + tr) / 2;
      update(2 * v, tl, tm, l, r, val);
      update(2 * v + 1, tm + 1, tr, l, r, val);

      t[v] = add(mult(t[2*v], PW[tr - tm] ), t[2*v + 1]);
   }
 
   int query(int v, int tl, int tr, int l, int r) {
      push(v, tl, tr);
      if (tl > tr || tl > r || tr < l) return 0;
 
      if(tl >= l && tr <= r){
         return t[v];
      }

      int tm = (tl + tr) / 2;
      return add(mult(query(2*v, tl, tm, l, r), PW[tr - tm]), query(2*v + 1, tm + 1, tr, l, r));
   }
};

int32_t main() {
   fast;
   PW[0] = 1;
   ele[1] = 1;

   f(i,1,N) PW[i] = mult(PW[i-1], 10);

   f(i,2,N) ele[i] = add(ele[i-1], PW[i-1]);

   int n,q;
   cin >> n >> q;

   segmentTree st(n+1);
   st.update(1,1,n,1,n,1);

   while(q--){
      int l,r,x;
      cin >> l >> r >> x;
      st.update(1,1,n,l,r,x);
      cout << st.query(1,1,n,1,n) << "\n";
   }
}

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

int main() {

    int n;
    cin >> n;

    int a = 0; 

    long int b = 0;

    for (int i = 1; i <= n; i++) {
        
        if (i % 3 == 0 && i % 5 == 0) { a++; }

        else if (i % 3 == 0) { a++; }

        else if (i % 5 == 0) { a++; }

        else {b += i;}
    }

    cout << b << endl;

}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
typedef long long ll;
typedef pair<int,int> P;


int main(){
   int N;
   cin>>N;
   double ans=(int)((N+1)/2)/(double)N;
   printf("%.6lf\n",ans);
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int x,y,z,max,ans,t;
	while(1){
		scanf("%d",&z);
		if(!z)
			break;
		max=0;
		for(x=1;x<1111;x++){
			for(y=1;y<1111;y++){
				t=x*x*x+y*y*y;
				if(t<=z*z*z&&max<t){
					max=t;
				}
				else if(t>z*z*z)
					break;
			}
		}
		printf("%d\n",z*z*z-max);
	}
	return 0;
}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		double x = 0.0;
		double y = 0.0;
		int theta = 90;
		
		String line;
		while ((line = br.readLine()) != null) {
			if (line.equals("0,0")) break;
			
			String[] arr = line.split(",");
			int hosu = Integer.parseInt(arr[0]);
			int kakudo = Integer.parseInt(arr[1]);
			
			x += hosu * Math.cos(Math.toRadians(theta));
			y += hosu * Math.sin(Math.toRadians(theta));
			
			theta -= kakudo;
		}
		
		System.out.println((int)x);
		System.out.println((int)y);
	}

}

Measured memory_bytes: 24140
from bisect import bisect_left

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    L, R = 0, 2 * 10**5 + 1
    while L+1 < R:
        P = (L+R)//2
        cnt = 0
        for v in a:
            x = P - v
            cnt += n - bisect_left(a, x)
        if cnt >= m:
            L = P
        else:
            R = P
    csum = [0]
    for v in a:
        csum.append(v)
    for i in range(n):
        csum[i+1] += csum[i]
    ans = 0
    cnt = 0
    for v in a:
        x = L - v
        idx = bisect_left(a, x)
        cnt += n-idx
        ans += csum[-1] - csum[idx]
        ans += v * (n - idx)
    ans -= (cnt - m) * L
    print(ans)

if __name__ == "__main__":
    main()

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

void solve(const int &n, const int &x){
  
  int cnt = 0;
  
  for(int i = 1; i <= n; i++){
    for(int j = i+1; j <= n; j++){ 
      for(int k = j+1; k <= n; k++){ 
        
        if( i+j+k == x ){ cnt++;}
        
      }
    }
  }
  
  cout << cnt << endl;
  return ;
}

signed main(void){
  int n,x;
  while(cin >> n >> x){
    if( n == 0 && x == 0){ return 0;}
    
    solve(n,x);
  }
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;

    vector<int> v(2);
    REP(i, s.size()) {
        v[v.size() - 1]++;
        if (i != s.size() - 1 && s[i] != s[i + 1])
            v.emplace_back(0);
    }
    int ans = 0;
    vector<int> v_sum((int)v.size());
    partial_sum(ALL(v), v_sum.begin());

    if (s[0] == '0')
        v_sum.insert(v_sum.begin(), 0);
    for (int lft = 0; lft < v_sum.size(); lft += 2) {
        int rgt = min((int)v_sum.size() - 1, lft + K * 2 + 1);

        chmax(ans, v_sum[rgt] - v_sum[lft]);
    }

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

    return 0;
}

Measured memory_bytes: 1656
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s;
	int count=0,pos=0,count2=0;
	bool f=false;
	cin>>s;
	if(s[0]!='A'){
		cout<<"WA"<<endl;
		return 0;
	}
	for(int i=2;i<s.size()-2+1;i++){
		if(s[i]=='C'){
			count++,pos=i;
		}
	}
	DEB(count)END
	if(count!=1){
		cout<<"WA"<<endl;
		return 0;
	}
	for(int i=1;i<s.size();i++){
		if(i!=pos){
			if('a'<=s[i]&&s[i]<='z'){
				count2++;
			}
		}
	}
	if(count2==s.size()-2){
		cout<<"AC"<<endl;
	}
	else{
		cout<<"WA"<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

struct UnionFind {
    UnionFind(int n) {
        rank.assign(n, 0);
        parent.resize(n);
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

    int find(int x) {
        if (x == parent[x])
            return x;
        return parent[x] = find(parent[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        parent[x] = y;
    }

    vector<int> rank;
    vector<int> parent;
};

ll T[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll sum = 0;
    memset(T, 0, sizeof(T));
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
        T[A[i]]++;
    }

    // UnionFind uf(100005);

    ll Q;
    cin >> Q;
    REP(i, Q) {
        ll b, c;
        cin >> b >> c;

        sum -= b * T[b];
        sum += c * T[b];
        T[c] += T[b];
        T[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 5128
(
  stdin.ReadLine() |> int,
  stdin.ReadLine(),
  stdin.ReadLine()
)
|> fun (n, ps, qs) ->
  [1..n]
  |> fun list ->
    list
    |> List.tail
    |> List.fold (
      fun acc i ->
        acc
        |> List.collect (
          fun cs ->
            list
            |> List.except cs
            |> List.map (fun x -> cs @ [x])
        )
    ) (list |> List.map (fun x -> [x]))
    |> List.mapi (
      fun i order ->
        (
          i,
          order
          |> List.map string
          |> List.reduce (fun a b -> a + " " + b)
        )
    )
    |> fun dict ->
      (
        (dict |> List.find (fun (_, v) -> v = ps) |> fun (i, _) -> i),
        (dict |> List.find (fun (_, v) -> v = qs) |> fun (i, _) -> i)
      )
|> fun (a, b) -> (a - b) |> abs
|> printfn "%d"


Measured memory_bytes: 48664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
#define MAX 500000
#define VMAX 10000
#define SENTINEL 2000000000
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int N;

int main(){
   int C[10001];
    for(int i = 0; i < 10001; i++) C[i] = 0;
    int n;
    scanf("%d",&n);
    int* A = new int[n];
    int* B = new int[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
        C[A[i]]++;
    }

    for(int i = 0,j=0; i < 10001; i++){
        if(C[i] != 0){
            for(int k = 0; k < C[i]; k++){
                B[j++] = i;
            }
        }
    }

    for(int i = 0; i < n-1; i++) printf("%d ",B[i]);
    printf("%d\n",B[n-1]);
    delete[] A;
    delete[] B;
    return 0;
}



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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vl a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vll dp(k, vl(n, -INF));
  rep (i, n) {
    dp[0][i] = a[i];
  }
  rep (i, k - 1) {
    deque<pll> dq;
    dq.push_back(pll(dp[i][0], 0));
    rep1 (j, n - 1) {
      while (!dq.empty()) {
        int idx = dq.front().second;
        if (j - idx > m) {
          dq.pop_front();
        }
        else {
          break;
        }
      }
      chmax(dp[i + 1][j], dq.front().first + (i + 2) * a[j]);
      while (!dq.empty() && dq.back().first <= dp[i][j]) {
        dq.pop_back();
      }
      dq.push_back(pll(dp[i][j], j));
    }
  }
  ll ans = 0;
  rep (i, n) {
    chmax(ans, dp[k - 1][i]);
  }
  cout << ans << endl;
}
        


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

int main() {
	ll n,k;
  	cin>>n>>k;
  	
	ll s=n%k;
  	ll ans=min(n%k,k-s);
  
  cout<<ans<<endl;
  
  

}

Measured memory_bytes: 3580
import sys
import numpy as np

N = int(input())
A = list(map(int, input().split()))

if len(np.where(np.array(A) == 0)[0]) != 0:
    print(0)
    sys.exit(0)

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        sys.exit(0)

print(ans)


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

int main(){
    int n, sum1, sum2;
    sum1 = 0;
    sum2 = 0;
    cin >> n;
    int list[n];
    for (int x = 0; x < n; x++){
        cin >> list[x];
    }
    for (int x = 0; x < n; x++){
        sum1 += list[x] * list[x];
        for (int i = 0; i < n ; i++){
            sum2 += list[x] * list[i];
        }
    }
    cout << (sum2 - sum1) / 2 << endl;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a != b && a == c) cout << b << endl;
  else if(a == b && a != c) cout << c << endl;
  else cout << a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int mod = 1000000007;

int main()
{
    IOS
    int t = 1;
    //cin >> t;
    while (t--)
    {
        ll N, D;
        cin >> N >> D;
        int res = 0;
        for (int i = 0; i < N; i++)
        {
            ll a, b;
            cin >> a >> b;
            if (a * a + b * b <= D * D)
                res++;
        }
        cout << res;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
#define REP(m,n) for(int i=m;i<n;++i)
#define REPj(m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define ll long long
#define mp make_pair

int main() {
	vector<int>v;
	ll n, a = 0, b = 0, ans;
	cin >> n;
	REP(0, n) {
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}
	sort(v.begin(), v.end());
	REP(0, n - 1) {
		if (v[n - 1 - i] == v[n - 2 - i]) {
			if (a == 0) {
				a = v[n - i - 1];
			}
			else {
				if (b == 0) {
					b = v[n - i - 1];
					break;
				}
			}
			i++;
		}
	}
	ans = a*b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn],n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans=0;
	for(int i=1,j;i<=n;i=j+1){
		j=i;
		ans++;
		while(j+1<=n&&a[i]==a[j+1])j++;
		if(j+1<=n){
			if(a[i]<a[j+1]){
				while(j+1<=n&&a[j]<=a[j+1])j++;
			}else{	
				while(j+1<=n&&a[j]>=a[j+1])j++;
			}	
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll X;
    scanf("%lld", &X);
    if(X<1200)printf("ABC\n");
    else printf("ARC\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9 + 7;

template <typename T>
T pow_mod(T n, T p, T m)  // (n^p) % m
{
    if(p == 0) return 1;
    if(p%2 == 1) return pow_mod<T>(n, p-1, m) * n % m;
    else{
        T tmp = pow_mod<T>(n, p/2, m) % m;
        return tmp * tmp % m;
    }
}

// nCk を O(n) で求めるクラス
template <typename T>
class Combination 
{
    private:
        int _mod;
        std::vector<T> factorial, factorial_inv;

    public:
        Combination(int n, int mod): _mod(mod), factorial(n+1, 1), factorial_inv(n+1)
        {
            for(int i = 1; i <= n; ++i) factorial[i] = (i*factorial[i-1]) % _mod;
            factorial_inv[n] = pow_mod<T>(factorial[n], _mod-2, _mod);  // 逆元を取る操作は重いので一回のみ行う
            for(int i = n; i >= 1; --i) factorial_inv[i-1] = (i*factorial_inv[i]) % _mod;
        } 

        T operator()(int n, int k)
        {
            if(n < 0 or k > n) return 0;
            return factorial[n] * factorial_inv[k] %_mod * factorial_inv[n-k] %_mod;
        }
};


int main()
{
    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    Combination<long long> comb(r2+c2+2, MOD);
    auto g = [&](int i, int j){
        return comb(i+j+2, min(i, j)+1) - 1;
    };

    long long ans = 0;
    ans += g(r2, c2);
    ans -= g(r1-1, c2);
    ans -= g(r2, c1-1);
    ans += g(r1-1, c1-1);
    cout << (ans+MOD)%MOD << endl;
    
    return 0;
}

Measured memory_bytes: 31488
# include <bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
const double pi=3.1415926535897932;
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FDR(i,a,n) for(int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=200005;
//Code begin....

struct Node{int x, y;}node[N], p1, p2, tmp;
int pos, lis[N];

bool comp(Node a, Node b){return a.x<b.x;}
int main ()
{
    int n, x, y, min_x, min_y, max_x, max_y;
    scanf("%d%d%d%d%d",&p1.x,&p1.y,&p2.x,&p2.y,&n);
    min_x=min(p1.x,p2.x); max_x=max(p1.x,p2.x);
    min_y=min(p1.y,p2.y); max_y=max(p1.y,p2.y);
    double ans=(double)(max_x-min_x+max_y-min_y)*100;
    //cout<<ans<<endl;
    FOR(i,1,n) {
        scanf("%d%d",&x,&y);
        if (x>=min_x&&x<=max_x&&y>=min_y&&y<=max_y) node[++pos]=Node{x,y};
    }
    sort(node+1,node+pos+1,comp);
    if (p1.y>p2.y) tmp=p1, p1=p2, p2=tmp;
    int len=0, p;
    if (p1.x<p2.x) {
        FOR(i,1,pos) {
            if(len==0||node[i].y>lis[len-1]) lis[len++]=node[i].y;
            else p=lower_bound(lis,lis+len,node[i].y)-lis, lis[p]=node[i].y;
        }
    }
    else {
        FDR(i,pos,1) {
            if(len==0||node[i].y>lis[len-1]) lis[len++]=node[i].y;
            else p=lower_bound(lis,lis+len,node[i].y)-lis, lis[p]=node[i].y;
        }
    }
    if (len==min(max_x-min_x,max_y-min_y)+1) printf("%.15f\n",ans+10*pi-20+(len-1)*(5*pi-20));
    else printf("%.15f\n",ans+len*(5*pi-20));
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#define MAX 100
#define IN 10000


int main(){
  int n,i,j,dat[MAX][MAX],min,tmp[MAX],mini=0,a[MAX],flag[MAX],k,sum=0;

  scanf("%d",&n);

  for ( i = 0; i < n;i++){
    for (j = 0;j < n;j++){
      scanf("%d",&dat[i][j]);
    }
  }
  for ( i =0 ;i < n; i++){
    flag[i]=0;
    a[i]=IN;
  }
  a[0] =0;

  for (k = 0 ;k < n-1;k++){
    min =IN;
  
    for ( i = 0; i < n;i++){
      if(a[i] < min && flag[i] ==0){
	min = a[i];
	mini = i;
      }
    }
    flag[mini]= 1;

    for (j = 0;j < n;j++){

      if(dat[mini][j] < a[j] && dat[mini][j] != -1 && flag[j]==0){
	a[j] = dat[mini][j];
      }
     
      
     
    }
   
  }

  for ( i =0 ; i < n; i++){
    sum += a[i];
  }
  printf("%d\n",sum);








  return 0;

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n;
    string s;
    cin >> s;
    n = s.length();
    int zero=0,one=0;
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            zero++;
        }
        else{
            one++;
        }
    }
    cout << min(zero,one)*2 <<endl;

}

Measured memory_bytes: 512
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // ll INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;
 
// const int N = 2e5 + 5;



  // void solve(){

  //   int n,m;

  //   cin>>n>>m;
  //   for (int tt=0;tt<m;tt++){
  //     int x,y;
  //     cin>>x>>y;
  //     adj[x].push_back()
  //   }
  // }


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      // ifstream cin("input.txt");

 ll n;
 cin>>n;
 ll zn = 5;
 ll num = 0;
 if (n%2==1){
  cout<<"0\n";
  return 0;
 }
 while (n/zn>=1){
  num+=(n/zn+n%2)/2;
  
  zn*=5;
  
 }

 cout<<num<<"\n";


}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)

#define REP(i, n) FOR(i, 0, n)
#define REPE(i, n) for (int i = 0; i <= (n); ++i)

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

//DP法
template <class T>
inline bool chmin(T &a, T b) //change minimum
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) //change max
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

typedef long long ll; //64bit型
using namespace std;

const long long INF = 1LL << 60; //無限大の値
static const int N = 1000;

int lcs(string X, string Y)
{
    int C[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    REPE(i, m)
    {
        REPE(j, n)
        {
            C[i][j] = 0;
        }
    }
    FORE(i, 1, m)
    {
        FORE(j, 1, n)
        {
            if (X[i] == Y[j])
            {
                C[i][j] = C[i - 1][j - 1] + 1;
            }
            else
            {
                C[i][j] = max(C[i - 1][j], C[i][j - 1]);
            }
            maxl = max(maxl, C[i][j]);
        }
    }
    return maxl;
}

int main()
{
    string s1, s2;
    int n;
    cin >> n;
    REP(i, n)
    {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}




Measured memory_bytes: 6980
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

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

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

template <class _T> class SegTree {
protected:
	int _size = 0;
	std::vector<_T> _data;
	_T _initValue;

public:
	SegTree(int n, _T initValue) {
		int size = 1;
		while (size < n) size *= 2;
		_data.resize(size * 2, initValue);
		_initValue = initValue;
		_size = size;
	}

	~SegTree() {}

	void add(_T& a, _T& b, _T& c) {
		for (int i = 0; i < 26; i++) {
			c[i] = a[i] + b[i];
		}
	}

	void setValues(std::vector<_T>& values) {
		int size = std::min(_size, (int)values.size());
		int segtSize = _size;

		for (int i = 0; i < size; i++) {
			int idx = i + segtSize - 1;
			_data[idx] = values[i];
		}

		for (int i = segtSize - 2; i >= 0; i--) {
			add(_data[2 * i + 1], _data[2 * i + 2], _data[i]);
		}
	}

	void update(int k, _T value) {
		k += _size - 1;
		_data[k] = value;

		while (k > 0) {
			//	順に親に向かっていく
			k = (k - 1) / 2;
			add(_data[k * 2 + 1], _data[k * 2 + 2], _data[k]);
		}
	}

	_T query(int a, int b, int k, int l, int r) {
		//	呼ぶときは query(a, b, 0, 0, size(=segtree size))
		if (r <= a || b <= l) return _initValue;

		if (a <= l && r <= b) return _data[k];
		else {
			_T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			_T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			_T ans(vl);
			add(vl, vr, ans);
			return ans;
		}
	}

	_T query(int a, int b) {
		return query(a, b, 0, 0, _size);
	}
# if 0 //	segt 呼び出しサンプル
	static void segt()
	{
		int i = 100;
		SegmentTree<int> segt(10, 100);

		segt.update(1, 13);

		segt.update(9, 11);

		segt.update(0, 9);

		int d = segt.query(1, 9, 0, 0, 10);
		printf("%d\n", d);	// 表示は11
	}
#endif
};

static void exec()
{
	int N, Q;
	std::string str;
	get(N);
	get(str);

	std::vector<int> data(26, 0);
	SegTree<std::vector<int>> st(N, data);

	for (int i = 0; i < N; i++) {
		data[str[i] - 'a'] = 1;
		st.update(i, data);
		data[str[i] - 'a'] = 0;
	}
	get(Q);
	for (int i = 0; i < Q; i++) {
		int q;
		get(q);
		if (q == 1) {
			int iq;
			char cq;
			get(iq); iq--;
			get(cq);
			data[cq - 'a'] = 1;
			st.update(iq, data);
			data[cq - 'a'] = 0;
		}
		else {
			int lq, rq;
			get(lq, rq); lq--;// rq--;
			std::vector<int> d(st.query(lq, rq));
			int kind = 0;
			for (int i = 0; i < 26; i++) {
				if (d[i]) kind++;
			}
			printf("%d\n", kind);
		}
	}
}


Measured memory_bytes: 142976
#include <bits/stdc++.h>
using namespace std;
int main(void){
  char s[2];
  cin >> s[0] >> s[1];
  if(s[0] == '9' || s[1] == '9'){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false;
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<string> grid(H);
	for (int i = 0; i < H; i++) {
		cin >> grid[i];
	}

	int ans = 0;
	int h = pow(2, H), w = pow(2, W);
	for (int i = 0; i < h; i++) {
		vector<string> gr1 = grid;
		int tp = i;
		vector<int> hb(H);
		for (int j = 0; tp; j++) {
			hb[j] = tp % 2;
			tp /= 2;
			if (hb[j]) {
				for (int a = 0; a < W; a++) {
					gr1[j][a] = 'r';
				}
			}
		}

		for (int k = 0; k < w; k++) {
			vector<string> gr2 = gr1;
			tp = k;
			vector<int> wb(W);
			for (int j = 0; tp; j++) {
				wb[j] = tp % 2;
				tp /= 2;
				if (wb[j]) {
					for (int a = 0; a < H; a++) {
						gr2[a][j] = 'r';
					}
				}
			}

			int cnt = 0;
			for (int b = 0; b < H; b++) {
				for (int c = 0; c < W; c++) {
					if (gr2[b][c] == '#')cnt++;
				}
			}

			if (cnt == K) ans++;


		}

		

	}
	cout << ans << endl;
}


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

using namespace std;

int main()
{
    long long int n, i, l[87]={0};

    l[0]=2;
    l[1]=1;

    cin>>n;

    for(i=2;i<=n;i++)
    {
        l[i]=l[i-1]+l[i-2];
    }

    cout<<l[n]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    vector<int> idx(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        idx[i] = a[i];
    }
    idx.push_back(-10);
    sort(idx.begin(), idx.end());
    idx.erase(unique(idx.begin(), idx.end()), idx.end());
    int l = idx.size();

    vector<vector<pair<int, lint>>> edges(l);
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        l--;
        int ll = prev(upper_bound(idx.begin(), idx.end(), l)) - idx.begin();
        int rr = prev(upper_bound(idx.begin(), idx.end(), r)) - idx.begin();
        if (ll == rr)
            continue;
        edges[ll].emplace_back(rr, i + 1);
        edges[rr].emplace_back(ll, i + 1);
    }

    vector<int> bomb(l, 0);
    for (int i = 0; i < n; ++i) {
        int k   = lower_bound(idx.begin(), idx.end(), a[i]) - idx.begin();
        bomb[k] = b[i];
    }

    for (int z = 0; z < 2; ++z) {
        bomb[0] = z;

        vector<int> cut(l, 0);
        if (bomb[l - 1] == 1)
            cut[l - 1] = 1;
        for (int i = l - 2; i >= 0; --i) {
            if (bomb[i] != bomb[i + 1])
                cut[i] = 1;
        }

        vector<bool> done(l, false);
        vector<int> ret;
        function<void(int, int)> dfs = [&](int c, int p) {
            done[c] = true;
            for (auto &v : edges[c]) {
                if (done[v.first])
                    continue;
                dfs(v.first, c);
                if (cut[v.first] % 2 == 1)
                    ret.push_back(v.second);
                cut[c] += cut[v.first];
            }
        };
        bool ok = true;
        for (int i = 0; i < l; ++i) {
            if (done[i])
                continue;
            dfs(i, -1);
            if (cut[i] % 2 == 1) {
                ok = false;
            }
        }
        if (ok) {
            sort(ret.begin(), ret.end());
            cout << ret.size() << endl;
            for (int i = 0; i < (int)ret.size(); ++i) {
                if (i)
                    cout << " ";
                cout << ret[i];
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << "\n";
    return 0;
}

Measured memory_bytes: 21496
#include <bits/stdc++.h>
#define LL long long
const int INF = 1000 * 1000 * 1000;
const int mod = 998244353;
using namespace std;
int add(int a , int b)
{
    return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a , int b)
{
    return a - b < 0 ? a - b + mod : a - b;
}
int mult(int a , int b)
{
    return a * (LL)b % mod;
}
int a[305];
const int MX = 305 * 305;
int dp[2][MX];
int dp2[2][MX];
int main() {
    int n;
    cin >> n;
    int suma = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        suma += a[i];
    }
    dp[0][0] = 1;
    LL ans = 1;
    for(int i = 1; i <= n; i++)
    {
        ans *= 3;
        ans %= mod;
    }
    for(int i = 0; i < n; i++)
    {
        memset(dp[1] , 0 , sizeof dp[1]);
        for(int j = MX - 1; j >= 0; j--)
        {
            if(j + a[i] < MX)
                dp[1][j + a[i]] = add(dp[1][j + a[i]] , dp[0][j]);
            dp[1][j] = add(mult(2 , dp[0][j]) , dp[1][j]);
        }
        for(int j = 0; j < MX; j++)
            dp[0][j] = dp[1][j];
    }
    for(int i = 0; i < MX; i++)
    {
        if(i >= (suma + 1) / 2)
        {
            ans = sub(ans , mult(3 , dp[0][i]));
        }
        /*if(i == suma / 2 && suma % 2 == 0)
        {
            ans = add(ans , );
        }*/
    }
    memset(dp[0] , 0 , sizeof dp[0]);
    dp[0][0] = 1;
    
    for(int i = 0; i < n; i++)
    {
        memset(dp[1] , 0 , sizeof dp[1]);
        for(int j = MX - 1; j >= 0; j--)
        {
            if(j + a[i] < MX)
                dp[1][j + a[i]] = add(dp[1][j + a[i]] , dp[0][j]);
            dp[1][j] = add(dp[0][j] , dp[1][j]);
        }
        for(int j = 0; j < MX; j++)
            dp[0][j] = dp[1][j];
    }
    
    //cerr << suma << endl;
   // cerr << dp[0][8] << endl;
    if(suma % 2 == 0)
    {
        ans = add(ans , mult(3 , dp[0][suma / 2]));
    }
      
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a;
  if(a==1)cout << "Hello World";
  else{
    cin >> b >> c;
    cout << b+c;
  }
  //cout << min(min(abs(a-b),abs(b-c)),abs(c-a));
}
/*
  for(int i=0;i<4;i++){
    if(s[i]=='-')o----;
    o++;
  }
  cout << o;
}
*/


Measured memory_bytes: 256
#入力
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

#空のリストを作る事で，求めた値をそのリストに追加していく
#そして，そのリストの中から一番値が近いものをprintする
l = []
for i in range(N):
    a = T - H[i]*0.006
    b = abs(a-A)
    l.append(b)

c = l.index(min(l))
print(c +1)

#空のリストの作成方法
#l = []
#l.append(引数)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
int n,a;cin>>n>>a;
cout << n*n-a<< endl;


return 0;
}
        
    


 


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

using namespace std;

int main() {
  int n, m;
  int a[50];
  int b[50];
  int c[50];
  int d[50];

  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> c[j] >> d[j];
  }

  for (int i = 0; i < n; i++) {
    int min = abs(a[i] - c[0]) + abs(b[i] - d[0]);;
    int k = 1;
    for (int j = 1; j < m; j++) {
      int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (tmp < min) {
        min = tmp;
        k = j + 1;
      }
    }
    cout << k << endl;
  }
}


Measured memory_bytes: 256
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

//#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) /b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1 * 1000 * 1000 * 1000 + 200;
const int MAXN = 100 * 1000 + 10;
const int MLOG = 30;
const int NMAX = 20;

int n, mark[MAXN];
vector <pair<int, int>> adj[MAXN];

void dfs(int a) {
	//cout << a << ' ' << mark[a] - INF << endl;
	for(auto pr : adj[a]) {
		if(!mark[pr.X]) {
			mark[pr.X] = mark[a] + pr.Y;
			dfs(pr.X);
		}
	}
}

bool check() {
	for(int i = 0; i < n; i++) {
		for(auto pr : adj[i]) {
			if(mark[i] == mark[pr.X] - pr.Y) continue;
			else  return false;
		}
	}
	return true;
}

signed main() {
	int m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		l--;
		r--;
		adj[l].pb({r, d});
		adj[r].pb({l, -d});
	}
	for(int i = 0; i < n; i++) {
		if(!mark[i]) {	
			mark[i] = INF;
			dfs(i);
		}
	}
	if(check()) cout << "Yes";
	else cout << "No";
}



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

int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	deque<char>d(s.begin(),s.end());
// 	if(s.length()>0)
// 	d.push_back(s);
	
	int q,r=0;
	cin>>q;
	while(q--)
	{
	    int t;
	    cin>>t;
	    if(t==1)
	    {
	        //if(s.length()!=1)
	        r=1-r;
	    }
	    else
	    {
	        int f;
	        cin>>f;
	        char a;
	        cin>>a;
	        if(r==1)
	        {
	            if(f==2)
	            {
	            
	            d.push_front(a);
	            }
	           else
	           {
	            d.push_back(a);
	           }
	            
	        }
	        else{
	            if(f==1)
	        {
	            
	            d.push_front(a);
	        }
	        else
	        {
	            d.push_back(a);
	        }
	            
	        }
	        
	    }
	}
	string ans="";
	if(r==1)
	{
	    while(!d.empty())
	    {
	        ans+=d.back();
	        d.pop_back();
	    }
	}
	else
	{
	    while(!d.empty())
	    {
	        ans+=d.front();
	        d.pop_front();
	    }
	    
	}
//	reverse(s.begin(),s.end());
	cout<<ans;
	
	
}


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

int main()
{
  int N;
  double x[11];
  char u[11][4];
  double res=0;
  cin >> N;

  rep(i,N) {
    cin >> x[i] >> u[i];
  }

  rep(i,N){
    //cout << x[i] << u[i];                                                     
    if(strcmp(u[i],"JPY")==0) res += x[i];
    else res += x[i] * 380000.0;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
	return b == 0 ? a : gcd(b, a % b);
}

long long lcm(long long a, long long b)
{
	return a / gcd(a, b) * b;
}

long long calc(long long x, long long n, long long m)
{
	return x - (x / n) - (x / m) + (x / lcm(n, m));
}

int main()
{
	long long A, B, C, D;
	cin >> A >> B >> C >> D;

	long long ans = calc(B, C, D) - calc(A - 1, C, D);
	cout << ans << endl;
}


Measured memory_bytes: 256