akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  ll a;
  int cnt_odd = 0;
  int cnt_4   = 0;
  int cnt_2   = 0;
  for(int i = 0; i < N; i++){
    cin >> a;
    if(a%2 == 1){
      cnt_odd += 1;
    }
    if(a%2==0 && a%4 != 0){
      cnt_2++;
    }
    if(a%4==0){
      cnt_4 += 1;
    }
  }
  if(cnt_2 > 0){
    cnt_odd++;
  }

  if(cnt_4 + 1 < cnt_odd){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}


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

int const N = 200000;
bool dp[N + 1];
vector<int> tr[N + 1];

pair<int, int> go(int v = 1, int p = 0){
	int mx1 = 0, mx2 = 0, an = 1;
	for (int &u: tr[v])if (u != p){
		pair<int, int> t = go(u, v);
		an = max(an, t.second);
		if (t.first > mx1)mx2 = mx1, mx1 = t.first;
		else if (t.first > mx2)mx2 = t.first;
	}
	return make_pair(mx1 + 1, max(an, mx1 + mx2 + 1));
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n){
		int a, b;
		scanf("%d%d", &a, &b);
		tr[a].push_back(b);
		tr[b].push_back(a);
	}
	int d = go().second;
	dp[1] = true;
	dp[2] = false;
	f(i, 3, N + 1)if (!dp[i - 1] || !dp[i - 2])dp[i] = true;
	printf("%s\n", dp[d] ? "First" : "Second");
}

Measured memory_bytes: 26368
import numpy as np
buf = input().split()
N = int(buf[0])
C = int(buf[1])
D = np.zeros((C, C))
for i in range(C):
	buf = input().split()
	for j in range(C):
		D[i][j] = int(buf[j])

grid = np.zeros((3, C))
for i in range(N):
	buf = input().split()
	for j in range(N):
		groop = (i+1+j+1)%3
		bufcolor = int(buf[j])-1 
		grid[groop][bufcolor] += 1
#print(grid)

iwakan = np.zeros((3, C))
for groop in range(3):
	for color in range(C):
		iwakan[groop][color] = np.sum(grid[groop]*(D.T)[color])
#print(iwakan)

miniwakan = np.zeros((3, 3))
cminiwakan = np.zeros((3, 3))
for groop in range(3):
	buf = iwakan[groop]
	for best in range(3):
		mcolor = np.argmin(buf)
		miniwakan[groop][best] = buf[mcolor]
		cminiwakan[groop][best] = mcolor
		buf[mcolor] = np.max(buf)+1
#print(miniwakan)
#print(cminiwakan)
min = iwakan[0][0]+iwakan[1][1]+iwakan[2][2]
for i in range(3):
	for j in range(3):
		for k in range(3):
			bufmin = miniwakan[0][i] + miniwakan[1][j] + miniwakan[2][k]
			
			c0 = cminiwakan[0][i]
			c1 = cminiwakan[1][j]
			c2 = cminiwakan[2][k]
			#print(bufmin, c0, c1, c2)
			if((c0!=c1) and (c0!=c2) and (c1!=c2) and bufmin<min):
				min = bufmin
			#	print(min)

print(int(min))
					
			

# your code goes here


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

using namespace std;

int main() {
  int H, W; cin >> H >> W;

  string s[H];
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }


  bool ans = true;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      
      if(s[i][j] != '#'){
        continue;
      }

      if(!( (i-1 >= 0 && s[i-1][j] == '#') || (i+1 < H && s[i+1][j] == '#') || (j-1 >= 0 && s[i][j-1] == '#') || (j+1 < W && s[i][j+1] == '#') )) {
        ans =  false;
      }
    }
  }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		boolean found = false;
		for (int j = A; j <= B; j++) {
			if(j%K == 0) {
				System.out.println("OK");
				found = true;
				break;
			}
		}
		if(!found) {
			System.out.println("NG");
		}
		sc.close();
	}

}


Measured memory_bytes: 35688
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int n,k,q; cin >>n>>k>>q;
    vector<int> a(q); rep(i,q) cin >> a[i];
    vector<int> poi(n, 0);

    for (int i = 0; i < q; i++) {
        int j = a[i] - 1;
        poi[j] += 1;
    }

    for (int i = 0; i < n; i++) {
        if (k - (q - poi[i]) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        } 
    }
    
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

ll powmod(ll a, ll p, ll MOD) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
		if ((p & 1) == 1)ans = (ans * mul) % MOD;
	}
	return ans;
}

