akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
int main(){
	map<string,set<int> >index;
	string tmp;
	int tmp2;
	
	while(cin>>tmp>>tmp2){
		index[tmp].insert(tmp2);
	}
	
	map<string,set<int> >::iterator k=index.begin();
	while(k!=index.end()){
		
		tmp2=0;
		set<int>::iterator g=index[k->first].begin();
		cout<<k->first<<endl;
		while(g!=index[k->first].end()){
			if(tmp2)cout<<" ";
			cout<<(*g);
			g++,tmp2++;
		}
		cout<<endl;
		k++;
		
	}
	/*
	C++ マップ(std::map)
	
	C++ マップはキー／値の対を保持する連想コンテナである。
	
	begin()	マップの先頭を指すイテレータを返す。
	clear()	全ての要素を削除する
	count()	キー値が一致する要素の数を返す
	empty()	マップが空なら真
	end()	マップの末尾を指すイテレータを返す
	equal_range()	特定のキーと一致する先頭・末尾要素を指すイテレータを返す
	erase()	要素を削除する
	find()	要素を検索する
	get_allocator()	マップのアロケータを返す
	insert()	要素を挿入する
	key_comp()	キーを比較する関数を返す
	lower_bound()	キーが特定の値以上である最初の要素を指すイテレータを返す
	max_size()	要素の最大数を返す
	rbegin()	マップの末尾を指すリバースイテレータを返す
	rend()	マップの先頭を指すリバースイテレータを返す
	size()	マップ中の要素数を返す
	swap()	二つのマップを入れ替える
	upper_bound()	キーが特定の値を越える最初の要素を指すイテレータを返す
	value_comp()	値を比較する関数を返す
	*/
	
	return 0;
}


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

using namespace std;
using ll = long long;

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  for (int i = 0; i < a; i++)
    cin >> p[i];
  for (int i = 0; i < b; i++)
    cin >> q[i];
  for (int i = 0; i < c; i++)
    cin >> r[i];

  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());

  vector<ll> v;
  for (int i = 0; i < x; i++)
    v.push_back(p[i]);
  for (int i = 0; i < y; i++)
    v.push_back(q[i]);
  for (int i = 0; i < c; i++)
    v.push_back(r[i]);

  sort(v.begin(), v.end(), greater<ll>());
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += v[i];
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

int add(int a, int b){
    return (a+b)%MOD;
}

int mul(int a, int b){
    return ((ll)a*b)%MOD;
}

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    int last = 0;
    int res = 1;
    for(int i=0; i<n; i++){
        if(s1[i] == s2[i]){
            if(last == 1) res = mul(res, 2);
            if(last == 0) res = mul(res, 3);
            last = 1;
        }
        else if(last == 0){
            res = mul(res, 6);
            last = 2;
        }
        else if(last == 1){
            res = mul(res, 2);
            last = 2;
        }
        else if(last == 2){
            last = 3;
        }
        else if(last == 3){
            res = mul(res, 3);
            last = 2;
        }
    }
    cout << res;
    return 0;
}


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

const int MOD = 1000000007;
#define p(var)  std::cout<<var<<std::endl
#define pp(var) std::cout<<#var" = "<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for (int i = 0; i <  (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a;}
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b;}

/*-----8<-----8<-----*/

int main(){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> a(X,0),b(Y,0),c(Z,0);
    rep(i,X)
        cin >> a[i];
    rep(i,Y)
        cin >> b[i];
    rep(i,Z)
        cin >> c[i];


    //nth_element(a.begin(), a.begin() + K-1, a.end(), greater<ll>());
    //nth_element(b.begin(), b.begin() + K-1, b.end(), greater<ll>());
    //nth_element(c.begin(), c.begin() + K-1, c.end(), greater<ll>());
    sort(all(a),greater<ll>());
    sort(all(b),greater<ll>());
    sort(all(c),greater<ll>());
    
    vector<ll> v;
    rep(i,X){
        rep(j,Y){
            rep(k,Z){
                if((i+1)*(j+1)*(k+1)>K)continue;
                ll t=a[i]+b[j]+c[k];
                v.pb(t);
                //pp(t);
            }
        }
    }

    //sort(all(a));

    //nth_element(v.begin(), v.begin() + K-1, v.end(), greater<ll>());
    //sort(v.begin(), v.end(), greater<ll>());
    //cout << v.end()-v.begin() <<endl;
    partial_sort(v.begin(), v.begin() + K, v.end(), greater<ll>());
    //p("------");
    rep(i,K)cout << v[i] << endl;

    return 0;
    
}






