akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**7)

def dfs(num,log):
    visited[num]=min(log,visited[num])
    for item in way[num]:
        if visited[item]==10**7:
            dfs(item,log)
    return 

N,M=map(int,input().split())

visited=[10**7]*N
way=[[] for i in range(N)]
order=[]

for _ in range(M):
    X,Y,Z=map(int,input().split())
    X,Y=min(X,Y),max(X,Y)
    order.append([X-1,Y-1,Z])

order.sort(key=lambda x:(x[0],x[1]))

for item in order:
    way[item[0]].append(item[1])
    way[item[1]].append(item[0])
    
for i in range(N):
    dfs(i,i)

visited=list(set(visited))
print(len(visited))

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

// a + b = a XOR b  <->  aとbで同じbitが同時には立たない
// 上の条件のもとで、a XOR b <= L
// Lの最上位bitがa, bで立っていなければOK
// Lの最上位bitがa, bどちらかで立っているときは、それ以下のbitの場合に帰着（DP）

long long mod = 1e9 + 7;
string L;
long long dp[100001];
int on_bit_cnt = 0;

long long pow(long long a, long long x){
    a %= mod;
    if(x == 0){
        return 1;
    }
    if(x % 2){
        return pow(a * a % mod, x / 2) * a % mod;
    }else{
        return pow(a * a % mod, x / 2) % mod;
    }
}