ll combmod(ll n, ll r, ll MOD){
  if(n < r) return 0LL;
  if (n < 0 || r < 0) return 0LL;
  vector<ll> ff(n+1), vff(n+1);
  // 1! ~ n!
  ff[0] = 1;
  for(ll i = 1; i < n + 1; i++) {
    ff[i] = ff[i - 1] * i % MOD;
  }
  // n!^(MOD-2) (= n!^(-1))
  ll inv = powmod(ff[n], MOD - 2, MOD);

  // n!^(-1) ~ 1!^(-1)
  vff[n] = inv;
  for(ll i = n - 1; i >= 0; i--) {
    vff[i] = vff[i + 1] * (i + 1) % MOD;
  }

  // n combination r
  ll comb = (((ff[n] * vff[r]) % MOD) * vff[n - r]) % MOD;

  return comb;
}


int main() {
  int N, K;
  cin >> N >> K;
  const ll MOD = 1e9 + 7;

  ll left, right, ans;

  for(int i = 1; i <= K; i++){
    if (i == 1){
      left = N - K + 1;
      right = 1;
    }else{

      right = combmod(N - K +1, i, MOD);
      left = combmod(K - 1, i - 1, MOD);

    }

    left %= MOD;
    right %= MOD;
    ans = left * right;
    ans %= MOD;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib> 
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			cnt += 1;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Set<Integer> s = new HashSet<>(n);
        boolean dup = false;
        for(int i=0; i<n; i++) {
            int a = in.nextInt();
            if(s.contains(a)) {
                dup = true;
            }
            else {
                s.add(a);
            }
        }
        System.out.println(dup ? "NO" : "YES");
    }
}


Measured memory_bytes: 100600
r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
A=2*(10**6)+3
P=[0 for i in range(A+1)]
P[1]=1
for i in range(2,A):
    P[i]=P[i-1]*i%mod

dr2=pow(P[r2],mod-2,mod)
dr1=pow(P[r1-1],mod-2,mod)
def combr2(x):
    y=r2
    if y>x or x<=0:
        return(0)
    elif y==0:
        return(1)
    else:
        return(P[x]*pow(P[x-y],mod-2,mod)%mod*dr2%mod)

def combr1(x):
    y=r1-1
    if y>x or x<=0:
        return(0)
    elif y==0:
        return(1)
    else:
        return(P[x]*pow(P[x-y],mod-2,mod)%mod*dr1%mod)
count=0
for i in range(c1+1,c2+2):
    count=(count+combr2(i+r2)-combr1(i+r1-1))%mod
print(count%mod)


Measured memory_bytes: 123368
# Handstand

n, k = map(int, input().split())
s = list(str(input()))

t = [0]
cnt = 1
for i in range(n):
    if i==n-1 or s[i]!=s[i+1]:
        t.append(cnt)
        cnt = 1
    else:
        cnt += 1
t.append(0)

tsum = [0]*(len(t)+1)
for i in range(len(t)):
    tsum[i+1] = tsum[i] + t[i]

#print(tsum)

ans = 0
for i in range(1+int(s[0])%2, len(tsum)-2*k,2):
    tmp = tsum[i+2*k] - tsum[i-1]
    #print(tmp)
    ans = max(ans, tmp)

if ans==0:
    ans = len(s)
print(ans)


Measured memory_bytes: 8568
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 
int main() {
	float N;
	cin >> N;
	cout << ((int)N+1)/2/N << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	int k;
	cin>>s>>k;
	int len=s.size();
	vector<string> t;
	REP(i, min(len, k)){
		REP(j, len-i){
			t.push_back(s.substr(j, i+1));
		}
	}
	sort(ALL(t));
	REP(i, t.size()){
		if(k==1){
			cout<<t[i]<<'\n';
			return 0;
		}
		if(t[i]!=t[i+1]) --k;
	}
	return 0;
}


Measured memory_bytes: 1660
import java.util.Scanner

object Main extends App  {
  val sc = new Scanner(System.in)

  val s = sc.next
  
  val stack =
    s.foldLeft( Vector.empty[Char] ){(stack, ch) =>
      ch match{
        case '0' if stack.headOption.contains('1') => stack.tail
        case '0'                                   => ch +: stack
        case '1' if stack.headOption.contains('0') => stack.tail
        case '1'                                   => stack :+ ch
        case _                                     => ch +: stack
      }
  }

  val res = s.length - stack.length

  println(res)
}

Measured memory_bytes: 43924
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();

    let ans = f(a - 1) ^ f(b);
    println!("{}", ans);
}

