akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

long long bpow(long long a,long long b){
	return b ? bpow(a*a%10,b/2) * (b&1?a:1) % 10 : 1;
}

int main(){
	while(1){
	long long n,m,k;
	cin >> n >> m >> k;
	
		
	n %= 10;
	long long power = bpow(n,m);
	
	vector<int> loop;
	map<int,int> pos;
	
	
	long long cur = 1;
	int start = -1, end = -1;
	long long initsum = 0;
	for(int i = 0 ; i < k ; i++){
		if( pos.count(cur) ){
			start = pos[cur];
			end = i;
			break;
		}else{
			loop.push_back(cur);
			pos[cur] = i;
		}
		initsum += (cur * n )%10;
		cur *= power;
		cur %= 10;

	}
	long long answer = initsum;	
	if( end != -1 ){
		//cout << wow << endl;
		
		//cout << wow << endl;
		long long loopsum = 0;
		for(int i = start ; i < end ; i++){
			loopsum += (n * loop[i]) % 10;
		}
		long long remain = k - end;
		answer += remain / (end-start) * loopsum;
		for(int i = 0 ; i < remain%(end-start) ; i++){
			answer += (n * loop[start+i]) % 10;
		}
	}		
	cout << answer << endl;
	return 0;
	}
}


Measured memory_bytes: 1216
#include <stdio.h>

int main(void) {
 char a[1200],c[1200];
 int b;
 while(1){
  scanf("%c",&a[b]);
   if(a[b]=='\n')
    break;
  c[b]=a[b];
  if('a'<=a[b]&&'z'>=a[b])
  c[b]=a[b]-32; 
  else if('A'<=a[b]&&'Z'>=a[b])
  c[b]=a[b]+32;
  b=b+1;
 }
 for(int d=0;d<b;d++)
 printf("%c",c[d]);
 printf("\n");
  return 0;
}


Measured memory_bytes: 2108
//要するに最大公約数を求めようとしたがアルゴリズムがゴミだから一つのデータセットでタイムアウトする
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<tuple>
#include<limits>//ex numeric_limits<int>::max()
#include<unordered_set>
#include<math.h>
// #include"gcd.h"
#define lli long long int

using namespace std;

int gcd(int,int);

int main(void){
    int result=0;
    int N,X;
    cin >> N;
    cin >> X;
    int first;
    int second;
    cin >> first;
    first=abs(X-first);
    for (int i = 0; i < N-1; ++i)
    {
        cin >> second;
        first=gcd(abs(first),abs(X-second));
    }
    cout << first << endl;
}

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


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACoffee solver = new ACoffee();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACoffee {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String str = s.nextString();
            if (str.charAt(2) == str.charAt(3) && str.charAt(4) == str.charAt(5)) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main() {
  int n;
  cin >> n;
  int p[50];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] != i+1) ans++;
  }
  if (ans > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = LongArray(n + 1)
    a[0] = 1
    a[1] = 1
    var sum = 2L
    for (i in 2..n) {
        a[i] = (sum - a[i - 2] + MOD) % MOD
        sum = (sum + a[i]) % MOD
    }
    var ans = 0L
    for (i in 0..n - 1) {
        ans = (ans + a[i] * (n - 1)) % MOD
        if (i < n - 1) ans = (ans + a[i] * (i + 1)) % MOD
        if (i < n - 1) ans = (ans + a[i] * (n - 1) % MOD * (n - 2)) % MOD
    }
    ans = (ans + a[n]) % MOD
    println(ans)
}

val MOD = 1000000007

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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)


