akhauriyash/Code-Regression huggingface dataset:
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

using s64 = int64_t;

constexpr s64 INF = 1'010'000'000'000'000'000LL;

template<typename T, typename U>
bool chmin(T& xmin, const U& x) {
    if(x < xmin) {
        xmin = x;
        return true;
    }
    else {
        return false;
    }
}

#define FOR(i, start, end) for(s64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

s64 N;
s64 M;
vector<vector<s64>> G;

void print_g(ostream& out) {
    REP(i, N) {
        REP(j, N) {
            s64 c = G[i][j];
            if(c == INF)
                out << "INF";
            else
                out << c;
            out << (j==N-1 ? '\n' : ' ');
        }
    }
}

bool floyd() {
    REP(k, N) {
        REP(i, N) {
            if(G[i][k] == INF) continue;
            REP(j, N) {
                if(G[k][j] == INF) continue;
                chmin(G[i][j], G[i][k] + G[k][j]);
                if(i == j && G[i][j] < 0) return false;
            }
        }
    }

    return true;
}

void solve() {
    if(!floyd()) {
        cout << "NEGATIVE CYCLE\n";
        return;
    }

    print_g(cout);
}

int main() {
    cin >> N;
    G.assign(N, vector<s64>(N, INF));
    REP(i, N) { G[i][i] = 0; }

    cin >> M;
    REP(_, M) {
        s64 a, b, c; cin >> a >> b >> c;
        G[a][b] = c;
    }

    solve();

    return 0;
}

Measured memory_bytes: 3220
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<numeric>
#include<set>

using namespace std;

typedef long long ll;

int main()
{
	int N;
	while (cin >> N, N) {
		vector<ll> v(N + 1);
		for (int i = 0; i < N + 1; i++) {
			cin >> v[i];
		}

		bool flag = 0;
		for (int i = 0; i < N + 1; i++){
			ll d = 100000000000,pre_d = 100000000000;
			flag = 0;
			for (int j = N; j >= 1; j--){
				if (j == i)continue;
					if (j - 1 == i) {
						if (j - 2 >= 0) {
							d = v[j] - v[j - 2];
						}
						/*
						else {
							d = v[j];
						}
						*/
					}
					else {
						d = v[j] - v[j - 1];
					}

					if (d != 100000000000 && pre_d != 100000000000) {
						if (pre_d != d) {
							flag = 1;
							break;
						}
				    }
					pre_d= d;
			}
			if (!flag) {
				cout << v[i] <<  endl;
				break;
			}
		}		
	}
	return 0;
}