fn f(a: i64) -> i64 {
    let cnt = (a + 1) / 2;
    let mut ans = cnt % 2;
    if a % 2 == 0 {
        ans ^= a;
    }
    ans
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

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

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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 int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int N;
  cin >> N;
  vector<ll> a(N);
  REP(i,N)cin >> a[i];
  sort(RALL(a));
  ll ans=a[0];
  REP(i,N-2){
    ans+=a[i/2+1];
  }
  PRINT(ans);
}



Measured memory_bytes: 4744
#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>;
//vector<> vec(n);

int main(){
  int n=0,s=0,cnt=0,m=0;

  cin >> n;

  rep(i,n){
  cin >> s >> m;
  if(s==m){cnt++;}
  else{cnt=0;}
  if(cnt==3){cout << "Yes" << endl; return 0;}
  }
  cout << "No" << endl;
  return 0;
}

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

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


int main() {
  int k;
  cin >> k;
  int64_t ans=0;
  rep(i,k)rep(j,k)rep(l,k){
    
    ans += gcd(i+1,gcd(j+1,l+1));
  }
  cout << ans << endl;
  

}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d,maxx;
	cin>>a>>b>>c>>d;
	maxx=max(a*c,a*d);
	maxx=max(maxx,max(b*c,b*d));
	cout<<maxx;
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();
        int l = input.nextInt();
        long[][] A = new long[n][m];
        long[][] B = new long[m][l];
        long[][] C = new long[n][l];
        for(int i = 0; i < n; i ++ )
            for(int j = 0; j < m; j ++ )
                A[i][j] = input.nextInt();
        for(int i = 0; i < m; i ++ )
            for(int j = 0; j < l; j ++ )
                B[i][j] = input.nextInt();
        for(int i = 0; i < n; i ++ )
            for(int j = 0; j < l; j ++ ){
                C[i][j] = 0;
                for(int k = 0; k < m; k ++)
                    C[i][j] += A[i][k] * B[k][j];
            }
        for(int i = 0; i < n; i ++ ){
            System.out.print(C[i][0]);        
            for(int j = 1; j < l; j ++ )
                System.out.print(" " + C[i][j]);
            System.out.println();
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dp[1005][1005]{};

int main() {
    string s,t;
    cin >> s >> t;
    REP(i,s.size()+1)fill(dp[i],dp[i]+t.size()+1,999999);
    REP(i,s.size()+1)dp[i][0] = i;
    REP(j,t.size()+1)dp[0][j] = j;
    REP(i,s.size()){
        REP(j,t.size()){
            if(s[i]==t[j])dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]);
            dp[i+1][j+1] = min(dp[i+1][j+1],dp[i+1][j]+1);
            dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j+1]+1);
            dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+1);
        }
    }
    cout << dp[s.size()][t.size()] << endl;
    return 0;
}



Measured memory_bytes: 7144
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

void main() {
    const tmp = readln.split.to!(long[]);
    const N = tmp[0], K = tmp[1];
    const as = readln.split.to!(long[]);

    ulong X = 0;
    foreach_reverse(i; 0..64) {
        const cnt = as
            .map!(a => a >> i)
            .map!(a => a & 1)
            .sum;

        if (cnt * 2 >= N) continue;
        const po = (1L << i);
        if ((X | po) > K) continue;
        X |= po;
    }
    writeln(as.map!(a => a^X).sum);
}



Measured memory_bytes: 4732
#include <iostream>
#include <unordered_set>
#include <string>

int main(){
    std::unordered_set<std::string> s;
    int n;
    std::cin >> n;
    std::string command, str;
    for(int i=0; i<n; ++i){
        std::cin >> command >> str;
        if(command == "insert"){
            s.insert(str);
        }else{
            std::cout << ((s.count(str) == 1) ? "yes" : "no") << std::endl;
        }
    }
}


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

int a[1000][1000], H, W, h, w;
int main(void)
{
	scanf("%d%d%d%d", &H, &W, &h, &w);
	if ((H%h == 0) && (W%w == 0)) {printf("No\n"); return 0;}
	printf("Yes\n");
	a[0][0]= (H/h)*(W/w) + 1;
	a[h - 1][w - 1] = -a[0][0] - 1;
  for (int i =0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      printf("%d ",a[i%h][j%w]);
    }
    printf("\n");
  }
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int X, Y;
void func()
{
    cin >> X >> Y;
    bool ans = false;
    if (Y >= X * 2 && Y <= X * 4 && Y % 2 == 0)
        ans = true;
    if (ans)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
}
int main()
{
    func();
}

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

