akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(map(lambda x: 0 if x == 'o' else 1, list(input())))
# o: 0, x: 1

def decode_animals(l):
    return "".join(list(map(lambda x: 'S' if x == 0 else 'W', animals)))

def check(first, second, pre_last, last, first_coment, last_coment):
    # 最初と最後の帳尻合わせ
    f1 = False
    if first == 0:
        if first_coment == 0:
            f1 = second == last
        else:
            f1 = second != last
    else:
        if first_coment == 0:
            f1 = second != last
        else:
            f1 = second == last
    f2 = False
    if last == 0:
        if last_coment == 0:
            f2 = first == pre_last
        else:
            f2 = first != pre_last
    else:
        if last_coment == 0:
            f2 = first != pre_last
        else:
            f2 = first == pre_last
    return f1 and f2

for i in range(4):
    animals = []
    for j in range(2):
        # S: 0, W: 1
        if i >> j & 1:
            animals.append(1)
        else:
            animals.append(0)
    for i in range(2, n):
        next_animal = 0
        if animals[i-1] == 0 and s[i-1] == 0 or animals[i-1] == 1 and s[i-1] == 1:
            next_animal = animals[i-2]
        elif animals[i-1] == 0 and s[i-1] == 1 or animals[i-1] == 1 and s[i-1] == 0:
            next_animal = [1, 0][animals[i-2]]
        animals.append(next_animal)
    if check(animals[0], animals[1], animals[-2], animals[-1], s[0], s[-1]):
        ans = decode_animals(animals)
        print(ans)
        exit()
print(-1)

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

int main() {
  int n;
  cin >> n;
  bool f = false;
  for (int i = 1; i <= n; ++i) {
    if ((int)((double)i * 1.08) == n) {
      cout << i << endl;
      f = true;
      break;
    }
  }
  if (!f) cout << ":(" << endl;
  return 0;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    ll n,l; cin >> n >> l;
    vl a(n);
    rep(i,n)cin>>a[i];
    bool can = false;
    int idx = -1;
    for(int i=0;i<n-1;i++){
        if(a[i] + a[i+1] >= l){
            can = true;
            idx = i;
            break;
        }
    }
    if(can == false){
        out("Impossible");
        return 0;
    }
    out("Possible");
    rep(i,n-1){
        if(i == idx)break;
        out(i+1);
    }
    for(int i=n-2;i>=0;i--){
        if(i == idx)break;
        out(i+1);
    }
    out(idx+1);
}

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

using namespace std;
typedef long long ll;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < m; ++i)
    cin >> b[i];
  ll ans = 0, tot = 0, l = 0;
  while (tot <= k) {
    ans = l;
    if (l == n)
      break;
    tot += a[l++];
  }
  for (int r = 1; r <= m; ++r) {
    tot += b[r - 1];
    while (l >= 1 && tot > k)
      tot -= a[--l];
    if (tot > k)
      break;
    ans = max(ans, l + r);
  }
  cout << ans;
}

Measured memory_bytes: 4848
using System;


namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;
            int y = 0;
            while (true)
            {
                String s = Console.ReadLine();
                string[] ss = s.Split(' ');
                x = int.Parse(ss[0]);
                y = int.Parse(ss[1]);
                if ((x == 0) && (y == 0))
                {
                    break;
                    
                }
                else if (x > y)
                {
                    int t;
                    t = x;
                    x = y;
                    y = t;
                }
                Console.WriteLine(x + " " + y);
            }
        }
    }
}

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

int done = 0;
int n;

int pr(int a){
    if(done) return 0;
    cout << a % n << endl;
    string f;
    cin >> f;
    if(f[0] == 'V'){
        done = 1;
        return 0;
    } else if(f[0] == 'M'){
        return 0;
    } else {
        return 1;
    }
}

int main(){
    cin >> n;
    int s = 0;
    int e = s + n;
    int ss = pr(s);
    int se = ss;
    while(1){
        if(done) break;
        int m = (s + e)/2;
        int sm = pr(m);
        if((m - sm + s - ss) % 2 == 1){
            e = m;
            se = sm;
        } else{
            s = m;
            ss = sm;
        }
    }
}


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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

vector<bool> isPrimes(int n) {
	vector<bool> res(n, true);
	res[0] = res[1] = false;
	for (int i = 2;i < sqrt(n);i++) {
		if (res[i]) {
			for (int j = 0;i * (j + 2) < n;j++) {
				res[i * (j + 2)] = false;
			}
		}
	}
	return res;
}

