akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <limits>
#include <cmath>

using namespace std;

#define EPS (numeric_limits<double>::epsilon())
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0) : x(x), y(y) {}

    Point operator+(const Point &p) const
    {
        return Point(x + p.x, y + p.y);
    }

    Point operator-(const Point &p) const
    {
        return Point(x - p.x, y - p.y);
    }

    Point operator*(const double &a) const
    {
        return Point(a * x, a * y);
    }

    Point operator/(const double &a) const
    {
        return Point(x / a, y / a);
    }

    double abs()
    {
        return sqrt(norm());
    }

    double norm()
    {
        return x * x + y * y;
    }

    bool operator<(const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator==(const Point &p) const
    {
        return equals(x, p.x) && equals(y, p.y);
    }
};

typedef Point Vector;

double dot(Vector a, Vector b)
{
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b)
{
    return a.x * b.y - a.y * b.x;
}

bool isParallel(Vector a, Vector b)
{
    return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2)
{
    return equals(cross(a2 - a1, b2 - b1), 0.0);
}

bool isOrthogonal(Vector a, Vector b)
{
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2)
{
    return equals(dot(a2 - a1, b2 - b1), 0.0);
}


int main()
{
    int query;
    cin >> query;
    Point p0, p1, p2, p3;
    for(int q = 0; q < query; q++)
    {
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
        if(isParallel(p0, p1, p2, p3))
            cout << "2" << endl;
        else if(isOrthogonal(p0, p1, p2, p3))
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
}


Measured memory_bytes: 3224
def solve(y, x, way)
  if y==0&&x==0&&way==3 then
    print 'L'
    return
  end
  if y==1&&x==0&&way==2 then
    print 'U'
    return
  end
  if way==1 then
    print 'R'
    if y>0&&$d[y-1][x+1]=='1' then
      solve(y-1,x+1,2)
    elsif x<5&&$d[y][x+1]=='1' then
      solve(y,x+1,1)
    elsif y<8&&$d[y+1][x+1]=='1' then
      solve(y+1,x+1,4)
    elsif x>0&&$d[y][x]=='1' then
      solve(y,x,3)
    end
  elsif way==2 then
    print 'U'
    if x>0&&$d[y-1][x-1]=='1' then
      solve(y-1,x-1,3)
    elsif y>1&&$d[y-2][x]=='1' then
      solve(y-2,x,2)
    elsif x<4&&$d[y-1][x]=='1' then
      solve(y-1,x,1)
    elsif y<7&&$d[y][x]=='1' then
      solve(y,x,4)
    end
  elsif way==3 then
    print 'L'
    if y<8&&$d[y+1][x]=='1' then
      solve(y+1,x,4)
    elsif x>0&&$d[y][x-1]=='1' then
      solve(y,x-1,3)
    elsif y>0&&$d[y-1][x]=='1' then
      solve(y-1,x,2)
    elsif x<4&&$d[y][x]=='1' then
      solve(y,x,1)
    end
  elsif way==4 then
    print 'D'
    if x<4&&$d[y+1][x]=='1' then
      solve(y+1,x,1)
    elsif y<7&&$d[y+2][x]=='1' then
      solve(y+2,x,4)
    elsif x>0&&$d[y+1][x-1]=='1' then
      solve(y+1,x-1,3)
    elsif y>1&&$d[y][x]=='1' then
      solve(y,x,2)
    end
  end
end
$d = Array.new(10)
9.times do |i|
  $d[i] = gets
end
solve(0,0,1)
puts

Measured memory_bytes: 6100
import * as process from "process";
import * as readline from "readline";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let lines = []
let reader = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

reader.on('line', line => {
    lines.push(line);
});

reader.on('close', () => {
    let x = parseInt(lines[0]);
    if (x < 1200) {
        console.log("ABC");
    } else {
        console.log("ARC");
    }
});

Measured memory_bytes: 7628
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

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

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

template <typename T>
void say(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}


/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int A, B;
	cin >> A >> B;
	if (A == 1) A = 14;
	if (B == 1) B = 14;

	if (A > B) cout << "Alice" << endl;
	else if (A < B) cout << "Bob" << endl;
	else cout << "Draw" << endl;

	return 0;
}

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