typedef long long ll;
#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll A;
    ll B;

    cin >> A >> B;

    if( A >= 13 ){
        cout << B << endl;
    }else if(A >= 6){
        cout << B/2 << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>


using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9 + 7;
vi alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };

ll Foo(ll num) {
    ll a;
    if ((num % 4) == 0) a=num;
    else if ((num % 4) == 1) a=1;
    else if ((num % 4) == 2) a=num+1;
    else a=0;
    return a;
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll ans;
    if (A == 0) ans = Foo(B);
    else {
        ll a = Foo(A-1);
        ll b = Foo(B);
        ans = a ^ b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> v(1e6,0);
  for(int i=0;i<M;i++){
    int l,r;cin>>l>>r;
    v[l]++;
    v[r+1]--;
  }
  for(int i=0;i<1e6-1;i++)v[i+1]+=v[i];
  int ans=0;
  for(int i=0;i<1e6;i++)if(v[i]==M)ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 8064
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

// ifstream fin("test.in");

// #define int_max 0x3f3f3f3f
// #define int_min -0x3f3f3f3f

int main()
{
    long long int n, k;
    cin >> n >> k;
    vector<long long int> heights(n + 1, 0);
    vector<long long int> dp(n + 1, 0);
    long long int h;

    for (long long int i = 1; i <= n; i++)
    {
        cin >> h;
        heights.at(i) = h;
    }

    dp[1] = 0;
    dp[2] = abs(heights[2] - heights[1]);

    for (long long int i = 3; i <= n; i++)
    {
        long long int best = dp[i - 1] + abs(heights[i] - heights[i - 1]);

        for (long long int j = 2; j <= k && j < i; j++)
            best = min(best, dp[i - j] + abs(heights[i] - heights[i - j]));

        dp[i] = best;
    }

    cout << dp[n] << endl;
}

Measured memory_bytes: 4320
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;
#define show2(a, n, m) rep(i, n) {rep(j, m) {cout<<a[i][j]<<' ';} cout<<endl;}

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
//const int INF = 10000;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 1000000;

int main() {
//	cout << fixed << setprecision(15);
	vi v[2];
	int n = 1, m;
	while(true) {
		m = n * (n + 1) * (n + 2) / 6;
		if(m > N) break;
		v[0].push_back(m);
		if(m % 2 == 1) v[1].push_back(m);
		n++;
	}

	vi in;
	while(true) {
		int n;
		cin >> n;
		if(n == 0) break;
		in.push_back(n);
	}

	vi dp(N+1), ans[2];
	rep(i, 2) {
		fill(dp.begin(), dp.end(), INF);
		dp[0] = 0;
		for(int j = 0; j < v[i].size(); j++) {
			for(int k = v[i][j]; k <= N; k++) {
				dp[k] = min(dp[k - v[i][j]] + 1, dp[k]);
			}
		}
		for(auto j : in) ans[i].push_back(dp[j]);
	}
	rep(i, in.size()) cout << ans[0][i] << ' ' << ans[1][i] << endl;
}



Measured memory_bytes: 6684
#include<iostream>
#include<cstring>
using namespace std;
char ca[2][205];

void print(int n){
	if(n<0)cout<<"DIFFERENT"<<endl;
	if(n==0)cout<<"CLOSE"<<endl;
	if(n>0)cout<<"IDENTICAL"<<endl;
}

bool check(int a,int b){
	if(a>=strlen(ca[0]) && b>=strlen(ca[1]))return true;
	if(a>=strlen(ca[0]) || b>=strlen(ca[1]))return false;
	if(ca[0][a]=='\"' && ca[1][b]=='\"')return true;
	if(ca[0][a]=='\"' || ca[1][b]=='\"')return false;
	if(ca[0][a]!=ca[1][b])return false;
	return check(a+1,b+1);
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	int t[5];
	int flag;
	while(cin>>ca[0]){
		if(ca[0][0]=='.')break;
		cin>>ca[1];
		t[0]=0;t[1]=0;
		for(i=0;i<2;i++){
			for(j=0;j<strlen(ca[i]);j++){
				if(ca[i][j]=='\"')t[i]++;
			}
		}
		if(t[0]!=t[1]){
			print(-1);
			continue;
		}
		a=t[0]+1;
		t[0]=0,t[1]=0,flag=1;
		for(i=0;i<a;i++){
			if(!check(t[0],t[1])){
				if(i%2==0 || flag==0){
					flag=-1;
					break;
				}else flag=0;
			}
			for(j=0;j<2;j++){
				for(;t[j]<strlen(ca[j]) && ca[j][t[j]]!='\"';t[j]++);
				t[j]++;
			}
		}
		print(flag);
	}
}
			



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

using namespace std;

typedef long long ll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define mp make_pair
#define pb push_back
#define all(name) (name.begin(), name.end())
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) power(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
// ll dp[105][100005];
int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
	{
		ll n, k;
		cin >> n;k = 2;
		ll arr[n];
		rep(i, 0, n)cin >> arr[i];
		ll dp[n];
		dp[0] = 0;
		rep(i, 1, n){
			dp[i] = dp[i-1] + abs(arr[i] - arr[i-1]);
			rep(j, 2, k+1)if(i-j >= 0)
				dp[i] = min(dp[i], dp[i-j] + abs(arr[i] - arr[i-j]));
		}
		cout << dp[n-1] ;
	}
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int N,W,w,v;
    cin>>N>>W;
    vector<vector<long long>> dp(N+1,vector<long long>(W+1,0));
    for(int i=1;i<=N;i++){
        cin>>w>>v;
        for(int j=1;j<=w;j++){
            dp[i][j]=dp[i-1][j];
        }
        for(int j=w;j<=W;j++){
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
        }
    }
    cout<<dp[N][W]<<"\n";
    return 0;
}

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

int cost[5][40];
int d[40][40],c[600][600];
vector <pair<int,int> > v[3];
int n,m;

int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) cin>>d[i][j];
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>c[i][j];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			v[(i+j)%3].push_back(make_pair(i,j));
		}
	}
	for(int i=0;i<3;i++){
		for(int j=1;j<=m;j++){
			for(int k=0;k<v[i].size();k++){
				int x=v[i][k].first;
				int y=v[i][k].second;
				cost[i][j]+=d[c[x][y]][j];
			}
		}
	}
	long long ans=1e11;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			for(int k=1;k<=m;k++){
				long long sum=0;
				if(i!=j&&j!=k&&i!=k){
					sum=cost[0][i]+cost[1][j]+cost[2][k];
					ans=min(ans,sum);
				}
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3760
//2018年  3月 21日 水曜日 23:11:04 JST-23:27:10
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 2002000;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll fac[MAX_N], inv[MAX_N], fiv[MAX_N]; //fiv:inv(fac(i))

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll invf(ll a) {
	return mod_pow(a, mod - 2);
}

void C_init(int n) {
	fac[0] = fac[1] = 1; inv[1] = 1;
	fiv[0] = fiv[1] = 1;
	rep(i, 2, n + 1) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fiv[i] = fiv[i - 1] * inv[i] % mod;
	}
}