vector<int> primes(int n) {
	vector<bool> is_primes = isPrimes(n);
	vector<int> res;
	for (int i = 2;i < n;i++) {
		if (is_primes[i]) {
			res.push_back(i);
		}
	}
	return res;
}

VI ps;
VI qs;
int n, p;

int main(void) {
	ps = primes(100000 * 2);
	while (1) {
		qs.clear();
		cin >> n >> p;
		if (n == -1 && p == -1) break;
		int idx = 0;
		rep (i, ps.size()) {
			if (n < ps[i]) {
				idx = i;
				break;
			}
		}
		REP (i, idx, p + idx) {
			REP (j, i, p + i) {
				qs.PB(ps[i] + ps[j]);
			}
		}
		sort(ALL(qs));
		cout << qs[p - 1] << endl;
	}
    return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include <string.h>
using namespace std;


int main()
{
    string str;
    cin>>str;
    size_t size =str.length();
    if(str[size-1] == 's')
    {
        cout<<str<<"es";
    }
    else
    {
        cout<<str<<'s';
    }

    return 0;
}

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

using namespace std;

int main(){

  string s;
  cin>>s;
  unordered_set<char> c;
  unordered_map<char,int> dict;
  for(char &ch:s){
    c.insert(ch);
    dict[ch]++;
  }

  if(c.size()==2){
    bool faro=true;
    for(auto x:dict){
      if(x.second!=2)
        faro=false;
    }
    if(faro)
      cout<<"Yes\n";
    else
      cout<<"No\n";
  }
  else
    cout<<"No\n";

  return 0;
}


Measured memory_bytes: 256
def sol():
    r,g,b,n=map(int,input().split())
    ans=chk=0
    for i in range(n+1):
        for j in range(n+1):
            if (i*r+j*g)>n: break
            if (n-(i*r+j*g))%b==0:
                ans+=1
    print(ans)
if __name__ == '__main__':
    sol()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    double a=0,b=0;
    rep(i,n){
      int tmp;cin>>tmp;
      a+=tmp*tmp;
      b+=tmp;
    }
    a/=n;
    b/=n;
    b*=b;
    printf("%.10f\n",sqrt(abs(a-b)));
  }
}

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

struct Node{
  int parent;
  int left;
  int right;
};

int *D;

Node *T;

void setdepth(int u, int p){
  D[u] = p;
  if(T[u].right != -1){
    setdepth(T[u].right, p);
  }
  if(T[u].left != -1){
    setdepth(T[u].left, p + 1);
  }
}


int main(){


  int n, x, i, r;

  cin >> n;

  T = new Node[n];

  D = new int[n];

  for(int i = 0; i < n; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }


  for(int k = 0; k < n; k++){

    cin >> x;

    int j;

    cin >> j;

    int y0 = 0, y1 = 0;

    for(int i = 0; i < j; i++){
      y0 = y1;
      cin >> y1;
      T[y1].parent = x;
      if(i == 0){
      T[x].left = y1;
      }
      else{
        T[y0].right = y1;
      }
    }
  }

  for(int i = 0; i < n; i++){
    if(T[i].parent == -1){
      r = i;
      break;
    }
  }

  setdepth(r,0);

  for(int i = 0; i < n; i++){

    int ind;

    cout << "node " << i << ": parent = " << T[i].parent << ", depth = " << D[i] << ", ";

    if(T[i].left  != -1){

      if(T[i].parent == -1) cout << "root, [";
      else cout << "internal node, [";

      ind = T[i].left;
      cout << T[i].left;
      while(T[ind].right != -1){
        cout << ", " << T[ind].right;
        ind = T[ind].right;
      }
    }
    else{
      if(T[i].parent == -1) cout << "root, [";
      else cout << "leaf, [";
    }
    cout << "]" << endl;
  }


  delete[] T;
  return 0;
}



Measured memory_bytes: 7576
#include <iostream>

using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int ret1=0,ret2=0;
		for(int i=0;i<n;i++){
			int a,b;
			cin >> a >> b;
			if(a > b) ret1+=a+b;
			if(a < b) ret2+=a+b;
			if(a == b) ret1+=a,ret2+=b;
		}
		cout << ret1 << " " << ret2 << endl;
	}
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int cnt[30];