int main() {
    long long N, D, X;
    cin >> N >> D >> X;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    long long ans = X;
    for (int i = 0; i < N; i++) {
        ans += (D - 1) / A[i] + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
static String p = "";
static String q = "";
static int intp=0;
static int intq=0;
static int count=1;
static String tmp = "";
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		for(int i = 0;i<n;i++){
			p += sc.next();
		}
		sc.nextLine();
		for(int i = 0;i<n;i++){
			q += sc.next();
		}
		String nString = "";
		for(int i = 1;i<n+1;i++){
			nString +=i;
		}
		if(p.equals(q)){
			System.out.println("0");
		}else{
			permutation(nString, "");
			System.out.println(Math.abs(intp - intq));
		}
	}

		public static void permutation(String a, String ans){
			// Base Case
			if(a.length() <= 1) {
				count++;
				tmp = ans;
				tmp +=a;
				if(tmp.equals(p)){
					intp = count;
				}else if(tmp.equals(q)){
					intq = count;
				}

			}
			// General Case
			else {
				for (int i = 0; i < a.length(); i++) {
					permutation(a.substring(0, i) + a.substring(i + 1),
							ans + a.charAt(i));
				}
			}
		}
}

Measured memory_bytes: 42964
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

#define INF 1e+9
#define MAX_V 100100

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

signed main(){
    int x,y;
    cin >> V >> x >> y;
    x--; y--;
    G[x].pb({y,1});
    G[y].pb({x,1});
    int ans[V];
    rep(i,V) ans[i]=0;
    rep(i,V-1){
        G[i].pb({i+1,1});
        G[i+1].pb({i,1});
    }
    
    rep(i,V){
        dijkstra(i);
        rep(j,V){
            if(d[j]!=INF) ans[d[j]-1]++;
        }
    }
    rep(i,V-1) cout << ans[i]/2 << endl;
}


