akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#include <queue>
#define INF 1000000000000000009;
#define WARU 1000000007;

using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}

int main() {
	int N = 0;
	long long ans = 1, zyo = 1, ka = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		ans *= 10;
		ans = ans % 1000000007;
	}
	//cout << ans << endl;
	for (int i = 0; i < N; i++) {
		zyo *= 9;
		zyo = zyo % 1000000007;
	}
	ans -= zyo;
	zyo = 1;
	//cout << ans << endl;
	for (int i = 0; i < N; i++) {
		zyo *= 9;
		zyo = zyo % 1000000007;
	}
	ans -= zyo;
	zyo = 1;
	//cout << ans << endl;
	for (int i = 0; i < N; i++) {
		ka *= 8;
		ka = ka % 1000000007;
	}
	//cout << ans << endl;
	ans += ka;
	ans %= 1000000007;
	ans += 1000000007;
	ans %= 1000000007;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3552
N, Y = map(int, input().split())

Y = Y // 1000
k10, k5, k1 = -1, -1, -1
success = False
price = 0

for i in range(N+1):
  for j in range(N-i+1):
    k = N - i - j
    price = i * 10 + j * 5 + k * 1
    if price == Y:
      k10, k5, k1 = i, j, k
      success = True
      break

  if success:
    break

print(k10, k5, k1)

Measured memory_bytes: 3188
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

    int r,d,x;
	cin>>r>>d>>x;
	rep(i,10){
		x=r*x-d;
		cout<<x<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		int num[101]={},ans=0,now=0;
		for(int i=0,x,y;i<n;i++){
			cin>>x;
			for(;x>0;x--){
				cin>>y;
				num[y]++;
			}
		}
		for(int i=100;i>0;i--){
			if(now<=num[i]){
				now=num[i];
				ans=i;
			}
		}
		if(now<m)cout<<0<<endl;
		else cout<<ans<<endl;
	}
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let km = (n - 1) * (n - 2) / 2;
    if k > km {
        println!("-1");
        return;
    }

    println!("{}", n - 1 + km - k);
    for i in 1..n {
        println!("{} {}", i, n);
    }

    let mut t = km;
    'outer: for i in 1..n {
        for j in 1..i {
            if t == k {
                break 'outer;
            }

            println!("{} {}", j, i);
            t -= 1;
        }
    }
}


Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author hamaron
 */

#include <iostream>
#include <fstream>

#include <iostream>

using namespace std;

class CVacation {
public:
	void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        int dp[N+1][3];
        for (int i = 1; i < N + 1; i++) {
            int happiness[3];
            in >> happiness[0] >> happiness[1] >> happiness[2];
            if (i == 1) {
                dp[1][0] = happiness[0];
                dp[1][1] = happiness[1];
                dp[1][2] = happiness[2];
                continue;
            }

            for (int j = 0; j < 3; j++) {
                if (j == 0) {
                    dp[i][j] = max(dp[i-1][1] + happiness[j], dp[i-1][2] + happiness[j]);
                    continue;
                }

                if (j == 1) {
                    dp[i][j] = max(dp[i-1][0] + happiness[j], dp[i-1][2] + happiness[j]);
                    continue;
                }

                dp[i][j] = max(dp[i-1][0] + happiness[j], dp[i-1][1] + happiness[j]);
            }
        }

        int temp = 0;
        for (int j = 0; j < 3; j++) {
            temp = max(temp, dp[N][j]);
        }

        out << temp;
	}
};


int main() {
	CVacation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> C(N);
	vector<int> cnt(M, 0);
	for(int i = 0; i < N; i++) {
		cin >> C[i];
		C[i]--;
		cnt[C[i]]++;
	}

	vector<vector<int>> acc(M, vector<int>(N + 1, 0));
	for(int c = 0; c < M; c++) {
		int sum = 0;
		for(int i = 0; i < N; i++) {
			sum += C[i] == c ? 1 : 0;
			acc[c][i + 1] = sum; // acc[c][i + 1] : [0, i]
		}
	}

	vector<int> dp(1 << M, 1 << 30);
	dp[0] = 0;

	for(int i = 0; i < 1 << M; i++) {
		int length = 0;
		for(int j = 0; j < M; j++) {
			if (i >> j & 1) {
				length += cnt[j];
			}
		}

		for(int j = 0; j < M; j++) {
			if (i >> j & 1) {
				dp[i] = min(dp[i], dp[i & ~(1 << j)] + cnt[j] - (acc[j][length] - acc[j][length - cnt[j]]) );
			}
		}
	}

	cout << dp[(1 << M) - 1] << endl;

	return 0;
}



