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

int main() {
  int N;
  cin >> N;
    vector<int> vec(N);
  int Alice, Bob, answer;
    for(int i = 0; i < N; i++){
      cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end()); 
    reverse(vec.begin(), vec.end());
  if(N % 2 == 0){
  for(int i = 0; i < N; i += 2){
    answer = answer + vec.at(i) - vec.at(i + 1);
  }
  }
  else{
    for(int i = 1; i < N; i += 2){
      answer = answer + vec.at(i - 1) - vec.at(i);
    }
    answer += vec.at(N - 1);
  }
  cout << answer << endl;
}



Measured memory_bytes: 256
//ABC162 D

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint n;
string s;


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

  lint r = 0;
  lint g = 0;
  lint b = 0;
  rep(i,n){
    if(s[i] == 'R') r++;
    else if(s[i] == 'G') g++;
    else b++;
  }
  
  lint tmp_r = 0;
  lint tmp_g = 0;
  lint tmp_b = 0;
  if(s[0] == 'R') tmp_r++;
  else if(s[0] == 'G') tmp_g++;
  else tmp_b++;

  reps(j,1,n-1){
    if(s[j] == 'R') tmp_r++;
    else if(s[j] == 'G') tmp_g++;
    else tmp_b++;
    rep(i,j){
      if(s[i] == s[j]) continue;
      else if(s[i] != 'R' && s[j] != 'R'){
        ans += r-tmp_r;
        //if((j-i)%2 == 0 && s[(j-i)/2] == 'R') ans--;
        if(j*2-i < n && s[j*2-i] == 'R') ans--;
      }
      else if(s[i] != 'G' && s[j] != 'G'){
        ans += g-tmp_g;
        //if((j-i)%2 == 0 && s[(j-i)/2] == 'G') ans--;
        if(j*2-i < n && s[j*2-i] == 'G') ans--;
      }
      else if(s[i] != 'B' && s[j] != 'B'){
        ans += b-tmp_b;
        //if((j-i)%2 == 0 && s[(j-i)/2] == 'B') ans--;
        if(j*2-i < n && s[j*2-i] == 'B') ans--;
      }
    }
  }
  
  printf("%lld\n",ans);
}