Measured memory_bytes: 3068
/*
    Those who cannot remember the past are condemned to repeat it.
                                            - Dynamic Programming
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        st = new StringTokenizer(br.readLine());
        int h = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        long sum = 0;
        st = new StringTokenizer(br.readLine());
        for(int i=0 ; i<n ; i++) {
            sum += Integer.parseInt(st.nextToken());
        }

        if(h <= sum) {
            pw.println("Yes");
        }
        else {
            pw.println("No");
        }
        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 33372
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

bool judgePrimeNumber(int n) {
    for(int i = 2; i <= sqrt(n); i ++) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {
    int n; cin >> n;
    int ans = 0;
    REP(i,n) {
        int num; cin >> num;
        ans += judgePrimeNumber(num);
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a;

int main()
{
    _FastIO;
    cin >> a;
    cout << 3 * a * a << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

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

func distance(x, y []int, d int) float64 {
	ret := 0
	for i := 0; i < d; i++ {
		di := abs(x[i] - y[i])
		ret += di * di
	}
	return math.Sqrt(float64(ret))
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	d := nextInt()
	x := make([][]int, n)

	for i := range x {
		x[i] = make([]int, d)
		for j := range x[i] {
			x[i][j] = nextInt()
		}
	}

	ans := 0
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			d2 := distance(x[i], x[j], d)
			if float64(int64(d2)) == d2 {
				ans++
			}
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    char n[3];
    cin >> n;
    for (int i = 0; i < 3; i++) {
        if (n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    int a, b; cin >> a >> b;
    if(a <= 0 && 0 <= b) cout << "Zero" << endl;
    else if(b < 0 && (b-a+1)%2==1) cout << "Negative" << endl;
    else cout << "Positive" << endl;
}




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


public class Main{
    static long MOD = 1000000007;
    static long dp[] = new long[1 << 21];
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        long MOD = 1000000007;
        //int t = sc.nextInt();
        int t = 1;
        while(t -- > 0)
        {
            int n = sc.nextInt();
            int a[][] = new int[n][n];
            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++)
                    a[i][j] = sc.nextInt();
                Arrays.fill(dp, -1l);
            long res = Main.solve(0, a, (1 << n) - 1);
            out.println(res);
            //for(int ii = 0; ii <= n; ii++) System.out.println(Arrays.toString(dp[ii]));
        }
        out.close();
    }
    public static long solve(int m, int[][] a, int state){
        int n = a.length;
        if(m >= n) return 1l;
        if(dp[state] != -1) return dp[state];
        if(state == 0) return 1l;
        long res = 0l;
        for(int i = 0;i < n; i++)
            if(a[m][i] == 1 && ((state & (1 << i)) > 0))
                res = (res + solve(m + 1, a, state ^ (1 << i))) % MOD;
        return dp[state] = res;
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 39892
n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

for _ in range(n):
    s, t, _c = map(int, input().split())
    for j in range(s, t + 1):
        cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
    ans = max(ans, sum(cnt[j][i] for j in range(c)))
print(ans)

Measured memory_bytes: 26672
#include <bits/stdc++.h>
#define int long long int
#define get(a)  int a[n]; for(int i=0;i<n;i++){cin>>a[i];}
#define out(a) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define db(x) cout<<x<<" "<<endl;
#define deb  cout<<"hi"<<" "<<endl;
#define endl "\n"
using namespace std;
int mod(int a,int b)
{
    if(a-b<=0)
    {
        return b-a;
    }
    else
    {
        return a-b;
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
//    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
       get(a);
       int b[n];b[0]=0;b[1]=b[0]+mod(a[0],a[1]);
       for(int i=2;i<n;i++)
       {
           b[i]=min(b[i-1]+mod(a[i-1],a[i]),b[i-2]+mod(a[i-2],a[i]));
       }
       db(b[n-1]);
    }
  
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


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

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 10001;

int main() {
	int N;
	int a[MAX];
	int b[MAX];
	long long asum = 0;
	long long bsum = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}

	for (int i = 0; i < N; i++) {
		int d = b[i] - a[i];
		long long ac = 0;
		long long bc = 0;

		if (d >= 0) {
			ac = d / 2;
		}
		else {
			bc = -d;
		}

		asum += ac;
		bsum += bc;
	}

	if (asum < bsum)cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

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

using namespace std;

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

#define X first
#define Y second

const int MAXN = 110;

int n;
int a[MAXN];
bitset<10010> F;

int main()
{
	
	scanf("%d", &n);
	F[0] = 1;
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%d", &a[i]);
		F |= F<<a[i];
	}
	int ans = 0;
	for (int i = 10000; i >= 0; -- i)
		if (i%10 != 0 && F[i])
			ans = max(ans, i);
	printf("%d\n", ans);
	
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
using namespace std;

int main(){
ll N;
cin>>N;
vector<ll> h(N);
for(ll i=0;i<N;i++){
  cin>>h[i];
}

ll ans=1;
ll tmp=1;
for(ll i=1;i<N;i++){
if(h[i-1]>=h[i]){
tmp++;
}
else{
if(ans<tmp){
  ans=tmp;
}
tmp=1;
}


}
if(ans<tmp){
  ans=tmp;
}
tmp=1;


cout<<ans-1<<endl;

}


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

using namespace std;

const int N = 3e3 + 10;
int a[N];
long long f[N][N];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i]; 

    for(int st = n; st >= 1; st--)
        for(int en = st; en <= n; en++) 
            f[st][en] = max(a[st] - f[st + 1][en], a[en] - f[st][en - 1]);
    cout << f[1][n];
}


Measured memory_bytes: 70016
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    S = input()

    que = deque()
    for s in S:
        if len(que) == 0:
            que.append(s)
        elif que[-1] == "(" and s == ")":
            que.pop()
        else:
            que.append(s)

    d = defaultdict(int)
    while len(que):
        d[que[-1]] += 1
        que.pop()

    print("(" * d[")"] + S + ")" * d["("])


if __name__ == '__main__':
    main()


Measured memory_bytes: 4212
N,x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = 0
for i in range(N):
  if x-a[i] >=0:
    ans += 1
    x -= a[i]
  else:
    break

if x == 0 or ans < N:
  print(ans)
else:
  print(ans-1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){

    int n;
    n = 0;
    string s, s1;
    cin>>s>>s1;
    for(int i = 0;i<s.size();i++)if(s[i] != s1[i])n++;
    cout<<n<<endl;

    
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 1e5+5;

int N;
vector<int> al[MX_N];
int k[MX_N], bm[MX_N];

void dfs(int u, int p) {
    int cnt[20] = {0};
    for (int v : al[u]) if (v != p) {
        dfs(v,u);
        FOR(i,0,19){
            cnt[i] += ((bm[v]&(1<<i)) > 0 ? 1 : 0);
            bm[u] |= bm[v];
        }
    }

    int j = 19;
    RFOR(i,19,0){
        if (cnt[i] >= 2) break;
        else if (cnt[i] == 0) j = i;
    }
    bm[u] &= ~((1<<j)-1);
    bm[u] |= (1<<j);
    k[u] = j;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    FOR(i,1,N-1){
        int A, B; cin >> A >> B;
        al[A].push_back(B);
        al[B].push_back(A);
    }

    dfs(1,-1);
    int ans = 0;
    FOR(i,1,N) ans = max(ans,k[i]);
    cout << ans;

    //cout << endl;
    //FOR(i,1,N){
    //    cout << k[i] << ' ';
    //}
    //cout << endl;
}



Measured memory_bytes: 17920
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
ll n; // n <= 1e6
ll f[1000010], s[1000010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	f[0] = 1; f[1] = 1; f[2] = 1;
	s[0] = 1; s[1] = 2; s[2] = 3;
	for(ll i = 3; i <= n; ++i)
	{
		f[i] = (f[i-1] + s[i-3])%mod;
		s[i] = (s[i-1] + f[i])%mod;
	}
	ll ans = 0;
	for(ll i = 0; i <= n-2; ++i) ans = (ans + f[i])%mod;
	ans = (n-1)*(n-1)%mod*ans%mod;
	ans = (((n-1)*f[n-1]%mod + f[n])%mod + ans)%mod;
	for(ll i = 1; i <= n-1; ++i) ans = (ans+f[i-1]*i)%mod;
	cout << ans;
	return 0;
}

Measured memory_bytes: 15872
def insertionSort(A, N, g):
    global cnt
    for i in range(g, N):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v


def shellSort(A, n):
    global cnt
    G = []
    m = 1
    G.append(1)
    while 3*G[-1]+1 <= n:
        g = G[-1]
        G.append(g*3+1)
        m += 1
    G = sorted(G, reverse=True)
    for i in range(m):
        g = G[i]
        insertionSort(A, n, G[i])

    print(m)
    print(*G)
    print(cnt)
    for a in A:
        print(a)


def main():
    global cnt
    cnt = 0
    N = int(input())
    A = [int(input()) for i in range(N)]
    shellSort(A, N)

 
if __name__ == '__main__':
    main()



Measured memory_bytes: 45512
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>

using namespace std;

#define mod 1000000007

long long modpow(long long a, long long b){
  long long ret = 1;
  while(b){
    if(b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}

long long solve(string s, long long k){
  int cnt = 0;
  long long ret = 0;
  for(int i = 0; i < k ; i++){
    if(s[i] == '1'){
      ret = (ret + modpow(2, cnt) * modpow(3, k - i-1)) % mod;
      cnt++;
    }
  }
  return (ret + modpow(2, cnt)) % mod;
}

int main(){
  string s;
  cin >> s;
  long long keta = s.length();
  cout << solve(s, keta) << endl;
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define ALL(v) (v).begin(), (v).end()

#define DEBUG(x) cerr << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                                                                   \
  cerr << #v << ": ";                                                                                                  \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                                                                     \
  cerr << endl

const ll MOD = 1000000007ll;

int main() {
  int n;
  cin >> n;
  vl arr(n);
  REP(i, n) cin >> arr[i];

  ll m = MOD;
  FORR(i, 0, n) {
    if (arr[i] > m + 1) {
      cout << "No" << endl;
      return 0;
    }
    CHMIN(m, arr[i]);
  }
  cout << "Yes" << endl;
}


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

int main() {
  ll N, K, ans;
  cin >> N >> K;
  if (K % 2 == 0) {
    ll x, y;
    x = N / K;
    y = (N * 2 / K) - (N / K);
    ans = x * x * x + y * y * y;
  } else {
    ll z;
    z = N / K;
    ans = z * z * z;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 51
ll dp[N][2*N*N+300], d[N];

int main(){
	int n, a;
	cin>>n>>a;
	rep(i, n) cin>>d[i];
	rep(i, n) d[i] -= a;
	int off = N*N+100;
	dp[0][0+off] = 1;
	rep(i, n) for(int j = N*N; j >= -N*N; j--) dp[i+1][j+d[i]+off] = dp[i][j+d[i]+off]+dp[i][j+off];
	cout<<dp[n][0+off]-1<<endl;
	return 0;
}


Measured memory_bytes: 2432
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int s;
    cin >> s;
    int d=s%10;
    s/=10;
    int c=s%10;
    s/=10;
    int b=s%10;
    s/=10;
    int a=s%10;
    s/=10;
    if(a+b+c+d==7){
        cout << a << '+' << b << '+' << c << '+' << d << "=7";
        return 0;
    }else if(a+b+c-d==7){
        cout << a << '+' << b << '+' << c << '-' << d << "=7";
        return 0;
    }else if(a+b-c+d==7){
        cout << a << '+' << b << '-' << c << '+' << d << "=7";
        return 0;
    }else if(a+b-c-d==7){
        cout << a << '+' << b << '-' << c << '-' << d << "=7";
        return 0;
    }else if(a-b+c+d==7){
        cout << a << '-' << b << '+' << c << '+' << d << "=7";
        return 0;  
    }else if(a-b+c-d==7){
        cout << a << '-' << b << '+' << c << '-' << d << "=7";
        return 0;
    }else if(a-b-c+d==7){
        cout << a << '-' << b << '-' << c << '+' << d << "=7";
        return 0;
    }else if(a-b-c-d==7){
        cout << a << '-' << b << '-' << c << '-' << d << "=7";
        return 0;      
    }
}

Measured memory_bytes: 256
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 07/Mar/20 05:35:24 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n, a, b;
	cin >> n >> a >> b;
	int t = a + b;
	int ans = a * (n / t);
	int p = n - (n / t) * t;
	ans += min (a, p);
	pr (ans);
	return 0;
}

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



int main(){
    long long N;
    long long X;
    cin>>N>>X;
    cout<<N+X/2<<endl;
    
    
    
    

}


Measured memory_bytes: 256
import Data.List
main = do
    [n,k] <- map read . words <$> getLine
    s <- getLine
    let gs = (\x -> if even (length x) then x ++ [0] else x) . (\x -> if head s == '0' then 0:x else x) . map length $ group s
        xs = scanl' (+) 0 gs
        k' = min (2*k+1) (length gs)
        ans = maximum . map snd . filter fst . zip (cycle [True,False]) $ zipWith (-) (drop k' xs) xs
    print ans

Measured memory_bytes: 20860
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let res = 2*std::cmp::max(a, b) + if a == b{
        0
    }else {
        -1
    };

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


Measured memory_bytes: 4352
# Grand Garden
N = int(input().strip())
h = list(map(int, input().strip().split()))

def mizu(h, s):
	for k in range(s, len(h)):
		if h[k] > 0:
			h[k] -= 1
		else:
			break
	return h

count = 0
while True:
	s = min((i for i in range(len(h)) if h[i] > 0), default = -1)
	if s == -1:
		break
	else:
		h = mizu(h, s)
		count += 1

print(count)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, l; cin >> n >> l;
	vector<string>s(n); rep(i, n)cin >> s[i];
	sort(s.begin(), s.end());
	rep(i, n) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    ll x;
    cin >> x;
    ll a = 100;
    int ans = 0;
    //double dif;
    while(a < x){
        //dif = a / (double)100;
        //cout << "dif= " << dif << " ";
        a += a/100;
        //cout << "a= " << a << endl;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3548
while True:
    n = int(input())
    if n == 0: break
    age = [0] * 7
    for _ in range(n):
        x = int(input())
        if x < 10:
            age[0] += 1
        elif 10 <= x < 20:
            age[1] += 1
        elif 20 <= x < 30:
            age[2] += 1
        elif 30 <= x < 40:
            age[3] += 1
        elif 40 <= x < 50:
            age[4] += 1
        elif 50 <= x < 60:
            age[5] += 1
        elif 60 <= x:
            age[6] += 1
    print('\n'.join(map(str, age)))



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}



void solve()
{
  ll x;
  cin>>x;
  if(x) cout<<0;
  else cout<<1;
}

int main()
{
  ll tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
}

Measured memory_bytes: 3632
var main = (input: string) => {
    const a: string[] = input.split('\n');
    const n: number = parseInt(a[0]);

    let xy: number[][] = [];
    for (let i: number = 1; i <= n; i++) {
        xy.push(a[i].split(' ').map(p => parseInt(p)));
    }

    let z: number[] = [];
    for (let i: number = 0; i < n; i++) {
        z.push(xy[i][0] + xy[i][1]);
    }
    let zmax: number = z.reduce((a, b) => Math.max(a, b));
    let zmin: number = z.reduce((a, b) => Math.min(a, b));

    let w: number[] = [];
    for (let i: number = 0; i < n; i++) {
        w.push(xy[i][0] - xy[i][1]);
    }
    let wmax: number = w.reduce((a, b) => Math.max(a, b));
    let wmin: number = w.reduce((a, b) => Math.min(a, b));

    console.log(Math.max(zmax - zmin, wmax - wmin));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 112240
import std;

void main() {
    string s = read;
    string t = read;
    if (s.length + 1 == t.length && s == t.take(s.length).to!string) {
        writeln("Yes");
    } else writeln("No");
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       double w,h,x,y;
       cin>>w>>h>>x>>y;
       double area=w*h;
       area=area/2;
       //cout.precision(6);
       cout<<fixed<<setprecision(6)<<area<<" ";
       if(w/2==x && h/2==y)
       cout<<"1";
       else
       cout<<"0";
    } 
    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <sstream>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int A, B, M, x, y, c;
int a[100005];
int b[100005];

int main() {
    int ans = INT_MAX;
    int m_a = INT_MAX;
    int m_b = INT_MAX;

    cin >> A >> B >> M;

    for (int i = 1; i <= A; ++i) {
        cin >> a[i];
        m_a = min(a[i], m_a);
    }

    for (int i = 1; i <= B; ++i) {
        cin >> b[i];
        m_b = min(b[i], m_b);
    }

    ans = min(ans, m_a + m_b);

    for (int i = 0; i < M; ++i) {
        cin >> x >> y >> c;
        ans = min(ans, a[x] + b[y] - c);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) cerr << #A << " = "; for (int i=1; i<=n; ++i) cerr << A[i] << ' '; cerr << '\n';
#define PR0(A, n) cerr << #A << " = "; for (int i=0; i<n; ++i) cerr << A[i] << ' '; cerr << '\n';

const int maxn = 1002;
const int maxm = 200002;
const int inf = 1e9;

int n, m, cnt[maxn], num[maxn], low[maxn], nTime;
int scc[maxn], nSCC, curBranch[maxn];
stack<int> st;
bool ok[maxn][maxn];
vector<int> g[maxn];
pair<int, int> e[maxm];

void tarjan(int u) {
	st.push(u);
	num[u] = ++nTime;
	low[u] = inf;
	for (int i=0; i<g[u].size(); ++i) {
		int v = g[u][i];
		if (scc[v]!=0)
			continue;
		if (num[v])
			low[u] = min(low[u], num[v]);
		else {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		}
	}
	if (low[u]<num[u])
		return;
	++nSCC;
	while (true) {
		int x = st.top(); st.pop();
		scc[x] = nSCC;
		if (x==u)
			break;
	}
}

void visit(int u, int branch, int root) {
	if (u!=branch)
		ok[root][u] = true;
	++cnt[u];
	for (int i=0; i<g[u].size(); ++i) {
		int v = g[u][i];
		if (v!=root && cnt[v]<2 && curBranch[v]!=branch) {
			curBranch[v] = branch;
			visit(v, branch, root);
		}
	}
}

void init(int x) {
	memset(cnt, 0, sizeof(cnt));
	memset(curBranch, 0, sizeof(curBranch));
	for (int i=0; i<g[x].size(); ++i) {
		int u = g[x][i];
		curBranch[u] = u;
		//debug(u);
		//debug(ok[3][4]);
		visit(u, u, x);
	}
}

int main() {
	//freopen("data.inp", "r", stdin);
	//freopen("data.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i=1; i<=m; ++i) {
		cin >> e[i].first >> e[i].second;
		g[e[i].first].push_back(e[i].second);
	}
	for (int i=1; i<=n; ++i) {
		if (scc[i]==0) {
			tarjan(i);
		}
	}
	init(3);
	//debug(ok[3][4]);
	for (int i=1; i<=n; ++i) {
		init(i);
	}
	debug(ok[3][4]);
	for (int i=1; i<=m; ++i) {
		int u = e[i].first, v = e[i].second;
		if (scc[u]==scc[v]) {
			if (ok[u][v])
				cout << "same\n";
			else 
				cout << "diff\n";
		}
		else {
			if (ok[u][v])
				cout << "diff\n";
			else 
				cout << "same\n"; 
		}
	}
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

string solve(const vector<int> x, const vector<int> y, const vector<long> h)
{
  int vertex_x = 0, vertex_y = 0;
  long vertex_height = 0;

  int x_compared = -1, y_compared = -1;
  long h_compared = -1;

  for (int i = 0; i < int(h.size()); i++)
  {
    if (h.at(i))
    {
      x_compared = x.at(i);
      y_compared = y.at(i);
      h_compared = h.at(i);
      break;
    }
  }

  for (int i = 0; i < 101; i++)
  {
    for (int j = 0; j < 101; j++)
    {
      const long cand_vertex_height = h_compared + abs(j - x_compared) + abs(i - y_compared);

      for (int k = 0; k < int(h.size()); k++)
      {
        const int point_x = x.at(k);
        const int point_y = y.at(k);
        const long point_h = h.at(k);

        const int diff_x = abs(j - point_x);
        const int diff_y = abs(i - point_y);
        const long cand_height_per_point = max(cand_vertex_height - diff_y - diff_x, 0l);

        if (point_h == cand_height_per_point) {
          if (k >= int(h.size()) - 1)
          {
            vertex_x = j;
            vertex_y = i;
            vertex_height = cand_vertex_height;
          }
        } else {
          break;
        }
      }
    }
  }

  return to_string(vertex_x) + " " + to_string(vertex_y) + " " + to_string(vertex_height);
}

int main(int argc, char **argv)
{
  int n;

  cin >> n;

  vector<int> x(n), y(n);
  vector<long>h(n);
  for (int i = 0; i < n; i++)
  {
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }

  cout << solve(x, y, h) << endl;

  return 0;
}


Measured memory_bytes: 256
s = input()
c = list(s)
c2 = set(c)
al = sorted(list("qwertyuiopasdfghjklzxcvbnm"))
#26文字未満なら追加

if len(c)<26:
    for i in range(26):
        if al[i] not in c2:
            print(s+al[i])
            exit()

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

rev = "zyxwvutsrqponmlkjihgfedcba"
for i in range(25,-1,-1):
    x = sorted(c[i:])
    for j in x:
        if ord(s[i])<ord(j):
            print(s[:i]+j)
            exit()

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(){
	int i,n;
	int debt=100000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		debt+=debt*0.05;
		if(debt%1000>0)debt=debt+1000-(debt%1000);
	}
	printf("%d\n",debt);
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
long long n,a[200010],num,ans;
long long x(long long b,long long c){
	if (b>=c)
		return b-c;
	else
		return (1000000007+(b-c));
}
int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++) num+=a[i],num=num%(1000000007);
//	for (int i=0;i<n;i++) ans=(ans+x(num,a[i])*a[i])%(1000000007);
//	cout<<(ans%1000000007)/2<<endl;;
	for (int i=0;i<n;i++){
		num=x(num,a[i]);
		ans=(ans+num*a[i])%(1000000007);
	}
	cout<<(ans%1000000007)<<endl;
	return 0;
}

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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define PI 3.1415926535897932384626433832795
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
*/

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    ll a,b,c;
    cin>>a>>b>>c;

    if(b>a*c)cout << c << "\n";
    else cout << b/a << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