Measured memory_bytes: 14996
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int n,k;
  vector<long long> h(101000);
  vector<long long> dp(101000);

  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 0; i < n; i++) dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
    }
  }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++)
	{
		s[i]-='A';
		s[i]+=n;
		s[i]%=26;
	}
	for(int i=0;i<s.size();i++)
		cout<<char(s[i]+'A');
	return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 3e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi m;
vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	m = vi(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}
lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}
int dx[4]={-1,0,0,1}, dy[4]={0,1,-1,0};

// ---- コーディングはここから！ ('-')7

void solve(){
	int n; cin>>n;
	vvi v(n+1);
	fore(i,0,n-1){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	if(n==1){cout<<2<<ENDL;return;}
	vvl dp(n+1,vl(2,1));
	auto f=[&](auto f, int u, int pr)->void{
		for(auto i:v[u])if(i!=pr)f(f,i,u);
		for(auto i:v[u])if(i!=pr)dp[u][1]=PROD(dp[u][1],SUM(dp[i][0],dp[i][1]));
		for(auto i:v[u])if(i!=pr)dp[u][0]=PROD(dp[u][0],dp[i][1]);
	};
	f(f,1,1);

	cout<<SUM(dp[1][0],dp[1][1])<<ENDL;
}

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


Measured memory_bytes: 22328
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

int main(){
	int N; 
	cin >> N;
	vLL x(N), y(N);
	map<P, int>	mp;
	for(int i = 0;i < N;i++)	cin >> x[i] >> y[i];
	for(int i = 0;i < N;i++){
		for(int j = 0;j < N;j++){
			if(i != j){
				LL xi = x[i]-x[j];
				LL yi = y[i]-y[j];
				mp[P(xi, yi)]++;
			}
		}
	}
	int num = 0;
	for(auto v : mp)	num = max(num, v.second);
	cout << (N-num) << endl; 
}

Measured memory_bytes: 384
N = int(input())
mod = 10**9+7
memo = [{} for _ in range(N+1)]
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >=1:
            t[i-1],t[i] = t[i],t[i-1]
        if ''.join(t).count('AGC') >=1:
            return False
    return True
def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur ==N: return 1
    res = 0
    for c in 'ACGT':
        if ok(last3+c):
            res  = (res + dfs(cur+1,last3[1:]+c))%mod
    memo[cur][last3] = res
    return res
print(dfs(0,'TTT'))

Measured memory_bytes: 75820
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, k, a[500], sum = 0, b[500], ans = 1;
  vector<int> v;
  pair<int, int> l, r;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      v.push_back(i);
      if (i != sum / i) {
        v.push_back(sum / i);
      }
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < n; j++) {
      b[j] = a[j] % v[i];
    }
    sort(b, b + n);
    l = {0, 0};
    r = {n - 1, 0};
    while (l.first < r.first) {
      if (b[l.first] == b[r.first] && b[l.first] == 0) {
        l.first++;
        r.first--;
      } else if (b[l.first] == 0) {
        l.first++;
      } else if (l.second == r.second) {
        l.second += b[l.first];
        r.second += v[i] - b[r.first];
        l.first++;
        r.first--;
      } else if (l.second < r.second) {
        l.second += b[l.first];
        l.first++;
      } else {
        r.second += v[i] - b[r.first];
        r.first--;
      }
    }
    if (l.second <= k && l.first == r.first && b[l.first] == 0) {
      ans = v[i];
    }
    if (l.second <= k && l.first > r.first && l.second == r.second) {
      ans = v[i];
    }
    if (l.first == r.first &&
        (l.second <= k && l.second == r.second + v[i] - b[r.first] ||
         l.second + b[l.first] <= k && l.second + b[l.first] == r.second)) {
      ans = v[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.*;

public class Main {

	public static void main(String[] args) {
	Scanner s= new Scanner(System.in);
	 int n=s.nextInt();
	 
	 char[] col=s.next().toCharArray();
	 int count=0;
	int si=0;
	int ei=n-1;
	while(si<ei) {
		if(col[si]=='W'&&col[ei]=='R') {
			col[si]='R';
			col[ei]='W';
			count++;
		}
		else if(col[si]=='R') {
			si++;
		}
		else if(col[ei]=='W') {
			ei--;
		}
		
	}
	 System.out.println(count);
	

	
	

}}


Measured memory_bytes: 40820
#include<stdio.h>
#include<string.h>
#include<ctype.h>


int main(){

  char s[200], t[200];
  int m, h, i, j;

  while(1){
    scanf("%s", s);
    if(s[0]=='-') break;

    scanf("%d", &m);
    for(i=0;i<m;i++){
      scanf("%d", &h);
      for(j=0;j<h;j++) t[j]=s[j];
      for(j=h;j<strlen(s);j++) s[j-h]=s[j];
      for(j=0;j<h;j++) s[strlen(s)-h+j]=t[j];
    }
    printf("%s\n", s);
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
long double pi = acos(-1);

using namespace std;

long long ar[(int)3e5];

int main() {

    __int128_t ans , a ;
    int n ;
    cin >> n ;
    ans = 1 ;
    for( int i = 1 ; i <= n ; i++ ){ cin >> ar[i] ; if( ar[i] == 0 ) { cout << 0 ; return 0 ; } }
    for( int i = 1 ; i <= n ; i++){
        ans *= ar[i] ;
        if( ans > 1'000'000'000'000'000'000 ){
            cout << -1 ; return 0 ;
        }
    }
    cout << (long long)ans ;

}

Measured memory_bytes: 4372
#include<stdio.h>

int main()
{
  int A,B,flag=0;
  
  scanf("%d",&A);
  scanf("%d",&B);
  
 if(B%A==0)
 {
   flag=1;
 }
     
  if(flag)
  {
    printf("%d",A+B);
  }
  else
  {
    printf("%d",B-A);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
string ans = "No";
void Main(){
    int n;
    cin >> n;
    vector v(n+1, 0);
    For(i,0,n){
        int s, t;
        cin >> s >> t;
        if(s == t) v[i+1] = v[i] + 1;
        else v[i+1] = 0;
        if(v[i+1] == 3) ans = "Yes";
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3628
import numpy as np
import fractions as fra

n=int(input())
a = [0] + [int(input()) for _ in range(n)]
#print(a)

k=1
c=0
while(c<=n*2):
    k=a[k]
    c+=1
    if(k==2):break

if(c>=n):c=-1
print(c)

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

int main(void){
    int K,N,ans=0;
    int d_tmp,sunuke_tmp;
 
//  cin >> in_str;
    cin >> N >> K;
    
    long long sunuke_donot[200]={0};
    
    for(int i=0;i<N;i++){
        cin >> d_tmp;
        
        for(int j=0;j<d_tmp;j++){
            cin >> sunuke_tmp;
            sunuke_donot[sunuke_tmp-1]=1;
        }
        
    }


//    int length = int(in_str.length());
  
    for(int k=0;k<N;k++){
        if(sunuke_donot[k]==0) ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64
    }
    println!("{}", (a+b)%24);
}

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

int main(void){
    int N;
    cin >> N;

    long long f[11000]={};

    for(long long x=1; x<100; ++x){
        for(long long y =1 ; y < 100; ++y){
            for(long long z=1; z <100; ++z){
                long long nn = x*x + y*y + z*z + x*y + y*z + z*x;
                if(nn > N) continue;
                f[nn] += 1;
            }
        }
    }

    for(int i=1; i <= N; ++i) cout << f[i] << endl;
}

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


void solve(long long N, std::vector<long long> A){
    vector<long long> A2 = A;
    sort(A2.begin(), A2.end(), greater<long long>());
    //for(auto i : A2) cout << i << endl;
    long long max_val = A2[0];
    long long sec_val = A2[1];
    for(auto a : A){
        if(a == max_val) cout << sec_val << endl;
        else cout << max_val << endl;
    }
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 6408
#include <iostream>
#include <cstdlib> // abs() for integer
#include <cmath>   // abs() for float, and fabs()
#include <climits>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    double T,A;

    cin >> N >> T >> A;

    int  H[N];
    double val;
    double ANS = 100000;
    int  ANS_NO;
    for(int i = 0; i < N; i++){
        cin >> H[i];
        val = T - (H[i] * 0.006);
        if (abs(val - A) < ANS)
        {
            ANS = abs(val - A);
            ANS_NO = i + 1;
        }
    }
    cout << ANS_NO << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using tp = tuple<ll,ll,ll>;
ll n,m,s;
ll a,b; 
ll c[55],d[55];       //存获得的银币和消耗的时间 
ll dp[55][2505];            //到达i时还有j银币的最小时间 
vector<tp> G[55];          //目标点 a b 
tp info;              // 时间 目标点 当前的钱 
const ll inf = 0x3f3f3f3f3f3f3f3f;
int main(){
	cin>>n>>m>>s;
	s = min(s,2504LL);
	for(ll i=0;i<m;i++){
		ll ta,tb,tc,td;
		cin>>ta>>tb>>tc>>td;
		G[ta].push_back(tp(tb,tc,td));        //目标点 时间 钱 
		G[tb].push_back(tp(ta,tc,td));	 
	}
	for(ll i=1;i<=n;i++){
		ll tc,td;
		cin>>tc>>td;
		c[i] = tc;
		d[i] = td;
	}
	fill(dp[0] , dp[0] + 54*2504 , inf); //这招太秀了 
	dp[1][s] = 0;
	priority_queue<tp,vector<tp>,greater<tp>> pq;            //以最短时间为优先的优先队列
	pq.push(tp(0,1,s));                                       //首先录入时间为0，起点，钱 
	while(!pq.empty()){                                    //若非空 
		info = pq.top();                                  //取出时间最短点 
		pq.pop();
		ll t = get<0>(info) , u = get<1>(info) , w = get<2>(info);        //t为此时时间     u为点      w为剩下的钱 
		//printf("%lld %lld %lld\n",t,u,w);
		if(dp[u][w] > t){
			//printf("pass\n");
			continue;
		}                      //如果此时时间小于“到达u时还有w银币的最小时间”，continue
		                                                 //这意思是。。。不可能到达？还是什么，为啥要continue 
		for(auto i:G[u]){                               //遍历u向外的连线 
			ll v = get<0>(i) , aa = get<1>(i) , bb = get<2>(i);           //得到路径对面点  钱 花费时间  
			if(w>=aa and dp[v][w-aa] > t + bb){                 //如果剩下的钱大于需要花费的钱。且。到达对面的剩下的钱的dp比此时大  
				dp[v][w-aa] = t + bb;                    //更新。 
				pq.push(tp(t+bb , v , w-aa));           //把这个点push。 
			}
		}
		if(dp[u][min(w + c[u] , 2504LL)] > t + d[u]){     //如果在这个站点充钱所耗费的时间比dp少 那就在这里充钱 
			dp[u][min(w + c[u] , 2504LL)] = t + d[u];      //不懂为什么只充一块钱 
			pq.push(tp(t + d[u] , u , min(w + c[u] , 2504LL)));   //然后把这个点录入 
		}
	}	
	for(ll i=2;i<=n;i++){
			ll ans = inf;
			for(ll j=0;j<2504;j++){                 //寻找最短路 
				ans = min(ans,dp[i][j]);
			}
			cout<<ans<<endl;
		}
	return 0;
}

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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define MAXN 200002

int n;
int a[MAXN];
int d[MAXN];
vector <int> g[MAXN];

void dfs(int v, int pr = -1) {
	d[v] = a[v];
	if (sz(g[v]) == 1) return;
	ll s = 0;
	int tt = 0;
	for (const int& v2 : g[v]) {
		if (v2 == pr) continue;
		dfs(v2, v);
		tt = max(tt, d[v2]);
		s += d[v2];
	}
	ll k = s - a[v];
	d[v] = s - k * 2;
	ll maxk = s / 2;
	if (tt * 2 > s) maxk = s - tt;
	if (k < 0 || d[v] < 0 || k > maxk) {
		puts("NO");
		exit(0);
	}
}

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);

	if (n == 2) {
		puts(a[0] == a[1] ? "YES" : "NO");
		return 0;
	}

	for (int i = 0; i < n - 1; ++i) {
		int v1, v2;
		scanf("%d%d", &v1, &v2);
		--v1, --v2;
		g[v1].pb(v2);
		g[v2].pb(v1);
	}

	int root = 0;
	for (int i = 0; i < n; ++i) {
		if (sz(g[i]) > 1) {
			root = i;
			break;
		}
	}

	dfs(root);
	puts(!d[root] ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
int main()
{
	ld a,b;
	cin>>a>>b;
	ld k = a*b;
	ll cc = k;
	cout<<cc<<endl; 
	return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
ll n;
  cin >> n;
vector<ll>a(n+1,0);
  ll che=0;
  for(int i=0;i<n;i++){
    ll z;
    cin >> z;
    a.at(i+1)=a.at(i)+z;
    }
  che = a.at(n);
  ll ans = 10e17;
  for(int i=1;i<n;i++){
    ll sunuke = a.at(i);
    ll kuma = che-sunuke;
    ans = min(ans,abs(sunuke-kuma));
    }
  cout << ans <<endl;
}





Measured memory_bytes: 1792
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::*;
use proconio::{input, fastout, marker::*};

#[fastout]
fn main() {
  input!{
      s:Chars,
      t:Chars,
  }
  let mut ans = 10000;
  for i in 0..=s.len()-t.len() {
      let mut x = 0;
      for j in 0..t.len() {
          if s[i+j] != t[j] {
            x += 1;
          }
      }
    ans = cmp::min(ans,x);
  }
  println!("{}",ans);
}


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

using namespace std;

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

pair<int, int> check(vector<int>& taro, vector<int>& hanako) {
  
  int a = 0, b = 0;
  rep(i, taro.size())
    if(taro[i] != -1) { a ++; }
  rep(i, hanako.size())
    if(hanako[i] != -1) { b ++; }
  
  if(a == 0 || b == 0) { return make_pair(b, a); }
  return make_pair(-1, -1);
}

int main() {
  
  int N;
  while(cin >> N && N) {
    vector<int> taro(N);
    rep(i, N) cin >> taro[i];
    sort(taro.begin(), taro.end());
    int j = 0, k = 0;
    vector<int> hanako(N);
    rep(i, 2*N) {
      if(i+1 == taro[j]) { j++; }
      else { hanako[k++] = i+1; }
    }
    
    int now = 0;
    int turn = 0;
    for(;;) {
      j = 0, k = 0;
      if(turn) {
        while(k < N && now >= hanako[k]) { k++; }
        if(k == N) { now = 0; }
        else { now = hanako[k]; hanako[k] = -1; }
      }
      else {
        while(j < N && now >= taro[j]) { j++; }
        if(j == N) { now = 0; }
        else { now = taro[j]; taro[j] = -1; }
      }
      pair<int, int> res(check(taro, hanako));
      if(res.first != -1) {
        cout << res.first << '\n' << res.second << endl;
        break;
      }
      turn ^= 1;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


#define debug 1

int n, m,k;
string s,t;

int main() {
	cin>>n;
	ll po2n = 1<<n;
	vector<ll> s(po2n);
	for (int i = 0; i < po2n; i++)
	{
		cin >> m;
		s[i] = m;
	}
	sort(s.begin(), s.end());
	vector<ll> prt(1);
	prt[0] = s.back();
	s[po2n - 1] = -1;
	for (int i = 0; i < n; i++)
	{
		sort(prt.begin(), prt.end());
		VLL tmp = prt;
		ll it = po2n - 1;
		while (it >= 0 && tmp.size()) {
			if (s[it] == -1) {
				it--;
				continue;
			}
			if (s[it] >= tmp.back()) {
				it--;
				continue;
			}
			prt.push_back(s[it]);
			s[it] = -1;
			tmp.pop_back();
		}
		if (tmp.size()) {
			puts("No");return 0;
		}
	}
	cout << "Yes" << endl;return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int n; string s;
  cin>>n>>s;
  
  if (n<3200) out("red");
  out(s);

  return 0;
}


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

#define int long long

using namespace std;
template<class T>
using V = vector<T>;

int N, T;
V<int> vec;

int ans;

signed main(){

  	cin >> N >> T;
    vec.resize(N);
    for(auto &e: vec){
        cin >> e;
    }

    ans = T;
    int prev = vec[0] + T;
    for(int i = 1; i < N; i++){
        if(prev > vec[i]){
            ans += T - (prev - vec[i]);
        }else{
        	ans += T;
        }
        prev = vec[i] + T;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
  int i,j,k,l,m,a,b;
  vector <int> v;
  
  cin>>a>>b;
  
  for(i=a;i<=b;i++){
    j=i%10;
    k=(i/10)%10;
    l=(i/1000)%10;
    m=i/10000;
    
    if(j==m&&k==l)
      v.push_back(i);
  }
 
  cout<<v.size()<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    Queue q = new LinkedList<Long>();
    for(int i = 1; i < 10; i++) {
      q.add((long)i);
    }
    long ans = 0;
    for(int i = 0; i < k; i++) {
      long t = (long)q.poll();
      if(i == (k - 1)) {
        ans = t;
        break;
      }
      long d = (t % 10);
      long t1 = 10 * t + (d - 1);
      long t2 = 10 * t + d;
      long t3 = 10 * t + (d + 1);
      if(d == 0) {
        q.add(t2);
        q.add(t3);        
      } else if(d == 9) {
        q.add(t1);
        q.add(t2);
      } else {
        q.add(t1);
        q.add(t2);
        q.add(t3);
      } 
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 36052
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<(b-a)*(b-a+1)/2-b;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	char c; cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef pair<int, int> pa;
typedef vector<pair<int,int> > vepa;
typedef map<int, int> mp;
const ll N=1e6+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
ll cnt[N]={};
bool f;
int main()
{
    ll n,k;
    cin>>n>>k;
    rep(i,n&&cin>>arr[i]);
     sort(arr,arr+n);
     ll l=0 , r=k-1;
     ll ans=arr[r]-arr[l];
     while(r<n)
     {
         ans=min(ans,arr[r]-arr[l]);
         l++ , r++;
     }
     cout<<ans;



go;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d)
    cout << "Left" << endl;
  else if(a+b==c+d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#define ll long long
#define rg register int
#define max(a, b) ((a)>(b)?(a):(b))
#define min(a, b) ((a)<(b)?(a):(b))
#define rep(a, b, c) for(rg a=b; a<=c; ++a)

inline ll read() {
	ll x=0; char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x;
}

ll dfs(ll a, ll b) {	//a>=b
	ll ans;
	if(a%b==0) ans=(a<<1)-b;
	else {
		ans=(a/b*b)<<1;
		ans+=dfs(b, a%b);
	}
	return ans;
}

int main() {
	ll n, x, ans;
	n=read(); x=read();
	ans=n;
	ans+=dfs(max(x, n-x), min(x, n-x));
	printf("%lld", ans);
	return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> cell(h + 2);
  string head, bottom;

  for (int i = 0; i < w + 2; i++) {
    head += '#';
    bottom += '#';
  }
  
  cell.at(0) = head;
  cell.at(h + 1) = bottom;

  for (int i = 1; i < h + 1; i++) {
    string a;
    cin >> a;
    cell.at(i) = '#' + a + '#';
  }

  for (int i = 0; i < h + 2; i++) cout << cell.at(i) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, m, ary[105][105]={0}, a[105]={0};
    while(scanf("%d %d", &n, &m) != EOF)
    {
       for(int i = 0; i < n; i++)
        {
            int sum = 0;
            for(int j = 0; j < m; j++)
            {
                scanf("%d", &ary[i][j]);
                sum += ary [i][j];
            }
            ary[i][m] = sum;
        }
        
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j <= m; j++)
            {
                printf("%d", ary[i][j]);
                if(j != m)
                {
                    printf(" ");
                }
            }
            printf("\n");
        }
        
        for(int i = 0; i <= m; i++)
        {
            int sum = 0;
            for(int j = 0; j < n; j++)
            {
                sum += ary [j][i];
            }
            /*if(i != m)
            {
                //printf(" ");
            }*/
        }
        
        for(int i = 0; i <= m; i++)
        {
            int tmp = 0;
            for(int j = 0; j <= n; j++)
            {
                tmp += ary[j][i];
            }
            printf("%d", tmp);
            if(i != m)
            {
                printf(" ");
            }
        }
        printf("\n");
        
    }
    return 0;
}



Measured memory_bytes: 2788
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
maze = [input() for _ in range(h)]
walk = [(-1, 0),  (1, 0), (0, -1), (0, 1)]
teleport = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
            (-1, -2), (-1, -1),          (-1, 1), (-1, 2),
            (0, -2),                              (0, 2),
            (1, -2),  (1, -1),           (1, 1),  (1, 2),
            (2, -2),  (2, -1),  (2, 0),  (2, 1),  (2, 2)]

INF = 10 ** 9
mp = [[INF for _ in range(w)] for _ in range(h)]
mp[ch][cw] = 0
walkable = [(ch, cw)]
while True:
    for y, x in walkable:
        for dy, dx in walk:
            ny, nx = y + dy, x + dx
            if (ny < 0 or h <= ny) or (nx < 0 or w <= nx):
                continue
            if maze[ny][nx] == '#':
                continue
            if mp[ny][nx] != INF:
                continue
            mp[ny][nx] = mp[y][x]
            walkable.append((ny, nx))

    teleportable = []
    for y, x in walkable:
        for dy, dx in teleport:
            ny, nx = y + dy, x + dx
            if (ny < 0 or h <= ny) or (nx < 0 or w <= nx):
                continue
            if maze[ny][nx] == '#':
                continue
            if mp[ny][nx] != INF:
                continue
            mp[ny][nx] = mp[y][x] + 1
            teleportable.append((ny, nx))

    if mp[dh][dw] != INF:
        print(mp[dh][dw])
        break
    if teleportable == []:
        print(-1)
        break
    walkable = teleportable

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

int main(){
    int n; cin >> n;
    vector<vector<pair<int, int>>> a(n);
    rep(i, n){
        int tmp; cin >> tmp;
        a[i].resize(tmp);
        rep(j, tmp){
            cin >> a[i][j].first >> a[i][j].second;
            a[i][j].first --; 
        }
    }
    int ans = 0;
    rep(b, (1<<n)){
        bitset<15> bit(b);
        bool check = true;
        int cnt = 0;
        rep(i, n){
            if (bit.test(i)){
                for (auto ai: a[i]){
                    if (ai.second == 1 && !bit.test(ai.first)) check = false;
                    else if (ai.second == 0 && bit.test(ai.first)) check = false;
                }
            }
        }
        rep(i, n){
            if (b & (1 << i)) cnt ++;
        } 
        if (check) ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
f,p[5];main(i){for(;({for(i=f=0;i<5;f|=1<<p[i++])scanf("%d\n",p+i);*p;});)for(i=-1;i++<4;puts(f^1<<p[i]&&14^f?f%5-p[i]%3?"2":"1":"3"));}

Measured memory_bytes: 0
import java.util.Scanner;

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

		int x = sc.nextInt();
		int max = 1;
		for (int i = 2; i <= x; i++) {
			int tmp = i * i;
			while (tmp <= x) {
//				max = Math.max(max, tmp);
				if (tmp > max) {
					max = tmp;
				}
				tmp *= i;
			}
		}
		System.out.println(max);
		sc.close();
	}
}


Measured memory_bytes: 25044
# A - Wanna go back home
def can_go_home(dir1, dir2):
	if dir1 > 0 and dir2 > 0:
		return True
	elif dir1 == 0 and dir2 == 0:
		return True
	else:
		return False


n, w, s, e = 0, 0, 0, 0

for dir in input():
	if dir == 'N':
		n += 1
	elif dir == 'W':
		w += 1
	elif dir == 'S':
		s += 1
	else:
		e += 1

if can_go_home(n, s) and can_go_home(e, w):
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d, score;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26)), pos(26);

int get_score(vector<int> t){
    vector<int> pos(26, 0);
    int ans = 0;
    rep(i, t.size()){
        int l = i + 1 - pos[t[i]];
        ans -= (l * (l-1) / 2) * c[t[i]];
        ans += s[i][t[i]];
        pos[t[i]] = i+1;
    }
    rep(i, 26){
        int l = t.size() + 1 - pos[i];
        ans -= (l * (l-1) / 2)* c[i];
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    vector<int> t, pos(26, 0);
    rep(i, d){
        int max_score = -mod;
        int best_j = -1;
        rep(j, 26){
            t.push_back(j);
            int score = get_score(t);
            if(max_score < score){
                best_j = j;
                max_score = score;
            }
            t.pop_back();
        }
        t.push_back(best_j);
    }
    vector<int> ans = t;
    double start_temp = 50, end_temp = 10;
    int current_max_score = get_score(t);
    while(clock() < 1.95 * CLOCKS_PER_SEC){
        if(rand() % 2 == 0){
            int D = rand() % d, q = rand() % 26;
            int old = t[D];
            int olds = get_score(t);
            t[D] = q;
            int score = get_score(t);
            double temp = start_temp + (end_temp - start_temp) * clock() / (1.95 * CLOCKS_PER_SEC);
            double prob = exp((olds - score)/temp);

            if(chmax(current_max_score, score)){
                ans = t;
            }else{
                if(prob <= (double)(rand() % 10000) / 10000){
                    t[D] = old;
                }
            }

            if(prob >= ((rand()%inf)/(double)inf))t[D] = old;
        }else{
            int a = 5 + rand() % (d-10), b = 1 + rand() % 4;
            int olds = get_score(t);
            swap(t[a], t[b]);
            int score = get_score(t);
            if(score < olds){
                swap(t[a], t[b]);
            }
        }
    }
    rep(i, d)cout << ans[i]+1 << endl;
}


Measured memory_bytes: 3804
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 18:25:14 2020

@author: liang
"""

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

field = [input() for i in range(H)]

def Init():
    return [[-1]*W for _ in range(H)]

ans = -1

from collections import deque
q = deque()
adj = ((1,0), (-1,0), (0,1), (0,-1))
def BFS(y,x):
    def isValid(t):
        if t[0] < 0 or t[0] >= H or t[1] < 0 or t[1] >= W or field[t[0]][t[1]] == "#":
            return False
        return True
    d = Init()
    if field[y][x] == '#':
        return -1
    d[y][x] = 0
    q.append((y,x))
    res = 0
    while q:
        cur = q.popleft()
        for a in adj:
            nex = (cur[0]+a[0], cur[1]+a[1])
            if isValid(nex) and (d[nex[0]][nex[1]]== -1 or d[nex[0]][nex[1]] > d[cur[0]][cur[1]]+1):
                d[nex[0]][nex[1]] = d[cur[0]][cur[1]]+1
                #if res < d[nex[0]][nex[1]]:
                #    res = d[nex[0]][nex[1]]
                res = max(res, d[nex[0]][nex[1]])
                q.append(nex)
    return res

for i in range(H):
    for j in range(W):
        tmp = BFS(i,j)
        if tmp > ans:
            ans = tmp
print(ans)

Measured memory_bytes: 9288
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

n = INT()
d = LIST()
d.sort()
a = d[n // 2]
b = d[n // 2 - 1]
print(a - b)

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

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define ll                long long
#define mod               1000000007
#define fr                first
#define sc                second
#define vl                vector<ll>
#define pll               pair<ll,ll>
#define u_map             unordered_map<ll,ll>

#define pi                3.141592653589793
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define printV(v) for(auto itr:v) cout<<itr<<" "; cout<<endl;
#define printA(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printC cout<<"yes"<<endl;
#define printVP(v) for(auto itr:v) cout<<itr.fr<<" "<<itr.sc<<endl;
#define cinarr(a,n) for(int i=0; i<n; i++) cin>>a[i];



void solve(){
	ll n; cin>>n;
	vl a(n); cinarr(a,n);
	
	vl preb(n,0); preb[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--) preb[i]=preb[i+1]+a[i];
	
	ll ans=0;
	for(int i=0;i<n-1;i++) 
		ans=   ( ans+ (   (preb[i+1])%mod  * a[i]  )%mod ) %mod ;
	cout<<ans<<endl;
}



signed main(){
    ios;
	int testcases=1;
	//cin >> testcases;

	while(testcases--){
	    solve();
	}

	return 0;
}


Measured memory_bytes: 6300
N = int(input())
a = tuple(map(int, input().split()))
b = [-1] * N
for i in range(N//2, N):
    b[i] = 1 if a[i] == 1 else 0
for j in range(N//2-1, -1, -1):
    acc = sum([b[i] for i in range(2*j+1, N, j+1)])
    if a[j] == 1 and acc % 2 == 0:
        b[j] = 1
    elif a[j] == 0 and acc % 2 != 0:
        b[j] = 1
    elif a[j] == 0 and acc % 2 == 0:
        b[j] = 0
    elif a[j] == 1 and acc % 2 != 0:
        b[j] = 0
if -1 in b:
    print(-1)
    exit()
ans = len([i for i in b if i == 1])
print(ans)
if ans == 0:
    exit()
print(*[j+1 for j, v in enumerate(b) if v == 1])

Measured memory_bytes: 129624
#include <iostream>
#include <complex>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
using P = complex<double>;
using L = pair<P,P>;
#define X real()
#define Y imag()
const double EPS = 1e-6, INF = 1e12;

double dot(P &a, P &b){ return a.X*b.X + a.Y*b.Y;}
double cross(P &a, P &b){ return a.X*b.Y - a.Y*b.X;}

int ccw(P a, P b, P c){
  b -= a, c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < EPS) return 2;
  if(norm(b) - EPS < norm(c)) return -2;
  return 0;
}

bool is_cross(L a, L b){
  P af = a.first, as = a.second, bf = b.first, bs = b.second;
  return (ccw(af,as,bs)*ccw(af,as,bf) <= 0) and (ccw(bf,bs,af)*ccw(bf,bs,as) <= 0);
}

int main(){
  int n;
  while(cin >> n, n){
    vector<L> Lines;
    for(int i = 0; i < n; ++i){
      double x, y, z, w;
      cin >> x >> y >> z >> w;
      x *= 200;
      y *= 200;
      z *= 200;
      w *= 200;
      Lines.emplace_back(P(x,y),P(z,w));
    }
    for(int i = 0; i < n; ++i){
      P d = Lines[i].second - Lines[i].first;
      d /= abs(d);
      Lines[i].second += d;
      Lines[i].first -= d;
    }
    vector< vector<int> > Adj(2*n+2, vector<int>(2*n+2,true));
    int M = 2*n + 2;
    vector<P> Points(M);
    for(int i = 0; i < n; ++i){
      Points[2*i] = Lines[i].first;
      Points[2*i+1] = Lines[i].second;
    }
    Points[2*n] = P(0,0);
    Points[2*n+1] = P(200000,200000);
    for(int i = 0; i < M; ++i){
      for(int j = 0; j < i; ++j){
        if(i == j) continue;
        if(i < 2*n and i%2 == 0 and (j-i) == 1) continue;
        for(int k = 0; k < n; ++k){
          if(is_cross(L(Points[i],Points[j]),Lines[k])){
            Adj[i][j] = false;
            Adj[j][i] = false;
            break;
          }
        }
      }
    }
    for(int k = 0; k < M; ++k){
      for(int i = 0; i < M; ++i)
        for(int j = 0; j < M; ++j)
          Adj[i][j] |= Adj[i][k]&Adj[k][j];
    }
    if(Adj[M-1][M-2]) cout << "no" << endl;
    else cout << "yes" << endl;
  }
}



Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, h[200100], i, ans=0;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h, h+n);
    for(i=0;i<n-k;i++){
        ans+=h[i];
    }
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.regex.Pattern;;
class Main{
    public static void main(String[] args){
	try{
	    BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	    Pattern patt = Pattern.compile("this|that|the");
	    String st;
	    while((st=sc.readLine())!=null){
		char[] xx = st.toCharArray();
		for(int i=0; !patt.matcher(String.valueOf(xx)).find() & i<26; i++)
		    for(int j=0; j<xx.length; j++){
			if(xx[j]>='a' && xx[j]<'z')
			    xx[j]++;
			else if(xx[j]=='z')
			    xx[j]='a';
		    }
		System.out.println(xx);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9164