signed main()
{
  int N;
  cin >> N;
  REP(n,N) {
    cin >> cnt[n];
  }

  int ans = 0;
  REP(n,N-2) {
    if(min(cnt[n+2],min(cnt[n], cnt[n+1])) != cnt[n+1] && max(cnt[n+2],max(cnt[n], cnt[n+1])) != cnt[n+1]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		Integer num = Integer.parseInt(s.nextLine());
		String input = s.nextLine();
		s.close();

		Integer[] seq = new Integer[num];
		if(input.contains("  ")){
			input = input.replace("  ", " ");
			input = input.substring(0, input.length() - 1);
		}
		String[] input_list = input.split(" ");
		for(int i = 0; i < num; i++){
			seq[i] = Integer.parseInt(input_list[i]);
		}

		for(int j = 1;j < seq.length; j++){
			print_seq(seq);
			Integer key = seq[j];
			Integer i = j - 1;
			while(i >= 0 && seq[i] > key){
				Integer bkp = seq[i+1];
				seq[i+1] = seq[i];
				seq[i] = bkp;
				i -= 1;
			}
		}
		print_seq(seq);
	}

	private static void print_seq(Integer[] seq){
		for(int i = 0; i < seq.length; i++){
			if(i == seq.length - 1){
				System.out.print(seq[i]);
			}
			else{
				System.out.print(seq[i] + " ");
			}
		}
		System.out.print("\n");
	}
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)


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

	ll ans = 0;
	for(int a=1; a<=k; a++) {
		for(int b=1; b<=k; b++) {
			for(int c=1; c<=k; c++)  {
				ans += gcd(gcd(a, b), c);
			}
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int MAX_A = 1e5 + 3;

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

  IN(N);

  int X[MAX_A]; // 0, 1, ... 10^5 + 1, -1
  REP(i, MAX_A)
    X[i] = 0;

  REP(i, N) {
    IN(a);
    ++X[(a-1+MAX_A) % MAX_A];
    ++X[a];
    ++X[a+1];
  }
  int ans = 0;
  REP(i, MAX_A)
    ans = max(ans, X[i]);

  OUT(ans);

  return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("O3") 
#include<bits/stdc++.h>
#define ll      				long long int
#define vi      				vector<int>
#define ii      				pair<int,int>
#define iii     				pair<ii,int>
#define iiii    				pair<ii,ii>
#define fi      				first
#define se      				second
#define unord_map				unordered_map
#define nxt_pmt					next_permutation
#define clr					clear()
#define ALL(x) 					x.begin(),x.end()


#define pb      				push_back
#define pob     				pop_back

#define all(x)  				x.begin(), x.end()
#define len     				length()

#define db(x)					  cout << "!!!!!! " << #x << " => " << x << "\n"

#define fori(i, s, N)     for (int i = s; i <= N; i++)
#define ford(i, s, N)     for (int i = s; i >= N; i--)
using namespace std;

void init(int precision){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

int t;
void cjam(int z){
	cout<<"Case #"<<z<<": ";
	
}
string s;
int n,k;
int main(){
//	init(10);
	cin>>n>>k;
	int a[n+5] = {0};
	int b;
	fori(i,0,k-1){
		cin>>t;
		fori(j,0,t-1)
			cin>>b,a[b]++;//, db(b);
	}
	int ans = 0;
	fori(i,1,n){
		if(!a[i]) ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3588
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var A = Number(lines[0].split(" ")[1]) - 1;
    var B = Number(lines[0].split(" ")[2]) - 1;
    var C = Number(lines[0].split(" ")[3]) - 1;
    var D = Number(lines[0].split(" ")[4]) - 1;

    var S = lines[1].split("");

    var flag = false;

    for (var i = 0; i < S.length - 2; i++) {
        if ((S[i] === "#" && S[i + 1] === "#") && A <= i && i + 1 <= Math.max(C, D)) { console.log("No"); return (0) }
        if ((S[i] === "." && S[i + 1] === "." && S[i + 2] === ".") && B <= i + 1 && i + 1 <= D) { flag = true }
    }

    if (D < C && (S[B - 1] === "#" || S[B + 1] === "#" || S[D - 1] === "#" || S[D + 1] === "#") && flag === false) { console.log("No"); }
    else { console.log("Yes"); }
});


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

using namespace std;

const int N = 100010;

int n, m;
int deg[N];
map < int, int > a[N];
vector < pair < int, int > > g[N];

bool cut(pair < int, int > u, pair < int, int > v){
	return !(u.second < v.first || u.first > v.second);
}

int main(){
	
	scanf("%d%d", &n, &m);
	while(m--){
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		++deg[v];
		g[u].push_back(make_pair(v, w));
	}

	list < int > que;
	for(int i = 1; i <= n; ++i){
		if(deg[i] == 0){
			a[i][i] = 0;
			que.push_back(i);
		}
	}

	while(!que.empty()){
		int x = que.front();
		que.pop_front();

		for(auto p : g[x]){
			--deg[p.first];

			int v = p.first;

			for(auto t : a[x]){
				int c = t.first;
				if(a[v].count(c) && a[v][c] != a[x][c] + p.second){
					cout << "No";
					return 0;
				}
				a[v][c] = a[x][c] + p.second;
			}

			if(deg[p.first] == 0) que.push_back(p.first);
		}
	}


	for(int i = 1; i <= n; ++i){
		if(deg[i]){
		  cout << "No";
			return 0;
		}
	}

	cout << "Yes";

	return 0;
}

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

// @@ !! LIM(mod)
// --> f:gcd mod
// ---- inserted function gcd from util.cc
// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

constexpr ll gcd(ll a, ll b) {
  ll dummy1 = 0;
  ll dummy2 = 0;
  return eGCD(a, b, dummy1, dummy2);
}
// ---- end gcd
// ---- inserted library file mod.cc

ll MOD = 1e9 + 7;
// ll MOD = 998244353;

struct Fp {
  ll val;

  Fp(ll t = 0) {
    if      (t >= MOD)  val = t % MOD;
    else if (t >= 0)    val = t;
    else if (t >= -MOD) val = t + MOD;
    else {
      ll v = t % MOD;
      if (v == 0) val = 0;
      else        val = v + MOD;
    }
  }

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

class Comb {
  int nMax;
  vector<Fp> vFact;
  vector<Fp> vInvFact;
public:
  Comb(int nm) : nMax(nm), vFact(nm+1), vInvFact(nm+1) {
    vFact.at(0) = 1;
    for (int i = 1; i <= nMax; i++) vFact.at(i) = i * vFact.at(i-1);
    vInvFact.at(nMax) = vFact.at(nMax).inv();
    for (int i = nMax; i >= 1; i--) vInvFact.at(i-1) = i * vInvFact.at(i);
  }
  Fp fact(int n) { return vFact.at(n); }
  Fp comb(int n, int r) {
    return vFact.at(n) * vInvFact.at(r) * vInvFact.at(n-r);
  }
  // The number of permutation extracting r from n.
  Fp perm(int n, int r) {
    return vFact.at(n) * vInvFact.at(n-r);
  }
};

// ---- end mod.cc
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  ll N = S.size();
  vector<vector<Fp>> cnt(N+1, vector<Fp>(13));
  cnt.at(0).at(0) = 1;
  for (ll i = 0; i < N; i++) {
    const auto& prev = cnt.at(i);
    auto& cur = cnt.at(i+1);
    for (ll j = 0; j < 13; j++) {
      if (S.at(i) == '?') {
	for (ll k = 0; k <= 9; k++) {
	  cur.at((10 * j + k) % 13) += prev.at(j);
	}
      }else {
	cur.at((10*j + S.at(i) - '0') % 13) += prev.at(j);
      }
    }
  }
  cout << cnt.at(N).at(5) << endl;

  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  
  int cardA = 0, cardB = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  
  sort(card.begin(), card.end());     //並べ替え
  reverse(card.begin(), card.end());  //逆順
  
  for (int i = 0; i < N; i++) {  
    if (i % 2 == 0) {
      cardA += card.at(i);
    } else {
      cardB += card.at(i);
    }
  }
  
  cout << cardA - cardB << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
int cnt[N];
int ans;
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
		++arr[i];
		++cnt[arr[i]];
	}
	for(int i = 1 ; i + 1 < N ; ++i){
		ans = max(ans , cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 1024
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        ax: [usize; n-1],
    }
    
    let mut v = vec![0; n];

    for &ai in ax.iter() {
        v[ai-1] += 1;
    }

    for i in v.iter() {
        println!("{}", i);
    }
}

Measured memory_bytes: 5544
using System;
using System.Linq;
using System.Numerics;
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var a = Console.ReadLine().Trim().Split(' ');
            var b = BigInteger.One;
            if (a.Contains("0"))
            {
                Console.WriteLine(0);
                return;
            }

            foreach (var item in a)
            {
                var c = BigInteger.Parse(item);
                b = b * c;
                if (BigInteger.Pow(10, 18) < b)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            Console.WriteLine(b.ToString());
        }
    }
}


Measured memory_bytes: 46996
#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()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll ans = 0;
  
  for (int i = 1; i < n;i++){
    ans += a[i/2];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4804
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

vector<ll>prime_factorize(ll n){
    vector<ll>res;
    for(ll p = 2;p <= sqrt(n);p++){
        ll cnt=0;
      if (n%p != 0) continue;
      while(n % p == 0){
        n /= p;
        //res.push_back(p);
        cnt++;
      }
      res.push_back(cnt);
    }
    if (n != 1) res.push_back(1);
    return res;
}

int main(){
    ll n; cin>>n;
    map<ll,ll>mp;
    for(ll i=2;i<=n;i++){
        ll a=i;
        for(ll j=2;j<=1000;j++){
            if(a%j!=0)continue;
            while(a%j==0){
                a/=j;
                mp[j]++;
            }
            if(a==1)break;
        }
    }
    ll ans=1;
    for(auto p:mp){
        ans*=p.second+1;
        ans%=mod;
    }
    cout<<ans<<endl;
}



















































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

using namespace std;

bool check(const string &s)
{
  int ret = 0;
  for(int i = 1; i <= 11; i++) {
    ret += (s[11 - i] - '0') * (i <= 6 ? i + 1 : i - 5);
    ret %= 11;
  }
  if(ret <= 1) return (s[11] == '0');
  return (s[11] == 11 - ret + '0');
}


int main()
{
  string S;
  cin >> S;
  auto question = S.find('?');
  vector< char > ans;
  for(char i = '0'; i <= '9'; i++) {
    S[question] = i;
    if(check(S)) ans.push_back(i);

  }
  if(ans.size() >= 2) cout << "MULTIPLE" << endl;
  else cout << ans.front() << endl;
}

Measured memory_bytes: 3212
// https://atcoder.jp/contests/abc128/tasks/abc128_c

#include <bits/stdc++.h>
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl;
using namespace std;

int ans = 0;
int N, M;
vector<int> A[15];
int p[15];
void permute(string s =".") {
    if(s.size()==N+1) {
       // watch(s)
        bool all = true;
        for(int i = 1; i <= M; i++) {
            int cnt = 0;
            for(int j: A[i]) {
               // cout << "a_" <<i <<" has " << j << endl;
                if(s[j]=='1') cnt++;
            }

            if(cnt%2!=p[i]) {
                all=false;
            }
        //    cout << "cnt for " << i << " is " << cnt << endl;
        } 

        if(all) {
          //  cout << "works" << endl;
            ans++;
        }
       // cout << endl;
    } else {
        permute(s+"1");
        permute(s+"0");
    }
}
int main() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int a;
        cin >> a;
        for(int j = 1; j <= a; j++) {
            int b;
            cin >> b;

            A[i].pb(b);
            
        }
    }

    for(int i = 1; i <= M; i++) cin >> p[i];
    permute();
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define EE emplace
#define RB rbegin()
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define EB emplace_back
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C;u.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL ar[100];
LL dxx[]= {-1,0,1,0};
LL dyy[]= {0,1,0,-1};
LL dx[]= {2,1,-1,-2,-2,-1,1,2};
LL dy[]= {1,2,2,1,-1,-2,-2,-1};
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        k=0;
        for(i=0;i<n;i++)
        {
            cin>>o;
            v.PSB(o);
        }
        for(i=1;i<n;i++)
        {
            if(v[i-1]>v[i])
            {
                k+=v[i-1]-v[i];
                v[i]=v[i-1];
            }
        }
        cout<<k<<endl;
    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 5332
N=int(input())
AN=list(map(int,input().split()[:N]))

ret=0
flg=True
while flg:
    for i in range(N):
        if AN[i]%2!=0:
            flg=False
            break
        AN[i]//=2

    if flg:
        ret+=1

print(ret)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  long n, m, k; int s = 0; cin >> n >> m >> k;
  v1li a(n), b(m);
  rep(i, n){
    long c; cin >> c;
    if(i == 0) a[0] = c;
    else a[i] = a[i-1] + c;
  }
  rep(i, m){
    long d; cin >> d;
    if(i == 0) b[0] = d;
    else b[i] = b[i-1] + d;
  }
  rep(i, n){
    int e = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
    if(k - a[i] < 0) break;
    s = max(s, i+e+1);
  }
  rep(i, m){
    int f = upper_bound(a.begin(), a.end(), k - b[i]) - a.begin();
    if(k - b[i] < 0) break;
    s = max(s, i+f+1);
  }
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
const int V=50;
const int MX=1e9+7;
int n,a[20],b[20],off[20][20],dp[1<<20][50];
int fun(int mask,int val)
{
    int ans=MX,d=0;
    if(mask==(1<<n)-1) return 0;
    if(dp[mask][val]!=-1) return dp[mask][val];
    int ln=__builtin_popcount(mask);
    for(int i=0;i<n;i++)
    {
        if(mask&(1<<i)) continue;
        if(off[ln][i]>=val)
        ans=min(ans,d+fun(mask|(1<<i),off[ln][i]));
        d++;
    }
    return dp[mask][val]=ans;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        off[i][j]=(i%2==j%2)?a[j]:b[j];
    }
    memset(dp,-1,sizeof(dp));
    int res=fun(0,0);
    if(res>=MX) cout<<"-1";
    else
    cout<<res;
    return 0;
}

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

int main(){

  int n;
  while(cin >> n, n){
    int a[4], b[4], ans[4];
    while(n--){
      cin >> a[0] >> a[1] >> a[2] >> a[3];
      cin >> b[0] >> b[1] >> b[2] >> b[3];
  
      cout << a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3] << " " << 
	a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2] << " " <<
	a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1] << " " << 
	a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0]  << endl;
    }
  }

}

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