Measured memory_bytes: 2688
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
int sum(int n){return n * (n + 1)/ 2;}
void main(){
	int m;m.read;
	for(;m>0;m--){
		string cars;cars.read;
		bool[string] exist;
		foreach(i;1..cars.length){
			auto f = (string a) =>[a,a.dup.reverse.idup];
			foreach(c1;f(cars[0..i])) {
				foreach(c2;f(cars[i..$])){
					exist[c1 ~ c2] = true;
					exist[c2 ~ c1] = true;
				}
			}
		}
		exist.length.writeln;
	}
}

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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool acgt(char c){
  if(c=='A'||c=='C'||c=='G'||c=='T')return true;
  return false;
}

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  str s;
  int ans=0,cnt=0;
  cin >> s;
  EACH(i,s){
    if(acgt(*i)) cnt++;
    else cnt=0;
    ans = max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

//long long
const long long mod = 1000000007;
long long n , a , b , c;
long long pwa[120000] , pwb[120000];
long long fac[420000] , ifac[420000];
long long ans;
long long ksm ( long long f , long long x ) {
	long long s = 1;
	while ( x ) {
		if ( x % 2 ) s = s * f % mod;
		f = f * f % mod; x = x / 2;
	}
	return s % mod;
}
long long inv ( long long x ) {
	return ksm ( x , mod - 2 );
}
long long C ( long long x , long long y ) {
	return fac[x] * ifac[y] % mod * ifac[x-y] % mod;
}
void work () {
	long long i;
	scanf ( "%lld%lld%lld%lld" , &n , &a , &b , &c );
	a = a * inv ( 100 - c ) % mod;
	b = b * inv ( 100 - c ) % mod;
	c = 100 * inv ( 100 - c ) % mod;
	fac[0] = 1;
	for ( i = 1 ; i <= 400000 ; i++ ) {
		fac[i] = fac[i-1] * i % mod;
	}
	ifac[400000] = inv ( fac[400000] );
	for ( i = 399999 ; i >= 0 ; i-- ) {
		ifac[i] = (ifac[i+1]*(i+1)) % mod;
	}
	pwa[0] = pwb[0] = 1;
	for ( i = 1 ; i <= n ; i++ ) {
		pwa[i] = pwa[i-1] * a % mod;
		pwb[i] = pwb[i-1] * b % mod;
	}
	for ( i = 0 ; i <= n - 1 ; i++ ) {
		ans = (ans + C(n+i-1,n-1)*((pwa[n]*pwb[i]+pwb[n]*pwa[i]) % mod)%mod * (n+i) % mod) % mod;
	}
	if ( c == 0 ) c = 1;
	printf ( "%lld\n" , ans * c % mod );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 8448
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a[:]
d=sum(a)
for j in range(1,n):
    b=[min(b[i],a[i-j])for i in range(n)]
    d=min(d,sum(b)+j*x)
print(d)

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;
const int T = 2e5;

ll f[T];
bitset<T> crivo;
vector<ll> primes;
vector<int> degrees;
ll n,m;

void pre() {
    for(int i = 2; i < T; i++) {
        if(!crivo[i]) {
            primes.pb(i);
            for(int j = i+i; j < T; j += i) crivo[j] = 1;
        }
    }
}

void decop(ll x) {
    for(int i = 0; i < primes.size() and primes[i]*primes[i] <= x; i++) {
        int dg = 0;
        while(x % primes[i] == 0) x /= primes[i], dg++;
        if(dg) degrees.pb(dg);
    }
    if(x > 1) degrees.pb(1);
}

ll ele(ll base, ll e) {
    ll ans = 1;
    while(e) {
        if(e&1) ans = (ans * base) % MOD;
        base = (base * base) % MOD;
        e >>= 1;
    }
    return ans;
}

ll fat(ll x) {
    if(~f[x]) return f[x];
    return f[x] = (x * fat(x-1)) % MOD;
}

ll choose(ll a, ll b) {
    ll x = a+b-1;
    ll y = fat(b);
    ll z = fat(a-1);
    return fat(x)*ele((y*z)%MOD,MOD-2)%MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    pre();
    memset(f, -1, sizeof f);
    f[0] = f[1] = 1;
    cin >> n >> m;
    decop(m);
    ll ans = 1;
    for(ll x : degrees) ans = (ans * choose(n,x)) % MOD;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3708
def linear_search(s, n, key):
    for i in s:
        if i == key:
            return 1
    return 0

n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
ans = 0
for i in t:
    if linear_search(s, n, i) != 0:
        ans += 1
print(ans)


Measured memory_bytes: 6544
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
      int w,h,n,fx,fy,tx,ty,solve=0,i=1;
      cin>>w>>h>>n>>tx>>ty;
      for(;i<n;i++){
            fx=tx,fy=ty;
            cin>>tx>>ty;
            if((tx-fx)*(ty-fy)>0)solve+=max(abs(tx-fx),abs(ty-fy));
            else solve+= abs(tx-fx)+abs(ty-fy);
      }
      cout<<solve<<endl;
}

Measured memory_bytes: 1160
use std::vec::Vec;
use std::cmp::*;

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

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

fn main() {
  let n: usize = read();
  let mut s: Vec<(String, i64)> = Vec::new();
  for _ in 0..n {
    let c: String = read();
    s.push((c, 1));
  }

  let m: usize = read();
  for _ in 0..m {
    let c: String = read();
    s.push((c, -1));
  }
  s.sort();

  let mut tmp: String = s[0].0.clone();
  let mut res = 0;
  let mut count: i64 = 0;
  for &(ref c, p) in &s {
    if *c == tmp {
      count += p;
    } else {
      tmp = c.to_string();
      res = max(res, count);
      count = p;
    }
    res = max(res, count);
  }

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


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

public class Main{
    static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public Reader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }

    public static void main(String[] args) throws IOException{
        Reader in = new Reader(System.in);
        int n = in.nextInt();
        int[] letters = new int[26];
        for(int i=0; i<26; i++){
            letters[i] = 4000;
        }
        for(int i=0; i< n; i++){
            String s = in.next();
            int[] let = new int[26];
            for(int j=0; j<s.length(); j++){
                let[s.charAt(j)-97]++;
            }
            for(int j=0; j<26; j++){
                letters[j] = Math.min(letters[j], let[j]);
            }
        }
        for(int i=0; i<26; i++){
            for(int j=0; j<letters[i]; j++){
                System.out.print((char)(i+97));
            }
        }
    }
}


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    vector<long> a(n);
    rep(i,n)cin >> a[i];

    int ans = 0;
    rep(i,n){
        while(a[i] %2 == 0){
            ans ++ ;
            a[i]/=2;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3660
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}

using ll = long long;

int N;

int main() {
    cin >> N;

    assert(N >= 3);

    int s = 0;
    vector<int> v;

    int count = 0;
    for (int j = 1; count < N-2; ++j) {
        if (j % 2 == 0 || j % 3 == 0 || j % 5 == 0) {
            s += j;
            ++count;
            v.push_back(j);
        }
    }


    bool found = false;
    for (int j = v.back()+1; j <= 30000; ++j) {
        if (j % 3 != 0 && j % 5 != 0) continue;
        for (int k = j+1; k <= 30000; ++k) {
            if (k % 3 != 0 && k % 5 != 0) continue;
            if ((s + j + k) % 30 == 0) {
                found = true;
                v.push_back(j);
                v.push_back(k);
                break;
            }
        }
        if (found) break;
    }

    assert(found);

    for (int j = 0; j < v.size(); ++j) {
        if (j > 0) cout << " ";
        cout << v[j];
    }
    cout << endl;

    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

pii solve(vector<vector<LL>> &graph, LL parent, LL idx)
{
  pii sum = {1,1};
  vector<pii> a;
  REP(i, graph[idx].size())
  {
    LL j = graph[idx][i];
    if (parent!=j)
    {
      a.push_back(solve(graph, idx, j));
    }
  }
  REP(i,a.size()){
    sum.first *= (a[i].first+a[i].second);
    sum.second *= a[i].first;
    sum.first %= mod;
    sum.second %= mod;
  }
  return sum;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  cin >> N;
  vector<vector<LL>> graph(N );

  REP(i, N - 1)
  {
    LL a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  auto ans = solve(graph, -1, 0);
  cout << (ans.first + ans.second)%mod << endl;
}


Measured memory_bytes: 14080
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

#pragma gcc target ("avx2")
#pragma gcc optimization ("o3")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define nopf(T) [](T a){return a;}
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	vector<int> a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	scanf("%d", &k);
	printf("%d\n", a[--k]);

	Please AC;
}


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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<long long> a(n + 1);
    for (int i = n; i >= 0; i--) cin >> a[i];
    //for (int i = n; i >= 0; i--) a[i] = 1;
    long long g = abs(a[n]);
    for (int i = 0; i <= n; i++) if (a[i] != 0) g = __gcd(g, abs(a[i]));
    for (int i = 0; i <= n; i++) a[i] /= g;
    vector<int> vec;
    for (int i = 2; i * i <= g; i++)
    {
        while (g % i == 0)
        {
            g /= i;
            vec.push_back(i);
        }
    }
    if (g > 1)
    {
        vec.push_back(g);
    }
    for (int p = 2; p <= n; p++)
    {
        int t = 1; for (int j = 2; j < p; j++) if (p % j == 0) t = 0;
        if (t == 1)
        {
            vector<long long> poly = a;
            for (int i = n; i - p + 1 >= 0; i--)
            {
                poly[i - p + 1] = (poly[i - p + 1] + poly[i]) % p;
            	if (poly[i - p + 1] < 0) poly[i - p + 1] += p;
                poly[i] = 0;
            }
            int fl = 0;
            for (int i = 0; i <= n; i++) if (poly[i] % p != 0) fl = 1;
            if (a[0] % p == 0 && fl == 0) vec.push_back(p);
        }
    }
    sort(vec.begin(), vec.end());
    vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
    for (auto e : vec) cout << e << "\n";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

int main()
{
    int n,i;
    cin>>n;
    int arr[n+10];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    double sum = ((double)arr[0]+(double)arr[1])/2.0;
    for(i=2; i<n; i++)
    {
       sum = (sum+(double(arr[i])))/2.0;
    }
    printf("%.10lf",sum);
}


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

int main(){
    int N,C,**D,**c,i,j,k,minim=999999999,cost=0,zer[30],fir[30],sec[30];
    cin >> N >> C;
    for(i=0;i<C;i++){
        zer[i] = 0;
        fir[i] = 0;
        sec[i] = 0;    
    }
    D = new int*[C];
    for(i=0;i<C;i++){
        D[i] = new int[C];
    }
    for(i=0;i<C;i++){
        for(j=0;j<C;j++){
            cin >> D[i][j];
        }
    }
    c = new int*[N];
    for(i=0;i<N;i++){
        c[i] = new int[N];
    }
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            cin >> c[i][j];
            switch((i+j)%3){
                case 0:
                    zer[c[i][j]-1]++;
                    break;
                case 1:
                    fir[c[i][j]-1]++;
                    break;
                default:
                    sec[c[i][j]-1]++;
            }
        }
    }
    for(i=1;i<=C;i++){
        for(j=1;j<=C;j++){
            if(i==j){
                continue;
            }
            for(k=1;k<=C;k++){
                if(i==k||j==k){
                    continue;
                }
                for(int l=0;l<C;l++){
                    cost += zer[l]*D[l][i-1] + fir[l]*D[l][j-1] + sec[l]*D[l][k-1];
                }
                minim = min(minim,cost);
                cost = 0;
            }
        }
    }
    cout << minim << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem049c(s))
}

fun problem049c(s: String): String {
    val list = listOf("dreameraser", "dreamerase", "eraser", "dreamer", "erase", "dream")
    var t = s
    loop@ while (t.isNotBlank()) {
        for (word in list) {
            if (t.length >= word.length && t.take(word.length) == word) {
                t = t.drop(word.length)
                continue@loop
            }
        }
        return "NO"
    }
    return "YES"
}

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

#define ll long long
#define ar array
#define INF INT_MAX

void solve(){
	int n;
	cin>>n;
	int a[n],b[n],c[n],dp[n][3];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[0][0]=max(b[0],c[0]);
	dp[0][1]=max(a[0],c[0]);
	dp[0][2]=max(b[0],a[0]);
	for (int i = 1; i < n; ++i)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}
	

Measured memory_bytes: 6000
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar ( x % 10 | 48 );
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	int main() {
		ll A = read(), B = read(), C = read();
		C = max(0ll, C - A + B); return wln(C), 0;
	}
	
}