int main(){
    int h,w;
    cin>>h>>w;
    char buf[w+1];
    bool map[h][w];
    REP(i,h){
        cin>>buf;
        REP(j,w){
            map[i][j]=buf[j]=='#';
        }
    }
    bool flag=true;//可能
    REP(i,h){
        REP(j,w){
            if(map[i][j]){
                if(
                    !(i>0&&map[i-1][j])&&
                    !(i<h&&map[i+1][j])&&
                    !(j>0&&map[i][j-1])&&
                    !(j<w&&map[i][j+1])
                ){ //周りに塗れるものがない
                    flag=false;
                    break;
                }
            }
        }
        if(!flag)break;
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll w, h, n;
  cin >> w >> h >> n;

  vector<ll> x(n);
  vector<ll> y(n);
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> a[i];
  }

  ll wi = 0;
  ll hi = 0;
  for (ll i = 0; i < n; ++i) {
    if (a[i] == 1) {
      wi = max(wi, x[i]);
    } else if (a[i] == 2) {
      w = min(w, x[i]);
    } else if (a[i] == 3) {
      hi = max(hi, y[i]);
    } else if (a[i] == 4) {
      h = min(h, y[i]);
    }
  }

  ll ans = 0;
  if ((w-wi) > 0 && (h-hi) > 0) {
    ans = (w-wi) * (h-hi);
  }
  cout << max(ans, 0LL) << endl;

  return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int d[10],vis[10];
int a[10][10];
int b[210][210];
int h,w;

void init(){
	for(int i=0;i<10;i++){
		d[i]=inf;
		vis[i]=0;
	}
}

int dij(int p){
	init();
	d[p]=0;
	
	while(true){
		int v=-1;
		for(int u=0;u<=9;u++){
			if(!vis[u]&&(v==-1||d[u]<d[v]))v=u;
		}
		if(v==-1)break;
		vis[v]=1;
		for(int u=0;u<=9;u++){
			d[u]=min(d[u],d[v]+a[v][u]);
		}
	}
	return d[1];
}

int  main(){
	
	scanf("%d %d",&h,&w);
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&b[i][j]);
		}
	}


	int mx[10];
	for(int i=0;i<10;i++){
		if(i==1)mx[i]=0;
		else mx[i]=dij(i);
	}
//	for(int i=0;i<10;i++)
//	printf("%d ",mx[i]);
	long long ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(b[i][j]>=0)ans+=mx[b[i][j]];
		}
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
a,b,x=map(int,input().split())
import math
if a*a*b/2>x:
    ans=math.atan((a*b*b)/(2*x))
    print(180*ans/math.pi)
else:
    ans=math.atan(2*(a*a*b-x)/(a**3))
    print(180*ans/math.pi)

Measured memory_bytes: 3188
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s, t;
    cin >> s >> t;
    vector<string> st;
    REP(i, s.length())
    {
        bool flag = true;
        REP(j, t.length())
        {
            if (i + j >= s.length())
            {
                flag = false;
                break;
            }
            if (not(s[i + j] == '?' or s[i + j] == t[j]))
            {
                flag = false;
            }
        }
        if (flag)
        {
            string tmp = s;
            REP(j, t.length())
            {
                tmp[i + j] = t[j];
            }
            REP(j, s.length())
            {
                if (tmp[j] == '?')
                    tmp[j] = 'a';
            }
            st.push_back(tmp);
            //cout << tmp << endl;
            //return 0;
        }
    }
    if (st.size() > 0)
    {
        sort(st.begin(), st.end());
        cout << st[0] << endl;
    }
    else
        cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
package main

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

func solve() {
	n := getInt()
	as := getIntSlice(n)

	now := 0
	m := make(map[int]int)
	m[0]++
	for i := 0; i < n; i++ {
		now += as[i]
		m[now]++
	}

	ans := 0
	for _, v := range m {
		ans += v * (v - 1) / 2
	}
	puts(ans)
}

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// scanner.Buffer(make([]byte, buf), buf)
	scanner.Split(bufio.ScanWords)
	solve()
	writer.Flush()
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}

