akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int l = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    if (x < K - x){
      l += 2 * x;
    }
    else {
      l += 2 * (K - x);
    }
  }
  cout << l <<endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    arr1 = []
    arr2 = []
    for x, y in XY:
        arr1.append(x)
        arr2.append(y)


    minX, maxX = min(arr1), max(arr1)
    minY, maxY = min(arr2), max(arr2)

    ans = 0
    # For all four corners, calculate the max distance differences
    for point in [(minX, minY), (maxX, minY), (minX, maxY), (maxX, maxY)]:
        minD = float('inf')
        maxD = float('-inf')
        for i in range(0, len(arr1)):
            distance = abs(arr1[i] - point[0]) + abs(arr2[i] - point[1])
            minD = min(minD, distance)
            maxD = max(maxD, distance)
        ans = max(ans, maxD - minD)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 123604
S =  int(input())
  
hh = 0
mm = 0
ss = 0
  
while S >= 3600:
     S -= 3600
     hh += 1
      
while S >= 60:
     S -= 60
     mm += 1
       
      
ss = S
print(hh,mm,ss, sep=':') 


Measured memory_bytes: 5592
#include <stdio.h>
int main(void){
	long int a,b,c,d,max;
	scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
	max=a*c;
	if(max<a*d){
		max=a*d;
	}
	if(max<b*c){
		max=b*c;
	}
	if(max<b*d){
		max=b*d;
	}
	printf("%ld\n",max);
	return 0;
}

Measured memory_bytes: 1680
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] numbers = new int[n];
    
    int ave_1 = 0;
    int ave_2 = 0;
    for(int i=0; i<n; i++){
      numbers[i] = Integer.parseInt(sc.next());
      ave_1 += numbers[i];
      ave_2 += numbers[i];
    }
    ave_1 /= n;
    ave_2 /= n;
    ave_2++;
    
    int judge_1 = 0;
    int judge_2 = 0;
    for(int j=0; j<n; j++){
      judge_1 += (numbers[j]-(ave_1))*(numbers[j]-(ave_1));
      judge_2 += (numbers[j]-(ave_2))*(numbers[j]-(ave_2));
    }
    
    System.out.println(Math.min(judge_1, judge_2));
  }
}

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

int main(){
    //input
    int n,m,x;
    cin >> n >> m >> x;
    int mi=0,ma=0;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        a < x ? mi++ : ma++;
    }

    cout << min(mi,ma) << endl;

    return 0;
}

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

s = []
l = []
top = 2*(10**9)+1
low = 0
for j in range(N):
    t = sum(M[j])
    if low == t:
        s.append(M[j])
    elif low < t:
        low = t
        s = []
        s.append(M[j])

    if top == t:
        l.append(M[j])
    elif top > t:
        top = t
        l = []
        l.append(M[j])