int main()
{
	return Cesare::main();
}

/*

*/



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<map>
#include<algorithm>
#define int long long 
using namespace std;
map<int,int>thh;
int a[100005],tot;
main()
{
	int i,j,k,n,x;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		thh[x]++;
		if(thh[x]>1)
		{
			tot++;
			a[tot]=x;
			thh[x]=0;
		}
	}
	sort(a+1,a+tot+1);
	if(tot==0)
	{
		cout<<0;
		return 0;
	}
	cout<<a[tot]*a[tot-1];
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string s;
    cin>>s;
    ll n=(s.length()-1)/2;
    rep(0,i,n){
        if(s.substr(i,1)!=s.substr(n-1-i,1)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(n,i,2*n+1){
        if(s.substr(i,1)!=s.substr((2*n+1)-1-i,1)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define sf(i,s) for(i=0;s[i]!='\0';i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define inf INT_MAX
#define pb push_back
#define mp make_pair
#define gcd(x,y) __gcd(x,y)
#define bc(x) __builtin_popcountll(x)
//cin.ignore(1, '\n');
ll power(ll a,ll b)
{
    if(b==0)
    return 1;
    if(b==1)
    return a;
    else
    {
        ll t=power(a,b/2);
        if(b%2==0)
        return ((t%mod)*(t%mod))%mod;
        else
        return ((((t%mod)*(t%mod))%mod)*((a%mod)%mod))%mod;
    }
}
void solve()
{
  ll n,i,k,j;
  cin>>n>>k;
  ll a[n+1],dp[n+1];
  f(i,1,n+1)
  {
      cin>>a[i];
  }
  f(i,1,n+1)
  {
      dp[i]=INT_MAX;
  }
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(a[2]-a[1]);
  f(i,3,n+1)
  {
      f(j,1,k+1)
      {
          if(i-j>0)
     dp[i]=min(dp[i-j]+abs(a[i-j]-a[i]),dp[i]);
      }
      //watch(dp[i]);
  }
  cout<<dp[n];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a);i!=(b);++i)
#define all(v) (v).begin(), (v).end()
#define rs resize
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

ostream& operator<<(ostream &out, const pii &a) { return out << '(' << a.x << ", " << a.y << ')'; }
istream& operator>>(istream &in, pii &a) { return in >> a.x >> a.y; }

const ll INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

ll pow10(ll n)
{
	ll r = 1;
	while (n--) r *= 10;
	return r;
}

void run()
{
	ll a, b;
	cin >> a >> b;
	stringstream ss;
	ss << b;
	ll N = ss.str().length();

	ll SUM = a * pow10(N) + b;
	double s = SUM;
	double sq = sqrt(s);

	ll sss = (ll) (sq + 0.5);
	cout << ((sss * sss == SUM) ? "Yes" : "No") << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// cerr << boolalpha;
	(cout << fixed).precision(10);

	run();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	vector<int> table(n, 0);
	table[0]=0;
	for(int i = 1; i < n; ++i){
		if(i == 1){
			table[i] = abs(vec[i] - vec[i - 1]);
		}
		if(i >= 2){
			table[i] = min(table[i - 1] + abs(vec[i] - vec[i - 1]), table[i - 2] + abs(vec[i] - vec[i - 2]));
		}
	}
	cout<<table[n - 1]<<endl;	
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vll red(a), green(b), white(c);
  vrep(red) cin >> i;
  vrep(green) cin >> i;
  vrep(white) cin >> i;

  sort(all(red), greater<ll>());
  sort(all(green), greater<ll>());
  priority_queue<ll> eat;
  rep(i, 0, x) eat.push(red.at(i));
  rep(i, 0, y) eat.push(green.at(i));
  rep(i, 0, c) eat.push(white.at(i));
  
  ll ans =0;
  rep(i, 0, x + y){
    ans += eat.top();
    eat.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 8432
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

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

    int a[2][n];
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }

    int max = 0;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum = 0;
        for (int j = 0; j < n; j++)
        {
            if (j < i)
            {
                sum += a[0][j];
            }
            else if (j == i)
            {
                sum += a[0][j] + a[1][j];
            }
            else
            {
                sum += a[1][j];
            }
        }
        if (sum > max)
        {
            max = sum;
        }
    }

    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
x = list(input())
#print(x[])

if x[0]=="A" :
	for i in range(2, len(x)-1, 1):
		if x[i]=="C":
			#print(x)
			del	x[i]
			del x[0]
			y="".join(x)
			#print(y)
			if y.islower():
				print("AC")
				break
			else:
				print("WA")
				break
	else:
		print("WA")

else:
	print("WA")

#print(x)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
	int n,x,i,j,k,a;
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0&&x==0){
			break;
		}
		a=0;
		for(i=1;i<=n-2;i++){
			for(j=i+1;j<=n-1;j++){
				for(k=j+1;k<=n;k++){
					if(i+j+k==x){
						a++;
					}
				}
			}
		}
		printf("%d\n",a);
	}
	return 0;
}

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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int stone[2<<19];

int m,n;

int main(){
    int i,j,k;
    
    cin >> n;
    n = 1<<n;
    for (i=0;i<n;i++){
        scanf("%d",stone+i);
    }
    for (;1<n;n>>=1){
        for (i=0;i<n/2;i++){
            stone[i] = abs(stone[i*2] - stone[i*2+1]);
        }
    }
    cout << stone[0] << endl;

    return 0;
}

Measured memory_bytes: 1280
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << (b - a) * (b - a + 1) / 2 - b << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3632
import math

k = int(input())
a = []
result = []

for i in range(1,k+1):
    for j in range(1,k+1):
        a.append(math.gcd(i,j))

for i in range(1,k+1):
    result.extend(math.gcd(n,i) for n in a)

print(sum(result))

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if(A+B > C+D) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int a,b,c;

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
  int n;
  long long ans_sum = 0;
  int ans = 0;//台
  cin >> n;
  int p[n] = {};
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  int max = p[0];
  //最大を出す
  for(int i=1;i < n;i++){
    if(max <= p[i]){//１つ前が高いので、台がいる
      max = p[i];//最大値更新
      ans = 0;
    }
    else if(max > p[i]){//足すのは、１つ前が低いとき
      ans = max - p[i];
    }
    ans_sum += ans;
    //cout << ans << i << endl;
  }
   cout << ans_sum << endl;
  
} 