ll C(int a, int b) { //assume a >= b
	if(a < b || a < 0 || b < 0) return 0;
	return fac[a] * fiv[b] % mod * fiv[a - b] % mod;
}


int H, W, A, B;

void solve() {
	cin >> H >> W >> A >> B;
	C_init(100000 * 2 + 10);
	ll res = 0;
	for(int i = B; i < W; i++) {
		ADD(res, C(H - A - 1 + i, i) * C(A + W - i - 2, A - 1) % mod);
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	string S;
	while(cin >> S){
		vector<int> dp(S.size()+1, 0);
		dp[0] = 1;
		for(int i=0;i<S.size();++i){
			if(!dp[i]) continue;
			if(S.find("dream", i) == i) dp[i+5] = 1;
			if(S.find("dreamer", i) == i) dp[i+7] = 1;
			if(S.find("erase", i) == i) dp[i+5] = 1;
			if(S.find("eraser", i) == i) dp[i+6] = 1;
		}
		cout << (dp.back() ? "YES" : "NO") << endl;
	}
}


Measured memory_bytes: 896
N, A, B = map(int, input().split())

d, m = divmod(N, (A+B))
ans = 0
# print(d)
# print(m)
if m >= 0:
    if m <= A:
#         print(d)
#         print(A)
#         print(m)
        ans = d*A + m
    else:
        ans = d*A + A
print(ans)

Measured memory_bytes: 3060
import math

def main():
    N, K = map(int, input().split())
    probs = list()
    for i in range(1, N+1):
        p = math.pow(1/2, get_time(i, K))
        probs.append(p)
    p = sum(probs)/N
    print(p)

def get_time(num, goal):
    time = 0
    while(num < goal):
        num *= 2
        time += 1
    return time

if __name__ == "__main__":
    main()

Measured memory_bytes: 6296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll a[N],prime[N],k,vis[N];
int n,flag=0;
bool isprime[N];
void Prime(){
    fill(isprime,isprime+N,1);
    k=0;
    prime[1]=0;
    for(ll i=2;i<N;i++){
        if(isprime[i]){
            prime[k++]=i;
            for(ll j=2;i*j<N;j++)
                isprime[i*j]=0;
        }
    }
}

void solve(ll n){
    for(ll i=0;i<k&&prime[i]*prime[i]<=n;i++){
        if(n%prime[i]==0){
            if(vis[prime[i]]==0) vis[prime[i]]=1;
            else{
                flag=1;
                return;
            }
            while(n%prime[i]==0){
                n/=prime[i];
            }
        }
    }
    if(n>1){
         if(vis[n]==0) vis[n]=1;
        else{
            flag=1;
            return;
        }
    }
}

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

int main(){
    Prime();
    cin>>n;
    ll GCD=0;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(!flag) solve(a[i]);
        if(GCD==0) GCD=a[i];
        else GCD=gcd(GCD,a[i]);
    }
    if(!flag) printf("pairwise coprime");
    else if(flag&&GCD==1) printf("setwise coprime");
    else printf("not coprime");
}