int main(){
    cin >> L;
    dp[0] = 1;
    for(int i = 1; i <= L.length(); i++){
        int pos = L.length() - i;
        if(L[pos] == '0'){
            dp[i] = dp[i - 1] + 0;
        }else{
            dp[i] = pow(3, i - 1) + 2 * dp[i - 1];
            dp[i] %= mod;
        }
    }

    cout << dp[L.length()] << endl;
    
}


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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
  ll k;
  ll x=0;
  ll ans = -1;

  scanf("%lld", &k);

  if(k%2 == 0 || k%5 == 0){
      printf("-1\n");
      return 0;
  }

  for(int i=1; i<=k+5; i++){
      x = (10*x+7) % k;
      if(x == 0){
          ans = i;
          break;
      }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
//#define N 1000000007

using namespace std;

int main(){
    lli n,m,a,b;
    lli i;
    string ans="IMPOSSIBLE";
    vector<lli> v,w;
    cin>>n>>m;
    bool s[n],g[n];
    rep(i,0,n){
        s[i]=false;
        g[i]=false;
    }
    rep(i,0,m){
        cin>>a>>b;
        if(a==1){
            s[b-1]=true;
        }
        if(b==n){
            g[a-1]=true;
        }
    }
    rep(i,0,n){
        if((s[i]==true)&&(g[i]==true)){
            ans="POSSIBLE";
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;


#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;
int n, k, r, s, p;

char f(char x){
  if(x == 'r'){
    return 'p';
  } else if(x == 's'){
    return 'r';
  } else {
    return 's';
  }
}
char win;
char next_win;
bool judge(char x){
  if(win != x && next_win != x) return true;
  else return false;
}

int main(){
  
  string t;
  cin >> n >> k >> r >> s >> p;
  cin >> t;

  ll ans = 0;
  vector<char> a(n);

  map<char, int> scores;
  scores['p'] = p;
  scores['r'] = r;
  scores['s'] = s;

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

    win = f(t[i]);

    if(i >= k){
      if(a[i - k] == win){
        if(i + k < n){
          next_win = f(t[i + k]);

          if(judge('p'))  a[i] = 'p';
          if(judge('r'))  a[i] = 'r';
          if(judge('s'))  a[i] = 's';
        }

      } else {

        ans += scores[win];
        a[i] = win;

      }
    } else {
      a[i] = win;

      ans += scores[win];
    }
  }

  cout << ans << endl;

}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
const ll inf = (ll)1e15;
const ll N = (ll)2e5+77;
const ll mod = (ll)1e9+7;

int main() {
    fast;
    ll h, w, c[10][10], a[1001][1001];
    cin >> h >> w;
    forn(i, 10) forn(j, 10) cin >> c[i][j];
    forn(i, h) forn(j, w) cin >> a[i][j];

    forn(k, 10) forn(i, 10) forn(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

    ll ans = 0;
    forn(i, h) forn(j, w) {
            if (a[i][j] == -1) continue;
            ans += c[a[i][j]][1];
        }

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

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

int main(void){
	string s;
	cin >> s;
	string ans = "keyence";
	bool fl = true;
	for(int i = 0; i < s.size(); ++i){
		int j, k = 0;
		fl = true;
		for(j = 0; j < i; ++j, k++){
			if(s[j] != ans[k]) fl = false;
		}
		for(j = i + s.size() - 7; j < s.size(); ++j, ++k){
			if(s[j] != ans[k]) fl = false;
		}
		if(fl){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

class Program
{
	static void Main(string[] args)
	{
		string str = Scan.Str();

		bool w = false;
		bool e = false;
		bool n = false;
		bool s = false;
		foreach (var ch in str)
		{
			if (ch == 'W') w = true;
			if (ch == 'E') e = true;
			if (ch == 'N') n = true;
			if (ch == 'S') s = true;
		}

		if (!w && e) { Console.WriteLine("No"); return; }
		if (w && !e) { Console.WriteLine("No"); return; }
		if (!n && s) { Console.WriteLine("No"); return; }
		if (n && !s) { Console.WriteLine("No"); return; }

		Console.WriteLine("Yes");
	}
}



static class Scan
{
	static Queue<string> _queue = new Queue<string>();
	public static string Str()
	{
		return Read();
	}
	public static char Char()
	{
		return Read()[0];
	}
	public static int Int()
	{
		return int.Parse(Read());
	}
	public static long Long()
	{
		return long.Parse(Read());
	}
	public static BigInteger BigInt()
	{
		return BigInteger.Parse(Read());
	}
	public static double Double()
	{
		return double.Parse(Read());
	}
	static string Read()
	{
		if (_queue.Count > 0)
			return _queue.Dequeue();
		foreach (var s in Console.ReadLine().Split()) _queue.Enqueue(s);
		return _queue.Dequeue();
	}
}


Measured memory_bytes: 2904
// Code for A - Security
#include <bits/stdc++.h>
using namespace std;

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

  for (int i = 0;i < S.size() - 1; i++) {
    if (S[i] == S[i+1]) {
      cout << "Bad";
      return 0;
    }
  }
	cout << "Good";
	return 0;
}


Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from heapq import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
3 4
4 3
4 1
2 2
'''

def solve(l,m):
	n = len(l)
	L = [[] for i in range(10**5+1)]
	for i in l:
		d,r = i
		L[d].append(r)
	ans = 0
	hp = []
	for i in range(1,m+1):
		for j in L[i]:
			heappush(hp,-j)
		if(hp):
			ans -= heappop(hp)
	return ans

N,M = list(map(int, stdin.readline().rstrip().split()))
l = []
for _ in range(N):
	a,b = list(map(int, stdin.readline().rstrip().split()))
	l.append([a,b])
ans = solve(l,M)
print(ans)


Measured memory_bytes: 81116
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);
    int M = INF, nm = 0;
    int ans = 0;
    REP(i, N){ 
        ans += llabs(A[i]);
        Min(M, llabs(A[i]));
        if(A[i] <= 0){
            nm++;
        }
    }
    if(nm % 2) ans -= 2 * M;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();

		int[] a = new int[A.length()];
		int[] b = new int[B.length()];

		if(A.length()>B.length()){
			System.out.println("GREATER");
			return;
		}else if(A.length()<B.length()){
			System.out.println("LESS");
			return;
		}else{
			for(int i=0; i<A.length(); i++){
				String a1 = String.valueOf(A.charAt(i));
				String b1 = String.valueOf(B.charAt(i));
				a[i] = Integer.parseInt(a1);
				b[i] = Integer.parseInt(b1);
				if(a[i]>b[i]){
					System.out.println("GREATER");
					return;
				}else if(a[i]<b[i]){
					System.out.println("LESS");
					return;
				}
			}
		}
		System.out.println("EQUAL");
	}
}


Measured memory_bytes: 23764
/*
 * a.cc: 
 */

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

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  string s;
  getline(cin, s);

  int n = s.size();

  for (int i = 0; i < n; i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') putchar(s[i] - 'A' + 'a');
    else if (s[i] >= 'a' && s[i] <= 'z') putchar(s[i] - 'a' + 'A');
    else putchar(s[i]);
  }
  putchar('\n');
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll n; cin>>n;
  cout<<n*(n-1)/2;
}

Measured memory_bytes: 256
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
counter = dict(Counter(A))
counter_list = list(counter.values())
counter_list.sort()

ans = 0


z = len(counter_list)
for c in counter_list:
    if z > K:
        z -= 1
        ans += c
    else:
        print(ans)
        break




Measured memory_bytes: 38696
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,count=0,c=0;
    cin >>a;
    c=a*800;
    while(c>=0){
        c -= 800*15;
        count++;
    }
    cout<<a*800-(200*(count-1))<<endl;
}


Measured memory_bytes: 256
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();

        StringBuffer sb = new StringBuffer();
        if (a < b) {
            for (int i = 0; i < b; i++) {
                sb.append(a);
            }
        }else {
            for (int i = 0; i < a; i++) {
                sb.append(b);
            }
        }

        System.out.println(sb.toString());
    }
}

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

signed main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    S += '-';

    vector<int> v, ac;
    ac.push_back(0);
    bool hand = (S[0] == '0');
    for (int cnt = 0, i = 0; i < N + 1; i++) {
        if (i && S[i] != S[i - 1]) {
            v.push_back(cnt);
            ac.push_back(ac.back() + cnt);
            cnt = 0;
        }
        cnt++;
    }

    int ans = 0;
    int l = 0, r = 0;
    for (int i = 1; i < ac.size(); i++) {
        r = i;
        l = max(l, r - K * 2 - (i + hand) % 2);
        int t = max(ans, ac[r] - ac[l]);
        ans = max(ans, t);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2164
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>

using namespace std;

#define NODE (128)
#define INF (1 << 30)
#define SHOP (6)

int cost[NODE][NODE];
int v[1 << (SHOP)][NODE];
int V;
int m, n, k, d;
int cake[SHOP];

typedef struct{
	int pos, val, bit;
} State;

bool operator > (const State &a, const State &b)
{
	return (a.val > b.val);
}

int conv(char *s)
{
	if (s[0] == 'H') return (0);
	if (s[0] == 'D') return (m + n + 1);
	if (s[0] == 'C') return (atoi(s + 1));
	return (atoi(s + 1) + m);
}

void dijkstra()
{
	priority_queue<State, vector<State>, greater<State> > que;
	State st;
	
	st.pos = 0, st.val = 0, st.bit = 0;
	que.push(st);
	
	for (int i = 0; i < 1 << (SHOP); i++){
		for (int j = 0; j < V; j++){
			v[i][j] = INF;
		}
	}
	v[0][0] = 0;
	
	while (!que.empty()){
		State temp = que.top(); que.pop();
		for (int i = 0; i < V; i++){
			if (i == temp.pos || cost[temp.pos][i] == INF){
				continue;
			}
			
			State next;
			next.val = temp.val + cost[temp.pos][i];
			next.pos = i;
			next.bit = temp.bit;
			if (1 <= i && i <= m){
				if (!((next.bit >> (i - 1)) & 1)){
					next.bit |= (1 << (i - 1));
					next.val -= cake[i - 1];
				}
				else continue;
			}
			
			if (v[next.bit][i] > next.val){
				v[next.bit][i] = next.val;
				que.push(next);
			}
		}
	}
}

int main(void)
{
	int i, j, l;
	int from, to;
	int cal;
	char div[5];
	
	while (1){
		scanf("%d %d %d %d", &m, &n, &k, &d);
		if (m + n + k + d == 0){
			break;
		}
		
		V = m + n + 2;
		
		for (i = 0; i < m; i++){
			scanf("%d", &cake[i]);
		}
		
		for (i = 0; i < V; i++){
			for (j = 0; j < V; j++){
				cost[i][j] = INF;
			}
		}
		
		for (i = 0; i < d; i++){
			scanf("%s", div);
			from = conv(div);
			scanf("%s", div);
			to = conv(div);
			
			scanf("%d", &cal);
			
			cost[from][to] = cost[to][from] = cal * k;
		}
		
		int ans = INF;
		
		dijkstra();
		
		for (i = 0; i < 1 << (SHOP); i++){
			ans = min(ans, v[i][m + n + 1]);
		}
		
		printf("%d\n", ans);
	}
	return (0);
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        bool flg = false;

        rep(i, 1, 10) {
                rep(j, 1, 10) {
                        if (i * j == N) flg = true;
                }
        }
        if (flg) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}

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

const int MAX_H = 510;

int main(){
    int H, W;  cin >> H >> W;
    int a[MAX_H][MAX_H] = {0};
    FOR(i, 1, H + 1){
        FOR(j, 1, W + 1){
            cin >> a[i][j];
        }
    }
    
    int cnt = 0;
    vector<vector<int>> ans;
    FOR(h, 1, H + 1){
        FOR(w, 1, W + 1){
            vector<int> tmp;
            if(a[h][w] % 2 == 1 && !(h == H && w == W)){
                cnt++;
                tmp.push_back(h);
                tmp.push_back(w);
                if(w + 1 <= W && a[h][w+1] % 2 == 1){
                    a[h][w+1]++;
                    tmp.push_back(h);
                    tmp.push_back(w+1);
                }else if(h + 1 <= H && a[h+1][w] % 2 == 1){
                    a[h+1][w]++;
                    tmp.push_back(h+1);
                    tmp.push_back(w);
                }else if(w + 1 <= W){
                    a[h][w+1]++;
                    tmp.push_back(h);
                    tmp.push_back(w+1);
                }else if(h + 1 <= H){
                    a[h+1][w]++;
                    tmp.push_back(h+1);
                    tmp.push_back(w);
                }
                ans.push_back(tmp);
            }
        }
    }
    cout << cnt << endl;

    rep(i, ans.size()){
        rep(j, 4){
            cout << ans[i][j];
            if(j != 3) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 9904
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
    char c[4];
    for (int i = 0; i < 4; ++i)
    {
        cin >> c[i];
    }
    int val = 0;
    for (int i = 0; i < 4; ++i)
    {
        if (c[i] == '+')
        {
            ++val;
        }
        else
        {
            --val;
        }
    }
    cout << val << endl;
}

Measured memory_bytes: 256
/*package whatever //do not write package name here */

import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;

class Main {
    static long dp[][];
    public static long knapsack(int i,int v[],int w[],int C){
         if(i==0||C==0)return 0;
         if(dp[i][C]!=-1)return dp[i][C] ;
         if(C<w[i-1])dp[i][C]= knapsack(i-1, v, w, C);
         else dp[i][C]= Math.max(v[i-1]+knapsack(i-1, v, w, C-w[i-1]),knapsack(i-1, v, w, C));
         return dp[i][C];
    }
	public static void main (String[] args)throws IOException{
		//code
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		String[]s=br.readLine().split("\\s+");
		
            int n=Integer.parseInt(s[0]);
            int C=Integer.parseInt(s[1]);
            int []v=new int[n];
            int []w=new int[n];
		   
		    for(int i=0;i<n;i++){
                s=br.readLine().split("\\s+");
                w[i]=Integer.parseInt(s[0]);
                v[i]=Integer.parseInt(s[1]);
            }
            dp=new long[n+1][C+1];
            for(int i=0;i<=n;i++)
            Arrays.fill(dp[i],-1);
            long res=knapsack(n, v, w, C);
            //for(int i=0;i<n;i++)
             //System.out.println(Arrays.toString(dp[i]));
            System.out.print(res);
		
		    
	
		
	}
}


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

void pok() {
  cout << "Yes" << endl;
}
void png() {
  cout << "No" << endl;
}

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

  if (N % 4 == 0) pok();
  else if (N % 7 == 0) pok();
  else {
    int four_max = N / 4 + 1;
    bool flg = false;
    for (int four_num = 1; four_num < four_max; four_num++) {
      int tmp = N - 4 * four_num;
      if (tmp % 7 == 0) {
        pok();
        flg = true;
        break;
      }
    }

    if(!flg) png();
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
     int a,b;
     cin >> a >> b;
     int A = b - a;
     int sum = 0;
     for(int i = 1; i < A + 1; i++){
          sum += i;
     }
     cout << sum - b << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count = 0
total = 0
for i in range(n):
    if count < m:
        count += ll[i][1]
        total += ll[i][0]*ll[i][1]
    else:
        c = count-m
        total -= ll[i-1][0]*c
        print(total)
        exit()
    if i == n-1:
        d = m - count
        total += ll[i][0]*d
        print(total)
        exit()

Measured memory_bytes: 61788
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 15;
char s[N];

inline void GG(){
	puts("No");exit(0);
}

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	if (n&1) GG();
	For(i,1,n) 
		if (i&1){
			if (s[i]!='h') GG(); 
		} else if (s[i]!='i') GG();
	puts("Yes");
}

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

string lcs(string a,string b){
    int la=a.length();
    int lb=b.length();
    vector<vector<int>> dp(la+1,vector<int>(lb+1,0));
    for(int i=1;i<=la;++i){
        for(int j=1;j<=lb;++j){
            if(a[i-1]==b[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }else{
                dp[i][j]=max(dp[i-1][j],max(dp[i][j-1],dp[i-1][j-1]));
            }
        }
    }
    //cout<<dp[la][lb]<<endl;
    string ans="";
    int i=la;int j=lb;
    while(i!=0 and j!=0){
        if(a[i-1]==b[j-1]){
            ans.push_back(a[i-1]);
            i=i-1;j=j-1;
        }else if(dp[i][j-1]==dp[i][j]){
            j=j-1;
        }else{
            i=i-1;
        }
    }
    reverse(ans.begin(),ans.end());
    return ans;
}


int main() {
    string a="";cin>>a;
    string b="";cin>>b;
    cout<<lcs(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 35584
X, Y  = map(int,input().split())
def check(kame, tsuru):
    if kame*4 + tsuru*2 == Y:
        return True
        
def checkWhole():
    for kame in range(X+1):
        if check(kame, X-kame):
            return True
    return False


if checkWhole():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
#include<stdio.h>

int main(){
  int x,y,d,t;

  scanf("%d %d",&x,&y);

  if(x < y){
    t = x;
    x = y;
    y = t;
  }

  d = x % y;
  while(d != 0){
    x = y;
    y = d;
    d = x % y;
  }
  
  printf("%d\n",y);
  
  return 0;
}



Measured memory_bytes: 2144
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    X, Y = LI()
    ans = 0
    if X == 1:
        ans += 300000
    elif X == 2:
        ans += 200000
    elif X == 3:
        ans += 100000

    if Y == 1:
        ans += 300000
    elif Y == 2:
        ans += 200000
    elif Y == 3:
        ans += 100000

    if X == 1 and Y == 1:
        ans += 400000

    print(ans)
    return


# B
def B():
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    A()
    return


# Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]  # parent
        self.rank = [0 for i in range(n)]  # depth
        self.size = [1 for i in range(n)]   # size

    def find(self, x):
        if self.par[x] == x:  
            return x
        else:
            self.par[x] = self.find(self.par[x])  
            return self.par[x]

    def unite(self, x, y):
  
        x = self.find(x) 
        y = self.find(y)  
        if x == y: 
            return
        if self.rank[x] < self.rank[y]:  
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M = [int(x) for x in input().split()]

bridge = []
for i in range(M):
    xi, yi = [int(x) for x in input().split()]
    xi -= 1
    yi -= 1
    bridge.append([xi, yi])

temp = N*(N-1)//2
ans = []
unionfind = UnionFind(N)
# print(unionfind.size)
# print(huben)
ans.append(temp)
i = 0
for xi, yi in (reversed(bridge)):
    #print(unionfind.par,unionfind.rank,unionfind.size,xi,yi)

    if not unionfind.same(xi, yi):
        temp -= unionfind.size[unionfind.find(xi)] * unionfind.size[unionfind.find(yi)]

    ans.append(temp)
    # print(huben)
    unionfind.unite(xi, yi)
    # print(unionfind.size)

#print(ans)

for i in range(2,M+2):
    print(ans[-i])


Measured memory_bytes: 114392
K,A,B=gets.split(" ").map(&:to_i)
if B>A+2
	if K<A
		puts K+1
	else
		puts A+((K-(A-1))/2)*(B-A)+K-(A-1)-((K-(A-1))/2)*2
	end
else
	puts K+1
end

Measured memory_bytes: 1788
#include <iostream>
using namespace std ;
int main(){

int x;
int z;
int c;
cin >> x>> z>> c;
if (x+c<=x+z&&x+c<=z+c){
    cout << x+c;
    }

    else if (x+z<=x+c&&x+z<=z+c){
        cout << x+z;
    }


    else if (c+z<=c+x&&c+z<=z+x){
        cout << c+z;
    }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int dp[100110];

int main(int argc, char const *argv[])
{
	int n, k; cin >> n >> k;
	vector<int> h(n); {
		rep(i, n) cin >> h[i];
	}

	rep(i, 100110) dp[i] = INF;
	dp[0] = 0;

	rep(i, n) rep(t, k) {
		int j = i + t + 1;
		int cost = abs(h[i] - h[j]);
		dp[j] = min(dp[i] + cost, dp[j]);
	}

	printf("%d\n", dp[n - 1]);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <string>

typedef long long ll;
using namespace std;

ll MAX = 1<<10;

int chs[] = {'1','0','+','-','*','(',')'};
int dotpoint[6],dotnum;

int idx=0,pos=0;
char str[101];
char dot[101];
int p7[10];

char peekc(){
  if(str[pos]=='.')
    return dot[pos];
  else 
    return str[pos];
}

char readc(){
  char c=peekc();
  pos++;
  return c;
}

int opcall(char op,int a,int b){
  if(a==-1||b==-1){
    return -1;
  }

  int c;
  switch(op){
  case '+':
    c = a+b;
    break;
  case '-':
    c = a-b;
    break;
  case '*':
    c = a*b;
  }
  if(c<0||c>=1024)
    return -1;
  else
    return c;
}

int read1();
int read2();
int read3();
int readparen();
int readnum();
bool flag=false;

int read1(){
  int l=read2();
  while(1){
    char op=peekc();
    if(op=='+'||op=='-'){
      flag=true;
      readc();
      l=opcall(op,l,read2());
    }else{
      break;
    }
  }
  return l;
}

int read2(){
  int l=read3();
  while(1){
    char op=peekc();
    if(op=='*'){
      flag=true;
      readc();
      l=opcall(op,l,read2());
    }else{
      break;
    }
  }
  return l;
}

int read3(){
  if(peekc()=='('){
    return readparen();
  }else if(peekc()=='0'||peekc()=='1'){
    return readnum();
  }else{
    return -1;
  }
}

int readparen(){
  readc(); // '('
  bool flag2=flag;
  flag=false;
  int l=read1();;
  if(flag&&readc()==')'){
    flag=flag2;
    return l;
  }else{
    return -1;
  }
}

int readnum(){
  int i=0;
  for(;peekc()=='0'||peekc()=='1';)
    i=i*2+(readc()-'0');
  if(i<0||i>=1024)
    return -1;
  else
    return i;
}

int main(){
  p7[0]=1;
  for(int i=1; i<6; i++)
    p7[i]=7*p7[i-1];

  scanf("%s",str);

  dotnum=0;
  for(int i=0; str[i]; i++){
    if(str[i]=='.'){
      dotpoint[dotnum++]=i;
    }
  }

  int ans=-1;
  for(int stat=0; stat<p7[dotnum]; stat++){
    for(int j=0; j<dotnum; j++){
      dot[dotpoint[j]]=chs[(stat/p7[j])%7];
    }
    pos=0;
    int ret=read1();
    if(str[pos]==0)
      ans=(ans<ret)?ret:ans;
  }

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

Measured memory_bytes: 968
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll A;
    cin >> A;
    double B;
    cin >> B;
    ll b = round(B * 100.0);
    ll v1 = (A / 100) * b;
    ll a = A % 100;
    double ad = (double) a;
    ad = floor(ad * B);
    v1 += (ll) ad;
    print(v1);


    

}

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


Measured memory_bytes: 3788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20180319_AOJ
{
    class ALDS1_11B
    {
        static int time;
        static int[,] graph;
        static int[,] outArr;
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int n = int.Parse(line);
                time = 1;
                graph = new int[n + 1, n + 1];
                for (int i = 0; i < n; i++)
                {
                    int[] vertex = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    int u = vertex[0];
                    for (int k = 0; k < vertex[1]; k++)
                    {
                        graph[u, vertex[k + 2]] = 1;
                    }
                }

                outArr = new int[n + 1, 2];  // id : d, f

                for (int i = 1; i <= n; i++)
                {
                    DepthFirstSearch(i);
                }

                for (int i = 1; i < outArr.GetLength(0); i++)
                {
                    int d = outArr[i, 0];
                    int f = outArr[i, 1];
                    Console.WriteLine("{0} {1} {2}", i, d, f);
                }
            }
        }

        static void DepthFirstSearch(int id)
        {
            if (outArr[id, 0] > 0)
            {
                return;
            }

            outArr[id, 0] = time++;

            for (int i = 1; i < graph.GetLength(1); i++)
            {
                if (graph[id, i] == 1)
                {
                    DepthFirstSearch(i);
                }
            }

            outArr[id, 1] = time++;
        }
    }
}



Measured memory_bytes: 9756
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    ll N;cin>>N;
    string s;cin>>s;
    ll w[300010],e[300020],cn=0;
    w[0]=0;e[N-1]=0;
    rep(i,1,N){
        if(s.at(i-1)=='W'){
            cn++;
        }
        w[i]=cn;
    }
    cn=0;
    rep(i,1,N){
        if(s.at(N-i)=='E'){
            cn++;
        }
        e[N-i-1]=cn;
    }
    ll MIN=5555555;
    rep(i,0,N){
        MIN=min(MIN,w[i]+e[i]);
    }
    cout<<MIN<<endl;
}






Measured memory_bytes: 5380
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
int n,k,i,x,ans,f[100005];
int top,nex[200005],to[200005],fir[100005];
void lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
void ss(int u,int v){
	for(int top1=fir[v];top1;top1=nex[top1]){
		ss(v,to[top1]);
		f[v]=max(f[to[top1]],f[v]);
	}
	if(v==1)
		return;
	f[v]++;
	if(f[v]==k&&u!=1){
		ans++;
		f[v]=0;
	}
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();k=read();
   	x=read();
   	if(x!=1)
   		ans++;
   	for(i=2;i<=n;i++){
   		x=read();   		
   		lj(x,i);
   	}
   	ss(1,1);
   	pus(ans,2);
    return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 1;
		int unchange = K;

		while(N/K>0) {
			ans++;
			K = K*unchange;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
L, R = map(int, input().split())

module = []
for i in range(L, R):
    for j in range(i+1, R+1):
        #print("({} * {}) mod 2019 = {}".format(i, j, (i * j) % 2019))
        if (i * j) % 2019 == 0:
            print("0")
            exit()
        else:
            module.append((i * j) % 2019)

if not module:
    print("0")
else:
    print(min(module))


Measured memory_bytes: 6800
N = int(input())

ss = [[1], [1]]
n = 2

for i in range(1, N):
    l = i + 1
    ss = [ss[i] + [n + i] for i in range(l)]
    ss += [[n + i for i in range(l)]]
    n += l
    if n - 1 >= N:
        break

if n - 1 == N:
    print("Yes")
    print(len(ss))
    for r in ss:
        print(len(r), *r)
else:
    print("No")


Measured memory_bytes: 13960
#include <stdio.h>
int n, a;
long long d;
long long x, y, r;
int main() {
	scanf("%d%lld", &n, &d);
	d = d * d;
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &x, &y);
		r = x * x + y * y;
		if (r <= d)a++;
	}
	printf("%d\n", a);
}

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

int cmp(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}

int main(){
	int i,w[10],k[10],point[2];
	for(i=0;i<10;i++){
		scanf("%d",&w[i]);
	}
	for(i=0;i<10;i++){
		scanf("%d",&k[i]);
	}
	qsort(w,10,sizeof(int),cmp);
	qsort(k,10,sizeof(int),cmp);
	point[0]=w[0]+w[1]+w[2];
	point[1]=k[0]+k[1]+k[2];
	printf("%d %d\n",point[0],point[1]);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b;
  c=a+b;
  if(c>=10){
    cout<<"error"<<"\n";
  }
  else{
    cout<<c<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3652
n = list(map(int, list(input())))
k = int(input())

dp0 = [0]*3
dp1 = [[0]*3]*len(n)
dp0[0] = 1
dp1[0][0] = max(0, n[0]-1)
for i in range(1, len(n)):
    dp1[i] = [
        dp1[i-1][0]+dp0[0]*(n[i]!=0)+9,
        dp1[i-1][1]+dp0[1]*(n[i]!=0)+dp0[0]*max(0, n[i]-1)+dp1[i-1][0]*9,
        dp1[i-1][2]+dp0[2]*(n[i]!=0)+dp0[1]*max(0, n[i]-1)+dp1[i-1][1]*9,
    ]
    if n[i] != 0:
        dp0 = [0]+dp0[:2]
print(dp0[k-1]+dp1[-1][k-1])

Measured memory_bytes: 9156
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-04-19 21:24:22 +0900
# LastModified: 2020-04-19 21:31:26 +0900
#


import os
import sys
from collections import Counter as ct


def main():
    n=int(input())
    a = list(map(int,input().split()))
    c = ct(a)
    
    for i in range(1,n+1):
        if i in c.keys():
            print(c[i])
            continue
        print(0)

if __name__ == "__main__":
    main()


Measured memory_bytes: 33976
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(N-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    
    int ans = 0;
    rep(i, n) {
        for (int j = i + 1; j < n; j++) {
            ans += data[i] * data[j];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	defer writer.Flush()
	N, Q := ReadInt(), ReadInt()
	c := append([]int{0}, ReadInts(N)...)
	lefts := make([]int, Q)
	rights := make([]int, Q)
	queryIDs := make([]int, Q)
	for q := 0; q < Q; q++ {
		queryIDs[q] = q
		lefts[q], rights[q] = ReadInt(), ReadInt()+1
	}
	sort.Slice(queryIDs, func(i, j int) bool {
		return rights[queryIDs[i]] < rights[queryIDs[j]]
	})

	t := MakeSegTree(N + 1)
	seen := make([]int, N+1)
	q := 0
	answers := make([]int, Q)
	for i := 1; i <= N && q < Q; i++ {
		if seen[c[i]] > 0 {
			t.Add(seen[c[i]], -1)
		}
		t.Add(i, 1)
		seen[c[i]] = i
		for q < Q && i+1 == rights[queryIDs[q]] {
			answers[queryIDs[q]] = t.Sum(lefts[queryIDs[q]], rights[queryIDs[q]])
			q++
		}
	}
	for _, answer := range answers {
		Println(answer)
	}
}

type SegTree []int

func MakeSegTree(n_ int) SegTree {
	n := 1
	for n < n_ {
		n <<= 1
	}
	return make([]int, n*2)
}

func (t SegTree) Add(i, x int) {
	i += len(t) >> 1
	for i > 0 {
		t[i] += x
		i >>= 1
	}
}

func (t SegTree) Sum(a, b int) int {
	return t.sumRecur(a, b, 1, 0, len(t)>>1)
}
func (t SegTree) sumRecur(a, b, k, l, r int) int {
	if b <= l || r <= a {
		return 0
	}
	if a <= l && r <= b {
		return t[k]
	}
	v := 0
	v += t.sumRecur(a, b, k<<1, l, (l+r)>>1)
	v += t.sumRecur(a, b, k<<1+1, (l+r)>>1, r)
	return v
}

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        string S; cin >> S;
        bool ok = true;
        rep(i, S.size()) {
            if(i % 2 == 0) ok &= (S[i] == 'R' or S[i] == 'U' or S[i] == 'D');
            else ok &= (S[i] == 'L' or S[i] == 'U' or S[i] == 'D');
        }
        cout << (ok ? "Yes" : "No") << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

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

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

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

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

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

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

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

fn main() {
    input! {
        a: usize,
        p: usize,
    }
    println!("{}", (a*3 + p)/2);
}


Measured memory_bytes: 4352
#include <stdio.h>
int main (int argc, char * argv[])
{
    char x[1000];
    int sum;
    while (1){
        sum =0;
        scanf("%s",x);
        if(x[0] == '0'){
            break;
        }
        for(int i=0;x[i]!='\0';i++){
            sum += x[i]-'0';
        }
        printf("%d\n",sum);
        
        }
    return 0;
}



Measured memory_bytes: 2040
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();    
        int[] a = r.ii();
        int count = 0;
        loop: for(int i = 0; i < 3001; i++){
            for(int j = 0; j < 3001; j++){
                int rR = a[3]-a[2]*i-a[1]*j;
                if(rR >= 0){
                    if(rR%a[0] == 0){
                        count++;
                    }
                }
                else{
                    continue loop;
                }
            }
        }
        print(count);
    }

    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 21204