Measured memory_bytes: 4348
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


class BIT:
    def __init__(self, n):
        self.num = n
        self.dat = [0] * (self.num + 1)

    def add(self, i, x):
        i += 1
        while i <= self.num:
            self.dat[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.dat[i]
            i -= i & -i
        return s

n, q = LI()
ans = [0] * q
C = LI()
Q = defaultdict(list)
for i in range(q):
    l, r = LI()
    Q[r - 1] += [(i, l - 1)]

last = [-1] * (n + 1)
bit = BIT(n + 1)
for i, c in enumerate(C):
    col = C[i]
    bit.add(i, 1)
    if last[col] != -1:
        bit.add(last[col], -1)
    last[col] = i
    for qi, li in Q[i]:
        ans[qi] = bit.sum(i) - bit.sum(li - 1)


print(*ans, sep="\n")


Measured memory_bytes: 235236
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n,x,y,z,dp[45][1<<17];
int main()
{
    scanf("%d%d%d%d",&n,&x,&y,&z);
    int mask=(1<<(x+y+z))-1;
    int valid=(1<<(x+y+z-1))+(1<<(x+y-1))+(1<<(x-1));
    dp[0][0]=1;
    for (int i=1;i<=n;++i)
        for (int j=1;j<=10;++j)
            for (int k=0;k<=mask;++k) {
                int t=mask&((k<<j)+(1<<(j-1)));
                if ((t&valid)==valid) continue;
                dp[i][t]=(dp[i][t]+dp[i-1][k])%mod;
            }
    int res=1;
    for (int i=1;i<=n;++i)
        res=10ll*res%mod;
    for (int i=0;i<=mask;++i)
        res=((res-dp[n][i])%mod+mod)%mod;
    printf("%d\n",res);
    return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long i64;
typedef pair<i64, i64> pii;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) ++cnt;
    }
    if (cnt == 8) ++ans;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