func puts(a ...interface{}) {
	if _, err := fmt.Fprintln(writer, a...); err != nil {
		panic(err)
	}
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

	vector<int> cr(N), cb(N), cg(N);
	for(int i=0; i<N; i++){
		if(i>0){
			cr[i] = cr[i-1];
			cb[i] = cb[i-1];
			cg[i] = cg[i-1];
		}

		if(S[i]=='R') cr[i]++;
		if(S[i]=='G') cg[i]++;
		if(S[i]=='B') cb[i]++;
	}

	ll ans = 0;
	for(int j=1; j<N; j++) for(int k=j+1; k<N; k++){
		if(S[j]=='R'&&S[k]=='G'||S[j]=='G'&&S[k]=='R'){
			ans += cb[j-1];
			if(j-k+j>=0 && S[j-k+j]=='B') ans--;
		}
		if(S[j]=='B'&&S[k]=='G'||S[j]=='G'&&S[k]=='B'){
			ans += cr[j-1];
			if(j-k+j>=0 && S[j-k+j]=='R') ans--;
		}
		if(S[j]=='B'&&S[k]=='R'||S[j]=='R'&&S[k]=='B'){
			ans += cg[j-1];
			if(j-k+j>=0 && S[j-k+j]=='G') ans--;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MXX = 1e5 + 5;
const int MOD = 1000000007;

ll a[MXX], n, m;
ll dp[MXX];
bool vis[MXX];

ll solve(ll i)
{
    if(i == n)return 1;
    if(i>n) return 0;
    if(vis[i])return 0;
    if(dp[i]!=-1)return dp[i];
    ll x = solve(i + 1);
    ll y = solve(i + 2);
    return dp[i] = (x + y) % MOD;
}
int main ()
{
    cin>>n>>m;for(int i = 1; i<=m; i++)cin>>a[i], vis[a[i]] = true;
    memset(dp, -1, sizeof(dp));
    cout<<solve(0)<<endl;
    return 0;
}


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


int main() {
  long n,m,k;
  cin>>n>>m>>k;
  vector<long>a(n),b(m);
  rep(i,n){
    cin>>a.at(i);
  }
  rep(i,m){
    cin>>b.at(i);
  }
  long tot=0;
  long p=0;
  long q=-1;
  rep(i,n){
    if(tot+a.at(i)<=k){
      tot+=a.at(i);
      p=i+1;
      q=i;
    }
    else{
      break;
    }
  }
  long ans=p;
  long now=0;
  
  while(now<m){
    if(tot+b[now]<=k){
      tot+=b.at(now);
      p++;
      now++;
      ans=max(ans,p);
      
    }
    else{
      if(q>=0){
      tot-=a.at(q);
      q--;
      p--;
      ans=max(ans,p);
      }
      else{
        
        ans=max(ans,p);
        break;
      }
    }
    
  }
  
  cout<<ans<<endl;
}



Measured memory_bytes: 6420
#include<algorithm>
#include<chrono>
#include<ctime>  
#include<climits>
#include<functional>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
// #include<bits/stdc++.h>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

const int MAXN = 40 + 5;
int n;
string a[MAXN];
long long dp[MAXN][MAXN][MAXN];

long long dp_cal(int i, int j, int k) {
	if(dp[i][j][k] >= 0) return dp[i][j][k];
	if(i == j && k == j) return dp[i][j][k] = 1;
	// if(i + 1 >= j || k - 1 <= j) return dp[i][j][k] = 0;
	long long res = 0;
	for(int ii = i; ii < j; ii++) {
		for(int jj = k; jj > j; jj--) {
			if(a[ii][jj] == '0') continue;
			for(int iii = ii; iii < j; iii++) {
				for(int jjj = jj; jjj > j; jjj--) {
					res += dp_cal(i, ii, iii) * dp_cal(iii + 1, j, jjj - 1) * dp_cal(jjj, jj, k);
				}
			}
		}
	}
	// debug << i << j << k << res << endl;
	return dp[i][j][k] = res;
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

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

    for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    		for(int k = 0; k < n; k++)
    			dp[i][j][k] = -1;

    long long res = 0;
    for(int i = 1; i <= n - 1; i++) {
    	// debug << 0 << i << n - 1 << endl;
    	if(a[0][i] == '1')
	    	res += dp_cal(1, i, n - 1);
    }
    cout << res << endl;


    return 0;
 
}























Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main() {
    int r, g, b;

    cin >> r >> g >> b;

    if ((100 * r + 10 * g + b) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <iomanip>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
#include <cmath>

using namespace std;

int main(){

	double x1, y1, x2, y2;
	double ans;

	cin >> x1 >> y1 >> x2 >> y2;

	ans = sqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));

	printf("%.5f\n", ans);

	return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split(" " );
        int n = Integer.parseInt( params[0] );
        int k = Integer.parseInt( params[1] );
        params = in.nextLine().split(" " );
        int r = Integer.parseInt( params[0] );
        int s = Integer.parseInt( params[1] );
        int p = Integer.parseInt( params[2] );
        String t = in.nextLine();

        long ans = 0;
        char[] tChars = t.toCharArray();
        for( int i = 0 ; i < n ; i++ ){
            char housing = tChars[i];
            if( k <= i ){
                char beforeHousing = tChars[ i - k ];
                if( beforeHousing == housing ){
                    tChars[ i ] = 'a';
                    continue;
                }
            }

            if( housing == 'r' ){
                ans += p;
            }
            else if( housing == 's' ){
                ans += r;
            }
            else {
                ans += s;
            }
        }

        System.out.println( ans );

    }

}


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

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

  int sum = 1;
  for(int i = 0; i < N; i++){
    if(sum * 2 <= sum + K){
      sum *= 2;
    }
    else{
      sum += K;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3600
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int n;
    cin>>n;
    int a[n];
    rep0(i,n) cin>>a[i];
    int pre[n+1]={0};
    pre[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        pre[i]=(pre[i+1]+a[i])%mod;
    }
    int ans=0;
    rep0(i,n){
        ans=(ans+(a[i]*pre[i+1])%mod)%mod;
    }
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define pb push_back
typedef long long int ll;
using namespace std;
int main(void){
	fast;
	int n,q,i,x,y;
	ll s=0;
	cin>>n;
	int a[n];
	int pre[n+1]={0};
	int suf[n+2]={0};
	for(i=0;i<n;i++){
		cin>>a[i];
		pre[i+1]=pre[i]^a[i];
	}
	for(i=n-1;i>=0;i--){
		suf[i+1]=suf[i+2]^a[i];
	}
	for(i=1;i<=n;i++){
		ll k=pre[i-1]^suf[i+1];
		cout<<k<<" ";
	}
}


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

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

    int h,w;
    cin>>h>>w;
    vector<vector<char>> a(h,vector<char>(w));
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cin>>a[i][j];
        }
    }
    for(int i=0; i<w+2; i++) cout<<'#';
  	cout<<"\n";
    for(int i=0; i<h; i++) {
        cout<<'#';
        for(int j=0; j<w; j++) {
            cout<<a[i][j];
        }
        cout<<'#'<<"\n";
    }
    for(int i=0; i<w+2; i++) cout<<'#';
  	cout<<"\n";
}

Measured memory_bytes: 256
N,K=map(int,input().split())
S=list(map(str,input()))
if S[K-1]=="A":
  S[K-1]="a"
elif S[K-1]=="B":
  S[K-1]="b"
elif S[K-1]=="C":
  S[K-1]="c"
print("".join(map(str,S)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	int n,m;
	cin >> n >> m;
	vector<pair<bool,int>> box(n);
	box[0].first = true;
	box[0].second = 1;
	for(int i=1;i<n;i++){
		box[i].first = false;
		box[i].second = 1;
	}
	rep(i,m){
		int x,y;
		cin >> x >> y;
		x--;y--;
		if(box[x].first==true)
			box[y].first = true;
		box[y].second++;
		box[x].second--;
		if(box[x].second == 0)
			box[x].first = false;
	}
	int cnt=0;
	rep(i,n){
		if(box[i].first == true)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 110;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

int n, x, cnt;

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

	cin >> n >> x;

	vector<int> l(n + 1);

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

	for (int i = 1 ; i <= n ; ++i) {
		l[i] += l[i - 1];
	}

	for (int i = 0 ; i <= n; ++i) {
		cnt += (l[i] <= x);
	}

	cout << cnt << endl;


	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];
	vi dup = arr;
	sort(dup.begin(), dup.end());
	int lo = dup[(N-1)/2];
	int hi = dup[N/2];
	for (int x : arr) {
		if (x <= lo) print(hi);
		else print(lo);
	}
}

Measured memory_bytes: 4760
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

string str[3000];

int cell_sum[3000][3000];
int edge_t_sum[3000][3000];
int edge_y_sum[3000][3000];

int main(){
	
	int N, M, Q;
	
	cin >> N >> M >> Q;
	
	string piyo = "";
	
	for(int i = 0; i <= M; i++){
		piyo = piyo + "0";
	}
	
	str[0] = piyo;
	
	for(int i = 1; i <= N; i++){
		string hoge;
		cin >> hoge;
		str[i] = "0" + hoge;
	}
	/*
	for(int i = 0; i <= M; i++){
		cout << str[i] << endl;
	}
	*/
	for(int i = 0; i <= N + 1; i++){
		cell_sum[i][0] = 0;
		edge_t_sum[i][0] = 0;
		edge_y_sum[i][0] = 0;
		cell_sum[i][M + 1] = 0;
		edge_t_sum[i][M + 1] = 0;
		edge_y_sum[i][M + 1] = 0;
	}
	for(int i = 0; i <= M + 1; i++){
		cell_sum[0][i] = 0;
		edge_t_sum[0][i] = 0;
		edge_y_sum[0][i] = 0;
		cell_sum[N + 1][0] = 0;
		edge_t_sum[N + 1][0] = 0;
		edge_y_sum[N + 1][0] = 0;
	}
	
	for(int i = 1; i <= N; i++){
		int count = 0;
		for(int j = 1; j <= M; j++){
			if(str[i][j] == '1'){
				count++;
			}
			cell_sum[i][j] = cell_sum[i - 1][j] + count;
			//cout << cell_sum[i][j] << " ";
		}
		//cout << endl;
	}
	
	for(int i = 1; i <= N; i++){
		int count = 0;
		for(int j = 1; j <= M; j++){
			if(str[i][j] == '1' && str[i - 1][j] == '1'){
				count++;
			}
			edge_t_sum[i][j] = edge_t_sum[i - 1][j] + count;
			//cout << edge_t_sum[i][j] << " ";
		}
		//cout << endl;
	}
	
	for(int i = 1; i <= N; i++){
		int count = 0;
		for(int j = 1; j <= M; j++){
			if(str[i][j] == '1' && str[i][j - 1] == '1'){
				count++;
			}
			edge_y_sum[i][j] = edge_y_sum[i - 1][j] + count;
			//cout << edge_y_sum[i][j] << " ";
		}
		//cout << endl;
	}
	
	for(int i = 0; i < Q; i++){
		int x1, x2, y1, y2;
		cin >> y1 >> x1 >> y2 >> x2;
		int ans = cell_sum[y2][x2] - cell_sum[y1 - 1][x2] - cell_sum[y2][x1 - 1] + cell_sum[y1 - 1][x1 - 1];
		ans -= edge_t_sum[y2][x2] - edge_t_sum[y1][x2] - edge_t_sum[y2][x1 - 1] + edge_t_sum[y1][x1 - 1];
		ans -= edge_y_sum[y2][x2] - edge_y_sum[y1 - 1][x2] - edge_y_sum[y2][x1] + edge_y_sum[y1 - 1][x1];
		//cout << cell_sum[y2][x2] - cell_sum[y1 - 1][x2] - cell_sum[y2][x1 - 1] + cell_sum[y1 - 1][x1 - 1] << " " << edge_t_sum[y2][x2] - edge_t_sum[y1][x2] - edge_t_sum[y2][x1 - 1] + edge_t_sum[y1][x1 - 1] << " " << edge_y_sum[y2][x2] - edge_y_sum[y1 - 1][x2] - edge_y_sum[y2][x1] + edge_y_sum[y1 - 1][x1] << endl;
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 79616
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPP(i,m,n) for(ll i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll H,W;
char S[401][401];
bool used[401][401];
queue<int> Q;
ll cntb = 0,cntw = 0;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};

void dfs(ll x,ll y){
    if(S[x][y] == '#') cntb++;
    else cntw++;
    used[x][y] = true;
    REP(i,4){
        ll nx = x + dx[i];
        ll ny = y + dy[i];
        if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
        if(!used[nx][ny] && S[nx][ny] != S[x][y]) dfs(nx,ny);
    }
}

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            cin >> S[i][j];
        }
    }
    ll ans = 0;
    REP(i,H){
        REP(j,W){
            if(used[i][j]) continue;
            cntb = 0;
            cntw = 0;
            dfs(i,j);
            ans += cntb * cntw;
        }
    }
  cout << ans << endl;
}

Measured memory_bytes: 8064
#include <stdio.h>
int main(){
  int S,h,m,s;
  scanf("%d",&S);
  h=S/3600;
  m=(S-3600*h)/60;
  s=S-(h*3600+m*60);
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

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

#define lowbit(x) ((x) & (-x))

const int maxn = (int)(2e5) + 5;
const double pi = acos(-1.0);
int f[maxn], C[maxn], tbX[maxn], tbY[maxn];

struct node {
	int x, y;
} p[maxn];

bool operator < (node a, node b) {
	return a.x != b.x ? a.x < b.x : a.y < b.y;
}

inline int hs(int a[], int x) {
	return lower_bound(a + 1, a + a[0] + 1, x) - a;
}

inline int gmx(int x) {
	int ret = 0; for (; x; x -= lowbit(x)) ret = max(ret, C[x]); return ret;
}

inline void add(int x, int v) {
	for (; x <= tbY[0]; x += lowbit(x)) C[x] = max(C[x], v);  
}

int main() {
	int Xs, Ys, Xt, Yt;
	scanf("%d%d%d%d", &Xs, &Ys, &Xt, &Yt);
	int n, m = 0;
	scanf("%d", &n);
	int Xl = Xs, Xr = Xt, Yl = Ys, Yr = Yt;
	if (Xl > Xr) swap(Xl, Xr);
	if (Yl > Yr) swap(Yl, Yr);
	for (int i = 1; i <= n; ++i) {
		int x, y; scanf("%d%d", &x, &y);
		if (Xl <= x && x <= Xr && Yl <= y && y <= Yr) {
			++m; p[m].x = x - Xl; p[m].y = y - Yl;
		}
	}
	int h = Xr - Xl, w = Yr - Yl;
	if (Xs > Xt) {
		for (int i = 1; i <= m; ++i) p[i].x = h - p[i].x;
	}
	if (Ys > Yt) {
		for (int i = 1; i <= m; ++i) p[i].y = w - p[i].y;
	}
	tbX[++tbX[0]] = 0; tbY[++tbY[0]] = 0;
	for (int i = 1; i <= m; ++i) tbX[++tbX[0]] = p[i].x, tbY[++tbY[0]] = p[i].y;
	tbX[++tbX[0]] = h; tbY[++tbY[0]] = w;
	sort(tbX + 1, tbX + tbX[0] + 1);
	tbX[0] = unique(tbX + 1, tbX + tbX[0] + 1) - tbX - 1;
	sort(tbY + 1, tbY + tbY[0] + 1);
	tbY[0] = unique(tbY + 1, tbY + tbY[0] + 1) - tbY - 1;
	for (int i = 1; i <= m; ++i) p[i].x = hs(tbX, p[i].x), p[i].y = hs(tbY, p[i].y);
	h = hs(tbX, h); w = hs(tbY, w);
	sort(p + 1, p + m + 1);
	int ret = 0;
	memset(C, 0x80, sizeof(C)); add(1, 0);
	for (int i = 1; i <= m; ++i) {
		f[i] = gmx(p[i].y - 1) + 1; add(p[i].y, max(f[i], 0)); ret = max(ret, f[i]); 
	} 
	return printf("%.10lf\n", 100.0 * (tbX[h] + tbY[w]) - ret * (20 - pi * 5) + (ret == min(tbX[h], tbY[w]) + 1) * (pi * 5)), 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
long long int euclidean_gcd(long long int a, long long int b) {
	if (a < b) return euclidean_gcd(b, a);
	long long int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
int main() {
	int N, Q;
	cin >> N >> Q;
	vector<int>ten(N);
	vector<int>atai(N,0);
	int a, b;
	for (int i = 0; i < N-1; i++)
	{
		cin >> a >> b;
		a--;
		b--;
		ten[b]=a;
	}
	
	for (int i = 0; i < Q; i++)
	{
		cin >> a >> b;
		a--;
		atai[a] += b;
	}
	for (int i = 0; i < N; i++)
	{
		int ans = atai[i];
		if (i != 0) {
			ans += atai[ten[i]];
		}
		atai[i] = ans;
		cout << ans<<" ";
	}
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll x,sum[200009],n,ans,minn;
int main()
{
    scanf("%lld",&n);
    sum[0]=0;
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        sum[i]=sum[i-1]+x;
    }
    ans=sum[n];
    minn=abs(2*sum[1]-sum[n]);
    for(ll i=2;i<=n-1;i++)
    {
        minn=min(minn,abs(2*sum[i]-sum[n]));
    }
    printf("%lld\n",minn);
    return 0;
}

Measured memory_bytes: 1792
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
x = abs(b - a)
ans = ''
if v <= w:
  ans = 'NO'
else:
  if x / (v - w) <= t:
    ans = 'YES'
  else:
    ans = 'NO'
print(ans)

Measured memory_bytes: 9068
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_INPUT_SIZE  1024

void dumpData(int* array, int num);
void readData(int* array, int num, FILE* stdin);
int  selectionSort(int* array, int num);

int
main(int argc, char* argv[])
{
    char input[MAX_INPUT_SIZE];
    int num = atoi(fgets(input, sizeof(input), stdin));

    int* array = new int[num];
    if (!array) {
        fprintf(stderr, "Error. Cannot allocate memory\n");
        exit(1);
    } 

    readData(array, num, stdin);
    //dumpData(array, num);
    int exchangeNum = selectionSort(array, num);
    dumpData(array, num);
    printf("%d\n", exchangeNum);

    if (!array) {
        delete [] array;
        array = NULL;
    }

    return 0;
}

void
dumpData(int* array, int num)
{
    for (int i = 0; i < num; i++) {
        if (i != 0) printf(" ");
        printf("%d", array[i]);
    }
    printf("\n");
}

void
readData(int* array, int num, FILE* stdin)
{
    char input[MAX_INPUT_SIZE];

    fgets(input, sizeof(input), stdin);

    for (int i = 0; i < num; i++) {
        char* tok = i == 0 ? strtok(input, " ") : strtok(NULL, " ");
        array[i] = atoi(tok);
    }

    return;
}

int
selectionSort(int* array, int num)
{
    int exchangeNum = 0;

    for (int i = 0; i < num; i++) {
        int minElem = i;
        for (int j = i+1; j < num; j++) {
            if (array[j] < array[minElem]) {
                minElem = j;
            }
        }
        if (array[i] > array[minElem]) {
            int tmp = array[i];
            array[i] = array[minElem];
            array[minElem] = tmp;
            exchangeNum++;
        }
    }

    return exchangeNum;
}

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

#define int long long 
#define MOD 1000000007


using namespace std;


signed main(){

	int n;
	cin >> n;
	
	if(n==3||n==5||n==7){
		cout << "YES" <<endl;
	
		return 0;
	}
 	
 	else{
 		cout << "NO" <<endl;
 	}
 	
 	return 0;
	

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mod;
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=1ll*res*b%mod;
		b=1ll*b*b%mod; n>>=1;
	}
	return res;
}
int f[2][105][105],pw[105][10005],C[105][105];
void init(int n){
	for(int i=0;i<=n;++i){
		pw[i][0]=1;
		for(int j=1;j<=n*n;++j)
			pw[i][j]=1ll*pw[i][j-1]*i%mod;
	}
	C[0][0]=1;
	for(int i=1;i<=n;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
}
void add(int &x,int y){
	x=(x+y)%mod;
}
signed main(){
	int n,k;
	cin>>n>>k;
	if(k>(n+1)/2) return puts("-1"),0;
	int l=n/2,r=2*n-1;
	for(int i=3*n-1;i>=2*n;--i){
		cout<<l+k<<" "<<r+k<<" "<<i+k<<endl;
		r-=2;l++;
		if(r<n) r=2*n-2;
		if(l==n) l=0;
	}
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 3000000007;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------
ll inf = 1000000010000;

int main(){
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<ll> s(A+2);
  vector<ll> t(B+2);
  s[0] = -inf;
  for(int i=1; i<=A; i++){
    cin >> s[i];
  }
  s[A+1] = inf;
  t[0] = -inf;
  for(int i=1; i<=B; i++){
    cin >> t[i];
  }
  t[B+1] = inf;
  for(int i=0; i<Q; i++){
    ll x;
    cin >> x;
    ll ans;
    auto S = lower_bound(s.begin(),s.end(),x);
    ll sr = *S;
    ll sl = *(S-1);
    auto T = lower_bound(t.begin(),t.end(),x);
    ll tr = *T;
    ll tl = *(T-1);
    sr -= x;
    sl = x-sl;
    tr -= x;
    tl = x-tl;
    ans = inf;
    if(sr > tr){
      chmin(ans,sr);
    }else{
      chmin(ans,tr);
    }
    if(sl > tl){
      chmin(ans,sl);
    }else{
      chmin(ans,tl);
    }
    if(sr > tl){
      chmin(ans,sr+tl*2);
    }else{
      chmin(ans,sr*2+tl);
    }
    if(tr > sl){
      chmin(ans,tr+sl*2);
    }else{
      chmin(ans,tr*2+sl);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}

int main(){
	int n;
	cin>>n;
	vector<ll> a(n+1);
	a[0]=2;
	a[1]=1;
	FOR(i,2,n+1){
		a[i]=a[i-1]+a[i-2];
	}
	cout<<a[n]<<endl;
}


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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    s += s[0];
    s += s[1];
    for (int i = 0; i < 4; i++) {
        vector<int> a(N+2); //0:sheep, 1:wolf
        a[0] = i%2;
        a[1] = i/2;
        for (int j = 2; j <= N+1; j++) {
            if (s[j-1] == 'o' && a[j-1] == 0) a[j] = a[j-2];
            else if (s[j-1] == 'o' && a[j-1] == 1) a[j] = 1 - a[j-2];
            else if (s[j-1] == 'x' && a[j-1] == 0) a[j] = 1 - a[j-2];
            else if (s[j-1] == 'x' && a[j-1] == 1) a[j] = a[j-2];
        }
        if (a[0] == a[N] && a[1] == a[N+1]) {
            for (int j = 0; j < N; j++) {
                cout << ((a[j] == 0) ? "S" : "W");
            }
            cout << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 1016
#include <iostream>
#include <vector>

using namespace std;

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    bool same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    bool merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u == v) return false;
        root[u] = v;
        size[v] += size[u];
        return true;
    }
private:
    vector<int> root;
    vector<int> size;
};

bool solve(){
    long long N, M, Q; cin >> N >> M >> Q;
    UnionFind uf(N);
    vector<pair<int, int>> bi;
    long long sz = N;
    for(int i=0;i<Q;i++){
        int a, b, c; cin >> a >> b >> c;
        if(M == N-1 && c == 1) return false;
        if(c == 0){
            if(uf.merge(a, b)) --sz;
        } else {
            bi.emplace_back(a, b);
        }
    }
    if(M == N-1) return true;
    if(!bi.empty() && sz <= 2) return false;
    for(auto& p : bi){
        if(uf.same(p.first, p.second)) return false;
    }
    return N-sz + sz*(sz-1)/2 >= M;
}

int main(){
    cout << (solve() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    // ll N,S,K;
    ll a;
    // cin >> a >>b >>c;
    
    cin >> a;
    string s;
    cin >> s;

    if (a<3200){
      cout << "red" <<endl;
    }else{
      cout << s <<endl;
    }

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  cout<<(1000-N%1000)%1000<<endl;
}



Measured memory_bytes: 3620
#include<iostream>
#include<iostream>
using namespace std;
int main(){
  int N;
  int X;
  int M=100000;
  int i;
  
cin>>N;
cin>>X;
int snack[N];
for(i=0;i<N;i++){
cin>>snack[i];
  X-=snack[i];
  if(snack[i]<=M){
    M=snack[i];
  }
}
  cout<<X/M+N;
}


Measured memory_bytes: 256
#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
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef array <ll, 2> pii;
typedef vector <int> vi;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e5 + 123;
int n, k, a[N], p[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int cnt = 0;
	while (k--) {
		memset(& p, 0, sizeof(p));
		for (int i = 1; i <= n; i++) {
			int l = max(1, i - a[i]);
			int r = min(n, i + a[i]);
			p[l]++;
			p[r + 1]--;
		}
		int mn = N;
		for (int i = 1; i <= n; i++) {
			a[i] = a[i - 1] + p[i];
			mn = min(mn, a[i]);
		}
		cnt++;
		if (mn == n) {
			break;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << a[i] << ' ';
	}
}


Measured memory_bytes: 5228
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
        cout << 3 << endl;
    }else if( (s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << 2 << endl;
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << endl;
    else cout << 0 << endl; 
    return 0;
}

Measured memory_bytes: 3572
import math

def main():
    N = input()
    N = int(N)
    N = N+1
    
    sum = 0

    for a in range(1, N):
        for b in range(1, N):
            for c in range(1, N):

                if a == b or b == c or a == c:
                    tmp = math.gcd(a,b)
                    gcd = math.gcd(tmp,c)
                    sum = sum + gcd

                elif a < b and b < c:
                    tmp = math.gcd(a,b)
                    gcd = math.gcd(tmp,c)
                    sum = sum + 6*gcd

                else:
                    continue

    print(sum)




if __name__ == "__main__":
    main()

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

const string YES = "Yes";
const string NO = "No";
int main(){
  vector<int> A(9); rep(i, 9) cin >> A[i];
  int N; cin >> N;
  vector<bool> open(N, false);
  rep(i, N) {
    int b; cin >> b;
    rep(j, 9) if (A[j] == b) open[j] = true; 
  }

  int ans = 0;
  rep(i, 3) if (open[0 + i] && open[3 + i] && open[6 + i]) ans++;
  rep(i, 3) if (open[i * 3] && open[i * 3 + 1] && open[i * 3 + 2]) ans++;
  if (open[0] && open[4] && open[8]) ans++;
  if (open[2] && open[4] && open[6]) ans++;

  if (ans > 0) cout << YES << endl;
  else cout << NO << endl;
}


Measured memory_bytes: 256