akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define vi vector<ll>
#define vvi vector<vi>
#define llINF 1e18
#define ll long long
using namespace std;
bool vis[2510];
struct Edge{
  ll to,cost;
};
const ll MAX_V=2510;
vector<vector<Edge>> E(MAX_V);
vi dist(MAX_V,llINF);
bool bellman_ford(ll s){
  queue<ll>que;
  que.push(s);
  dist[s]=0;
  for(int i = 0;i < MAX_V;i++){
    ll n = que.size();
    bool used[MAX_V] = {};
    for(int j = 0;j < n;j++){
      ll now=que.front();
      que.pop();
      for(int k = 0;k < E[now].size();k++){
	Edge e = E[now][k];
	if(dist[e.to] > dist[now] + e.cost){
	  dist[e.to] = dist[now] + e.cost;
	  if(i == MAX_V-1)
	    if(vis[e.to])
	      return true;
	  if(used[e.to] == false){
	    que.push(e.to);
	    used[e.to] = true;
	  }
	}
      }
    }
  }
  return false;
}
vvi E2(MAX_V);
int main(){
  ll n,m,p;
  cin>>n>>m>>p;
  for(int i=0;i<m;i++){
    ll a,b,c;cin>>a>>b>>c;
    E[--a].push_back({--b,-(c-p)});
    E2[b].push_back(a);
  }
  queue<ll>que;
  que.push(n-1);
  vis[n-1]=true;
  while(que.size()){
    ll hoge=que.front();que.pop();
    for(auto a:E2[hoge])
      if(vis[a]==false){
	que.push(a);
	vis[a]=true;
      }
  }
  if(bellman_ford(0)==false){
    cout<<max(0LL,-dist[n-1])<<endl;
  }else cout<<-1<<endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N;

int main() {
  cin >> N;
  cout << 800 * N - 200 * (N / 15);
}


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main(void) {
	LL n, i, j, k, aa = 0, bb = 0;
	cin >> n;
	vector<LL> a(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<LL>());

	for (i = 0; i < n; i++) {
		if (i % 2 == 0) {
			aa += a[i];
		} else {
			bb += a[i];
		}
	}

	cout << aa - bb << endl;

	return 0;
}

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

using namespace std;

int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};

int main(void)
{
	int n;
	char s,t,b;
	int dp[5][5];
	int i1,i2,i3,i4,i5,i6;
	double ans;
	int temp[5][5];

	while(1){
		cin>>n;
		if(n==0) break;
		cin>>s>>t>>b;

		memset(dp,-1,sizeof(dp));
		memset(temp,0,sizeof(temp));
		for(i1=1;i1<=3;i1++){
			for(i2=1;i2<=3;i2++){
				dp[i1][i2]=0;
			}
		}
		dp[((s-'A')/3)+1][((s-'A')%3)+1] = 1;
		dp[((b-'A')/3)+1][((b-'A')%3)+1] = -1;
		temp[((b-'A')/3)+1][((b-'A')%3)+1] = -1;

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

			for(i2=1;i2<=3;i2++){
				for(i3=1;i3<=3;i3++){
					
					if(dp[i2][i3]>0){
						for(i4=0;i4<4;i4++){
							if(dp[i2+dy[i4]][i3+dx[i4]]==-1) temp[i2][i3]+=dp[i2][i3];
							else temp[i2+dy[i4]][i3+dx[i4]]+=dp[i2][i3];
						}
					}
				}
			}

			for(i5=1;i5<=3;i5++){
				for(i6=1;i6<=3;i6++){
					dp[i5][i6]=temp[i5][i6];
				}
			}
			memset(temp,0,sizeof(temp));
			temp[((b-'A')/3)+1][((b-'A')%3)+1] = -1;
		}

		ans=double(dp[((t-'A')/3)+1][((t-'A')%3)+1])/pow(4.0,n);
		printf("%.8lf\n",ans);


		/*for(i1=1;i1<=3;i1++){
			for(i2=1;i2<=3;i2++){
				cout<<dp[i1][i2]<<" ";
			}
			cout<<endl;
		}*/
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


void solve(){
  string s;
  int ans = 0;
  
  cin >> s;
  FOR(i,s.length()){
    iFOR(j,i,s.length()){
      bool hoge =true;
      iFOR(k,i,j+1){
        if(s[k]=='A' || s[k]=='C' || s[k] == 'G' || s[k]=='T' ){
        }else{
          hoge=false;
        }
      }
      if(hoge){
        chmax(ans,j-i+1);
      }
    }
  }
  
  cout << ans fin;
  


}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

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

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   ull A,B,C,X,Y;
   cin >> A >> B >> C >> X >> Y;
   if(X<Y)swap(A,B),swap(X,Y);
   if(C*2 < A + B){
      if(Y*C*2 + (X-Y)*A < X*C*2){
         cout << Y*C*2 + (X-Y)*A << endl;  
      }
      else{
         cout << X*C*2 << endl;
      }
   }
   else cout << A*X + B*Y << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;

  ll res = 0;
  for (ll i = k; i <= n + 1; i++) {
    ll minVal = i * (i - 1) / 2;

    ll maxVal = n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2;

    res += maxVal - minVal + 1;

    res = (res % mod + mod) % mod;
  }
  cout << res << en;

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    unordered_map<int,int> mod_cnts;
    mod_cnts.insert({0,1});
    int tmp = 0;
    rep(i,n)
    {
        tmp = (tmp + a[i]) % m;
        if(mod_cnts.count(tmp) > 0)
            mod_cnts[tmp]++;
        else
            mod_cnts[tmp] = 1;
    }

    i64 sum = 0;
    for(auto& mc:mod_cnts)
    {
        i64 k = mc.second;
        if(k > 1)
            sum += k*(k-1)/2;
    }

    cout << sum << endl;
    return 0;
}

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