ll mark[201];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
	ll n,x;
	cin>>x>>n;
	
	ll w;
	for(int i=0;i<n;i++)
	{
		cin>>w;
		mark[w]++;
	}
	ll ans,val,curr=1000;
	for(int i=-100;i<=200;i++)
	{
		if(i<0)
		{
			val=abs(-i+x);
			if(val<curr)
			{
				curr=val;
				ans=i;
			}
		}
		else
		{
			
			if(mark[i]==0)
			{
				val=abs(-i+x);
			if(val<curr)
			{
				curr=val;
				ans=i;
			}
			}
		    
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-

def main(n, S):
    ans = ""
    S_list = sorted((set(S[0])))
    for s in S_list:
        cnt = float("INF")
        for i in range(n):
            cnt = min(cnt, S[i].count(s))
        ans = ans + s * cnt
    print(ans)
if __name__ == '__main__':
    n = int(input())
    S = []
    for i in range(n):
        S.append(input())
    
    main(n, S)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  int a,b,c,d;cin>>a>>b>>c>>d;
  while(true) {
    c-=b;
    if(c<1) {
      pr("Yes");
      break;
    }
    a-=d;
    if(a<1) {
      pr("No");
      break;
    }
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const int MX = 100005;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

ll n, s;
int pos[MX];
ll num[MX];

pair<int, ll> calc(int l, int r)
{
	if(s <= pos[l]) return make_pair(pos[r], pos[r]-s);
	else if(s >= pos[r]) return make_pair(pos[l], s-pos[l]);
	else if(l+1 == r)
	{
		if(num[l] >= num[r]) return make_pair(pos[r], (s-pos[l]) + (pos[r]-pos[l]));
		else return make_pair(pos[l], (pos[r]-s) + (pos[r]-pos[l]));
	}
	else if(num[l] >= num[r])
	{
		num[l] += num[r];
		pair<int, ll> ret = calc(l, r-1);
		return  make_pair(pos[r], ret.second+pos[r]-ret.first);
	}
	else
	{
		num[r] += num[l];
		pair<int, ll> ret = calc(l+1, r);
		return  make_pair(pos[l], ret.second+ret.first-pos[l]);
	}
}

int main()
{
	read(n), read(s);
	for(int i=1; i<=n; i++) read(pos[i]), read(num[i]);
	printf("%lld\n", calc(1, n).second);
	return 0;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 2e5+5;
vector<int> A[maxn];

int main()
{
    int N,M,Q;
    scanf("%d %d %d",&N,&M,&Q);
    _for(i,0,M){
        int L,R;
        scanf("%d %d",&L,&R);
        A[L].push_back(R);
    }

    _for(i,1,maxn){
        sort(ALL(A[i]));
    }

    _for(i,0,Q){
        int L,R;
        scanf("%d %d",&L,&R);
        int val = 0;
        _rep(j,L,R){
            val += upper_bound(ALL(A[j]),R) - A[j].begin();
        }
        printf("%d\n",val);
    }

    return 0;
}

Measured memory_bytes: 6912