int main() {
	int N;
	cin >> N;
	cout << N * 800 - (N / 15) * 200;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

200円もらえた回数はNを15で割って端数切り捨てた値に等しいので、上の通りになる
*/

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

int h, w, n;
typedef pair<int, int> P;
map<P, int> mp;
long long v[10];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> h >> w >> n;
	for(int i=0; i<n; ++i){
		int a, b;
		cin >> a >> b;
		for(int j=0; j<3; ++j)
			for(int k=0; k<3; ++k)
				if(1<=a+j-2 && a+j-2<=h-2 && 1<=b+k-2 && b+k-2<=w-2){
					if(mp.find(P(a+j-2, b+k-2)) == mp.end()) mp[P(a+j-2, b+k-2)] = 1;
					else ++mp[P(a+j-2, b+k-2)];
				}
	}
	for(auto ite=mp.begin(); ite!=mp.end(); ++ite){
//		cout << ite->first.first << " " << ite->first.second << " " << ite->second << "\n";
		++v[ite->second];
	}
	v[0] = (long long)(h-2)*(w-2);
	for(int i=1; i<=9; ++i)
		v[0] -= v[i];
	for(int i=0; i<10; ++i)
		cout << v[i] << "\n";
}

Measured memory_bytes: 56448
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    string S,T;cin>>S>>T;
    int min = 1000;
    int ans = 0;
    for(int i=0;i<S.length()+1-T.length();i++){
        for(int j=0;j<T.length();j++){
            if(S[i+j]==T[j]) ans++; 
        }
        if(T.length() - ans < min) min = T.length() - ans;
        ans = 0;
    }
    cout << min << endl;
    return 0;
}

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