class Main {

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
        if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        }

        long[] dp = new long[(int)(N+1)];
        dp[2] = Math.abs(h[1] - h[0]);
        
        for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        }
        System.out.print(dp[(int)(N)]);
        return;
    }
}


Measured memory_bytes: 58764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

public class Don
{
    public Don() { }
    private Reader r = new Reader();

    public void Solve()
    {
        var N = r.nextInt();
        var M = r.nextInt();
        var red_possible = new List<bool>();
        var ballcounts = new List<int>();
        for (var i = 0; i < N + 1; i++)
        {
            red_possible.Add(false);
            ballcounts.Add(1);
        }
        red_possible[1] = true;

        for (var i = 0; i < M; i++)
        {
            var x = r.nextInt();
            var y = r.nextInt();

            ballcounts[x]--;
            ballcounts[y]++;

            if (red_possible[x])
            {
                if (ballcounts[x] == 0)
                {
                    red_possible[x] = false;
                    red_possible[y] = true;
                } else
                {
                    red_possible[y] = true;
                }
            }
        }

        var ret = 0;
        for (var i = 1; i <= N; i++)
        {
            if (red_possible[i])
            {
                ret++;
            }
        }

        Console.WriteLine(ret);
    }

    public static void Main(string[] args)
    {
        new Don().Solve();
    }

}

class Reader
{
    string[] s;
    int i;
    char[] cs = new char[] { ' ' };

    public Reader()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length)
            return s[i++];
        var input = Console.ReadLine();
        while (input == "")
            input = Console.ReadLine();
        s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 8136
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;
const ll INF = 1000000000;


int main() {
	char a;
	cin >> a;
	if (isupper(a)) {
		cout <<"A"<< endl;
	}
	else {
		cout << "a" << endl;
	}
	return 0;
}

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



int main()
{
    int n, x, time;
    int total;

    cin >> n >> x >> time;

    if (n % x > 0)
        total = n / x + 1;

    else
        total = n / x;

    cout << total * time << endl;


    return 0;
}