Measured memory_bytes: 3700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringBuilder sb = new StringBuilder();
		while (!(line = br.readLine()).equals("0")) {

			int total = Integer.parseInt(line);
			for (int i = 0; i < 9; i++) {
				total -= Integer.parseInt(br.readLine());
			}
			sb.append(total + "\n");
		}
		System.out.print(sb.toString());
	}
}

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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18
const int N=3005;
int dp[N][N];
void solve(){
  int n ;
  string s;
  cin>>n>>s;
  int l,r;
  vi pref(n+1,1);
  pref[0]=0;
  for(int i=2;i<=n;i++){
    vi p(n+1);
    for(int j=1;j<=i;j++){
      if(s[i-2]=='<')l=1,r=j-1;
      else l=j,r=i-1;
      dp[i][j]=(mod+pref[r]-pref[l-1])%mod;
      p[j]=(p[j-1]+dp[i][j])%mod;
    }
    pref=p;
  }
  cout<<pref[n];
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

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


int main(){
    string S, T;
    cin >> S >> T;
    int K = S.size();
    int L = T.size();
    ll ans = K;
    for (int i = 0; i < K-L+1; i++) {
        ll change = 0;
        for (int j = 0; j < L; j++) {
            if (S[i+j] != T[j]) change++;
        }
        ans = min(ans, change);
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);

    int n, k, a;
    cin >> n >> k;
    //vector<int> a(n);
    for (int i = 0; i < n; i++) scanf("%d", &a);

    int ans = (n - 1) / (k - 1);
    if ((n - 1) % (k - 1) != 0) ans++;
    cout << ans << endl;
}

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

int main() {
  ll n;cin>>n;
  ll sm = 0;
  rep(i,100000) {
    sm+=i;
    if (sm >= n) {
      cout << i;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
//import javafx.util.Pair;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		
		int X=Integer.parseInt(s[0]);
		int Y=Integer.parseInt(s[1]);
		int Z=Integer.parseInt(s[2]);
		
		out.println(Z+" "+X+" "+Y);
		
		
	}
	
	
}




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
typedef long long lint;
typedef vector<int> vi;

const int mod = 1e9 + 7;

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

lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}

// ?????????????????????????????????????????????
lint extgcd(lint a, lint b, lint& x, lint& y) {
	lint d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}

bool is_prime(lint n) {
	for (lint i = 2; i * i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

// n????´???° ???????????????unsorted
/*
vi divisor(lint n) {
	vi res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.pb(i);
			if (n / i != i) res.pb(n / i);
		}
	}

	return res;
}*/
vector<lint> divisor(lint n) {
	vector<lint> res;
	deque<lint> d;

	lint i = sqrt(n);
	if (i * i == n) {
		d.push_back(i);
		i--;
	}
	for (; i > 0; --i) {
		if (n % i == 0){
			d.push_front(i);
			d.push_back(n / i);
		}
	}

	res.insert(res.begin(), d.begin(), d.end());
	return res;
}


// 2 * 2 * 3 * 5 * 5 * 5 = {2:2, 3:1,5:3} ???????????? map ????????£????????????
map<int, int> prime_factor(lint n) {
	map<int, int> res;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}

	if (n != 1) res[n] = 1;
	return res;
}

const int MAX_N = 202020;
int prime[MAX_N];
bool memo[MAX_N + 1];

// ?´???°?????¨?????? n??\???????´???°????????°?????????
int sieve(int n) {
	int p = 0;
	memset(memo, true, sizeof(memo));
	memo[0] = memo[1] = false;

	for (int i = 2; i <= n; ++i) {
		if (memo[i]) {
			prime[p++] = i;
			for (int j = i * 2; j <= n; j += i) {
				memo[j] = false;
			}
		}
	}

	return p;
}

const lint MAX_LEN = 1000000;
const lint MAX_SQRT_B = 1000000;
bool memo_all[MAX_LEN];         //i means i + a
bool memo_small[MAX_SQRT_B];

// [a, b)????´???°????????°???????????????
lint count_prime(lint a, lint b) {
	for (int i = 0; (lint)i * i < b; i++) memo_small[i] = true;
	for (int i = 0; i < b - a; i++)     memo_all[i] = true;

	for (int i = 2; (lint)i * i < b; i++) {
		if (memo_small[i]) {
			for (int j = 2; (lint)j * j < b; j += i) memo_small[j] = false;
			for (lint j = max(2LL, (a + i - 1) / i) * i; j < b; j += i) memo_all[j - a] = false;
		}
	}

	lint ret = 0;
	for (lint i = a; i < b; i++) {
		if (memo_all[i]) ret++;
	}
	return ret;
}

// k???????????§????????£??????????????°??????{a_0 : 0, a_1 : 1, a_2 : 1, ... }
lint Fib[101010];
int calcFib(int k) {
	Fib[0] = 0;
	Fib[1] = Fib[2] = 1;
	for (int i = 3; i <= k; ++i) {
		Fib[i] = Fib[i - 1] + Fib[i - 2];
		// Fib[i] %= mod;
	}

	return Fib[k];
}


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

	cout << n << ":";
	map<int, int> po = prime_factor(n);
	for (auto u : po) {
		rep(_, u.second){
			cout << " " << u.first;
		}
	}
	
	cout << endl;
}

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

using namespace std;

bool compare(pair<int,int> a,pair<int,int> b){
	return a.second > b.second;
}

int main(){
	int N,M;
	long long int ans;
	int j;
	
	cin >> N >> M;
	
	vector<int> A(N);
	vector<pair<int,int>> B(M);
	
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	for(int i=0; i<M; i++){
		cin >> B[i].first >> B[i].second;
	}
	
	sort(A.begin(),A.end());
	
	sort(B.begin(),B.end(),compare);
	
	j=0;
	for(int i=0; i<N; i++){
		if(A[i] < B[j].second)	A[i]=B[j].second;
		B[j].first--;
		
		if(B[j].first == 0){
			if(j != M-1)	j++;
			else	break;
		}
	}
	
	ans=0;
	for(int i=0; i<N; i++){
		ans+=A[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int x; cin >> x;
	int ans = x / 500 * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	cout << ans << endl;
}


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

#define INF 2000000000

typedef pair<int, int> P;
struct edge{ int to, cost;};

int n;
vector<edge> G[10000];
int d[10000];

void dijkstra(int s){
  
  priority_queue<P, vector<P>, greater<P> > que;
  
  for(int i = 0;i < n;i++) d[i] = INF;
  d[s] = 0;
  que.push(P(0, s));
  
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    
    if(d[v] < p.first) continue;
    for(int i = 0;i < G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  
  int u, k;
  edge e;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> e.to >> e.cost;
      G[u].push_back(e);
    }
  }
  
  dijkstra(0);
  
  for(int i = 0;i < n;i++) cout << i << " " << d[i] << endl;
  
  return 0;
}


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

int main() {
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    cout << H*W-(h*W+w*H-h*w) << endl;
}

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

bool v[99][99][99];
int a[3];

int main() {
  for(int i=0;i<3;i++) scanf("%d",a+i);
  sort(a,a+3);
  queue<vector<int>> q;
  q.emplace(vector<int>({a[0],a[1],a[2],0}));
  v[a[0]][a[1]][a[2]] = true;
  int ans = 1e9;
  while(!q.empty()) {
    vector<int> c = q.front();
    q.pop();
    if(c[0] == c[1] && c[1] == c[2]) {
      ans = c[3];
      break;
    }
    vector<int> t = c;
    t[3]++;
    t[0]++;
    t[1]++;
    sort(t.begin(),t.begin()+3);
    if(!v[t[0]][t[1]][t[2]]) {
      v[t[0]][t[1]][t[2]] = true;
      q.push(t);
    }
    t = c;
    t[3]++;
    t[0]++;
    t[2]++;
    sort(t.begin(),t.begin()+3);
    if(!v[t[0]][t[1]][t[2]]) {
      v[t[0]][t[1]][t[2]] = true;
      q.push(t);
    }
    t = c;
    t[3]++;
    t[0]+=2;
    sort(t.begin(),t.begin()+3);
    if(!v[t[0]][t[1]][t[2]]) {
      v[t[0]][t[1]][t[2]] = true;
      q.push(t);
    }
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 512
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
e=[[]for _ in[0]*n]
for a,b in zip(t[:-n:2],t[1:-n:2]):e[a-1]+=b-1,;e[b-1]+=a-1,
q=[0]
f=q*n
while q:
 v=q.pop();n-=1;f[v]=c[n]
 for w in e[v]:q+=[w]*(f[w]<1)
print(sum(c[:-1]),*f)

Measured memory_bytes: 6732
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll ans = 0;
	if(a+b>c*2){
		int ab = min(x, y);
		ans += ab * c * 2;
		x -= ab; y -= ab;
	}
	ll ans2 = ans;
	ans += x*a;
	ans += y*b;
	ans2 += max(x,y)* c*2;
	cout<<min(ans, ans2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    ll ans = 1;
    if(a[0] != a[1]) ans++;
    if(a[1] != a[2]) ans++;
    print(ans);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb emplace_back
#define pii pair<int,int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}
const int N=1e2+10;
int a[N],n;
int main()
{
    n=read();
    rep(i,1,n) a[i]=read();
    int ans=0;
    rep(i,1,n)
    {
        if(i%2&&a[i]%2) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3592
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, k := readInt(), readInt()
	ans := 0
	for i := 0; i < n; i++ {
		x := readInt()
		ans += min(x, k-x) * 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int kSize = 101;

vector<int> adj[kSize];
bool isMarked[kSize];
int d[kSize];

void dfs(int v) {
    isMarked[v] = true;

    for (int i = 0; i < adj[v].size(); ++i) {
        int u = adj[v][i];
        if (!isMarked[u]) {
            dfs(u);
        }
    }
}

void bfs() {
    queue<int> q;
    q.push(1);
    d[1] = 0;
    int dis = 0;
    isMarked[1] = true;

    while (!q.empty()) {
        int size = q.size();
        for (int i = 0; i < size; ++i) {
            int u = q.front();
            q.pop();
            for (int j = 0; j < adj[u].size(); ++j) {
                int v = adj[u][j];
                if (!isMarked[v]) {
                    q.push(v);
                    isMarked[v] = true;
                }
            }

            d[u] = dis;
        }

        dis++;
    }
}

int main() {
    int n;
    fill(isMarked, isMarked + kSize, false);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            adj[id].push_back(v);
        }
    }

    bfs();
    for (int i = 1; i <= n; ++i) {
        if (i == 1) {
            cout << i << " " << d[i] << endl;
        } else {
            if (d[i] > 0) {
                cout << i << " " << d[i] << endl;
            } else {
                cout << i << " " << -1 << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3164
from collections import defaultdict
import sys
input = sys.stdin.readline


def main():
    node_num, edge_num = map(int, input().split())
    graph_data = defaultdict(set)

    abcde = [list(map(int, input().split())) for i in range(edge_num)]

    for i in range(edge_num):
        a, b = abcde[i]
        graph_data[a].add(b)

    start, goal = map(int, input().split())
    visit_flg = [0] * (node_num + 1)
    visit_flg2 = [0] * (node_num + 1)
    visit_flg3 = [0] * (node_num + 1)
    visit_flg[start] = 1

    now_set = set()
    now_set.add(start)
    next_set = set()

    ans = 0

    while len(now_set) > 0:
        ans += 1

        if visit_flg[goal]:
            break

        for now_node in now_set:
            search_now_set = set()
            search_now_set.add(now_node)
            search_next_set = set()

            for i in range(3):
                for search_now_node in search_now_set:
                    if i == 1 and visit_flg2[search_now_node]:
                        continue
                    elif i == 1:
                        visit_flg2[search_now_node] = 1
                    if i == 2 and visit_flg3[search_now_node]:
                        continue
                    elif i == 2:
                        visit_flg3[search_now_node] = 1
                    search_next_set |= graph_data[search_now_node]
                search_now_set = search_next_set
                search_next_set = set()

            for ele_check in search_now_set:
                if visit_flg[ele_check]:
                    continue
                else:
                    visit_flg[ele_check] = 1
                    next_set.add(ele_check)

                if visit_flg[goal]:
                    break

        if visit_flg[goal]:
            break

        now_set = next_set
        next_set = set()

    if visit_flg[goal]:
        print(ans)
    else:
        print(-1)












if __name__ == '__main__':
    main()


Measured memory_bytes: 96476
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

struct pro {
	int q;
	string name;
};

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

	queue<struct pro> que;
	int n, q0;
	int ans = 0;

	cin >> n >> q0;
	rep(i,0,n) {
		int qtmp;
		string ntmp;
		cin >> ntmp >> qtmp;
		struct pro p;
		p.q = qtmp;
		p.name = ntmp;
		que.push(p);
	}

	while(!que.empty()) {
		struct pro p = que.front();
		que.pop();
		if(p.q > q0) {
			p.q -= q0;
			ans += q0;
			que.push(p);
		} else {
			ans += p.q;
			cout << p.name << " " << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4412
X=[]
for i in range(3):
    a,b=map(int,input().split())
    X.append(a)
    X.append(b)
   
count_1=0
count_2=0
count_3=0
count_4=0
for i in range(6):
    if X[i]==1:
        count_1+=1
    if X[i]==2:
        count_2+=1
    if X[i]==3:
        count_3+=1
    if X[i]==4:
        count_4+=1
        
H=[count_1,count_2,count_3,count_4]

if set(H)=={1,3}:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int Pow6[10] = {}, Pow9[10] = {};
int Func(int n, int Ans) {
	if (n < 6) {
		return Ans + n;
	}
	int Cmp6, Cmp9;
	for (int i = 0; i < 10; i++) {
		if (Pow6[i] <= n) {
			Cmp6 = Pow6[i];
		}
		else break;
	}
	for (int i = 0; i < 10; i++) {
		if (Pow9[i] <= n) {
			Cmp9 = Pow9[i];
		}
		else break;
	}
	Ans++;
	return min(Func(n - Cmp6, Ans), Func(n - Cmp9, Ans));
}
signed main() {
	int Cmp = 1;
	Pow6[0] = 1, Pow9[0] = 1;
	for (int i = 1; i < 100; i++) {
		if (Cmp * 6 <= 100000) {
			Pow6[i] = Cmp * 6;
			Cmp *= 6;
		} else {
			break;
		}
	}
	Cmp = 1;
	for (int i = 1; i < 100; i++) {
		if (Cmp * 9 <= 100000) {
			Pow9[i] = Cmp * 9;
			Cmp *= 9;
		} else {
			break;
		}
	}
	// for (int i = 0; i < 10; i++) {
	// 	cout << Pow6[i] << " ";
	// }
	// cout << endl;
	// for (int i = 0; i < 10; i++) {
	// 	cout << Pow9[i] << " ";
	// }
	// cout << endl;
	Pow6[7] = INF, Pow9[6] = INF;
	int n;
	cin >> n;
	cout << Func(n, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

void solve(){
    int n;
    cin>>n;
    unordered_map<string,int> idx;
    vector<int> table(n,0);
    for(int i=0;i<n;i++){
        string s;
        int t;
        cin>>s;
        cin>> t;
        idx[s] = i;
        table[i] = t;
    }
    string start;
    cin>>start;
    LL ans = 0;
    for(int i = idx[start]+1;i<n;i++){
        ans += table[i];
    }
    cout<<ans<<endl;
}

int main(){
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]

ans="No"
for j in range(N-M+1):
    for i in range(N-M+1):
        isMatch=True
        for y in range(M):
            for x in range(M):
                if A[j+y][i+x]!=B[y][x]:
                    isMatch=False
                    
        if isMatch:
            ans="Yes"
            break        

print(ans)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
 template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  int n,x;
  cin>>n>>x;
  char num[x];
  for(int i=0;i<x;i++){
    cin>>num[i];
  }
  string s;
  int ok=0;
  for(int i=n;i<100010;i++){
    s=to_string(i);
    for(int j=0;j<s.size();j++){
      for(int k=0;k<x;k++){
        if(s[j]==num[k])
          ok++;
      }
    }
    if(ok==0){
      cout<<i<<endl;
      break;
    }
    else
      ok=0;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int N, Q;
    vector<int> acs;
    bool a;
    scanf("%d %d", &N, &Q); getchar();
    for (int i=0; i<N; i++) {
        int c = getchar();
        if (a && c == 'C') acs.push_back(i-1);
        if (c == 'A') a = true;
        else a = false;
    }
    for (int i=0; i<Q; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        auto first = lower_bound(acs.begin(), acs.end(), l-1),
             last = lower_bound(acs.begin(), acs.end(), r-1);
        printf("%ld\n", last - first);
    }
    return 0;
}

Measured memory_bytes: 1148
#include <stdio.h>

struct Node{int p,l,r;};

struct Node T[10000];
int n,D[10000],H[10000];

void setDepth(int u,int d){
  if(u==-1){
    return;
  }
  D[u]=d;
  setDepth(T[u].l,d+1);
  setDepth(T[u].r,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=-1){
    h1=setHeight(T[u].l)+1;
  }
  if(T[u].r!=-1){
    h2=setHeight(T[u].r)+1;
  }
  return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
  if(T[u].p==-1){
    return -1;
  }
  if(T[T[u].p].l!=u&&T[T[u].p].l!=-1){
    return T[T[u].p].l;
  }
  if(T[T[u].p].r!=u&&T[T[u].p].r!=-1){
    return T[T[u].p].r;
  }
  return -1;
}

void print(int u){
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].p,getSibling(u));
  int deg=0;
  if(T[u].l!=-1){
    deg++;
  }
  if(T[u].r!=-1){
    deg++;
  }
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
  if(T[u].p==-1){
    printf("root\n");
  }
  else if(T[u].l==-1&&T[u].r==-1){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int i,va,le,ri,root=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&va,&le,&ri);
    T[va].l=le;
    T[va].r=ri;
    if(le!=-1){
      T[le].p=va;
    }
    if(ri!=-1){
      T[ri].p=va;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==-1){
      root=i;
    }
  }
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++){
    print(i);
  }

  return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
 
int main(){
    int n, i;
    double x[1001] = {}, y[1001] = {}, p1, p2, p3, pinf, p2c, p3c;
 
    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        scanf("%lf", &x[i]);
    }
    for( i = 0; i < n; i++ ){
        scanf("%lf", &y[i]);
    }
    for( i = 0, p1 = 0; i < n; i++ ){
        p1 += fabs( x[i] - y[i] );
    }
    for( i = 0, p2 = 0; i < n; i++ ){
        p2 += pow( fabs( x[i] - y[i] ), 2 );
    }
    p2c = sqrt( p2 );
    for( i = 0, p3 = 0; i < n; i++ ){
            p3 += pow( fabs( x[i] - y[i] ), 3 );
    }
    p3c = pow( p3, 1.0 / 3.0 );
    for( i = 0, pinf = 0; i < n; i++ ){
        if( pinf < fabs( x[i] - y[i] ) ){
            pinf = fabs( x[i] - y[i] );
        }
    }
    printf("%f\n%f\n%f\n%f\n", p1, p2c, p3c, pinf);
    return 0;
}


Measured memory_bytes: 2060
import java.util.Scanner;

public class Main {

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

		String s = sc.next();

		boolean[] b = new boolean[26];
		for (int i = 0; i < s.length(); i++) {
			b[s.charAt(i) - 'a'] = true;
		}

		String ans = "None";
		for (int i = 0; i < b.length; i++) {
			if (!b[i]) {
				ans = "" + (char)('a' + i);
				break;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 25940
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

const long SIZE=200010;  //Nの最大値*2より大
long Sum(const long BIT[], long a){
    long ans=0;
    while(a){
        ans+=BIT[a];
        long least=a&-a;  //これで最も末位の1のビットを求める
        a-=least;
    }
    return ans;
}

void Add( long BIT[], long a, long x )
{
    while(a<=SIZE){
        BIT[a]+=x;
        long least=a&-a; //sumのleastど同様
        a+=least; //leastの桁を繰り上げます。
    }
    return;
}

long st_check( long n, long* a, long tmp )
{
    std::vector<long> s(n+1);
    long i;
    s[0] = n+1;
    for(i=0; i<n; i++) {
        s[i+1] = s[i];
        if(a[i]>=tmp) {
            s[i+1] ++;
        }
        else {
            s[i+1] --;
        }
    }

    long BIT[SIZE+1] = {0};
    long ans = 0;
    for(i=0; i<=n; i++) {
        ans += Sum(BIT, s[i]);
        Add(BIT, s[i], 1);
    }

    return ans;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    std::vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &(a[i]));
    }
    long m = (n*(n+1)/2+1)/2;

    long ll = 0;
    long rr = 1000000001;

    long ans = 0;
    while( 1 ) {
        if(rr-ll==1) {
            ans = ll;
            break;
        }
        long mid = (rr-ll)/2+ll;
        if( st_check( n, &(a[0]), mid ) >= m ) {
            ll = mid;
        }
        else {
            rr = mid;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 3340
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int n, a[105][105];

int main() {
    cin >> n;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        int new_sum = 0;
        for (int j = 1; j <= i; j++) new_sum += a[1][j];
        for (int j = i; j <= n; j++) new_sum += a[2][j];
        sum = max(sum, new_sum);
    }
    cout << sum << endl;
    return 0;
}

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

struct test {
    int H, A;
    int ans;
} td[] =
    {
        {
            10, 4,
            3,
        },
        {
            1, 10000,
            1,
        },
        {
            10000, 1,
            10000
        },
    };

void
solver(int h, int a)
{
    if (h%a==0)
        printf("%d\n", h/a);
    else
    {
        printf("%d\n", h/a+1);
    }
}

int
main(int argc, char *argv[])
{
    int H, A;
#if 0
    int tt;
    for(tt=0;tt<sizeof(td)/sizeof(struct test); tt++) {
        solver(td[tt].H, td[tt].A);
        printf("%d\n",td[tt].ans);
    }
#endif
#if 1
    scanf("%d%d", &H, &A);
    solver(H, A);
#endif
    return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int ans = 1;
		int flg = 1;
		for (int i = 0;i < n;i++) {
			int a;
			cin >> a;
			if (a >= 2)flg = 0;
			if (a != 0)ans++;
		}
		if (flg == 1)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,A,B,a;
  
  cin >> N >> A >> B;
  a=N*A;
  if(a>=B){
  	cout << B << endl;
  }else if(a<B){
  	cout << a << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
   int n , a , b ;
   cin >> n >> a >> b ;
   int keta = 0 ;
   int now ;
   int ans = 0 ;
   for(int i = 0 ; i < n ; i ++) {
       now = i+1 ;
       while(now > 0){
           keta += now % 10 ;
           now = now / 10 ;
       }
       if(a <=keta&& keta <=b){
           ans += i + 1 ;
       }
       keta = 0 ;
       
   }
   
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable LIM = 100 * 10^^3 + 10;

int N;
long W;
long[] X;
int[] V;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      W = readLong();
      X = new long[N];
      V = new int[N];
      foreach (i; 0 .. N) {
        X[i] = readLong();
        V[i] = readInt();
      }
      auto dp = new long[LIM];
      dp[] = W + 1;
      dp[0] = 0;
      foreach (i; 0 .. N) {
        foreach_reverse (v; V[i] .. LIM) {
          chmin(dp[v], dp[v - V[i]] + X[i]);
        }
      }
      int ans;
      foreach (v; 0 .. LIM) {
        if (dp[v] <= W) {
          chmax(ans, v);
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


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

//MS D
int main(){
	int n;
	cin >> n;
	long long a[87];
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	long long yen = 1000;
	for (int i = 1; i <= n - 1; i++){
		long long fx = 0;
		if (a[i] < a[i + 1]){
			fx = yen / a[i];
			yen += (a[i + 1] - a[i])*fx;
		}
	}
	cout << yen << endl;
	return 0;
}

Measured memory_bytes: 3568
h, w, k = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = []
n = 1
cnt = 0
for i in range(h):
    if "#" in S[i]:
        ans = []
        for j in range(w):
            if S[i][j] == "#":
                for _ in range(j+1-len(ans)):
                    ans.append(str(n))
                n += 1
        if len(ans) < w:
            x = ans[-1]
            for _ in range(w-len(ans)):
                ans.append(x)
    if ans:
        for _ in range(i+1-cnt):
            print(" ".join(ans))
            cnt += 1



Measured memory_bytes: 9960
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

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

void fastIO() {
    std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
    while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

int main(){
    int a, b, n;
    scan(n, a, b);
    int diff = b - a;
    printf("%s\n", diff % 2 == 0? "Alice": "Borys");
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =1e6+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int main()
{
	int n,x,t;
	scanf("%d %d %d",&n,&x,&t);
	if(n%x) n=(n/x)+1;
	else n=n/x;
	printf("%d\n",n*t);
} 

Measured memory_bytes: 3776
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static void Main()
    {
        var n = CRL().ToInt();
        var csfs = new long[n][];
        for (int i = 0; i < n - 1; i++)
        {
            csfs[i] = CRL().ArrayLongs();
        }

        for (int i = 0; i < n - 1; i++)
        {
            long sum = 0;
            for (int j = i; j < n - 1; j++)
            {
                var csf = csfs[j];
                var time = csf[0];
                var first = csf[1];
                var between = csf[2];
                if (sum < first)
                {
                    sum = first;
                }

                if (sum % between != 0)
                {
                    sum += between - (sum % between);
                }

                sum += time;
            }

            CWL(sum);
        }
        CWL("0");
    }
}

public static partial class Program
{
    //テンプレここから
    private static long ToInt(this string str) => long.Parse(str);
    private static long[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] { 0, -1, 0, 1 };
    public static long[] dy = new long[] { -1, 0, 1, 0 };
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array)
    {
        var list = array.ToList();
        list.Sort();
        return list.ToArray();
    }
    //テンプレここまで
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int sx; int sy; int tx; int ty;
	while (~scanf("%d%d%d%d", &sx, &sy, &tx, &ty)) {
		int x = tx - sx, y = ty - sy;
		string ans;
		rep(i, x)
			ans += 'R';
		rep(i, y)
			ans += 'U';
		rep(i, x)
			ans += 'L';
		rep(i, y)
			ans += 'D';
		ans += 'L';
		rep(i, y + 1)
			ans += 'U';
		rep(i, x + 1)
			ans += 'R';
		ans += 'D';
		ans += 'R';
		rep(i, y + 1)
			ans += 'D';
		rep(i, x + 1)
			ans += 'L';
		ans += 'U';
		puts(ans.c_str());
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
   ll N,a[200010];
   cin>>N;
   
   ll mod=1000000007;
   ll sum=0;
   for(int i=0;i<N;i++){
       cin>>a[i];
       sum+=a[i];
       sum%=mod;
   }
   ll ans=0;

   for(int i=0;i<N;i++)
   {
       sum-=a[i];
       if(sum<0) sum+=mod;

       ans+=a[i]*sum;
       ans%=mod;
   }
    cout<<ans<<endl;
   }

Measured memory_bytes: 5136
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const int N = 200000;
ll fac[N*2+10];
ll invfac[N*2+10];

ll mypow(ll x, ll n) {
  if(n == 0) return 1;
  if(n % 2 == 0) return mypow(x*x%MOD, n/2);
  return mypow(x*x%MOD, n/2) * x % MOD;
}

inline ll cmb(ll n, ll k) {
  if(k < 0 || n < k) return 0;
  return fac[n] * invfac[k] % MOD * invfac[n-k] % MOD;
}

int main(void) {
  fac[0] = 1;
  REP(i, N*2) {
    fac[i+1] = fac[i] * (i+1) % MOD;
  }
  invfac[N*2] = mypow(fac[N*2], MOD-2);
  for(int i = N*2; i > 0; --i) {
    invfac[i-1] = invfac[i] * i % MOD;
  }
  ll n, m, k;
  cin >> n >> m >> k;
  ll res = 0;
  for(ll d = 1; d <= n-1; ++d) {
    res = (res + d*m %MOD *m %MOD *(n-d)%MOD) % MOD;
  }
  for(ll d = 1; d <= m-1; ++d) {
    res = (res + d*n %MOD *n %MOD *(m-d)%MOD) % MOD;
  }
  cout << res * cmb(n*m-2, k-2) % MOD << endl;
  return 0;
}


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

int main(){
  char c1[3], c2[3];
  cin >> c1 >> c2;
  if (c1[0] == c2[2] & c1[1] == c2[1] & c1[2] == c2[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

int main()
{
    int x, y, z;
    
    while(1){
        cin >> x >> y;
        if( x == 0 && y == 0 ) break;
    
    if(x < y){
        cout << x << " " << y << endl;
    } else {
        cout << y << " " << x << endl;
    }
  
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define INF 1e16+1
#define se second
#define fi first

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector< vector<pll> > vvpll;

ll i,j,n,m,x,a,b,w,k;
vll dp,v;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>a;
		v.pb(a);
	}
	dp.assign(n,INF);
	dp[0]=0;
	for(i=0;i<n;i++){
		for(j=1;j<=k&&i+j<n;j++){
			dp[j+i] = min(dp[j+i] , dp[i]+abs(v[i]-v[i+j]));
		}
	}
	cout<<dp[n-1]<<'\n';
}


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

int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  long long int p = a*c;
  long long int q = a*d;
  long long int r = c*b;
  long long int s = b*d;
  cout << max(p,max(q,max(r,s)));
}

Measured memory_bytes: 3628
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int x = saori.saori_hayami();
		for(int A = 0;A <= 1000;A++){
			for(int B =-1000;B <= 1000;B++){
			  double res = Math.pow(A, 5) - Math.pow(B, 5);
			  if(res == x){
				System.out.println(A + " " + B);
				return;
			  }
			}
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main() {

    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    cout << H2 * 60 + M2 - H1*60 - M1 - K << endl;

    return 0;
}

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

struct DSU {
    int n;
    vector<int> p, sz;

    DSU(int n) : n(n) {
        p.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; i++) {
            p[i] = i;
            sz[i] = 1;
        }
    }

    int find_set(int x) {
        if (x == p[x]) return x;
        return p[x] = find_set(p[x]);
    }

    void union_set(int x, int y) {
        x = find_set(x); y = find_set(y);
        if (x != y) {
            if (sz[x] < sz[y]) swap(x, y);
            sz[x] += sz[y];
            p[y] = x;
        }
    }
};

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

    int n, q;
    cin >> n >> q;
    DSU dsu(n);
    while (q--) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) dsu.union_set(u, v);
        else cout << (dsu.find_set(u) == dsu.find_set(v)) << '\n';
    }
}

Measured memory_bytes: 4564
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


class Process(object):

    def __init__(self, name, time):
        self.name = name
        self.time = int(time)


def schedule(processes, quantum):
    queue = collections.deque(processes)
    time = 0
    while len(queue) > 0:
        p = queue.popleft()
        rest_time = p.time - quantum
        if rest_time > 0:
            time += quantum
            queue.append(Process(p.name, rest_time))
        else:
            time += p.time
            print("{name} {time:d}".format(name=p.name, time=time))


def main():
    [n, q] = list(map(int, input().split()))
    processes = [Process(*input().split()) for i in range(n)]
    schedule(processes, q)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22428