#define int long long

signed main() {
    string s, t;
    cin >> s >> t;

    int ans = 1e18;
    for(int i = 0; i < s.size() - t.size() + 1; i++) {
        int cnt = 0;
        for(int j = 0; j < t.size(); j++) {
            if(s[j + i] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }

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


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

int main() {

    vector<int> c(3);
    for (int i = 0; i < 3; i++) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    int k; cin >> k;

    int ans = 0;
    ans += c[0] + c[1];
    for (int i = 0; i < k; i++) {
        c[2] *= 2;
    }
    ans += c[2];

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

Measured memory_bytes: 256
import java.util.*;

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

        String ans = n.substring((n.length() - 1));
        int a = Integer.parseInt(ans);


        if (a == 3) {
            System.out.println("bon");
        } else if (a == 0 || a == 1 ||a == 6 ||a == 8){
            System.out.println("pon");
        }else{
            System.out.println("hon");
        }


            scn.close();
    }
}

Measured memory_bytes: 27012
n,m=map(int,input().split())
s=[]
for i in range(m):
    b = [int(i) for i in input().split()]
    s.append(b[1:])
p=[int(i) for i in input().split()]
ans=0
for i in range(2**n):
    s_ind=0
    k=bin(i)[2:]
    k=k.zfill(n)
    for j in s:
        c=0
        for M in j:
            if k[-M]=="1":c+=1
        if p[s_ind]!=c%2:break
        s_ind += 1
        if s[-1]==j:
            ans+=1
print(ans)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
n, m, s, t = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]
 
s -= 1
t -= 1
 
# O((V + E)log(V))
# Cは [[スタート頂点, ゴール頂点, 重み], ...] のリスト
 
M = [[] for i in range(n)]
for i in range(len(C)):
    M[C[i][0]-1].append([C[i][1]-1, C[i][2]])  # 無向グラフなら両方追加
    M[C[i][1]-1].append([C[i][0]-1, C[i][2]])  # 無向グラフなら両方追加
 
N = [[] for i in range(n)]
for i in range(len(C)):
    N[C[i][0]-1].append([C[i][1]-1, C[i][3]])  # 無向グラフなら両方追加
    N[C[i][1]-1].append([C[i][0]-1, C[i][3]])  # 無向グラフなら両方追加
 
import heapq
 
def dijkstra(s, M):
    D = [10**16] * n  # 頂点0からの距離
    P = [-1] * n  # 頂点0からの最短距離において、そこの直前の頂点(経路復元に利用)
    D[s] = 0
    V = [0] * n  # その頂点のD[i]が最短距離と確定したら1
    Q = []  # 優先度付きキュー
    for v in range(n):
        heapq.heappush(Q, [D[v], v])
 
    le = len(Q)
    while le > 0:
        q = heapq.heappop(Q)
        u = q[1]
        du = q[0]
        if V[u] == 0:
            V[u] = 1
            le -= 1
            for i in range(len(M[u])):
                v = M[u][i][0]
                luv = M[u][i][1]
                if V[v] == 0:
                    alt = du + luv
                    if D[v] > alt:
                        D[v] = alt
                        P[v] = u
                        heapq.heappush(Q, [alt, v])
    return D, P
 
Ds, _ = dijkstra(s, M)
Dt, _ = dijkstra(t, N)
 
ANS = [0] * n
 
# print(Ds,Dt)
 
ans = 10**16
for i in range(n-1, -1, -1):
    ans = min(ans, Ds[i] + Dt[i])
    ANS[i] = ans
 
for i in range(n):
    print(10**15 - ANS[i])

Measured memory_bytes: 148872
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    N,X = i_map()
    x = i_list()
    l = []
    for i in x:
        l.append(abs(X-i))
    ans = l[0]
    for k in l[1:]:
        ans = gcd(ans,k)
    print(ans)



if __name__=="__main__":
    main()


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S, S1, S2;
	int A, B;
	cin >> S;
	S1 = S.substr(0, 2);
	S2 = S.substr(2, 2);

	stringstream ss1, ss2;
	ss1 << S1;
	ss1 >> A;
	ss2 << S2;
	ss2 >> B;

	if (0 < A&&A < 13 && 0 < B&&B < 13)
	{
		cout << "AMBIGUOUS" << endl;
	}
	else if (0 < A&&A < 13)
	{
		cout << "MMYY" << endl;
	}
	else if (0 < B&&B < 13)
	{
		cout << "YYMM" << endl;
	}
	else
	{
		cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b == c or a + c == b or b + c == a) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main() {
  int n,x;
  cin >> n >> x;
  vector<int> v(n);
  rep(i,n) cin >> v[i];

  int ans = abs(v[0]-x);
  rep(i,n) ans = gcd(ans,abs(v[i]-x));
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
char B[101];
int A[10];
void Search(int num);
int main(void){
    int i;
    for(i=1;i<=6;i++)
        scanf("%d",&A[i]);
    scanf("%s",B);
    for(i=0;B[i] !='\0';i++){
        switch(B[i]){
            case 'N': Search(2); break;
            case 'W': Search(3); break;
            case 'E': Search(4); break;
            case 'S': Search(5); break;
        }
    }
    printf("%d\n",A[1]);
    return 0;
}
             
void Search(int num){
    int tmp;
    tmp = A[1];
    A[1] = A[num];
    A[num] = A[6];
    A[6] = A[7-num];
    A[7-num] = tmp;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("READ.txt", "r", stdin)
#define Write          freopen("OUTPUT.txt", "w", stdout)
#define INF            1000000007


void solve()
{
    int n;
    cin>>n;
    lll arr[n+3],ans=0;
    lll cum[n+3]={0};
    for(int i=1;i<=n;i++)
    {
    	cin>>arr[i];
    	cum[i]=(cum[i-1])+(arr[i]);
    }
    for(int i=1;i<=n;i++)
    {
       lll num=cum[n]-cum[i];
       num%=INF;
       lll X=(num)*(arr[i]);
       X%=INF;
       ans+=X;
       ans%=INF;
    }
    cout<<ans<<endl;
}

int main()
{
    fast
    #ifndef ONLINE_JUDGE
    Read;
    Write;
    #endif
    //sieve();
    //int cnt=1;
    //int t; cin>>t; while(t--) solve();
    solve();
}

Measured memory_bytes: 6700
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n,m,x=map(int,input().split())
    A=list(map(int,input().split()))

    B=sorted(A+[x])
    print(min(B.index(x), m-B.index(x)))

resolve()

Measured memory_bytes: 2940
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	int n;
	string s;
	cin >> s;
	n = s.length();
	v32 arr(n + 1, 0);
	for (int i = 1; i < n + 1; i++)
		arr[i] = s[i - 1] - '0';
	reverse(arr.begin(), arr.end());
	//print_container(arr);
	ll ans = 0;
	for (int i = 0; i < n + 1; i++)
	{
		arr[i + 1] += arr[i] / 10;
		arr[i] %= 10;
		if (arr[i] > 5)
		{
			ans += 10 - arr[i];
			arr[i + 1]++;
		}
		else if (arr[i] < 5)
			ans += arr[i];
		else
		{
			if (arr[i + 1] >= 5)
			{
				arr[i + 1]++;
				ans += 10 - arr[i];
			}
			else
				ans += arr[i];
		}
	}
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 5276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int N; std::cin >> N;
	std::vector<int> D(N);
	std::vector<int> DD(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> D[i];
		--D[i];
	}
	for (int i = 0; i < N; ++i)
		DD[D[i]] = i;
	for (int i = 0; i < N; ++i)
		std::cout << DD[i] + 1 << " ";

	return 0;
}

Measured memory_bytes: 4000
package main

import (
	"fmt"
	"sort"
)

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

func main() {
	var n, p int
	var s string
	fmt.Scan(&n)
	m := make(map[string]int)
	a := make([]string, n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&s, &p)
		a[i-1] = s + fmt.Sprintf("%03d", abs(p-100))
		m[a[i-1]] = i
	}
	sort.Strings(a)
	for _, v := range a {
		fmt.Println(m[v])
	}
}


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

int main()
{
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    sort(begin(x), end(x));
    cout << x[0] << " ";
    cout << x[1] << " ";
    cout << x[2] << "\n";
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
   string S;
   cin >> S;
   bool flag = true;
   REP(i, 3){
     if(S[i] == S[i+1]){
       flag = false;
     }
   }
   if(flag){
     cout << "Good" << endl;
   }
   else{
     cout << "Bad" << endl;
   }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a, int *b){
  int temp;

  temp = *a;
  *a = *b;
  *b = temp;
}

int main(void)
{
  int w,n;
  int a, b;
  int NoB[32];       //number of bottom
  int i, j, k;

  while (scanf("%d", &w) != EOF){
    for (i = 1; i < w+1; i++){
      NoB[i] = i;
    }
    scanf("%d", &n);
    for (i = 0; i < n; i++){
      scanf("%d,%d", &a, &b);
      swap(&NoB[a], &NoB[b]);
    }
    for (i = 1; i < w+1; i++){
      printf("%d\n", NoB[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 592
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		int a[] = new int[n];
		int c = 0;
		
		for(int i = 0;i<n;i++) {
			h[i] = sc.nextInt();
			a[h[i]-1] = i+1;
		}
		
		for(int i = 0;i<n;i++) {
			System.out.print(a[i]);
			System.out.print(" ");
		}


		sc.close();
	}
}



Measured memory_bytes: 62092
n = int(input())
a = input().split()
b = input().split()
c = input().split()
sum = 0
number = -2

for i in a:
  k = int(i)-1
  sum += int(b[k])
  if number + 1 == k:
    sum += int(c[k-1])
  number = k
print(sum)

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

using namespace std;

int main() {
    string S;
    int64_t K;
    cin >> S >> K;
    for(auto& c: S) {
        if(c == 'a') {
            continue;
        }
        auto d = 'z' - c + 1;
        if(d <= K) {
            c = 'a';
            K -= d;
        }
    }
    K %= 26;
    S[S.size()-1] += K;
    if(S[S.size()-1] > 'z')
        S[S.size()-1] -= 'a' - 1;

    cout << S << endl;

    return 0;
}



Measured memory_bytes: 3208