Measured memory_bytes: 13840
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
AP = [0]*N
AM = [0]*N

for i in range(N):
    AP[i]=i+A[i]
    AM[i]=i-A[i]

cnt=0
QC = Counter(AP)
for m in AM:
    cnt += QC[m]

print(cnt)

Measured memory_bytes: 50496
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int i;
    bool flag = false;
    while(true){
        flag = false;
        s.erase(s.end()-1);
        s.erase(s.end()-1);
        for(i = 0;i < s.size()/2;++i){
            if(s.at(i) != s.at(i+s.size()/2)){
                flag = true;
                break;
            }
        }
        if(flag){continue;}
        break;
    }
    cout << s.size() << endl;
    return 0;
}

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, k;
ll pref[N], suff[N], sum[N], a[N];

ll get(int l, int r) {
	if(l > r) return 0;
	return sum[r] - sum[l - 1];
}

ll res;

int main() {
	megaRandom();
	cin >> n >> k;
	for(int i = 1; i <= n; i ++)  {
		cin >> a[i];
		pref[i] = pref[i - 1] + max(0ll, a[i]); 
		sum[i] = sum[i - 1] + a[i];
	}
	for(int i = n; i >= 1; i --)
		suff[i] = suff[i + 1] + max(0ll, a[i]);
	for(int i = 1; i <= n - k + 1; i ++) 
		res = max(res, pref[i - 1] + suff[i + k] + max(0ll, get(i, i + k - 1)));		
	cout << res;
	return 0;  
}


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

using namespace std;
const int N = 2010;
const int INF = 1e9;
int _w;

int n, k, q, a[N], r[N], ban[N];

bool cmp( int i, int j ) {
	return a[i] < a[j];
}

int tmp[N], tn, t2[N];

void ins( int L, int R ) {
	if( R-L+1 < k ) return;
	for( int i = L; i <= R; ++i )
		t2[i] = a[i];
	sort(t2+L, t2+R+1);
	for( int i = L; i+k-1 <= R; ++i )
		tmp[tn++] = t2[i];
}