def cal_man(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


s.sort()
l.sort()


high = []
small = []
lowest = 2*(10**9)+1
topest = -2*(10**9)+1
for j in range(N):
    t = M[j][1] - M[j][0]
    if lowest > t:
        lowest = t
        small = []
        small.append(M[j])
    elif lowest == t:
        small.append(M[j])

    if topest < t:
        topest = t
        high = []
        high.append(M[j])
    elif topest == t:
        high.append(M[j])
high.sort()
small.sort()


print(max([cal_man(s[0], l[-1]), cal_man(s[-1], l[0]),
           cal_man(high[0], small[-1]), cal_man(high[-1], small[0])]))


Measured memory_bytes: 51564
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
ll mod = 1e9 + 7;
ll countr(vector<string> a)
{
	vector<ll> c;
	int n=1;
	ll ans = 0;
	for (int i = 0; i < a.size() - 1; i++)
	{
		if (a[i] != a[i + 1])
		{
			c.push_back(n);
			n = 1;
		}
		else n++;
	}
	c.push_back(n);
	for (int i = 0; i < c.size(); i++)
	{
		ans += c[i] * (c[i]-1) / 2;
		printf("%d\n", c[i]);
	}
	return ans;
}
int main()
{
	static int n, q, a[200000 + 10], b[200000 + 10], p[200000 + 10], x[200000 + 10], i, j, k;
	cin >> n >> q;
	static vector<int> ne[200000+10];
	static bool visit[200000 + 10];
	static int ct[200000 + 10];
	int oya = 0;
	for (i = 1; i <= n - 1; i++)
	{
		cin >> a[i] >> b[i];
		ne[a[i]].push_back(b[i]);
		ne[b[i]].push_back(a[i]);
	}
	for (i = 1; i <= q; i++)
	{
		cin >> p[i] >> x[i];
		ct[p[i]] += x[i];
	}
	int bct1 = ct[1];
	for (i = 1; i <= n; i++)
	{
		if (oya == 0 && ne[i].size() == 1) oya = i;
		for (j = 0; j < ne[i].size(); j++)
		{
			//printf(",%d", ne[i][j]);
		}
		//cout << endl;
		visit[i] = false;
	}
	queue<int> qe;
	oya = 1;
	qe.push(oya);
	int mae = 0;
	while (qe.size())
	{
		int now = qe.front();
		//printf("queue=%dnow\n", now);
		qe.pop();
		for (i = 0; i < ne[now].size(); i++)
		{
			if (visit[ne[now][i]]==false)
			{
				ct[ne[now][i]] += ct[now];
				//printf("now%d,ne%d=%d\n", now, ne[now][i], ct[ne[now][i]]);
				visit[ne[now][i]]++;
				qe.push(ne[now][i]);
			}
		}
		//mae = now;
	}
	ct[1] = bct1;
	for (i = 1; i <= n; i++)
	{
		printf("%d ", ct[i]);
	}
	cout << endl;
}


Measured memory_bytes: 18804
class Node:
  def __init__(self,key):
    self.key = key
    self.prev = None
    self.next = None

class Queue:
  def __init__(self):
    self.head = Node(0)
    self.tail = self.head

  def enqueue(self,key):
    node = Node(key)
    self.tail.next = node
    node.prev = self.tail
    self.tail = node

  def front(self):
    if self.head != self.tail:
      return self.head.next.key

  def dequeue(self):
    if self.head != self.tail:
      if self.head.next == self.tail:
        self.tail = self.head
      self.head.next = self.head.next.next


n,q = map(int,input().split())

Q = [Queue() for i in range(n)]

for i in range(q):
  com, index, *n = map(int,input().split())
  if com == 0:
    Q[index].enqueue(*n)
  elif com == 1:
    key = Q[index].front()
    if key != None:
      print(key)
  elif com == 2:
    Q[index].dequeue()



Measured memory_bytes: 45560
k,n = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ch = 0
for i in range(n-1):
    if a[i+1] - a[i] >= ch:
        ch = a[i+1] - a[i]
ch = max(ch, k -a[n-1] + a[0])
print(k-ch)

Measured memory_bytes: 25832
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
for i in range(n-1,-1,-2):
    print(a[i])
if n%2:
    j = 1
else:
    j = 0
for i in range(j,n,2):
    print(a[i])

Measured memory_bytes: 87124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

int main(int argc, char const *argv[])
{
  double N, K;
  double overK = 0, tmp_kakuritu = 0;
  cin >> N >> K;
  int tmp = 0, tmp_count = 0;
  int size_v = 0;
  if (K <= N){
    size_v = K;
    overK = (N - K +  1) / N;
  }else{
    size_v = N+1;
    overK = 0;
  }
  // cout << "overK" << overK << endl;
  vector<int> omote(size_v);
  for (int i = 1; i < size_v; ++i)
  {
    tmp = i;
    tmp_count = 0;
    while(tmp < K){
      tmp_count++;
      tmp = tmp * 2;
    }
    omote[i] = tmp_count;
    // cout << i << ":" << omote[i] << endl;
  }
  for (int i = 1; i < size_v; ++i)
  {
    tmp_kakuritu = pow(0.5, omote[i]) / N;
    // cout << "tmp_kakuritu" << i << ":" << tmp_kakuritu << endl;
    overK += tmp_kakuritu;
  }
  cout << std::setprecision(13) <<overK << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <queue>

#include <vector>

#include <map>



using namespace std;



typedef long long LL;


int n,m;
bool f[100005];
int x[100005],y[100005],a[100005];
int ans;

int main()

{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i) scanf("%d%d",&x[i],&y[i]);
	memset(f,false,sizeof(f));
	for (int i=1;i<=n;++i) a[i]=1;
	f[1]=true;
	for (int i=1;i<=m;++i)
	{
		a[x[i]]--;
		if (f[x[i]]) f[y[i]]=true;
		a[y[i]]++;
		if (a[x[i]]==0) f[x[i]]=false;
	}
	ans=0;
	for (int i=1;i<=n;++i) if (f[i]) ans++;
	printf("%d\n",ans);
	return 0;

}

Measured memory_bytes: 1536
# include <bits/stdc++.h>
# define rep(i, n) for (ll i = 0; i < (n); i++)
# define reps(i, n) for (ll i = 1; i <= (n); i++)
# define foreps(i, m, n) for (ll i = (m); i < (n); i++)
# define len(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

vector<ll> p = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
vector<ll> q = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
vector<ll> r = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };

int main() {
    ll n; cin >> n;
    vector<ll> march(5, 0);
    rep(i, n) {
        string s; cin >> s;
        if (s[0] == 'M') ++march[0];
        else if (s[0] == 'A') ++march[1];
        else if (s[0] == 'R') ++march[2];
        else if (s[0] == 'C') ++march[3];
        else if (s[0] == 'H') ++march[4];
    }

    ll ans = 0;
    rep(i, 10) {
        ans += march[p[i]] * march[q[i]] * march[r[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

template <class T1> void write(T1 e)
{
    cout << e << endl;
}
template <class T1,class T2> void write(T1 e1,T2 e2)
{
    cout << e1 << " "<< e2 << endl;
}
template <class T1,class T2,class T3> void write(T1 e1,T2 e2,T3 e3)
{
    cout << e1 << " " << e2 << " " << e3 << endl;
}

#define oo          (1<<30)
#define SZ(a)       (int)a.size()
#define LL          long long int
#define ULL         unsigned long long
#define ISS         istringstream
#define OSS         ostringstream
#define VS          vector <string>
#define VI          vector <int>
#define VD          vector <double>
#define VLL         vector <long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define fs          first
#define sc          second
#define pii         pair < int , int >

#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a,b,c)  for(int I=0;I<b;I++)    a[I] = c
#define CROSS(a,b,c,d) ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define FORE(i,a)   for(typeof((a).begin())i=(a).begin();i!=(a).end();i++)
#define BE(a)       a.begin(),a.end()
#define RBE(a)      a.rbegin(),a.rend()
#define rev(a)      reverse(BE(a));
#define sorta(a)    sort(BE(a))
#define pb          push_back
#define popb        pop_back
#define Round(i,a)  i = ( a < 0 ) ? a - 0.5 : a + 0.5;

#define makeint(n,s)  istringstream(s)>>n
#define string_to_int(str) atoll(str.c_str());

#define LCM(A,B)    ((__gcd(A,B))/A)*B
#define GCD(A,B)     __gcd(A,B)

#define YES     write("YES")
#define Yes     write("Yes")
#define yes     write("yes")
#define NO      write("NO")
#define No      write("No")
#define no      write("no")

#define read()      freopen("test.txt","r",stdin)
#define write_file()     freopen("WA.txt", "w", stdout);
#define Faster      {ios_base::sync_with_stdio(false); cin.tie(0);}

#define PI          3.141592653589793
#define pi          2*acos(0)
#define gama        0.57721566490
#define ERR         1e-5
#define PRE         1e-8
#define MAX         1000009

#define Scan(A)         scanf("%lld", &A)
#define Scan2(A, B) 	scanf("%lld %lld",&A, &B)
#define Scan3(A, B, C) 	scanf("%lld %lld %lld",&A, &B, &C)
#define Scan4(A, B, C, D) 	scanf("%lld %lld %lld %lld",&A, &B, &C, &D)

int dx[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1};
int dy4[] = {-1, 0, 1, 0};

bool isvowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u';
}

struct myStruct
{
    LL Sum;
    string name;
    string Party;
};

bool cmp(myStruct a, myStruct b)
{
    return a.Sum > b.Sum ? 0 : 1;
}

map <char, int> Mp;

void Method()
{
    int j = 0;
    for(char i = 'a'; i <= 'z'; i++)
    {
        char temp = (char) i;
        Mp[temp] = j;
        j++;
    }
}

int main()
{
    LL A, B;
    while(cin >> A >> B)
    {
        if((A*B) & 1)
            write("Odd");
        else
            write("Even");
    }
}


Measured memory_bytes: 256
<?php
list($N,$X)=explode(" ",trim(fgets(STDIN)));
$ans=$N;
--$N;
$min=trim(fgets(STDIN));
$X-=$min;
while($N>0){
  $m=trim(fgets(STDIN));
  $X-=$m;
  $min=min($min,$m);
  --$N;
}
$ans+=floor($X/$min);
echo $ans;

Measured memory_bytes: 4856
line = input()
q = int(input())
for _ in range(q):
    cmd = input().split()
    a = int(cmd[1])
    b = int(cmd[2])
    if cmd[0] == "print":
        print(line[a:b + 1])
    elif cmd[0] == "replace":
        line = line[:a] + cmd[3] + line[b + 1:]
    else:
        line = line[:a] + line[a:b + 1][::-1] + line[b + 1:]

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

//dijkstra

struct edge{
  int64_t to;
  int64_t cost;
};

using P = pair<int64_t,int64_t>;

const int MAX_N = 1e5;
const int64_t INF = 1e18;
vector<edge> G[MAX_N];
vector<int64_t> dist(MAX_N,INF);

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> PQ;
  dist[s] = 0;
  PQ.push(P(0,s));
  
  while(PQ.size()){
    P p = PQ.top();
    PQ.pop();
    int64_t v = p.second; //from
    if(dist[v] < p.first){ //現在わかっている距離が更新できない
      continue;
    }
    for(int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        PQ.push(P(dist[e.to], e.to));
      }
    }
  }
}


int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<vector<int64_t>> vec(M,vector<int64_t>(3));
  for(int i=0; i<M; i++){
    for(int j=0; j<3; j++){
      cin >> vec[i][j];
    }
  }
  vector<int> imos(N);
  
  for(int i=0; i<M; i++){
    int64_t a = vec[i][0];
    int64_t b = vec[i][1];
    int64_t c = vec[i][2];
    a--; b--;
    imos[a]++;
    imos[b]--;
    edge add = {b,c};
    G[a].push_back(add);
  }
  
  for(int i=1; i<N; i++){
    imos[i] += imos[i-1];
  }
  
  for(int i=0; i<N; i++){
    if(imos[i] > 0){
      edge add = {i,0};
      G[i+1].push_back(add);
    }
  }
  
  dijkstra(0);
  if(dist[N-1] == INF){
    cout << -1 << endl;
  }
  else{
    cout << dist[N-1] << endl;
  }
}