R1=range(-2,3)
R2=range(-1,2)
A1=[(x,y) for x in R1 for y in R1 if 3<x**2+y**2<6]
A2=[(x,y) for x in R2 for y in R2]
def fi(): return map(int,raw_input().split(" "))
def f(x,y,i):
  A=[A1,A2][i>0]
  return set([(x+dx,y+dy) for dx,dy in A if 0<=x+dx<10 and 0<=y+dy<10])

while 1:
  xf,yf=fi()
  if yf==xf==0: break
  ns=input()
  tmp=fi()
  PA=zip(tmp[0::2],tmp[1::2])
  FA=set([(xf,yf)])
  for xs,ys in PA:
    SA=f(xs,ys,1)
    tmp=set([])
    for xf,yf in FA: tmp=tmp|(SA&f(xf,yf,0))
    FA=tmp
  print ["NA","OK"][len(FA)>0]

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


int main() {
  ll x;
  cin >> x;
  ll c=x/500;
  ll d=x%500;
  cout << 1000*c+d/5*5 << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
Sum = 0
Dff = 0

for i in range(N-1):
    Dff = A[i] - A[i+1]
    if Dff > 0:
        A[i+1] += Dff
        Sum += Dff
    Dff = 0

print(Sum)

Measured memory_bytes: 32160
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
 int N; cin>>N;

 ll ans = 0;
 for(int i=0;i<N;i++){
   int l,r;
   cin>>l>>r;
   ans += r-l+1;
 }
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W,K;
    cin >> H >> W >> K;
    int maxH= (1<<H);
    int maxW= (1<<W);
    int c[H][W];
    char ch;
    int count=0,ans=0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> ch;
            if(ch=='#'){
                c[i][j]=1;
            }else{
                c[i][j]=0;
            }
        }
    }
    for(int i=0; i<maxH; i++){
        for(int j=0; j<maxW; j++){
            count=0;
            for(int s=0; s<H; s++){
                for(int t=0; t<W; t++){
                    if(c[s][t]==1 && !((i&(1<<s)) || (j&(1<<t)) )){
                        count++;
                    }
                }
            }
            if(count==K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3560
N=int(input())
c=0
l=list(map(int,input().split()))
for i in range(0,N):
  for j in range(i+1,N):
    for  k in range(j+1,N):
      if l[i]<l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[j]+l[i] and l[k]!=l[j] and l[k]!=l[i] and l[i]!=l[j] :
        c=c+1
print(c)

Measured memory_bytes: 9192
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int main(){
  string s;

  int w[26] = {};

  cin >> s;

  string ans(s);

  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    cout << "-1" << endl;
    return 0;
  }

  if(s.size() == 26){
    string tmp;
    char a = '{';

    char x = -1;
    for(int i = 25; ; i--){
      if(s[i] > x){
        tmp.push_back(s[i]);
        x = s[i];
      } else {
        REP(j, 0, tmp.size()){
          //cout << s[i] << " " << tmp[j] << endl;
          if(s[i] < tmp[j] && a > tmp[j]){
            a = tmp[j];
            //cout << a << endl;
          }
        }
      }
      if(a != '{'){
        //cout << "answer" << endl;
        s[i] = a;
        string ans2(s.substr(0, i+1));
        cout << ans2 << endl;

        return 0;
      }
    }
    
  } else {
    REP(i, 0, s.size()){
      w[s[i]-'a'] = 1;
    }

    int a = 0;

    REP(i, 0, 26){
      if(w[i] == 0){
        a = i;
        break;
      }
    }

    ans.push_back(a+'a');
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int a[305][305],sum[305];
bool vis[305];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	ans=n;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=m;j++) sum[j]=0;
		for(int j=1;j<=n;j++)
			for(int k=1;k<=m;k++)
				if( !vis[a[j][k]] ) 
				{
					++sum[a[j][k]]; 
					break;
				}
		int k=1;
		for(int j=1;j<=m;j++) 
			if(sum[j]>sum[k]) k=j;
		vis[k]=true;
		if(sum[k]<ans) ans=sum[k];
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int l[100010],r[100010];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> l[i] >> r[i];
	sort(l, l + m);
	sort(r, r + m);
	int ans = 0;
	if (r[0] >= l[m-1]) ans = r[0] - l[m-1] + 1;
	cout << ans;


}

Measured memory_bytes: 1024