Measured memory_bytes: 3632
#pragma warning (disable:4996)
#include<cstdio>
#include<cmath>
using namespace std;
int sum(int n) {
	int i = 0, s = 0, a[10] = { 0 };
	while (n>0) {
		a[i++] = n % 10;
		n /= 10;
	}
	for (; i >= 0; i--)s += a[i];
	return s;
}
int main() {
	int n;
	bool flag=0;
	scanf("%d", &n);
	for (int i = 1; i <= 5; i++)
	{
		if (n == pow(10, i)) flag = 1;
	}
	if (flag == 1) printf("10");
	else printf("%d", sum(n));
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#define MN 101000

int h[MN], nxt[2 * MN], to[2 * MN], K = 0;
int c[MN], q[MN], hh = 0, tt = 0;
int u[MN], v[MN], d[MN];
bool used[MN];
char s[MN];
int f[MN], g[MN], Ans = 0;

void ins(int u, int v) {nxt[++K] = h[u]; h[u] = K; to[K] = v;}

void dfs(int x, int fa)
{
	int M1 = 0, cM1 = 0, id1 = 0;
	int M2 = 0, cM2 = 0, id2 = -1;
	for(int i = h[x]; i; i = nxt[i])
	{
		if(to[i] == fa || used[to[i]]) continue;
		dfs(to[i], x);
		if(f[to[i]] >= M1) {cM1 = M1; M1 = f[to[i]]; id1 = to[i];}
		else if(f[to[i]] >= cM1) cM1 = f[to[i]];
		if(g[to[i]] >= M2) {cM2 = M2; M2 = g[to[i]]; id2 = to[i];}
		else if(g[to[i]] >= cM2) cM2 = g[to[i]];
		f[x] = std::max(f[x], f[to[i]]);
		g[x] = std::max(g[x], g[to[i]]);
	}
	
	if(id1 != id2) Ans = std::max(Ans, M1 + M2);
	else Ans = std::max(Ans, std::max(M1 + cM2, M2 + cM1));
	
	f[x]++; g[x]++;
	if(c[x] == 1) f[x]--;
	else f[x]++;
	if(c[fa] == 1) g[x]--;
	else g[x]++;
}

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		scanf("%d%d", &u[i], &v[i]);
		ins(u[i], v[i]); ins(v[i], u[i]);
		d[u[i]]++; d[v[i]]++;
	}
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) c[i] = (s[i] == 'B');
	
	for(int i = 1; i <= n; i++) if(d[i] == 1 && c[i] == 1) q[tt++] = i;
	while(hh < tt)
	{
		int u = q[hh++];
		used[u] = 1;
		for(int i = h[u]; i; i = nxt[i])
		{
			d[to[i]]--;
			if(d[to[i]] == 1 && c[to[i]] == 1)
				q[tt++] = to[i];
		}
	}
	
	memset(d, 0, sizeof(d));
	for(int i = 1; i < n; i++)
	{
		if(used[u[i]] || used[v[i]]) continue;
		d[u[i]]++; d[v[i]]++;
	}
	for(int i = 1; i <= n; i++) c[i] ^= (d[i] & 1);
	
	int rt = -1, ans = -2;
	for(int i = 1; i <= n; i++)
	{
		if(!used[i])
		{
			rt = i;
			ans += 2;
			if(!c[i]) ans++;
		}
	}
	if(rt == -1) return 0 * puts("0");
	
	dfs(rt, 0); 
	printf("%d\n", ans - Ans);
}

Measured memory_bytes: 12416
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
l_list = [0]
r_list = [0]
l_gcd, r_gcd = 0, 0
for i in range(n-1):
    l_gcd = gcd(l_gcd, a_list[i])
    l_list.append(l_gcd)
    r_gcd = gcd(r_gcd, a_list[-i-1])
    r_list.append(r_gcd)
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_list[i], r_list[-i-1]))
print(ans)


Measured memory_bytes: 14488
H,W = map(int, input().split())
s = [input() for _ in range(H)]
ans = 'Yes'
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                nx = j+dx[k]
                ny = i+dy[k]
                if nx < 0 or ny < 0 or nx >= W or ny >= H:
                    continue
                if s[ny][nx] == '#':
                    flag = True
            if not flag:
                ans = 'No'
                break
print(ans)           

Measured memory_bytes: 3064
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
cnt = Counter(a)

for i in range(1,n+1):
    print(cnt[i])


Measured memory_bytes: 123740
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: usize,
        As: [i64; N],
    }

    let mut prev = 0;
    let mut ans = 0;
    for &a in As.iter() {
        if prev > a {
            ans += prev - a;
        } else {
            prev = a;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 5584
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &x : a){
        cin >> x;
    }
    reverse(ALL(a));
    int ans = 0;
    int ct = 0;
    for(int i = 0; i + 1 < n; i++){
        if(a[i] <= a[i + 1]){
            ct++;
        }else{
            ans = max(ans, ct);
            ct = 0;
        }
    }
    ans = max(ans, ct);
    cout << ans;
    return 0;
}


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


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x=c-a, y=d-b;
    cout << c-y << " " << d+x << " " <<a-y << " " <<b+x;
    
    return 0;
}


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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{
    int n, k; in >> n >> k;
    int mn = MOD;
    int res = 0;
    int gap = 0;

    REP(i, n)
    {
        int x; in >> x;
        mn = min(mn, x);

        if(x-mn > gap)
        {
            res = 1;
            gap = x-mn;
        }
        else if(x-mn == gap) res++;
    }

    out << res << "\n";

    return 0;
}