Measured memory_bytes: 15096
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int counter = 700;
    
     for (int i = 0; i < s.size(); ++i) {
            if (s[i]=='o'){counter += 100;}   // 奇数があったらフラグを立てる
        }
    
    cout << counter << endl;
}

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

using namespace std;


int main(){
	int n;
	cin >> n;
	int a[n];
	map<long long, long long>maap;
	for(int i=0; i<n; i++) {
		cin >> a[i];
	}
	sort(a, a+n);
	for(int i=n-1; i>=0; i--){
		maap[a[i]]++;
	}
	long long cnt=0, res=0;
	for(map<long long, long long>::reverse_iterator it=maap.rbegin(); it!=maap.rend(); it++){
		if(it->second>=4){
			res=max(res, it->first*it->first);
		}
		if(cnt==0 && it->second>=2){
			cnt=it->first;
		}
		else if(cnt!=0 && it->second>=2){
			res=max(cnt*it->first, res);
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
const int N = 200100;
int g[N];

int32_t main(){
	fastio;
   double R;
   cin>>R;
   double PI = acos(-1);
   R = 2.0*PI*R;
   cout<<setprecision(2)<<fixed;
   cout<<R<<endl;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define INF 1e+12
#define EPS 1e-12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll a, b;
    double c, d;
    cin >> a >> b;
    c = ceil(a/0.08);
    d = ceil(b/0.1);
    if(c>d){
        if((ll)(c*0.1) == b) cout << (ll)c << endl;
        else cout << -1 << endl;
    }
    else{
        if((ll)(d*0.08) == a) cout << (ll)d << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dp[1010][(1 << 14)];
int k[100010];
int cost[100010];
int main(void){
   int n,m;cin >> n >> m;
   for(int i = 0;i < m;i++){
      int a,b;cin >> a >> b;
      cost[i] = a;
      for(int j = 0;j < b;j++){
         int c;cin >> c;
         k[i] += (1 << (c-1));
      }
   }
   rep(i,1010)rep(j,(1<<14)) dp[i][j] = INT_MAX;
   dp[0][0] = 0;
   //dp[0][k[0]] = a[0];
   
   rep(i,m){
      rep(j,(1<<13)){
         if(dp[i][j] == INT_MAX)continue;
         else{
            mins(dp[i+1][j],dp[i][j]);
            mins(dp[i+1][j | k[i]],dp[i][j] + cost[i]);
         }
      }
   }
   if(dp[m][(1<<n) - 1] == INT_MAX)cout << -1 << endl;
   else cout << dp[m][(1<<n)-1] << endl;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
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; }
int main(){


	lli n,m;
	cin>>n>>m;

	lli sum=0;
	REP(i,0,m){
		lli a;
		cin>>a;
		sum += a;
	}

	cout<<max(-1LL,n-sum)<<endl;


    return 0;
}


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

int parent[200010];
vector<int> child[200010];
long long int value[200010];
int height[200010];
vector<pair<int,int> > AB;

int dfs(int i,long long int parentsValue,int parent){
  long long int r=parentsValue;
  parentsValue+=value[i];
  value[i]+=r;
  for(vector<int>::iterator e=child[i].begin();e!=child[i].end();e++){
    if (*e!=parent){
      dfs(*e,parentsValue,i);
    }
  }
  return 0;
}

int main(){
  int N,Q;
  cin >> N >> Q;
  int a[N-1],b[N-1],p[Q],x[Q];
  for (int i=0;i<N+1;i++) parent[i]=0;
  for (int i=0;i<N+1;i++) value[i]=0;
  for (int i=0;i<N+1;i++) height[i]=200010;
  height[1]=0;
  for (int i=0;i<N-1;i++){
    cin >> a[i] >> b[i];
    child[a[i]].push_back(b[i]);
    child[b[i]].push_back(a[i]);
  }

  for (int i=0;i<Q;i++){
    cin >> p[i] >> x[i];
    value[p[i]]+=x[i];
  }

  dfs(1,0,0);

  for(int i=1;i<=N;i++){
    cout << value[i] <<" ";
  }
}


Measured memory_bytes: 28928
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string N;
	int k;
	
	cin >> N >> k;
	
	long long dp[100][2][4];
	
	dp[0][0][0] = 0;
	dp[0][0][1] = 1;
	dp[0][0][2] = 0;
	dp[0][0][3] = 0;
	dp[0][1][0] = 1;
	dp[0][1][1] = N[0]-'0'-1;
	dp[0][1][2] = 0;
	dp[0][1][3] = 0;

	for(int i = 0; i < N.length()-1; ++i) {
		int n = N[i+1]-'0';
		if(n == 0) {
			dp[i+1][0][0] = dp[i][0][0];
			dp[i+1][0][1] = dp[i][0][1];
			dp[i+1][0][2] = dp[i][0][2];
			dp[i+1][0][3] = dp[i][0][3];
			dp[i+1][1][0] = dp[i][1][0];
			dp[i+1][1][1] = dp[i][1][0]*9+dp[i][1][1];
			dp[i+1][1][2] = dp[i][1][1]*9+dp[i][1][2];
			dp[i+1][1][3] = dp[i][1][2]*9+dp[i][1][3];
		} else {
			dp[i+1][0][0] = 0;
			dp[i+1][0][1] = dp[i][0][0];
			dp[i+1][0][2] = dp[i][0][1];
			dp[i+1][0][3] = dp[i][0][2];
			dp[i+1][1][0] = dp[i][0][0]+dp[i][1][0];
			dp[i+1][1][1] = dp[i][0][0]*(n-1)+dp[i][0][1]+dp[i][1][0]*9+dp[i][1][1];
			dp[i+1][1][2] = dp[i][0][1]*(n-1)+dp[i][0][2]+dp[i][1][1]*9+dp[i][1][2];
			dp[i+1][1][3] = dp[i][0][2]*(n-1)+dp[i][0][3]+dp[i][1][2]*9+dp[i][1][3];
		}
	}
	
	cout << dp[N.length()-1][0][k]+dp[N.length()-1][1][k];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long

ll msize;
int N,Max=0;
vector<int> bit(1e7);
int lowbit(int x){
	return x&(-x);
}
void add(int x){
	for(int i=x;i<=1e7;i+=lowbit(i))
	bit[i]+=1;
}
ll sum(int a){
	ll ret = 0;
	for(int x = a;x>0;x -=x&-x)ret += bit[x];
	return ret;
}
ll count(vector<int> &c){
	ll ret = 0;
	fill(ALL(bit),0);
	for(int j=0;j<c.size();j++){
		ret += sum(c[j] + N+1);
		add(c[j] + N+1);
	}
	//cout << ret << endl;
	return ret;
}
bool check(vector<int> &a,int k){
	vector<int> b = a,c(a.size()+1);
	for(int i=0;i<b.size();i++){
		if(a[i] >= k)b[i]=1;
		else b[i] = -1;
	}
	//cout << "(msize+1)/2) =" << (msize+1)/2 <<" ";
	//cout << "k = " << k <<" ";
	c[0] = 0;
	for(int i=0;i<b.size();i++){
		c[i+1] = c[i] + b[i];
	}
	//cのある区間について、k以上の数をカウントする
	if(count(c) >= (msize+1)/2)return 1;
	else return 0;
}
int main(void){
	
	cin >> N;
	vector<int> a(N);
	msize = (ll)N*(N+1)/2;
	for(int i=0;i<N;i++){
		cin >> a[i];
		Max = max(Max,a[i]);
	}
	int ok = -1;
	int ng = 1e9+7;
	while(abs(ok-ng)>1){
		int mid = (ok+ng)/2;
		//check(vector<int> &a,mid)はmid以上の数がmに半分以上含まれていた場合1を返す
		if(check(a,mid)){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	cout << ok << endl;
}


Measured memory_bytes: 40536
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200010
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>h(n);
    REP(i,n)cin>>h[i];
    vector<int>to[n];
    REP(i,m){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    int ans=0;
    REP(i,n){
        if(SZ(to[i])==0){
            ans++;
            continue;
        }else{
            bool f=true;
            REP(j,SZ(to[i])){
                if(h[i]<=h[to[i][j]]){
                    f=false;
                    break;
                }
            }
            if(f)ans++;
        }
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 8728
#include <stdio.h>
int main(void)
{
	int i,j,h,w;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0){
			break;
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> S(100);
  for(int i = 0; i < 100; i++){
    if(A % (i + 1) == 0 && B % (i + 1) == 0){
      S.at(i) = (i + 1);
    }
  }
  sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  cout << S.at(K - 1) << endl;
}


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



int main() {
    int l, r, d;
    cin >> l >> r >> d;
    
    int cnt = 0;
    for(int i = l; i <= r; i++) {
        if(i%d == 0)
            cnt++;
    }
    
    cout << cnt << endl;
    
    return 0;
}




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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
vector<ll> lun;
set<ll> vst;
void myf(ll end, int ln, ll xx){
    if(ln>10) return;
    if(end>0 && vst.count(10ll*xx+(end-1))==0){
        ll nxt=10ll*xx+end-1;
        lun.push_back(nxt);
        vst.insert(nxt);
        myf(end-1,ln+1,nxt);
    }
    if(end<9 && vst.count(10ll*xx+(end+1))==0){
        ll nxt=10ll*xx+end+1;
        lun.push_back(nxt);
        vst.insert(nxt);
        myf(end+1,ln+1,nxt);    
    }
    if(vst.count(10ll*xx+end)==0){
        ll nxt=10ll*xx+end;
        lun.push_back(nxt);
        vst.insert(nxt);
        myf(end,ln+1,nxt);    
    }        
}
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    for(ll i=1;i<10;i++) lun.push_back(i), myf(i,1,i);
    sort(lun.begin(),lun.end());
    //for(int i=0;i<10;i++) debug(lun[i]);
    int k; cin>>k;
    cout<<lun[k-1];
    return 0;
}

Measured memory_bytes: 35176
#import sys,math,collections
from collections import defaultdict
import math,sys
#from itertools import permutations,combinations

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 
	

def get_array():
	l=list(map(int, input().split()))
	return l
def sod(n):
	n,c=str(n),0
	for i in n:	
		c+=int(i)
	return c	
#file()	
def main():
	#a,b=map(int, input().split())
	n=int(input())
	ans=1000
	
	for i in range(100000):
		if(ans>=n):
			print(ans-n)
			
			break
		else:	
			ans+=1000
	#for _ in range(int(input())):
		'''n,x=map(int, input().split())
		l=list(map(int, input().split()))
		l.sort()
		for i in range(len(l)):
			if(2*l[i]>x):
				ind=i
				break
		
		l=l[ind:]+l[:ind]
		print(l)
		cures=len(l)
		i,ans=0,0
		print('h')
		while(cures>0):
			print("nz")
			if(x>=l[i]):
				cures-=1
				x=2*l[i]
				i+=1
			else:
				temp=l[i]
				l[i]=l[i]-x

				l[i]=min(2*l[i],temp)
			ans+=1
		print(ans)'''



		







		
		
		











		








if __name__ == '__main__':
    main()


Measured memory_bytes: 9464
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
const int N = 102345;
int a[3][N], dp[3][N];

void solve() {
	int n;
	cin >> n;
	for (int t = 0; t < n; t++) {
		for (int i = 0; i < 3; i++)
			cin >> a[i][t];
	}
	dp[0][0] = a[0][0];
	dp[1][0] = a[1][0];
	dp[2][0] = a[2][0];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j == k)
					continue;
				dp[j][i] = max(dp[k][i - 1] + a[j][i], dp[j][i]);
			}
		}
	}
	cout << max({dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]});
}

int32_t main() {
	int t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 5956
import heapq
Q = int(input())
ans = 0
L = []
R = []
for _ in range(Q):
    q = input()
    if q[0] == '1':
        _, a, b = map(int, q.split())
        ans += b
        if len(L) > 0 and not -L[0] <= a <= R[0]:
            ans += min(abs(a + L[0]), abs(a - R[0]))
        l = heapq.heappushpop(L, -a)
        r = heapq.heappushpop(R, a)
        heapq.heappush(L, -r)
        heapq.heappush(R, -l)
    else:
        print(-L[0], ans)

Measured memory_bytes: 24864
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
vector<vector<int>> g;

void solve() {
	cin >> n;
    g.assign(n, vector<int>());
    vector<int> deg(n, 0);
    vector<bool> seen(n, 0);
    rep(i, n - 1) {
        int a, b; cin >> a >> b;
        -- a, -- b;
        g[a].pb(b);
        g[b].pb(a);
        deg[a] ++, deg[b] ++;
    }
    bool res = 1;
    queue<int> que;
    rep(i, n) if(deg[i] == 1) que.push(i);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        if(seen[v]) continue;
        seen[v] = 1;

        int k = -1;
        for(int nv: g[v]) if(!seen[nv]) k = nv;
        if(k == -1) {
            res = 0;
            break;
        }
        seen[k] = 1;
        for(int j: g[k]) {
            if(seen[j]) continue;
            deg[j] --;
            if(deg[j] == 1) que.push(j);
        }
    }
    cout << (res ? "Second" : "First") << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 9592
#include <stdio.h>

int mabs(int a){
	return (a>0)? a:-a;
}

int main(int argc, char const *argv[]){
	int n,z,w,i;
	int a[2000];
	scanf("%d%d%d",&n,&z,&w);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	if(n==1)
		printf("%d",mabs(a[0]-w));
	else
		printf("%d",(mabs(a[n-1]-w)>mabs(a[n-2]-a[n-1]))? mabs(a[n-1]-w):mabs(a[n-2]-a[n-1]));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if ((a==b && a!=c) || (a==c && a!=b) || (b==c && a!=b) ){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rint register int
inline int rf(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int a[100005], n; bool W(int i){bool U = (a[i+1]-i)&1, R = 0; for(rint j = i+1; j <= n && a[j]>i; R ^= 1, j++); return U&R;}
int main(){n = rf(); generate(a+1,a+n+1,rf); sort(a+1,a+n+1,greater<int>()); for(rint i = 2; i <= n+1; i++) if(a[i]<i) return puts(W(i-2)?"Second":"First"),0;}

Measured memory_bytes: 640
#include <cstdio>

int main(){
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);

    int left, right;
    left = A + B;
    right = C + D;

    if(left == right){
        printf("Balanced\n");
    }else if(left > right){
        printf("Left\n");
    }else{
        printf("Right\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
	int e,sub,data;
	int x,y,z;
	cin >> e;
	while(e!=0){
		for(z=1;;z++){
			if(z*z*z>e){
				z--;
				break;
			}
		}

		data=100000;

		for(;z>=0;z--){
			sub=z*z*z;
			for(y=1;;y++){
				if((sub+y*y)>e){
					y--;
					break;
				}
			}
			sub=sub+y*y;
			for(x=1;;x++){
				if((sub+x)>e){
					x--;
					break;
				}
			}	
			if(data>(x+y+z)){
				data=x+y+z;
			}

		}
		cout << data << '\n';
		cin >> e;
	}
}

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

def digit_num(n):
    for i in range(1, 7):
        if n < 10 ** i:
            return i
    return 6

ans = 0
for i in range(1, N + 1):
    #print(i, digit_num(i))
    if (digit_num(i) % 2)== 1:
        ans += 1
        
print(ans)

Measured memory_bytes: 2940
str = gets.split
N,K = str[0].to_i, str[1].to_i
mod = 1000000007

a = Array.new(0)
b = Array.new(0)
size = 0

i = 1
while i <= N/i
    a.push(i)
    b.push(N/i)
    i += 1
end
i = 0
size = a.size
if a[a.size-1] == b[b.size-1]
    i += 1
end
while i < size
    a.push(b[size-1-i])
    b.push(a[size-1-i])
    i += 1
end

c = Array.new(a.size,1)
for x in 1...c.size do
    c[x] = a[x] - a[x-1]
end

d = Array.new(2){Array.new(a.size)}
for x in 0...a.size do
    d[0][x] = a[x]
end
for x in 1...K do
    d[x%2][0] = d[(x-1)%2][a.size-1]
    for y in 1...a.size do
        d[x%2][y] = (d[x%2][y-1] + d[(x-1)%2][a.size-1-y] * c[y]) % mod
    end
end

puts d[(K-1)%2][a.size-1]

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

int partition(int a[], int p, int r)
{
    int x = a[r];
    int i = p - 1;

    for(int j = p; j < r; j++) {
        if (a[j] <= x) {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i + 1], a[r]);

    return i + 1;
}

int main()
{
    int n, a[100010];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];

    int t = partition(a, 0, n - 1);

    for(int i = 0; i < n; i++) {
        if (i) cout << " ";
        if (i == t) cout << "[" << a[i] << "]";
        else cout << a[i];
    }
    cout << endl;

    return 0;
}



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

int main()
{
	int b, r, g, c, s, t;
	
	cin >> b >> r >> g >> c >> s >> t;

	while (b > 0 || r > 0 || g > 0 || c > 0 || s > 0 || t > 0) {
		cout << 100 + b * 95 + r * 63 + g * 7 + c * 2 + s * 3 - t * 3 << endl;

		cin >> b >> r >> g >> c >> s >> t;
	}

	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define DOW(i, a, b) for(int i = (a), _b = (b); i >= _b; i--)

using namespace std;

typedef pair<long, pair<long, long>> PPI;
map<PPI, bool> ma;

PPI make(long long  a, long long  b, long long c) {
  vector<long long> ve = {a, b, c};
  sort(ve.begin(), ve.end());
  return make_pair(ve[0], make_pair(ve[1], ve[2]));
}

int main() {
  ios::sync_with_stdio(false);
  long long a, b, c, x, y, z;
  PPI p;
  while (cin >> a >> b >> c) {
    ma.clear();
    int i = 0;
    for(i = 0; ;i++) {
      if (a % 2 || b % 2 || c % 2) break;
      x = (b + c) / 2;
      y = (a + c) / 2;
      z = (a + b) / 2;
      p = make(x, y, z);
      if (ma.find(p) != ma.end()) {
        i = -1;
        break;
      } else ma[p] = true;
      a = x; b = y; c = z;
    }
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    int w;
    cin >> S >> w;

    string ans = "";
    for (int i = 0; i * w < S.length(); i++) { ans.push_back(S[i * w]); }

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

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

int main(){
    int r, c, temp;
    int A[101][101];
    
    cin >> r >> c;
    
    for (int i = 0; i < r; i++) {
        temp = 0;
        
        for (int j = 0; j < c; j++) {
            cin >> A[i][j];
            temp += A[i][j];
        }
        
        A[i][c] = temp;
    }
    
    for (int j = 0; j <= c; j++) {
        temp = 0;
        
        for (int i = 0; i < r; i++) {
            temp += A[i][j];
        }
        
        A[r][j] = temp;
    }
    
    for (int i = 0; i <= r; i++) {
        cout << A[i][0];
        
        for (int j = 1; j <= c; j++) {
            cout << ' ' << A[i][j];
        }
        
        cout << endl;
    }
    
    return 0;
}


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

const ll mod = 1e9 + 7;

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (j - 1 >= 0) dp[i][j] += dp[i - 1][j - 1];
            if (j + 1 <= n) dp[i][j] += 2 * dp[i - 1][j + 1];
            if (j == 0) dp[i][j] += dp[i - 1][j];
            dp[i][j] %= mod;
        }
    }
    int m = s.size();
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 195840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> G(N);
  vector<ll> cling(N, 0);
  vector<ll> ans(N);
  for (ll i = 0; i < N + M - 1; i++)
  {
    ll A, B;
    cin >> A >> B;
    A--, B--;
    G.at(A).push_back(B);
    cling.at(B)++;
  }

  for (ll i = 0; i < N; i++)
  {
    if (cling.at(i) == 0)
    {
      ans.at(i) = -1;

      queue<ll> Q;
      Q.push(i);
      while (!Q.empty())
      {
        ll V = Q.front();
        Q.pop();

        for (auto nv : G.at(V))
        {
          cling.at(nv)--;
          if (cling.at(nv) == 0)
          {
            ans.at(nv) = V;
            Q.push(nv);
          }
        }
      }

      break;
    }
  }

  for (ll i = 0; i < N; i++)
  {
    cout << ans.at(i) + 1 << endl;
  }
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;

#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll modinv(ll n)    { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}


int main()
{
	fast
	ll a,b;
	cin>>a>>b;

	ll ans=-inf;
	ans=max(max(a*b,a+b),a-b);
	cout<<ans;
	return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    //cerr << s << endl;
    //cerr << t << endl;
    int f = 0;
    rep(i, 0, min(s.size(), t.size())){    
        if(s[i] > t[i]){
            f = -1;
            break;
        }else if(s[i] < t[i]){
            f = 1;
            break;
        }
    }
    
    if(f == 1) cout << "Yes" << endl;
    else if(f == -1) cout << "No" << endl;
    else if(s.size() < t.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,n,t,a,b;
	double x,c;
	scanf("%d %d",&n,&t);
	x=0;
	for(i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		c=(double)b*t/a;
		if(c>x) x=c;
	}
	printf("%.6lf\n",x);
	return 0;
}


Measured memory_bytes: 2764
#include <iostream>
#include <algorithm>

using namespace std;

#define INF		(1000000000)
#define MAX_N	(100000+1)
#define ABS(val)	(val > 0 ? val : -(val))
int main(int argc,char **arv)
{
	int i;
	int N;
	static int ary_a[MAX_N];
	static int ary_b[MAX_N];
	static int ary_c[MAX_N];
	static long long dp[MAX_N][3] = {0};
	long long tmp;

	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> ary_a[i] >> ary_b[i] >> ary_c[i];
	}

	dp[0][0] = ary_a[0];
	dp[0][1] = ary_b[0];
	dp[0][2] = ary_c[0];

	for (i = 1; i < N; i++) {
		dp[i][0] = ary_a[i] + max({dp[i-1][1], dp[i-1][2]});
		dp[i][1] = ary_b[i] + max({dp[i-1][0], dp[i-1][2]});
		dp[i][2] = ary_c[i] + max({dp[i-1][0], dp[i-1][1]});
	}
#if 0
	for(i = 0; i < N; i++) {
		cout << "A dp:[" << i << "]:" << dp[i][0] << endl;
	}
	cout << endl;
	for(i = 0; i < N; i++) {
		cout << "B dp:[" << i << "]:" << dp[i][1] << endl;
	}
	cout << endl;
	for(i = 0; i < N; i++) {
		cout << "C dp:[" << i << "]:" << dp[i][2] << endl;
	}
	cout << endl;
#endif
	
	cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
	return 0;
}


Measured memory_bytes: 3712