int check() {
	tn = 0;
	int L = 1;
	for( int R = 1; R <= n; ++R )
		if( ban[R] )
			ins(L, R-1), L = R+1;
	ins(L, n);
	if( tn < q ) return INF;
	sort(tmp, tmp+tn);
	return tmp[q-1] - tmp[0];
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> k >> q;
	for( int i = 1; i <= n; ++i )
		cin >> a[i], r[i] = i;
	sort(r+1, r+n+1, cmp);
	int ans = INF;
	for( int i = 1; i+q-1 <= n; ++i ) {
		for( int j = 1; j <= n; ++j ) ban[j] = 0;
		for( int j = 1; j < i; ++j ) ban[r[j]] = 1;
		ans = min( ans, check() );
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	long long n, k = 999999999999999;
	cin >> n;
	long long a;
	for(int i = 0; i < 5; i++){
		cin >> a;
		k = min(k, a);
	}
	if(n <= k){
		cout << 5 << endl;
	}else{
		if(n % k == 0){
			cout << 4 + n / k << endl;
		}else{
			cout << 5 + n / k << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split(" ")))
count = 0
for i in range(n):
    li = l[i]
    for j in range(i + 1, n):
        lj = l[j]
        if li == lj:
            continue
        for k in range(j + 1, n):
            lk = l[k]
            if li == lk or lj == lk:
                continue
            if (
                li + lj > lk and
                lj + lk > li and
                lk + li > lj
            ):
                count += 1
print(count)


Measured memory_bytes: 9100
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <atcoder/all>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using namespace atcoder;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const int INF = 1e9;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<long double,long double> point;
typedef complex<long double> Point;
const ll MAX = 1e9;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    mcf_graph<ll,ll> g(n*2+2);
    ll c;
    rep(i,n){
        rep(j,n){
            cin >> c;
            g.add_edge(i,j+n,1,MAX-c);
        }
    }
    g.add_edge(2*n,2*n+1,n*k,MAX);
    rep(i,n){
        g.add_edge(2*n,i,k,0);
        g.add_edge(i+n,2*n+1,k,0);
    }
    auto ans = g.flow(2*n,2*n+1,n*k);
    ll res = MAX*n*k-ans.second;
    vector<string> grid(n,string(n,'.'));
    rep(s,n*n){
        auto e = g.get_edge(s);
        if (e.flow){
            grid[e.from][e.to-n] = 'X';
        }
    }
    PRINT(res);
    rep(i,n) PRINT(grid[i]);
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
 
using namespace std;
 
//const int MOD=1e9+7;
 
const int MOD=998244353;


 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,k,s;
    cin>>n>>k>>s;
    
    int b=s==1e9?1:1e9;
    
    for(int i=0; i<n; i++){
        cout<<(i<k?s:b)<<' ';
    }
    
    
    
    return 0;
}

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

#define    int               long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n,ans=0,c=0;
    cin>>n;
    int a[n+1];
    f(i,1,n)    cin>>a[i];
    r(i,n,1)
    {
        ans=(ans+ (c*a[i])%mod)%mod;
        c=(c+a[i])%mod;

    }
    cout<<ans;
}

Measured memory_bytes: 5176
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef unsigned long long ull;

const int maxn = 107;

int k;
int dir[maxn];
ull two[maxn];
char str[maxn];

ull gcd(ull _a, ull _b) {
    if (_a < _b) swap(_a, _b);
    return _b == 0 ? _a : gcd(_b, _a % _b);
}

struct Frac {
    ull a, b;
    void dis() {
        ull t = gcd(a, b);
        a /= t;
        b /= t;
    }
} res;

void dfs(int d) {
    if (d == k) {
        res.a = 90ull * dir[k];
        res.b = 1ull;
        res.dis();
        return ;
    }
    dfs(d + 1);
    ull xa = 90ull;
    ull xb = 1ull << (k - d);
    ull t = gcd(xa, xb);
    xa /= t;
    xb /= t;
    ull ta, tb;
    if (dir[d] == 0) {
        ta = res.a * xb - res.b * xa;
        tb = res.b * xb;
    } else {
        ta = res.a * xb + res.b * xa;
        tb = res.b * xb;
    }
    res.a = ta;
    res.b = tb;
    res.dis();
}

int main() {
    while (~scanf("%s", str) && str[0] != '#') {
        k = 0;
        int len = strlen(str);
        for (int i = 0; i < len; ) {
            if (str[i] == 'n') dir[++k] = 0, i += 5;
            else dir[++k] = 1, i += 4;
        }
        dfs(1);
        if (res.b == 1) printf("%llu\n", res.a);
        else printf("%llu/%llu\n", res.a, res.b);
    }
    return 0;
}
/*
north
west
northwest
northnorthwest
westwestwestnorth
#
*/

Measured memory_bytes: 960
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#define maxn 100005
using namespace std;

int T[maxn << 2][2];
int v[maxn][2];
int a[maxn];

void update(int rt, int l, int r, int pos, int f) {
	if (l == r) {
		T[rt][f] += 1;
		return;
	}
	int mid = (l + r) >> 1;
	if (mid >= pos) update(rt << 1, l, mid, pos, f);
	else	update(rt << 1 | 1, mid + 1, r, pos, f);
	T[rt][f] = max(T[rt << 1][f], T[rt << 1 | 1][f]);
}

int query(int rt, int l, int r, int L, int R, int f) {
	if (L <= l && R >= r) return T[rt][f];
	int mid = (l + r) >> 1, mx = 0;
	if (mid >= L)	mx = max(mx, query(rt << 1, l, mid, L, R, f));
	if (mid < R)	mx = max(mx, query(rt << 1 | 1, mid + 1, r, L, R, f));
	return mx;
}

