akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
e = [[] for _ in range(n)]

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    e[a-1].append(b-1)
    e[b-1].append(a-1)

shortest = []
def get_path(start, end, par):
    if end in e[start]:
        shortest.append(end)
        return True
    for item in e[start]:
        if item != par:
             if get_path(item, end, start):
                 shortest.append(item)
                 return True

def tree_count(start, par, a, b):
    count = 0
    for item in e[start]:
        if start == a and item == b:
            continue
        if start == b and item == a:
            continue
        if item != par:
            count += 1
            count += tree_count(item, start, a, b)
    return count

get_path(0, n-1, -1)
shortest.append(0)
shortest = shortest[::-1]
cut_l = (len(shortest)-1) // 2
p = tree_count(0, -1, shortest[cut_l], shortest[cut_l+1])
q = n - p - 2 
if p > q:
    print("Fennec")
else:
    print("Snuke")

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


int main(){
    int64_t n, a = 1, ans = 1;

    cin >> n;
    vector<string> vec(n);


    for (int i = 0; i < n; i++) cin >> vec.at(i);

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

    for (int i = 1; i < n; i++) {
        if(vec.at(i -1) != vec.at(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9584
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
#define int long long int

vector<int> A;

int take() {
  int i = A.size() - 1;
  while (i > 0) {
    if (A[i] == A[i - 1]) {
      int ret = A[i];
      A.resize(i - 1);
      return ret;
    }
    i--;
  }

  A.resize(0);
  return 0;
}

void solve() {
  int N;
  cin >> N;
  A.resize(N);
  for (int &a : A) {
    cin >> a;
  }

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

  cout << take() * take() << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main()

{
    int a ,b, c,d=3;
    cin>>a>>b>>c;
    if(a==b)
    {
        d--;

    }
    if(b==c)
        {
            d--;
        }
    if(a==c)
    {
        d--;
    }
    if(d==0)
    {
        d=1;
    }
    cout<<d;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,m;
int arr[100001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    /*
    for (int i=1;i<=n;i++){
        cin>>arr[i];
    }
    */
    cout<<(n*(n-1))/2+(m*(m-1))/2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d=0,e=0;
	cin>>a>>b>>c;
    d=a-b;
    e=d/c;
    if(a-b-e*c==0)
    cout<<"0"<<endl;
else
    cout<<a-b-e*c<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    N, M, K = (int(i) for i in input().split())
    par = [i for i in range(N)]
    rank = [1 for i in range(N)]

    def find_root(x):
        if par[x] == x:
            return x
        else:
            par[x] = find_root(par[x])
            return par[x]

    def is_same_group(x, y):
        return find_root(x) == find_root(y)

    def unite(x, y):
        x = find_root(x)
        y = find_root(y)
        if x == y:
            return
        if rank[x] < rank[y]:
            x, y = y, x
        rank[x] += rank[y]
        par[y] = x

    def size(x):
        # 連結成分のサイズを返す
        return rank[find_root(x)]

    fri = [[] for _ in range(N)]
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        fri[a-1].append(b-1)
        fri[b-1].append(a-1)
        unite(a-1, b-1)
    block = [[] for _ in range(N)]
    for i in range(K):
        a, b = (int(i) for i in input().split())
        if is_same_group(a-1, b-1):
            block[a-1].append(b-1)
            block[b-1].append(a-1)
    ans = []
    for i in range(N):
        cur = size(i) - len(fri[i]) - len(block[i]) - 1
        ans.append(cur)
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 122348
import sys
from collections import deque
s = deque(map(str, input().rstrip()))

if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    s = s[::-1]
    prev = s[0]
    add.append(prev)

    if prev == 122:
        s[1] = 122
        s = s[::-1]
        s = s[:-1]

    else:
        for i in range(1, len(s)):
            if prev > s[i]:
                add = [x for x in add if x > s[i]]
                s[i] = (min(add))
                s = s[::-1]
                s = s[:-i]
                break
            prev = s[i]
            add.append(prev)

s = [chr(x) for x in s]

print("".join(s))

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

using namespace std;

#define F 		first
#define S 		second
#define ll 		long long
#define ld 		long double
#define pii		pair<ll, ll>
#define vi		vector<ll>
#define si 		set<ll>
#define mii 	map<int, int>
#define umii 	unordered_map<ll, ll>
#define pb		push_back
#define mk		make_pair
#define all(a)	a.begin(), a.end()
#define ask(x) 	cerr << #x << " = " << x << "\n";
#define INF 	1000000007
#define hell 	998244353

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ll n, res = 0, t;
	cin >> n;

	if (n == 1) {
		cout << 0;
		return 0;
	}

	for (ll i = 2; i * i <= n; ++i) {
		t = i;
		while (n % t == 0) {
			n /= t;
			t *= i;
			++res;
		}
		while (n % i == 0)
			n /= i;
	}
	if (n > 1)
		++res;

	cout << res;

	return 0;
}

Measured memory_bytes: 3664
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

// fn solve(num: i64, hs: &Vec<i64>, a: i64, b: i64) -> bool {
//     let mut rem = num;
//     let damage = num * b;
//     for h in hs {
//         if h > &damage {
//             rem -= (h - damage + a - b - 1) / (a - b);
//         } else {
//             break;
//         }
//         if rem < 0 { return false; }
//     }
//     true
// }

fn main() {
    let input = readv();
    let (n, a, b) = (input[0], input[1], input[2]);
    let mut hs: Vec<i64> = (0..n).map(|_| { read() }).collect();
    hs.sort_by(|a, b| b.cmp(a));
    let sol = |num: i64| {
        let mut rem = num;
        let damage = num * b;
        for h in &hs {
            if h > &damage {
                rem -= (h - damage + a - b - 1) / (a - b);
            } else {
                break;
            }
            if rem < 0 { return false; }
        }
        true
    };
    let (mut l, mut r) = (0i64, 1e9 as i64);
    while l < r {
        let piv = (l + r) / 2;
        if sol(piv) {
            r = piv;
        } else {
            l = piv + 1;
        }
    }
    println!("{}", l);
}


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

int main() {
  int N, A, M = 1e6+1;
  vector<int> V(M);
  cin >> N;
  while (cin >> A) V.at(A)++;
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (V.at(i) == 0) continue;
    if (V.at(i) == 1) ans++;
    for (int j = 0; i * j < M; j++) V.at(i * j) = 0;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 7040
#include <iostream>
#include <cstdio>
using namespace std;
int mp[3][3];
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
int ans,all;
int n;
char s,t,b;
int memo[16][3][3];
int visited[16][3][3];
void saiki(int x,int y,int bat){
  visited[bat][x][y] = 1;
  if(n == bat) {
    if((t-'A')%3==x&&(t-'A')/3==y)memo[bat][x][y]=1;
    return;
  }
  for(int i=0;i<4;i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(((b-'A')%3==nx && (b-'A')/3==ny)||nx<0||ny <0||nx>=3||ny>=3) {
      if(visited[bat+1][x][y] == 1) memo[bat][x][y] += memo[bat+1][x][y];
      else {
	saiki(x,y,bat+1);
	if(memo[bat+1][x][y]>0)memo[bat][x][y] += memo[bat+1][x][y];
      }
    }
    else {
      if(visited[bat+1][nx][ny]) memo[bat][x][y] += memo[bat+1][nx][ny];
      else  {
	saiki(nx,ny,bat+1);
	if(memo[bat+1][nx][ny]>0)memo[bat][x][y] += memo[bat+1][nx][ny];
      }
    }
  }
}

int main() {


  while(1) {
  cin >> n;
  if(n==0) break;
  ans = all = 0;
  cin >> s >> t >> b;
  for(int i=0;i<=n;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++) memo[i][j][k] = visited[i][j][k]=0;
  saiki((s-'A')%3,(s-'A')/3,0);
  ans = memo[0][(s-'A')%3][(s-'A')/3];
    printf("%.8f\n",1.0*ans/(1<<(2*n)));
  }
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#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> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//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 mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll x ; cin >> x ;
	ll gohyaku = x/500 ;
	x %= 500 ;
	ll go = x/5 ;
	cout << gohyaku*1000+go*5 << endl ;
}


Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";
const string NO = "No";

ll N;
ll M;
string s;
vl a;
vl b;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    cin >> M;
    cin >> s;
    a = vl(M);
    b = vl(M);
    for(int i = 0; i < M; ++i){
        cin >> a[i];
        cin >> b[i];
    }
    solve();
}

// 2 <= N <= 2 × 10^{5}
// 1 <= M <= 2 × 10^{5}
// |s| = N
// s_i は A または B
// 1 <= a_i, b_i <= N
// 与えられるグラフは単純とも連結とも限らない

// ll N, ll M, string s, vl a, vl b
// ヌスークが文字 A,B のみからなる任意の文字列が作ることが可能なら Yes を、そうでなければ No を出力せよ。
void solve(){
    vvl g(N),cnt(N,vl(2));
    rep(i,M){
        g[a[i]-1].push_back(b[i]-1);
        g[b[i]-1].push_back(a[i]-1);
        ++cnt[a[i]-1][s[b[i]-1]-'A'];
        if(a[i]!=b[i])++cnt[b[i]-1][s[a[i]-1]-'A'];
    }

    queue<ll> q;
    rep(i,N){
        if(!cnt[i][0]||!cnt[i][1])q.push(i);
    }

    ll rem_cnt=0;
    vl used(N);
    while(q.size()){
        ll x=q.front();q.pop();
        if(used[x])continue;
        ++rem_cnt;
        used[x]=true;
        for(ll to:g[x]){
            --cnt[to][s[x]-'A'];
            if(!cnt[to][s[x]-'A'])q.push(to);
        }
    }
    cout<<(rem_cnt<N?YES:NO)<<endl;
}


Measured memory_bytes: 27344
N, M = map(int, input().split())
c = [0] * (N+1)

for _ in range(M):
    a, b = map(int, input().split())
    c[a] += 1
    c[b] += 1

print("YES" if all(c[i]%2 == 0 for i in range(N+1)) else "NO")

Measured memory_bytes: 3828
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]

c = 0
for i in range(1, n+1):
    a, b = l[-i]
    a += c
    if a >= b:
        if a%b > 0:
            c += b - (a%b)
    else:
        if a > 0:
            c += b-a
print(c)

Measured memory_bytes: 27380
# -*- coding: utf-8 -*-
import numpy as np

# worst order: 101^6 => 10^8

c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))

arr_c = np.array(c)
a_max = np.amax(arr_c, axis=1)
b_max = np.amax(arr_c, axis=0)

a = []
b = []
for i in range(3):
    if len(list(range(0, a_max[i]+1, 1)))==0:
        a.append([0])
    else:
        a.append(list(range(0, a_max[i]+1, 1)))
    
    if len(list(range(0, b_max[i]+1, 1)))==0:
        b.append([0])
    else:
        b.append(list(range(0, b_max[i]+1, 1)))

ans = 'No'
cnt = 0
for a0 in a[0]:
    for b0 in b[0]:
        if c[0][0] != a0 + b0:
            continue
        for a1 in a[1]:
            if c[1][0] != a1 + b0:
                continue
            for b1 in b[1]:
                if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:
                    continue   
                for a2 in a[2]:
                    if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:
                        continue
                    for b2 in b[2]:
                        if c[0][2] != a0 + b2 or c[1][2] != a1 + b2 or c[2][2] != a2 + b2:
                            continue

                        print("Yes")
                        exit(0)

print(ans)

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

public class Main {
    private static class Task {
        public void solve(InputReader in, PrintWriter out) {
            String s = in.next();
            if (s.contains("7")) out.println("Yes");
            else out.println("No");
        }
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(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 long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str;
            try {
                str = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = new File("in.txt").exists() ? new FileInputStream("in.txt") : System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
}


Measured memory_bytes: 32788
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;
bool block[11];

bool ok(int x)
{
	while (x > 0)
	{
		if (block[x % 10]) return 0;
		x /= 10;
	}
	return 1;
}
int main()
{
	boost;
	int n, k;
	cin >> n >> k;
	FOR(i, 1, k) {
		int a;
		cin >> a;
		block[a] = 1;
	}
	for (int i=n; i<=9999999; ++i)
		if (ok(i)) OUT(i);
}


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

int main() {
  
  int n,m;
  cin >> n >> m;
  
  vector<vector<char>> a(n,vector<char>(n)),b(m,vector<char>(m));
  
  for ( int i = 0; i < n; i++){
    for ( int j = 0; j < n; j++){
      cin >> a[i][j];
    }
  }
  
  for ( int i = 0; i < m; i++){
    for ( int j = 0; j < m; j++){
      cin >> b[i][j];
    }
  }
  
  int hantei = 1;
  
  for ( int s = 0; s <= n - m; s++){
    for ( int t = 0; t <= n - m; t++){
      for ( int i = 0; i < m; i++){
        for ( int j = 0; j < m; j++){
          if ( a[i+s][j+t] != b[i][j] ){
            hantei = 0;           
          }
        }
      }
      if ( hantei == 1 ){
        cout << "Yes" << endl;
        return 0;
      }else{
        hantei = 1;
      }
    }
  }
  
  cout << "No" << endl;  
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
 
typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;
 
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
 
#define f first
#define s second
 
#define en end()
#define bg begin()
 
#define rev reverse
#define mp make_pair
#define pb push_back
 
#define y1 y1234567890
#define um unordered_map
 
#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)
 
#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))
 
#define forn(i, n) for (int i = 1; i <= n; i++)
 
const ll INF = (ll)1e18;
const ll mod = 998244353;
const int inf = (int)2e9;
 
const db eps = (db)1e-9;
const db pi = acos(-1.0);
 
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
 
const int N = 1000500, M = 1000000;

int n, lp[N], mu[N];
ll ans, sum[N], a[N];

ll bp(ll x, ll y){
	ll z = 1;
	while(y){
		if(y & 1)
			z = z * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return z;
} 

int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
 
	//cout << setprecision(10) << fixed;
	
	cin >> n;          

   	for(int i = 2; i <= M; i += 2)
   		lp[i] = 2;
	    	
	for(int i = 3; i * i <= M; i += 2){
		if(!lp[i]){
			for(int j = i * i; j < M; j += i + i)
				lp[j] = i;
		}
	}

	for(int i = 3; i < M; i += 2)
		if(!lp[i])
			lp[i] = i;

	mu[1] = 1;


	for(int i = 2; i <= M; ++i){
		if(i % (lp[i] * lp[i]) == 0){
			mu[i] = 0;
		}else{
			mu[i] = -mu[i / lp[i]];
		}
	}

	for(int i = 1; i <= n; ++i){
		int x;
		cin >> x;
		a[x]++;
	}

	for(int i = 1; i <= M; ++i){
		for(int j = i; j <= M; j += i){
			sum[i] += 1LL * a[j] * j % mod; 
			sum[i] %= mod;
		}
	}

	for(int i = 1; i <= M; ++i)
		sum[i] = sum[i] * sum[i] % mod;

	for(int g = 1; g <= M; ++g){
		ll S = 0;
		for(int gr = g; gr <= M; gr += g){
			S += sum[gr] * mu[gr / g] % mod;
			S %= mod;
			if(S < 0)
				S += mod;
		}
		a[g] = a[g] * g % mod * g % mod;
		S -= a[g];
		if(S < mod)
			S += mod;
		ans += S * bp(g, mod - 2) % mod;
		ans %= mod;
	}

	cout << ans * bp(2, mod - 2) % mod << endl;

	return 0;
}

Measured memory_bytes: 23680
*a,=map(int,[*open(0)][1].split())
c=[s:=0]
for i in a[:0:-1]:c+=c[-1]+i,
b=1
for a in a:
  if b<a:
    s=-1
    break
  s+=b
  b=min(c.pop(),(b-a)*2)
print(s)

Measured memory_bytes: 20160
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;
using ll = long long;

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

	vector <ll> a(n);

	ll min = 1e10;

	int cnt = 0;
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum += abs(a[i]);

		if (min > abs(a[i]))
			min = abs(a[i]);

		if (a[i] < 0)
			cnt++;
	}

	if (cnt % 2 != 0)
		sum -= 2 * min;



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

Measured memory_bytes: 1024
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	P := sc.nextIntSlice(N)
	ans := 0
	for i := 0; i < N; i++ {
		if P[i] == i+1 {
			ans++
			if i < N-1 {
				P[i], P[i+1] = P[i+1], P[i]
			} else {
				P[i], P[i-1] = P[i-1], P[i]
			}
		}
	}

	fmt.Fprintln(wtr, ans)
}


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

using namespace std;

const int maxn = 1e5 + 10;
char s[maxn];
int preR[maxn], preL[maxn], a[maxn], b[maxn];
bool vis[maxn];

int main()
{
    scanf("%s", s);
    int n = strlen(s);
    int x = n - 1;
    for(int i = n - 2; i >= 0; i --)
    {
        if(s[i] == 'L') x = i;
        else preR[i] = x;
    }
    for(int i = 0; i < n - 1; i ++)
        if(s[i] == 'R' && s[i + 1] == 'L') vis[i] = vis[i + 1] = true;
    x = 0;
    for(int i = 0; i < n; i ++)
    {
        if(s[i] == 'R') x = i;
        else preL[i] = x;
    }
    int cnt = 0;
    for(int i = 0; i < n; i ++)
    {
        if(s[i] == 'L') cnt = max(i - preL[i], cnt);
        else cnt = max(preR[i] - i, cnt);
    }
    for(int i = 0; i < n; i ++)
    {
        if(s[i] == 'L')
        {
            int tm = i - preL[i];
            if(cnt % 2 == tm % 2) a[preL[i]] ++;
            else a[preL[i] + 1] ++;
        }
        else
        {
            int tm = preR[i] - i;
            if(cnt % 2 == tm % 2) a[preR[i]] ++;
            else a[preR[i] - 1] ++;
        }
    }
    if(cnt % 2)
    {
        for(int i = 0; i < n; i ++)
        {
            if(s[i] == 'R') b[i + 1] += a[i];
            else b[i - 1] += a[i];
        }
        for(int i = 0; i < n; i ++)
            a[i] = b[i], b[i] = 0;
    }
    for(int i = 0; i < n; i ++) printf("%d ", a[i]);
    return 0;
}


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

#define int long long

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof(i))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,K,M,A,B,C;
string s,t;
int a[100010],b[100010],c[100010];
int ans=INF;

signed main() {
    IOS();
    cin>>N>>K;
    rep(i,0,N)cin>>a[i];
    sort(a,a+N);
    rep(i,0,N-K+1){
        chmin(ans,a[i+K-1]-a[i]);
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    




















































    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end()
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;


void solve() {
	int n; cin >> n;
	map<string,int> m;
	int maxi = 0;
	rep(i, n) {
		string in; cin >> in;
		maxi = max(maxi, ++m[in]);
	}
	// for(auto [s,cnt]:m) { c++17 is not supported
	set<string> st;
	for(auto mm:m) {
		if(mm.second == maxi) st.insert(mm.first);			
	}
	for(auto s:st) cout << s << endl;
}
int main() {
	fastio;
	solve();
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
const ll inf = (ll)1e18;
const ll N = (ll)1e5+77;
const ll mod = (ll)1e9+7;

int main() {
    fast;
    string s;
    int x, y, hor[16077][2] = {0}, ver[16077][2] = {0};
    vector<int> xx, yy;
    cin >> s >> x >> y;

    int turns = 0, steps = 0;
    forn(i, sz(s)) {
        if (s[i] == 'T') {
            turns++;
            if (turns & 1) xx.push_back(steps);
            else yy.push_back(steps);
            steps = 0;
        } else {
            steps++;
        }
    }

    if (turns & 1) yy.push_back(steps);
    else xx.push_back(steps);

    hor[xx[0] + 8000][0] = 1;
    for1(i, sz(xx) - 1) {
        forn(displacement, 16002) {
            if (hor[displacement][0]) hor[displacement + xx[i]][1] = 1, hor[displacement - xx[i]][1] = 1;
        }

        forn(displacement, 16002) {
            hor[displacement][0] = hor[displacement][1];
            hor[displacement][1] = 0;
        }
    }

    ver[8000][0] = 1;
    forn(i, sz(yy)) {
        forn(displacement, 16002) {
            if (ver[displacement][0]) ver[displacement + yy[i]][1] = 1, ver[displacement - yy[i]][1] = 1;
        }

        forn(displacement, 16002) {
            ver[displacement][0] = ver[displacement][1];
            ver[displacement][1] = 0;
        }
    }

    if (hor[8000 + x][0] and ver[8000 + y][0]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 640
import collections

N = int(input())
A = list(map(int,input().split()))
odd = []
even = []
for i in range(N):
    if i % 2 == 1:
        odd.append(A[i])
    else:
        even.append(A[i])
Dic_odd = collections.Counter(odd)
Dic_eve = collections.Counter(even)
M_odd = Dic_odd.most_common()
M_eve = Dic_eve.most_common()
#print(M_odd, M_eve)
if M_odd[0][0] != M_eve[0][0]:
    ans = len(odd) - M_odd[0][1] + len(even) - M_eve[0][1]
else:
    if len(M_odd) == 1 and len(M_eve) == 1:
        ans = min(len(odd), len(even))
    elif len(M_odd) == 1:
        ans = min(len(even) - M_eve[1][1], len(even) - M_eve[0][1] + len(odd))
    elif len(M_eve) == 1:
        ans = min(len(odd) - M_odd[1][1], len(odd) - M_odd[0][1] + len(even))
    else:
        ans = len(odd) + len(even) - max(M_odd[0][1] + M_eve[1][1], M_odd[1][1] + M_eve[0][1])
print(ans)

Measured memory_bytes: 65516
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000+7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans, dp[800][800],a[2000000], b[2000000];
string str,ss;
bool f[800][800],flag[800],tdp[800][800];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<LL>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
 
int BipartiteGraph(LL point, vector<int>&color) {
	int cnt = 0;
	function<bool(int, int, int)> dfs = [&](int u, int prev, int c) {
		color[u] = c;
		if (c == 1) cnt++;
		rep(v, n)if (v != prev && v != u && f[u][v] == 0) {
			if (color[v] == -1) {
				if (!dfs(v, u, 1 - c)) return false;
			}
			else if (color[v] != 1 - c) {
				return false;
			}
		}
		return true;
	};
	if (!dfs(point, -1, 0)) return -1;
	return cnt;
}
int main() {
	ans = INF;
	cin >> n >> m;
	rep(i, m) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		f[x][y] = 1;
		f[y][x] = 1;
	}
	rep(i, n) {
		if (flag[i] == 0) {
			vector<int> color(n, -1);
			if (BipartiteGraph(i, color) == -1) {
				cout << -1 << endl;
				return 0;
			}
			cnt = 0, sum = 0;
			rep(j, n) {
				if (color[j] != -1) {
					flag[j] = 1;
					if (color[j] == 1)
						cnt++;
					sum++;
				}
			}
			v.push_back(Pll(sum - cnt, cnt));
		}
	}
	tdp[0][0] = 1;
	rep(i, v.size()) {
		Mfor(j, n) {
			if (tdp[i][j])
				tdp[i+1][j + v[i].fir] = 1, tdp[i+1][j + v[i].sec] = 1;
		}
	}
	rep(i, n) {
		if (tdp[v.size()][i]&&i) {
			ans = min(ans, i*(i - 1) / 2 + (n - i)*(n - i - 1) / 2);
		}
	}
	cout << ans << endl;
	return 0;
}

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

bool isPrime(int n){
	
	if(n == 2) return true;
	else if(n%2 == 0) return false;
	
	int i = 3;
	while(i <= sqrt(n)){
		if(n%i==0){
			return false;
		}
		else{
			i = i + 2;
		}
	}
	return true;
}


int main() {
	int N, element, count = 0;
	
	cin >> N;
	
	for(int i = 0; i<N ;i++){
		cin >> element;
		if(isPrime(element) == true) {
			count++;
			//cout << element << endl;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
long p[111111],a[111111],b[111111];
int compare(const void *c, const void *d) {
    return a[*(long*)c] - a[*(long*)d];
}
int main() {
    long a, b, pa[44], pb[44], i, ans = 0,ca,cb,t;
    scanf("%ld%ld", &a, &b);
    i = 0;
    ca = a;
    cb = b;
    while (ca != 0) {
        pa[i] = ca % 2;
        ca = ca / 2;
        i++;
    }
    while (i <= 40) {
        pa[i] = 0;
        i++;
    }
    i = 0;
    while (cb != 0) {
        pb[i] = cb % 2;
        cb = cb / 2;
        i++;
    }
    while (i <= 40) {
        pb[i] = 0;
        i++;
    }
    if (a%2==0) {
        if ((b - a) % 4 == 0)
            ans = b;
        if ((b - a) % 4 == 1)
            ans = 1;
        if ((b - a) % 4 == 2)
            ans = b + 1;
        if ((b - a) % 4 == 3)
            ans = 0;
    }
    else {
        if ((b - a) % 4 == 0)
            ans = a;
        if ((b - a) % 4 == 1) {
            t = 1;
            for (i = 0; i<=40; i++) {
                if (pa[i] != pb[i])
                    ans += t;
                t = t * 2;
            }
        }
        if ((b - a) % 4 == 2)
            ans = a-1;
        if ((b - a) % 4 == 3){
            t = 1;
        for (i = 0; i <= 40; i++) {
            if (pa[i] != pb[i])
                ans += t;
            t = t * 2;
        }
ans--;
}
    }
        printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();  // count
		int Y = sc.nextInt();  // total
		
		for (int x=0; x<=N; x++) {
			for (int y=0; y<=N; y++) {
				int z = N - (x+y);
				if (z < 0) continue;
				if ( (10000*x + 5000*y + 1000*z) == Y ) {
					System.out.println( String.format("%d %d %d", x, y, z) );
					return;
				}
			}
		}
		System.out.println( "-1 -1 -1" );
	}
}


Measured memory_bytes: 23124
import math
import heapq

N,H=map(int,input().split())

a,b=0,0
a_max=0
h=[]
heapq.heapify(h)

for i in range(N):
    a,b=map(int,input().split())
    a_max=max(a_max,a)
    heapq.heappush(h,-b) #heap化されたリストaに要素xを追加

ans=0
while H>0:
    if len(h)==0:
        ans+=math.ceil(H/a_max)
        break
    b_max=-heapq.heappop(h)
    if b_max<a_max:
        ans+=math.ceil(H/a_max)
        break
    ans+=1
    H-=b_max

print(ans)

Measured memory_bytes: 7184
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    exrep(i,1 , 9) {
        exrep(j, 1, 9) {
            if(i*j == n) {
                out("Yes");
                re0;
            }
        }
    }
    out("No");
    re0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
MAX = 10 ** 6
MOD = 10 ** 9 + 7

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def p(n, r, mod):
    return fac[n] * finv[n - r] % mod

comInit(MOD)

N, M = map(int, input().split())

ans = 0
for i in range(N + 1):
    now = com(N, i, MOD)
    now *= p(M - i, N - i, MOD)
    if i & 1 > 0:
        now = -now
    ans += now

ans *= p(M, N, MOD)
print(ans % MOD)


Measured memory_bytes: 211740
def main():
    import sys
    input=sys.stdin.readline
    while True:
        a,b=map(int,input().split())
        if a==0:
            break
        m=int(input())
        xy=[list(map(int,input().split())) for _ in [0]*m]
        memo=[[True]*a for _ in [0]*b]
        for x,y in xy:
            memo[y-1][x-1]=False
        def check(i,j):
            ans=0
            if i+1<b:
                if memo[i+1][j]:
                    ans+=check(i+1,j)
            if j+1<a:
                if memo[i][j+1]:
                    ans+=check(i,j+1)
            if i==b-1 and j==a-1:
                ans=1
            return ans
        print(check(0,0))
    
if __name__=='__main__':
    main()


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

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

	int num = 0;
	while (N > 0)
	{
		N = N - X;
		num++;
	}

	cout << T*num;
}

Measured memory_bytes: 3616
// Last Change: 07/07/2019 21:29:08.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll L, R;
  cin >> L >> R;

  if (R / 3 - (L - 1) / 3 > 0 and R / 673 - (L - 1) / 673 > 0) {
    cout << 0 << endl;
  } else {
    ll ans = 4e18;
    for (ll i = L; i <= R; ++i) {
      for (ll j = i + 1; j <= R; ++j) {
        ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int a,b;
    cin >> a >> b;
    if( a * b % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
using namespace std;

int64_t mod = 1000000007;

int main(){
	int64_t n;
	cin >> n;
	int dig[62];
	for (int i = 0; i < 62; ++i) {
		dig[i] = n % 2;
		n /= 2;
	}
	auto dp = vector<vector<int64_t>>(62, vector<int64_t>(3, 0));
	dp[60][0] = 1;
	for (int d = 59; d >= 0; d--) {
		if (dig[d] == 0) {
			dp[d][0] += dp[d + 1][0]; //00
			dp[d][0] += dp[d + 1][1]; //11
			dp[d][1] += dp[d + 1][1]; //01
			dp[d][2] += dp[d + 1][1]; //00
			dp[d][2] += dp[d + 1][2] * 3; // 00, 01, 11
		}
		else {
			dp[d][0] += dp[d + 1][0]; //01
			dp[d][1] += dp[d + 1][0]; //00
			dp[d][1] += dp[d + 1][1]; //11
			dp[d][2] += dp[d + 1][1]*2; //01,00
			dp[d][2] += dp[d + 1][2] * 3; //00,01,11
		}
		dp[d][0] %= mod;
		dp[d][1] %= mod;
		dp[d][2] %= mod;
	}
	cout << (dp[0][0] + dp[0][1] + dp[0][2])%mod << endl;
	return 0;
}

Measured memory_bytes: 256
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define MAXI (1<<32)
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define SIZ 1000005
#define SIZE 200005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair<ll,ll>&a,const pair<ll,ll>&b){
	return a.ss < b.ss;
}

//ll p[20000005]={0};
//vector<ll>ans;
/*void sieve(){
    ll i,j;
    p[0]=p[1]=1;
    for(i=2;i*i<=20000005;i++){
        if(!p[i]){
            for(j=2*i;j<20000005;j+=i){
                p[j]=1;
            }
        }
    }
    fo(i,2,20000005){
        if(!p[i]){
            ans.pb(i);
        }
    }
}*/

signed main(){ 
    IOS
    //io_set();
    ll a , b, c, d;
    cin >> a >> b >> c >> d;
    a += b;
    c += d;
    if(a == c){
        cout << "Balanced\n";
    }
    else{
        if(a > c){
            cout << "Left\n";
        }
        else{
            cout << "Right\n";
        }
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
	    String s=gs();

        boolean c=false;
        boolean f=false;
        for (int i=0; i<s.length();i++) {
        	if(s.charAt(i)=='C') {
        		c=true;
        	}
        	if(c&& s.charAt(i) =='F') {
        		System.out.println("Yes");
        		return;
        	}
        }
	    System.out.print("No");
//	    if (n%10==3) {
//	    	System.out.print("bon");
//	    }else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
//	    	System.out.print("pon");
//	    } else {
//	    	System.out.print("hon");
//	    }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

int n;
bool pr[101010];
int ps[101010], k;
long long ans[500][500];

long long gcd(long long x, long long y) {
  while (y != 0) {
    long long tmp = x;
    x = y;
    y = tmp % x;
  }
  return x;
}

long long lcm(long long x, long long y) {
  return x / gcd(x, y) * y;
}

int main() {
  for (int i = 2; i < 101010; i++) {
    if (!pr[i]) {
      ps[k++] = i;
      for (int j = i * 2; j < 101010; j += i) {
        pr[j] = true;
      }
    }
  }

  scanf("%d", &n);

  if (n == 2) {
    puts("4 7");
    puts("23 10");
    return 0;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans[i][j] = 1;
    }
  }

  int l = 0;
  for (int i = 0; i < n * 2; i += 2) {
    for (int j = 0; j <= i; j++) {
      if (i - j < n && j < n) {
        ans[i - j][j] *= ps[l];
      }
    }
    l++;
  }
  for (int i = 0; i < n; i += 2) {
    for (int j = 0; i + j < n; j++) {
      ans[i + j][j] *= ps[l];
    }
    l++;
  }
  for (int j = 2; j < n; j += 2) {
    for (int i = 0; i + j < n; i++) {
      ans[i][i + j] *= ps[l];
    }
    l++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i + j) % 2 == 1) {
        if (i - 1 >= 0) ans[i][j] = lcm(ans[i][j], ans[i - 1][j]);
        if (i + 1 < n) ans[i][j] = lcm(ans[i][j], ans[i + 1][j]);
        if (j - 1 >= 0) ans[i][j] = lcm(ans[i][j], ans[i][j - 1]);
        if (j + 1 < n) ans[i][j] = lcm(ans[i][j], ans[i][j + 1]);
        ans[i][j]++;
      }
      printf("%lld ", ans[i][j]);
    }
    putchar('\n');
  }
}


Measured memory_bytes: 5120
n = int(input())

h = list(map(int, input().split()))

ans = [0]

cnt = 0
l = h[0]
for i in range(1, n):
    r = h[i]
    if l >= r:
        cnt += 1
    else:
        cnt = 0
    l = h[i]
    ans.append(cnt)

print(max(ans))

Measured memory_bytes: 14252
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = 0;

void solve(){
	if(A[0]!=0){
		ans = -1;
		return;
	}
	for(int i=N-1;i>=1;i--){
		int seq_max = A[i];
		while(i>=1){
			if(A[i]==A[i-1]+1) i--;
			else break;
		}
		if(A[i]>A[i-1]+1){
			ans = -1;
			return;
		}
		ans += seq_max;
	}
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const int mod = 1e9+7;

int main() {
    ll N,r,x=0;
    string S1,S2;
    vector<ll> t;
    char p;
    cin >> N >> S1 >> S2;

    p = S1.at(0);
    if(S1.size() == 1) {
        cout << 3 << endl;
        return 0;
    }

    rep(i,N-1) {
        if(p == S1.at(i+1)) {
            t.push_back(2);
            i++;
            if(i == N-2) {
                t.push_back(1);
                break;
            } else if(i == N-1) {
                break;
            }
        } else {
            t.push_back(1);
        }
        p = S1.at(i+1);
    }

    rep(i,t.size())
        x += t.at(i);
    if(x+1 == N)
        t.push_back(1);

    if(t.at(0) == 1)
        r = 3;
    else
        r = 6;

    rep(i, t.size()-1) {
        if(t.at(i)==2 && t.at(i+1)==1)
            continue;
        else if(t.at(i)==2 && t.at(i+1)==2)
            r *= 3;
        else
            r *= 2;
        r %= mod;
    }

    cout << r << endl;    
}

Measured memory_bytes: 256