Measured memory_bytes: 384
#ifdef LOCAL
#include "libs/debug/print_list.hpp"
#define debug(x) (cout << # x ": " << x << endl)
#define dev(v, m, n) for(int i=0;i<n;++i){for(int j=0;j<m;++j){cout<<"|"<<v[j][i];}cout<<"|"<<endl;}
#else
#define debug(x) ;
#define dev(v, m, n) ;
#endif

// :----------------------------------------

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;
using Graph = vector<vector<int>>;

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 P (1'000'000'007)

template<int MOD=P>
struct Mod {
public:
    long long signed value;

    Mod(long long signed val): value(val % MOD) {
        if (value < 0) value += MOD;
    }

    constexpr Mod& operator+=(const Mod& other) noexcept { 
        value += other.value;
        value %= MOD;
        return *this;
    }
    constexpr Mod& operator-=(const Mod& other) noexcept {
        value -= other.value;
        if (value < 0) value += MOD;
        return *this;
    }
    constexpr Mod& operator*=(const Mod& other) noexcept {
        value *= other.value;
        value %= MOD;
        return *this;
    }

    constexpr Mod operator-() noexcept {
         return value == 0 ? 0 : MOD - value;
    }

    constexpr Mod operator+(const Mod& other) const noexcept { return Mod(*this) += other; }
    constexpr Mod operator-(const Mod& other) const noexcept { return Mod(*this) -= other; }
    constexpr Mod operator*(const Mod& other) const noexcept { return Mod(*this) *= other; }
    constexpr bool operator==(const Mod& other) const noexcept { return this->value == other.value; }
    constexpr bool operator!=(const Mod& other) const noexcept { return this->value != other.value; }
};

signed main() {
    int n;
    cin >> n;

    vi va;
    int sum = 0;

    rep(i, n) {
        capi(a);
        va.push_back(a);
        sum += a;
    }

    Mod ans(0);

    for (auto a: va) {
        Mod x(sum - a);
        x *= a;
        ans += x;
    }

    if (ans.value % 2 == 0) {
        cout << ans.value / 2;
    } else {
        cout << (ans.value + P) / 2;
    }
    
    return 0;
}


Measured memory_bytes: 4960
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def dominus(t):
    r = len(plus)-1
    ans = 0
    for m in minus:
        while r>=0 and m*plus[r] >= -t:
            r -= 1
            if r<0:
                break
        ans += len(plus)-r-1
        #ddprint("m {} r {} pr {}".format(m,r,plus[r]))
    #ddprint("domin t {} ans {}".format(t,ans))
    return ans

def doplus(t):
    return doplus1(t,plus)+doplus1(t,minus)

def doplus1(t,b):
    ans = 0
    r = 0
    for i in range(len(b)-1,0,-1):
        p = b[i]
        r = min(r,i-1)
        while p*b[r] <= t:
            r += 1
            if r>=i:
                break
        ans += r
    #ddprint("p1 t {} b {} ans {}".format(t,b,ans))
    return ans

n,k = inm()
a = inl()
plus = []
minus = []
nzero = 0
for x in a:
    if x<0:
        minus.append(-x)
    elif x>0:
        plus.append(x)
    else:
        nzero += 1
minus.sort()
plus.sort()
kminus = len(plus)*len(minus)
kzero = (2*n-1-nzero)*nzero//2
kmz = kminus+kzero
ddprint("n {} k {}".format(n,k))
ddprint("minus")
ddprint(minus)
ddprint(plus)
if kminus<k<=kminus+kzero:
    print(0)
else:
    dom = (kminus>=k)
    if not dom:
        mn = 0
        mx = 10**19
        while mx>mn+1:
            mid = (mx+mn)//2
            v = doplus(mid)
            if v>=k-kmz:
                mx = mid
            else:
                mn = mid
            #ddprint("ploop mn {} mx {} mid {} v {} k {} kmz {}".format(mn,mx,mid,v,k,kmz))
    else:
        mx = 0
        mn = -10**19
        while mx>mn+1:
            mid = (mx+mn)//2
            v = dominus(mid)
            if v>=k:
                mx = mid
            else:
                mn = mid
            #ddprint("mn {} mx {} mid {} v {} k {}".format(mn,mx,mid,v,k))
    print(mx)


Measured memory_bytes: 96980
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
int tree[1000000];
int N, Q;

int find(int p, int l, int r, int a, int b) {
  if (l <= a && b <= r) {
    return tree[p];
  } else if (b <= l || r <= a) {
    return INF;
  } else {
    int x = find(2*p+1,l,r,a,(a+b)/2);
    int y = find(2*p+2,l,r,(a+b)/2,b);
    return min(x, y);
  }
}

int find(int l, int r) {
  return find(0, l, r+1, 0, N);
}

void update(int p, int x) {
  p += N-1;
  tree[p] = x;
  while (p>0) {
    p = (p-1)/2;
    tree[p] = min(tree[2*p+1], tree[2*p+2]); 
  }
}

signed main() {
  int M;
  cin >> M >> Q;

  const int INIT = 2147483647;
  N = 1;
  while (N < M || N == 1) N *= 2;
  for (int i = 0; i < N*2; i++) tree[i] = INIT;
  
  for (int i = 0; i < Q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0) {
      update(b, c);
    } else {
      cout << find(b, c) << endl;
    }
  }
}




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

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}
int main(void)
{ 
 ll n;
 string ans = "";
 cin >> n;
 
 while(n!=0){
   n = n-1;
   ans += char(ll('a') + n%26);
   n /= 26;
 }
 reverse(ans.begin(), ans.end());
 cout << ans << endl;
 return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll nCr(int n, int r)
{
    ll ans = 1;
    for (int i = n; i > n - r; --i)
    {
        ans = ans * i;
    }
    for (int i = 1; i < r + 1; ++i)
    {
        ans = ans / i;
    }
    return ans;
}

int main()
{
    string T;
    cin >> T;
    for (int i = 0; i < T.size();i++)
    {
        if(T[i] == '?' && i != T.size()-1){
            if(i > 0){
                if(T[i-1] == 'P'){
                    T[i] = 'D';
                }
                else if(T[i+1] == 'D'){
                    T[i] = 'P';
                }
                else if(T[i+1] == '?'){
                    T[i] = 'P';
                    T[i + 1] = 'D';
                }
                else{
                    T[i] = 'D';
                }
            }
            else{
                if(T[i+1] != 'P'){
                    T[i] = 'P';
                }
                else{
                    T[i] = 'D';
                }
            }
        }
        else if(T[i] == '?'){
            T[i] = 'D';
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool func(ll n)
{
	if(n==0 || n==1)
		return false;
	for(int i=2;i<=sqrt(n);i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
int main()
{
	ll n;
	cin>>n;
	while(1)
	{
		bool res=func(n);
		if(res)
			break;
		n++;
	}
	cout<<n<<endl;
}

Measured memory_bytes: 256
N,A,B,C=map(int, input().split())
L=[int(input()) for _ in range(N)]

ans=10**9

for i in range(4**8):
    mp=0
    a=b=c=0
    ac=bc=cc=0
    for j in range(N):
        f=i&3
        i>>=2
        if f==1:
            a+=L[j]
            ac+=1
        elif f==2:
            b+=L[j]
            bc+=1
        elif f==3:
            c+=L[j]
            cc+=1
    if ac==0 or bc==0 or cc==0: continue
    mp+=10*(ac-1+bc-1+cc-1)
    mp+=abs(A-a)+abs(B-b)+abs(C-c)
    ans=min(ans,mp)

print(ans)

Measured memory_bytes: 45932
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int h, w;
    cin >> w >> h;
    if (h == 0 && w == 0) return 0;
    vector<vector<int>> tatenokabe(h, vector<int>(w - 1));
    vector<vector<int>> yokonokabe(h - 1, vector<int>(w));
    rep(i, h - 1) {
        rep(j, w - 1) cin >> tatenokabe[i][j];
        rep(j, w) cin >> yokonokabe[i][j];
    }
    rep(j, w - 1) cin >> tatenokabe[h - 1][j];
    
    vector<vector<int>> dist(h, vector<int>(w, 0));
    queue<int> q;
    dist[0][0] = 1;
    q.push(0);
    while (q.size()) {
        int x = q.front() % w;
        int y = q.front() / w;
        q.pop();
        if (w > x + 1) {
            if (tatenokabe[y][x] == 0 && dist[y][x + 1] == 0) {
                dist[y][x + 1] = dist[y][x] + 1;
                q.push(y * w + x + 1);
            }
        }
        if (h > y + 1) {
            if (yokonokabe[y][x] == 0 && dist[y + 1][x] == 0) {
                dist[y + 1][x] = dist[y][x] + 1;
                q.push((y + 1) * w + x);
            }
        }
        if (x > 0) {
            if (tatenokabe[y][x - 1] == 0 && dist[y][x - 1] == 0) {
                dist[y][x - 1] = dist[y][x] + 1;
                q.push(y * w + x - 1);
            }
        }
        if (y > 0) {
            if (yokonokabe[y - 1][x] == 0 && dist[y - 1][x] == 0) {
                dist[y - 1][x] = dist[y][x] + 1;
                q.push((y - 1) * w + x);
            }
        }
    }
    cout << dist[h - 1][w - 1] << endl;
    main();
}



Measured memory_bytes: 4212
#include <stdio.h>
int main(void){
    int n,i;
    int sum=0;
    int l,r;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&l,&r);
        sum+=(r-l+1);
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    bool f = false;
    rep(i,3){
        if(s[i]-'0'==7) f = true;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main()
{
	int t;
	t=1;
	while(t--)
	{
     int l,r,d;
     cin>>l>>r>>d;
     int count=0;
     for(int i=l;i<=r;i++)
     {
       if(i%d==0)
       {
       	count++;
       }
     }
     cout<<count;
	}
}

Measured memory_bytes: 3544
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi prime(1000001, 1);
	prime[0] = prime[1] = 0;
	FOR(i, 2, 1000) {
		if(prime[i]) {
			for(int j = i*2; j <= 1000000; j += i) {
				prime[j] = 0;
			}
		}
	}

	int n;
	while(cin >> n, n) {
		int count = 0, ans = 0;
		REP(i, 1000000) {
			if(prime[i]) {
				ans += i;
				count++;
			}
			if(count == n) {
				break;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int ps[26][100005];
char s[100005];

int main() {
	scanf("%s", s + 1);
	
	int n = strlen(s + 1);
	
	for (int i = 0; i < 26; i++) {
		for (int j = 1; j <= n; j++) {
			if (s[j] - 'a' == i) ps[i][j] = 1;
			ps[i][j] += ps[i][j - 1];
		}
	}
	
	for (int i = 0; i < 26; i++) {
		int p = -1;
		int mx = -1e9;
		
		for (int j = 1; j <= n; j++) {
			if (mx > j - 2 * ps[i][j] + 1) return 0 * printf("%d %d\n", p, j);
			if (j - 2 * ps[i][j - 1] > mx) {
				mx = j - 2 * ps[i][j - 1];
				p = j;
			}
		}
	}
	
	printf("-1 -1\n");
}

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

long long gcd(vector<long long> v) {
    long long n = v.size();
    long long res = v[0];

    for (long long i = 1ll; i < n; i++) {
        // res := gcd(res, v[i])
        long long a = res;
        long long b = v[i];

        while (true) {
            if (a < 0) a = -a;
            if (b < 0) b = -b;
            if (b == 0) {
                res = a;
                break;
            }
            else {
                long long x = a % b;
                a = b;
                b = x;
                continue;
            }
        }
    }

    return res;
}



int main() {
    long long n, x;
    cin >> n >> x;
    vector<long long> city(n);
    for (long long i = 0; i < n; i++) {
        cin >> city[i];
        city[i] = abs(city[i] - x);
    }

    long long res = gcd(city);

    cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    string s; cin >> s;
    ll ans = 0, ind = 0;
    rep(i, s.size()){
        if(s[i] == 'W') ans += i-ind, ind++;
    }
    cout << ans << endl;
}


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

int main(){
  int N; cin >> N;
  int A[300000];
  for(int i=0; i<3*N; i++){
    cin >> A[i];
  }
  sort(A,A+3*N);
  long long result=0;
  for(int i=0; i<N; i++){
    result+=(long long)(A[N+2*i]);
  }
  cout << result << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

int main() {
    int n, m;   cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}

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

int h,w,v[100][100];
char c[100][100];

void dfs(int i,int j, char s) {
    if(c[i][j]!=s||v[i][j]) return;
    v[i][j]=1;
    if(i!=0) dfs(i-1,j,s);
    if(i!=h-1) dfs(i+1,j,s);
    if(j!=0) dfs(i,j-1,s);
    if(j!=w-1) dfs(i,j+1,s);
}

int main(){
    while(~scanf("%d%d",&h,&w)&&h&&w){
        memset(c,0,sizeof(c));
        memset(v,0,sizeof(v));
        for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            scanf(" %c", &c[i][j]);

        int cnt =0;
		for(int i=0;i<h;i++)
        for(int j=0;j<w;j++) {
            if(v[i][j]) continue;
            dfs(i,j,c[i][j]);
            cnt++;
        }
		printf("%d\n",cnt);
    }
    return 0;
}



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

int main() {
	long long n, t[1010], a[1010];
	cin >> n;
	cin >> t[0] >> a[0];
	long long j;
	long long old;
	bool flag = false;
	for (int i = 1; i < n; i++) {
		cin >> t[i] >> a[i];
		if (t[i] < t[i - 1]) {
			old = t[i];
			if (t[i - 1] % t[i] != 0) {
				j = (t[i - 1] + t[i] - t[i - 1] % t[i]) / t[i];
			}
			else {
				j = t[i - 1] / t[i];
			}
			t[i] *= j;

			if (a[i] * j < a[i - 1]) {
				t[i] = old;
				flag = true;
			}
			else {
				a[i] *= j;
			}
			if (flag == true) {
				if (a[i - 1] % a[i] != 0) {
					j = (a[i - 1] + a[i] - a[i - 1] % a[i]) / a[i];
				}
				else {
					j = a[i - 1] / a[i];
				}
				t[i] *= j;
				a[i] *= j;
			}
		}
		else {
			if (a[i] < a[i - 1]) {
				if (a[i - 1] % a[i] != 0) {
					j = (a[i - 1] + a[i] - a[i - 1] % a[i]) / a[i];
				}
				else {
					j = a[i - 1] / a[i];
				}
				t[i] *= j;
				a[i] *= j;
			}
		}

		flag = false;
	}
	cout << t[n - 1] + a[n - 1] << endl;
	return 0;
}

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

int main(void){
	int a,b;
	char op;
	int ans;
	while(cin){
		cin >> a >> op >> b;
		if(op=='?') break;
		switch(op){
			case '+':
				ans=a+b;
				break;
			case '-':
				ans=a-b;
				break;
			case '*':
				ans=a*b;
				break;
			case '/':
				ans=a/b;
				break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
MOD = 998244353
n, a, b, k = map(int, input().split())
fac = [1] * (n + 1)
for i in range(n):
    fac[i + 1] = fac[i] * (i + 1) % MOD


def comb(n, k):
    return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD)


ans = 0
for x in range(n + 1):
    if k - x * a < 0 or (k - x * a) % b:
        continue
    y = (k - x * a) // b
    if n < y:
        continue
    ans += (comb(n, x) * comb(n, y)) % MOD
print(ans % MOD)


Measured memory_bytes: 44012
# エラトステネスの篩, 累積和
from math import sqrt

N = 10 ** 5

p = [True] * (N + 1)
p[0] = False
p[1] = False
n = int(sqrt(N) + 1)
for j in range(4, N + 1, 2):
  p[j] = False
for i in range(3, n + 1, 2):
  if p[i]:
    for j in range(i + i, N + 1, i):
      p[j] = False

c = [0] * (N + 1)
for i in range(3, N + 1, 2):
  if p[i] and p[(i + 1) // 2]:
    c[i] = 1
for i in range(1, N + 1):
  c[i] += c[i - 1]

Q = int(input())
for _ in range(Q):
  l, r = map(int, input().split())
  print(c[r] - c[l - 1])


Measured memory_bytes: 7156
#include <iostream>
#include <limits.h>
#define NMAX 500000
using namespace std;
int ncomp = 0;
void merge(int *A, int left, int mid, int right) {
    int n1 = mid - left, n2 = right - mid;
    int L[n1+1], R[n2+1];
    for (int i=0; i<n1; i++) L[i] = A[left+i];
    for (int i=0; i<n2; i++) R[i] = A[mid+i];
    L[n1] = R[n2] = INT_MAX;
    int i = 0, j = 0;
    for (int k=left; k<right; k++) {
        if ( L[i] <= R[j] ) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
        ncomp++;
    }
}
void mergeSort(int *A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
int main() {
    int n; cin >> n;
    int S[NMAX]; for (int i=0; i<n; i++) cin >> S[i];
    mergeSort(S, 0, n);
    for (int i=0; i<n; i++) {
        cout << S[i];
        if (i == n-1) cout << endl; else cout << ' ';
    }
    cout << ncomp << endl;
}


Measured memory_bytes: 6896
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        long sum = ary.Sum(x=>(long)x);
        long min = long.MaxValue;

        long y = 0;
        for (int i=0; i<n-1; i++) {
            y += ary[i];
            sum -= ary[i];
            min = Math.Min(min, Math.Abs(y - sum));
        }

        return min;
    }


    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 31452
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int res = INT_MAX;
    int m = s.size();
    int n = t.size();
    for(int i=0;i<m-n+1;i++){
        int temp = 0;
        for(int j=0;j<n;j++){
            if(s[i+j]!=t[j]) temp++;
        }
        res = min(temp,res);
    }
    cout << res;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int i;
	char s[4];
	scanf("%s", s);
	for(i=1; i<4; i++)
	{
		if(s[i-1]==s[i])
		{
			printf("Bad\n");
			break;
		}
		if(i==3)
		printf("Good\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 600000
#define inf 2e18
#define int long long
using namespace  std;
int newp=0,first[maxn+4]={0},st[maxn+4]={0},fa[maxn+4]={0}; 
struct edge{
	int l,r,w;
}e[maxn+4];
bool cmp(edge x,edge y){
	return x.w<y.w;
}
void add(int x,int y,int z){
	e[++newp]=(edge){y,first[x],z};
	first[x]=newp;
}
int find(int x){
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
signed main(){
	int n,q;
	scanf("%lld%lld",&n,&q);
	int u,v,w;
	for(int i=0;i<n;i++)st[i]=inf;
	for(int i=1;i<=q;i++){
		scanf("%lld%lld%lld",&u,&v,&w);
		e[++newp]=(edge){u,v,w};
		if(u==v)st[u]=min(st[u],w+1);
		st[u]=min(st[u],w+1);
		st[v]=min(st[v],w+2);
	}
	int ans=inf,re;
	for(int i=0;i<n;i++){
		st[i]=min(st[i],st[(i-1+n)%n]+2);
	}
	for(int i=0;i<n;i++){
		st[i]=min(st[i],st[(i-1+n)%n]+2);
	}
/*	for(int i=0;i<=n-1;i++)
		if(st[i]<ans){
			ans=st[i];
			re=i;
		}
	/*for(int i=0;i<=(n-1);i++){
		int j=(re+i)%n;
		st[j]=min(st[j],ans);
		ans=min(st[j],ans);
		ans+=2;
	}*/
	for(int i=0;i<=(n-1);i++)
		e[++newp]=(edge){i,(i+1)%n,st[i]};
	sort(e+1,e+newp+1,cmp);
	int cnt=0,ret=0;
	for(int i=0;i<n;i++)fa[i]=i;
	for(int i=1;i<=newp;i++){
		int u=e[i].l,v=e[i].r;
		if(find(u)!=find(v)){
			fa[find(u)]=find(v);
			cnt++;
			ret+=e[i].w;
			if(cnt==n-1)break;
		}
	}
	printf("%lld\n",ret);
	return 0;
 }

Measured memory_bytes: 16884
#define judge
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int ninf = 0xcfcfcfcf;
const double pi = acos(-1.0);
static int faster_iostream = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();
const int maxn = 1e2 + 10;
int n;
ll gcd(ll a, ll b) {
  if (b > a) swap(a, b);
  while (b != 0) {
    ll r = b;
    b = a % b;
    a = r;
  }
  return a;
}
ll low(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
#ifndef judge
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  cin >> n;
  ll x = 1, y;
  for (int i = 0; i < n; i++) {
    cin >> y;
    x = low(x, y);
  }
  cout << x << endl;
  return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pnn=pair<int ,int>;

#define ft first
#define sd second
#define fn front
#define pb push_back
#define it insert
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))

string yes="Yes",no="No";

int main() {
   string s;
   int q;
   cin>>s>>q;
   deque<char> r;
   rep(i,s.size()) r.pb(s[i]);
   bool str=true;
   rep(i,q){
       int ti;
       cin>>ti;
       if(ti==1){
           str=!str;
           continue;
       }
       int fi;
       char ci;
       cin>>fi>>ci;
       if(str){
           if(fi==1) r.push_front(ci);
           else r.pb(ci);
       }
       else{
           if(fi==2) r.push_front(ci);
           else r.pb(ci);
       }
   }
   if(str){
       rep(i,r.size()){
           cout<<r.at(i);
           
       }
       cout<<endl;
       return 0;
   }
   rep(i,r.size()){
           cout<<r.at(r.size()-i-1);
   }
   cout<<endl;
}


Measured memory_bytes: 3996