Measured memory_bytes: 1404
#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(){
  char num[5];

  scanf("%s", num);

  for (int i = 0; i < 3; i++)
  {
      if(num[i] == '7'){
          printf("Yes\n");
          return 0;
      }
  }

  printf("No\n");
  

  return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    string S;
    std::cin >> S;

    REP(i, S.size()) {
        int index = S[i] - 'A';
        index += N;
        index %= 26;
        S[i] = 'A' + index;
    }
    std::cout << S << std::endl;

    return 0;
}


Measured memory_bytes: 892
/**
*    author:  boutarou
*    created: 05.07.2020 21:11:02
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

int n;
lint a[200005];
lint ans = 0;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    for (int i = 1; i < n; i++) {
        ans += a[i / 2];
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s = 1e9, e;
  string ss;
  cin >> ss;
  int l = ss.size();
  for(int i = 0; i < l; i++)
  {
    if(ss[i] == 'A')s = min(s, i+1);
    if(ss[i] == 'Z')e = i+1;
  }
  printf("%d", e-s+1);
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    var S = sc.next
    if (S != "-") {
      Array.fill(sc.nextInt) {
        val n = sc.nextInt
        S = S.substring(n) + S.substring(0, n)
        ()
      }
      println(S)
      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}




Measured memory_bytes: 45280
import sys
input = lambda: sys.stdin.readline().rstrip()
R, C, N = map(int, input().split())
X = {0, R}
Y = {0, C}

Z = []
for i in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    if (x1 == 0 or x1 == R or y1 == 0 or y1 == C) and (x2 == 0 or x2 == R or y2 == 0 or y2 == C):
        Z.append((x1, y1, x2, y2))
        X.add(x1)
        X.add(x2)
        Y.add(y1)
        Y.add(y2)

DX = {a: i for i, a in enumerate(sorted(list(X)))}
DY = {a: i for i, a in enumerate(sorted(list(Y)))}
R, C = DX[R], DY[C]

def calc(a, b):
    if b == 0:
        return a
    if a == R:
        return b + R
    if b == C:
        return R + C + (R - a)
    if a == 0:
        return R + C + R + (C - b)

A = []
for i, (x1, y1, x2, y2) in enumerate(Z):
    x3, y3, x4, y4 = DX[x1], DY[y1], DX[x2], DY[y2]
    A.append((calc(x3, y3), i))
    A.append((calc(x4, y4), i))

A = [l[1] for l in sorted(A, key = lambda x: x[0])]
B = []

while A:
    while len(B) and A[-1] == B[-1]:
        A.pop()
        B.pop()
    if A:
        B.append(A.pop())

print("NO" if len(B) else "YES")

Measured memory_bytes: 120916
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;


const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ruiseki(n+2,0);
    REP(i,n-1){
        if(s[i]=='A'&&s[i+1]=='C'){
            ruiseki[i+2]++;
        }
    }
    int tmp=0;
    REP(i,n+1){
        ruiseki[i]+=tmp;
        tmp=ruiseki[i];
    }
    REP(i,q){
        int l,r;
        cin >> l >> r;
        cout << ruiseki[r]-ruiseki[l] << endl;
    }
}

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


int main() {
    int H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int res = H2*60 + M2 - H1*60 - M1;
    cout << res-K << endl;

}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	string s;
	cin >> s;
	if (s[0] == 'S') {
		cout << "Cloudy" << "\n";
	}
	else if (s[0] == 'C') {
		cout << "Rainy" << "\n";
	}
	else {
		cout << "Sunny" << "\n";
	}

	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    if (n == 1) {
        cout << 1 << '\n';
        return 0;
    }
    if (n == 2) {
        if (s[0] != s[1]) {
            cout << 2 << '\n';
        }
        else {
            cout << 1 << '\n';
        }
        return 0;
    }
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            continue;
        }
        else {
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
n,m=map(int,raw_input().split())
d=[int(raw_input()) for _ in xrange(n)]
c=[int(raw_input()) for _ in xrange(m)]
dp=[[float('inf')]*(m+1) for _ in xrange(n+1)]
for i in xrange(m+1):
    dp[0][i]=0
for i in xrange(n):
    for j in xrange(m):
        dp[i+1][j+1]=min(min(dp[i+1]),dp[i][j]+d[i]*c[j])
print(dp[n][m])

Measured memory_bytes: 17832
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>

int main() {
  std::int_fast64_t n, a, b;
  std::cin >> n >> a >> b;
  std::vector<std::int_fast64_t> x(n);
  for (std::int_fast64_t& x_i : x) {
    std::cin >> x_i;
  }
  std::int_fast64_t result = 0;
  for (std::int_fast64_t i = 1; i < n; ++i) {
    result += std::min(a * (x[i] - x[i - 1]), b);
  }
  std::cout << result << std::endl;
  return 0;
}

Measured memory_bytes: 1024
from itertools import combinations

N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    Ai = int(input())
    for _ in range(Ai):
        x, y = map(int, input().split())
        A[i].append((x - 1, y))

person = [x for x in range(N)]

for h_num in reversed(range(N + 1)):
    for h_ppl in combinations(person, h_num):
        ppl = [0] * N
        for i in h_ppl:
            ppl[i] = 1

        consistency = True
        for i, testimony in enumerate(A):
            for t in testimony:
                if (ppl[i] == 1 and ppl[t[0]] != t[1]):
                    consistency &= False

        if consistency:
            print(h_num)
            exit(0)


Measured memory_bytes: 3064
def c_good_sequence(N, A):
    from collections import Counter
    count = Counter(A)  # 要素iが何回数列に登場したか
    ans = 0
    for k, v in count.items():
        if k == 1:
            if v == 1:
                continue
            else:
                ans += v - k
        elif k != v:
            ans += v % k
    return ans
  
N = int(input())
A = [int(_) for _ in input().split()]
print(c_good_sequence(N, A))

Measured memory_bytes: 18164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 2e18;
const double PI = acos(-1);

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	while (N != 0)
	{

		int mav = 0;
		int miv = 1000;
		int sum = 0;
		REP(i, N)
		{
			int a;
			cin >> a;
			sum += a;
			mav = max(mav, a);
			miv = min(miv, a);
		}
		cout << (sum - mav - miv) / (N - 2) << endl;
		cin >> N;
	}
	return 0;
}



Measured memory_bytes: 3060
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		int N = nextInt();
		ArrayList<Integer> list = nextIntArray();
		int max = 0;
		int sum = 0;
		for(int i = 0; i < N; i++){
			if(list.get(i) > max){
				max = list.get(i);
			}
			sum += list.get(i);
		}
		sum -= max;
		myout((sum > max) ? "Yes" : "No");
	}
	//Method addition frame start



	//Method addition frame end
}


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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    
        int n;
        scanf("%d", &n);
        printf("%d\n", n + n * n + n * n * n);
    
    
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int INF=1<<29,MAX=2222;
int V,match[MAX];
vector<int> G[MAX];
bool used[MAX];
void add_edge(int u,int v){G[u].push_back(v);}

bool dfs(int v){
  used[v]=1;
  for(int i=0;i<G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(w<0||(!used[w]&&dfs(w))){
      match[v]=u;
      match[u]=v;
      return 1;
    }
  }
  return 0;
}

int bipartite_matching(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

int main() {
  int n,m,l;
  while(cin >> n >> m >> l&&n) {
    for(int i=0;i<MAX;i++)G[i].clear();
    V=l;
    int d[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)d[i][j]=INF;
      d[i][i]=0;
    }
    for(int i=0;i<m;i++) {
      int x,y,z;
      cin >> x >> y >> z;
      d[x][y]=min(d[x][y],z);
      d[y][x]=min(d[y][x],z);
    }
    for(int k=0;k<n;k++) {
      for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
          if(d[i][k]!=INF&&d[k][j]!=INF) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
      }
    }
    P a[l];
    for(int i=0;i<l;i++) cin >> a[i].first >> a[i].second;
    for(int i=0; i<l; i++) {
      for(int j=0; j<l; j++) {
        if(i!=j&&a[j].second-a[i].second>=d[a[i].first][a[j].first]) add_edge(i,j+1000);
      }
    }
    cout << l-bipartite_matching() << endl;
  }
  return 0;
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;

int main() {
    //input
    int n; cin >> n;
    long long tate = 0;
    long long yoko = 0;
    long long area = 0;
    vector<long> a(n + 1);
    for(int i = 1; i < n + 1; i++) cin >> a[i];

    //compute
    sort(a.begin() + 1, a.end());
    reverse(a.begin() + 1, a.end());
    int rest = 1;

    for(int i = 1; i < n + 1; i++){
        if(a[i] == a[i + 1]){
           tate = a[i];
           rest = i + 2;
           break;
        }
    }
    
    if(rest > n){
      cout << 0 << endl;
      return 0;   
    }

    for(int i = rest; i < n + 1; i++){
        if(a[i] == a[i + 1]){
           yoko = a[i];
           break;
        }
    }

    area = tate * yoko;

    //output
     cout << area << endl;
}


Measured memory_bytes: 4012
#import<cstdio>
int main(){for(int n,a,c,r,t;c=r=scanf("%d",&n),n;printf("%d\n",r))for(char d[]="123546",s[9];n--;r+=*d-48)scanf("%s",s),*s%6-4?a=*s%5+*s%2*2+c&3,t=*d,*d=d[++a],d[++a-1]=d[5],d[5]=d[a%4+1],d[a%4+1]=t:c+=*s+3;}

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

int main(){
int n,w;
long long dp[2][100002];
cin >>n>>w;
for (int i=0;i<w;i++){
  dp[0][i]=0;
  dp[1][i]=0;
}
for (int i=0;i<n;i++){
  int tmpw,tmpv;
  cin >> tmpw>>tmpv;
  for (int j=1;j<=w;j++){
    //new=dp[n%2] old=dp[(n+1)%2]
    if (tmpw<=j){
      dp[i%2][j]=max(dp[(i+1)%2][j],tmpv+dp[(i+1)%2][max(0,j-tmpw)]);
    } else {
      dp[i%2][j]=dp[(i+1)%2][j];
    }
  }
//  for (int j=1;j<=w;j++){
//    cout << dp[i%2][j]<<"    ";
//  }
//  cout <<endl;
}


cout << dp[(n-1)%2][w]<<endl;

return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x = i;
        if(x % 3 == 0){
            cout << ' ' << i;
            continue;
        }
        while(x){
            if(x % 10 == 3){
                cout << ' ' << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}

Measured memory_bytes: 3084
import sys
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w')\nexcept:pass")

n, m = map(int, input().split())
student, point = [], []
for i in range(n):
    student.append(list(map(int, input().split())))
for i in range(m):
    point.append(list(map(int, input().split())))
dist = []
for i in range(n):
    temp = []
    for j in range(m):
        temp.append([j, abs(student[i][0] - point[j][0]) +
                     abs(student[i][1] - point[j][1])])
    dist.append(temp)
# for dis in dist:
#     print(dis)
tot = []
for dis in dist:
    ans = []
    minn = min(dis, key=lambda i: i[1])
    for i in dis:
        if i[1] == minn[1]:
            ans.append(i[0])
    ans.sort()
    print(ans[0] + 1)
# print(tot)


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int c=0;
    for(i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
        {
            c++;
            a[i]=-1;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
struct node
{
    char a[104];
}st[200];
bool cmp(node s1,node s2)
{
    return strcmp(s1.a,s2.a)<0;
}
int main()
{
    int n,l;
    while(cin>>n>>l)
    {
        for(int i=1;i<=n;i++)
        {
                cin>>st[i].a;
        }
        sort(st+1,st+1+n,cmp);
         for(int i=1;i<=n;i++)
         {
                cout<<st[i].a;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;


int main() {
  int n,q;cin >> n >> q;
  string s;cin >> s;
  int count[n+1];
  rep(i,n+1)count[i]=0;
  //cout << (s[0]=='A'?"saf":"sd");
  reps(i,n){
    if(s[i-1]=='A'&&s[i]=='C'){
      count[i]=count[i-1]+1;
    }else count[i]=count[i-1];
  }
  //rep(i,n) cout << count[i]<< endl;
  rep(i,q){
     int l,r;cin >> l >> r;
     cout << count[r-1]-count[l-1]<< endl;
  }
}


Measured memory_bytes: 1408
import collections
import math


def main():
    n, k, s = map(int, input().split())
    if s > 1:
        print(" ".join([str(s)] * k + [str(s - 1)] * (n - k)))
    else:
        print(" ".join([str(s)] * k + [str(s + 1)] * (n - k)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11356
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	deque<int> dq;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
	
		if( ( (i + 1) % 2 ) ^ ( (n - 1) % 2) ) dq.push_front(a);
		else  dq.push_back(a);
	}
	
	for(auto& ans : dq) {
		cout << ans << " ";
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
string s;	
const int inf = 100000000;
int mem[333][333][333];

int dp(int l, int r, int k) {
	if(k < 0) return -inf;
	if(l == r) return 1;
	if(l > r) {
		return 0;
	}
	if(mem[l][r][k] != -1) return mem[l][r][k];
	int ans = -inf;
	if(s[l] == s[r]) ans = max(ans, 2 + dp(l + 1, r - 1, k));
	ans = max(ans, dp(l + 1, r, k));
	ans = max(ans, dp(l, r - 1, k));
	ans = max(ans, 2 + dp(l + 1, r - 1, k - 1));
	return mem[l][r][k] = ans;
}

int main(int argc, char const *argv[])
{
	cin >> s;
	int k;
	cin >> k;
	memset(mem, -1, sizeof mem);
	cout << dp(0, s.size() - 1, k) << endl;
	return 0;
}

Measured memory_bytes: 144512
s = input()
n = len(s) + 1
ans = 0
val = 0
segument = 0
buf = "<"
for char in s:
    if char == ">":
        if buf == "<":
            segument = 0
        val -= 1
        ans += val
        segument += 1
    else:
        if buf == "<":
            val += 1
            ans += val
            segument += 1
        else:
            if val < 0:
                ans -= (segument + 1) * val
            elif val > 0:
                ans -= segument * val
            segument = 0
            val = 1
            ans += val
    buf = char
if buf == ">":
    if val < 0:
        ans -= (segument + 1) * val
    elif val > 0:
        ans -= segument * val
print(ans)

Measured memory_bytes: 4124
#C
N = int(input())
alphabet = [chr(ord('a') + i) for i in range(26)]
i = 1
tmp = 0
tmppre = 0
while tmp < N:
    if i == 1:
        tmppre = 0
    else:
        tmppre =tmp 
    tmp += 26**i
    i += 1

i -= 1    
tmp = N - tmppre - 1
ans = []
for j in range(i):
    ans.append(tmp//(26 ** (i-j-1)))
    tmp -= (tmp//(26 ** (i-j-1))) * 26 ** (i-j-1)

ans_alpha = ''
for k in range(len(ans)):
    ans_alpha += alphabet[ans[k]]
    
print(ans_alpha)    

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 55;
char str[N][N];
int h, w;
bool ok(int x, int y) {
    if(str[x+1][y]=='#'||str[x-1][y]=='#'||str[x][y+1]=='#'||str[x][y-1]=='#') return 1;
    else return 0;
}
int main() {
    cin >> h >> w;
    for(int i = 1; i <= h; i ++) cin >> str[i]+1;
    for(int i = 1; i <= h; i ++) {
        for(int j = 1; j <= w; j ++) {
            if(str[i][j] == '#' && !ok(i,j))
                return 0*printf("No\n");
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        int NUM = 100001;
        List<Integer> primes = sieveOfEratosthenes(NUM);

        boolean[] isPrime = new boolean[NUM];
        for (int p : primes) {
            isPrime[p] = true;
        }

        int[] cnt = new int[NUM];
        for (int i = 0; i < cnt.length; i++) {
            if (isPrime[i] && (i + 1) % 2 == 0 && isPrime[(i + 1) / 2]) {
                cnt[i]++;
            }
        }

        for (int i = 1; i < cnt.length; i++) {
            cnt[i] += cnt[i - 1];
        }

        for (int i = 0; i < Q; i++) {
            out.println(cnt[r[i]] - cnt[l[i] - 1]);
        }
    }


    public static List<Integer> sieveOfEratosthenes(int max) {
        List<Integer> primes = new ArrayList<Integer>();

        int prime;
        int max_check = (int) Math.floor(Math.sqrt(max));   //ふるい落としのチェックに利用する値
        List<Integer> nums = new ArrayList<Integer>();     //素数候補
        for (int i = 2; i <= max; i++) {
            nums.add(i);
        }


        while (true) {
            // ふるい落とした先頭は素数
            if (nums.size() < 2) {
                break;
            }
            prime = nums.get(0);

            // ふるい落としのチェックに利用する値は最大値の平方根未満の最大値
            if (prime >= max_check) {
                break;
            }

            primes.add(prime);

            // primeでふるい落とし
            List<Integer> rest_nums = new ArrayList<Integer>();
            for (int n : nums) {
                if (n % prime != 0) {
                    rest_nums.add(n);
                }
            }

            // ふるい落とした候補に更新
            nums = rest_nums;
        }

        //残っている候補は素数
        for (int n : nums) {
            primes.add(n);
        }

        return primes;
    }

}

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

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

#define INF 1e10;

using namespace std;

int main(void){
	int N;
	cin >> N;
	vector<int> a(N), b(N), c(N);

	for(int i = 0;i < N;i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	vector<vector<int>> dp(N, vector<int>(3, 0));

	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (int i = 1; i < N; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}

	cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl;

	return 0;
}

Measured memory_bytes: 6912
// AGC 041
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    ll n,a,b; cin >> n >> a >> b;
    if((a%2 == 0 && b%2 == 0) || (a%2 != 0 && b%2 != 0)){
        cout << b - (a+b)/2 << endl;
    }else{
        cout << min(a-1, n-b) + 1 + (b-a-1)/2 << endl;
    }

    return 0;
}

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

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

	if (s[0] == s[1] && s[1] == s[2]) puts("Yes");
	else if (s[1] == s[2] && s[2] == s[3]) puts("Yes");
	else puts("No");

  return 0;
}

Measured memory_bytes: 256
#include<set>
#include<iostream>
#include<ctime>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<functional>
#include<string.h>
#include<limits.h>
using namespace std;

signed main() {
	int a, b, n; cin >> a >> b >> n;
	for (int i = 0; i < n; i++) {
		int c, d; cin >> c >> d;
		int e = min(b, d) - max(a, c);
		if (e > 0) { puts("1"); return 0; }
	}
	puts("0");
}

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

int main(){
    int n; cin >> n;
    map<string, int> m;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        m[s]++;
    }
    int s = m.size();
    pair<int, string> p[s];
    int i = 0;
    for(const auto &a: m){
        p[i].first = a.second; p[i].second = a.first;
        i++;
    }
    sort(p,p+s);
    int ma = p[s-1].first;
    vector<string> str;
    for(int i = s-1; i >= 0; i--){
        if(ma == p[i].first) str.push_back(p[i].second);
        else break;
    }
    for(auto t = str.rbegin(); t != str.rend(); t++){
        printf("%s\n", t->begin());
    }
    return 0;
}

Measured memory_bytes: 39284
//written by NewbieChd
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003;
int a[maxN], b[maxN], c[maxN], ind[maxN];

inline bool cmp(int x, int y) { return c[x] > c[y]; }

int main() {
    int n = read(), m = read(), i, j;
    long long ans = 0, all = 0, have = 0, sum = 0, tot = 0;
    for (i = 1; i <= n; ++i)
        all += a[i] = read();
    for (i = 1; i <= m; ++i)
        b[i] = read(), c[i] = read(), ind[i] = i;
    sort(a + 1, a + n + 1), sort(ind + 1, ind + m + 1, cmp);
    for (i = 1, j = 1; i <= n; ++i) {
        have += a[i];
        for (; j <= m && tot < i; ++j)
            tot += b[ind[j]], sum += 1ll * b[ind[j]] * c[ind[j]];
        if (tot >= i)
            ans = max(ans, all - have + sum - 1ll * c[ind[j - 1]] * (tot - i));
    }
    printf("%lld\n", max(ans, all));
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;
int main(){
    long long n,m;
    long long ans;
    long long nt,mt;
    nt = 1;
    mt=1;
    cin >> n >> m;
    for(long long i=1;i<=n;i++){
        nt=nt*i;
        if(nt>=1000000007){
            nt = nt%1000000007;
        }
    }
    for(long long i=1;i<=m;i++){
        mt=mt*i;
        if(mt>=1000000007){
            mt = mt%1000000007;
        }
    }
    if(abs(n-m)>=2){
        ans = 0;
    }else if((n%2==0&&m%2==0)||(n%2!=0&&m%2!=0)){
        ans = (nt*mt)*2;
    }else{
        ans = nt*mt;
    }
    if(ans>=1000000007){
        ans = ans%1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    arc080c()
}

fun arc080c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }

    val multipleOf2 = aList.filterNot { it % 4 == 0L }.count { it % 2 == 0L }
    val multipleOf4 = aList.count { it % 4 == 0L }

    val answer = when {
        multipleOf4 >= n / 2 -> "Yes"
        multipleOf4 * 2 + multipleOf2 >= n -> "Yes"
        else -> "No"
    }

    println(answer)
}


Measured memory_bytes: 56096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;


const ll mod = 998244353; 
int main(){
  ll n, k;
  cin >> n >> k;

  vector<pair<int,int>> s(0);
  rep(i,k){
    int l,r;
    cin >> l >> r;
    s.push_back({l,r});
  }

  static ll dp[200005] = {0};
  static ll dpsum[200005] = {0};
  dp[1] = 1;
  dpsum[1] = 1;
  for(int i = 2; i <= n; i++){
    for(int j = 0; j < k; j++){
      int li = i - s[j].second;
      int ri = i - s[j].first;
      if(ri < 0) continue;
      li = max(1, li);
      dp[i] += dpsum[ri]-dpsum[li-1]+mod;
      dp[i] %= mod;
    }
    dpsum[i] = dpsum[i-1]+dp[i];
    dpsum[i] %= mod;
  }
  cout << dp[n] << endl;
}


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

#define ll long long int
#define M 1000000007
ll path(vector<string> &grid, int r, int c, vector<vector<ll>> &dp)
{
    if(dp[r][c]!=-1)
        return dp[r][c];
    
    if((r==1 && c==1))
        dp[r][c]=1;
    else
    {
        if(grid[r-1][c-1]=='#')
            dp[r][c]=0;
        else
        {
            ll res1=0, res2=0;
            if(r-1>=1)
                res1=path(grid,r-1,c,dp);
            if(c-1>=1)
                res2=path(grid,r,c-1,dp);
            dp[r][c]=(res1+res2)%M;
        }
    }
    return dp[r][c];
    
}
int main()
{
    int r,c;
    cin>>r>>c;
    vector<string> grid(r,"");
    for(int i=0;i<r;i++)
    {
        cin>>grid[i];
    }
    vector<vector<ll>> dp(r+1,vector<ll>(c+1,-1));
    cout<<path(grid,r,c,dp)<<endl;
}

Measured memory_bytes: 13176
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, t, i, j, k, a, b, c, d, x, y, sq, aa, bb, ans;
	cin >> n >> t;

	vector<vector<tuple<int, int, int>>> adj(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b >> c >> d;
		adj[a].push_back(make_tuple(b, c, d));
		adj[b].push_back(make_tuple(a, c, d));
	}

	// root tree from 1
	// sq decomposition for distance and color
	vector<int> parent(n + 1, -1), depth(n + 1, 0), pcolor(n + 1, 0), pd(n + 1, 0), dparent(n + 1, 0);
	vector<int> dist(n + 1, 0);		// distance to the nearest sq point
	vector<unordered_map<int, int>> dc(n + 1), dccount(n + 1);		// color mix to the nearest sq point
	queue<int> q;
	//stack<int> st;

	q.push(1);
	parent[1] = 0;
	sq = max(3, (int)sqrt(n));
	sq = 200;

	while (!q.empty()) {
		int id = q.front();
		q.pop();

		if (id != 1) {
			if (depth[id] % sq != 1) {
				dist[id] = dist[parent[id]] + pd[id];
				dc[id] = dc[parent[id]];
				dc[id][pcolor[id]] += pd[id];
				dccount[id] = dccount[parent[id]];
				dccount[id][pcolor[id]]++;
				dparent[id] = dparent[parent[id]];
			}
			else {
				dist[id] = pd[id];
				//dc[id].clear(); 
				dc[id][pcolor[id]] += pd[id];
				//dccount[id].clear();
				dccount[id][pcolor[id]]++;
				dparent[id] = parent[id];
			}
		}

		for (auto p : adj[id]) {
			if (parent[get<0>(p)] == -1) {
				parent[get<0>(p)] = id;
				depth[get<0>(p)] = depth[id] + 1;
				pcolor[get<0>(p)] = get<1>(p);
				pd[get<0>(p)] = get<2>(p);
				q.push(get<0>(p));
				//st.push(get<0>(p));
			}
		}
	}

	// solve queries
	while (t--) {
		cin >> c >> d >> a >> b;

		// make sure b is deeper
		if (depth[a] > depth[b]) swap(a, b);

		ans = 0;
		while ((a != b) && (depth[dparent[b]] >= depth[a])) {
			ans += dist[b]; 
			if (dccount[b].find(c) != dccount[b].end()) {
				ans -= dc[b][c];
				ans += d * dccount[b][c];
			}
			b = dparent[b];
		}

		while (depth[b] > depth[a]) {
			ans += (pcolor[b] == c) ? d : pd[b];
			b = parent[b];
		}

		while (dparent[a] != dparent[b]) {
			ans += dist[a];
			if (dccount[a].find(c) != dccount[a].end()) {
				ans -= dc[a][c];
				ans += d * dccount[a][c];
			}
			a = dparent[a];

			ans += dist[b];
			if (dccount[b].find(c) != dccount[b].end()) {
				ans -= dc[b][c];
				ans += d * dccount[b][c];
			}
			b = dparent[b];
		}

		while (a != b) {
			ans += (pcolor[a] == c) ? d : pd[a];
			ans += (pcolor[b] == c) ? d : pd[b];
			a = parent[a];
			b = parent[b];
		}

		cout << ans << "\n";
	}
	   	   
	return 0;
}


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

using namespace std;

const int DIM = 2e5 + 7;

bool is = false;

string s;

bitset <DIM> vis;
bitset <DIM> v[4];

int n;

bool check(int p1, int p2, int t)
{
	vis.reset();
	
	vis[p1] = true;
	
	for(int i = p1; i < n; i++)
		if(vis[i] == true)
		{
			if(s[i + 1] == '.')
				vis[i + 1] = true;
			else
				if(i + 2 <= n && s[i + 2] == '.')
				{
					vis[i + 2] = true;
				}
		}
	
	for(int i = p1; i >= 2; i--)
		if(vis[i] == true)
		{
			if(s[i - 1] == '.')
				vis[i - 1] = true;
			else
				if(i - 2 > 0 && s[i - 2] == false)
				{
					vis[i - 2] = true;
				}
		}
	
	v[t] = vis;
	
	if(vis[p2] == true)
		return true;
	
	return false;
}

int main()
{
	int a, b, c, d;
	cin >> n >> a >> b >> c >> d;

	cin >> s;
	
	s = ' ' + s;
	
	if(check(a, c, 1) == false || check(b, d, 2) == false)
	{
		cout << "No";
		return 0;
	}
	
	if(c < d)
	{
		cout << "Yes";
		return 0;
	}
	
	bool is = false;
	
	for(int i = b - 1; i <= d - 1; i++)
		if(v[1][i] == true && v[1][i + 1] == true && v[1][i + 2] == true && v[2][i] == true && v[2][i + 1] == true && v[2][i + 2] == true)
		{
			is = true;
			break;
		}
	
	if(is == true)
	{
		cout << "Yes";
		return 0;
	}
	
	cout << "No";
}


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

namespace ABC157 {
    public class C {
        static void Main(string[] args) {
            var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var answer = Enumerable.Range(0, 10000).Where(x => Math.Truncate(x * 0.08) == inputs[0] && Math.Truncate(x * 0.1) == inputs[1]);

            Console.WriteLine(answer.Any() ? answer.Min() : -1);
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){

int num = 0;
int *data;
int i;
int k;
int count = 0;
int finalans = 0;

while(1){
  scanf("%d",&num);
  if(1 <= num && num <=10000){
    break;
  }
}

data = (int *)malloc(sizeof(int)*num);

for(i = 0;i < num;i++){
  scanf("%d",&data[i]);
if(data[i] > 2 && data[i] % 2 == 0){
  continue;
}
  for(k = 1;k <= sqrt(data[i] + 1);k++){
   if(data[i] % k == 0){
    count++;
   }
}
if(count == 1){
  finalans++;
}
count = 0;
}

printf("%d",finalans);
printf("\n");
return 0;
}



Measured memory_bytes: 2136
N = gets.to_i

str = gets.split
T,A = str[0].to_i, str[1].to_i

str2 = gets.split
H = []

for x in 0...N
  H[x+1] = str2[x].to_i
end

TminusA = T-A

dif_min = (TminusA - H[1] * 0.006).abs
answer = 1

for x in 2..N
  dif = (TminusA - H[x] * 0.006).abs
  if dif < dif_min
    dif_min = dif
    answer = x
  end
end

puts(answer)

Measured memory_bytes: 1788
### constant

MAX_INT = 1 << 31 - 1

### global variables

$g_cache = []

### subroutines

def check_grv(bits, wsum, fs)
  return $g_cache[bits] if ! $g_cache[bits].nil?
  return ($g_cache[bits] = [0, []]) if bits == 0

  n = fs.length

  min_gw = MAX_INT
  min_ids = []

  for i in (0...n)
    b = 1 << i
    if (bits & b) != 0
      fi, wi, si = fs[i]
      if si >= wsum - wi
        gw0, ids0 = check_grv(bits & ~b, wsum - wi, fs)
        gw = gw0 + wsum

        if min_gw > gw
          min_gw = gw
          min_ids = [i] + ids0
        end
      end
    end
  end

  $g_cache[bits] = [min_gw, min_ids]
end

### main

while true
  n = gets.strip.to_i
  break if n == 0

  fs = []
  n.times.each do
    fi, wi, si = gets.strip.split(' ')
    fs << [fi, wi.to_i, si.to_i]
  end

  $g_cache = []

  wsum = fs.inject(0){|s, f| s + f[1]}

  gw, ids = check_grv((1 << n) - 1, wsum, fs)
  #p ids
  #p (gw.to_f / w)

  ids.each do |i|
    puts fs[i][0]
    #p fs[i]
  end
end

Measured memory_bytes: 6136
n = int(input())
score = [int(input()) for _ in range(n)]
score.append(0)
score.sort()
sum_value = sum(score)
cnt = 0

for num in score:
    if (sum_value-num) % 10 != 0:
        sum_value -= num
        break
    cnt += 1

if cnt == n+1:
    sum_value = 0

print(sum_value)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
class UnionFindWithPotential{
private:
    std::vector<int> par;
    std::vector<int> rank;
    std::vector<int> diff_weight;

public:
    void init(int N){
        par.resize(N);
        rank.resize(N);
        diff_weight.resize(N);

        for(int a = 0;a < N;a++)
        {
            par[a]=-1;
            rank[a]=0;
            diff_weight[a]=0;
        }
    }
    int root(int a)
    {
        if(par[a] < 0){
            return a;
        }else{
            int r = root(par[a]);
            diff_weight[a] += diff_weight[par[a]];
            return par[a] = root(par[a]);
        }
    }
    int weight(int a){
        root(a);
        return diff_weight[a];
    }

    void connect(int a,int b, int w)
    {
        w += weight(a);w -= weight(b);

        a = root(a);
        b = root(b);
        if(a==b)return;

        if(rank[a] < rank[b]){
            par[a] = b;
            diff_weight[a] = -w;
        }else{
            par[b] = a;
            if(rank[a] == rank[b])rank[a]++;
            diff_weight[b] = w;
        }
    }

    bool check(int a,int b){
        return root(a) == root(b);
    }
    int diff(int a, int b){
        return weight(b) - weight(a);
    }
};
int main(){
    UnionFindWithPotential Uni;
    CIN(N);CIN(M);
    bool result = true;
    Uni.init(N);
    REP(a,M){
        CIN(x);CIN(y);CIN(z);
        if(Uni.check(x,y)){
            int d = Uni.diff(x,y);
            if(d != z)result = false;
        }else{
            Uni.connect(x, y, z);
        }
    }
    Yes(result);
    return 0;
}


Measured memory_bytes: 1408