int main() {
	int n;	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i += 2) update(1, 1, maxn - 1, a[i], 1);
	for (int i = 1; i <= n; i += 2) v[a[i]][1]++;
	for (int i = 2; i <= n; i += 2) update(1, 1, maxn - 1, a[i], 0);
	for (int i = 2; i <= n; i += 2) v[a[i]][0]++;
	int mi = 0x3f3f3f3f;
	for (int i = 1; i <= n; i += 2) {
		int tmp_sum = v[a[i]][1] + query(1, 1, maxn - 1, a[i] + 1, maxn - 1, 0);
		mi = min(mi, n - tmp_sum);
	}
	for (int i = 2; i <= n; i += 2) {
		int tmp_sum = v[a[i]][0] + query(1, 1, maxn - 1, a[i] + 1, maxn - 1, 1);
		mi = min(mi, n - tmp_sum);
	}
	printf("%d\n", mi);
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <random>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1ll<<50 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

void solve(){
	ll n ; cin >> n ;
	vll a(n),b ;
	for(auto &i:a) cin >> i ;
	string s ; cin >> s ;
	for(int i=n-1;i>=0;i--){
		ll v = a[i] ;
		for(auto j:b) chmin(v,v^j) ;
		if(s[i]=='1'){
			if(v){
				cout << 1 << endl ;
				return ;
			}
		}else{
			b.push_back(v) ;
		}
	}
	cout << 0 << endl ;
}

int main(){
	ll t ; cin >> t ;
	while(t--){
		solve() ;
	}
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <cstdio>

using namespace std;
#define N 4
#define N2 16

static const int dx[4] = {0,-1,0,1};
static const int dy[4] = {1,0,-1,0};
static const char dir[4] = {'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle 
{ 
	int f[N2], space, MD;
	int cost;

	bool operator < (const Puzzle &pz) const
	{
		for (int i = 0; i < N2; ++i)
		{
			if (f[i] == pz.f[i]) continue;
			return f[i] < pz.f[i];
		}
		return false;
	}
};

struct State
{
	Puzzle puzzle;
	int estimated;
	bool operator < (const State &s) const
	{
		return estimated > s.estimated;
	}
};
int getAllMD(Puzzle pz)
{
	int sum = 0;
	for (int i = 0; i < N2; ++i)
	{
		if (pz.f[i] == N2) continue;
		sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

int astar(Puzzle s)
{
	priority_queue<State> PQ;
	s.MD = getAllMD(s);
	s.cost = 0;
	map<Puzzle, bool> V;
	Puzzle u,v;
	State initial;
	initial.puzzle = s;
	initial.estimated = s.MD;
	PQ.push(initial);

	while(!PQ.empty())
	{
		State st = PQ.top(); PQ.pop();
		u = st.puzzle;
		if (u.MD == 0) return u.cost;
		V[u] = true;

		int sx = u.space / N;
		int sy = u.space % N;

		for (int r = 0; r < 4; ++r)
		{
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			v = u;

			v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1]; 
			v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1]; 

			swap(v.f[tx * N + ty], v.f[sx * N + sy]);
			v.space  = tx * N + ty;
			if (!V[v])
			{
 				v.cost++;
				State news;
				news.puzzle = v;
				news.estimated = v.MD + v.cost;
				PQ.push(news);
			}
		}
	}
	return -1;
}

int main()
{
	for (int i = 0; i < N2; ++i)
	{
		for (int j = 0; j < N2; ++j)
		{
			MDT[i][j] = abs(i / N - j / N) + abs (i % N - j % N);
		}
	}
	Puzzle in;

	for (int i = 0; i < N2; ++i)
	{
		cin>>in.f[i];
		if (in.f[i] == 0)
		{
			in.f[i] = N2;
			in.space = i;
		}

	}

	int ans = astar(in);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 257728
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    ll ans = 1;
    for(ll d = 1; d * d <= m; d++) {
        if(m % d == 0) {
            if(n * d <= m) {
                ans = max(ans, d);
            }
            if(n * m / d <= m) {
                ans = max(ans, m / d);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    string s, t;
    cin >> s;
    cin >> t;
    char ch;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]!=t[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n,k;
   cin>>k>>n;

   vector<long int> v(n);
   for(long int i = 0; i < n; i++)
   	 cin>>v[i];

   vector<long int> diff;

   for(long int i = 1; i < n; i++)
   		diff.push_back(v[i] - v[i - 1]);

   diff.push_back(k - v.back() + v[0]);

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

   long int ans = accumulate(diff.begin(),diff.end(),0LL) - diff.back();
   cout<<ans;
   return 0;
}

Measured memory_bytes: 3956
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,ans=0;
  cin>>N;
  ll L[N],R[N];
  REP(i,N){
    cin>>L[i]>>R[i];
    ans+=R[i]-L[i]+1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256