akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
	string s,t,s1,t1;
	cin>>s;
	int len=s.size();
	t=s;
	reverse(t.begin(),t.end());
	if(s!=t)
	{
		cout<<"No";
		return 0;
	}
	s1=s.substr(0,(len-1)/2);
	t1=s1;
	reverse(t1.begin(),t1.end());
	if(s1!=t1)
	{
		cout<<"No";
		return 0;
	}
	
	cout<<"Yes";
	return 0;
 } 

Measured memory_bytes: 256
n = int(input())

L = [0] * (n + 1)

for i in range(1, n + 1):
    for j in range(1, (n // i)+1):
        L[i * j] += 1

i = 0
ans = 0
for i in range(len(L)):
    ans += i *L[i]

print(ans)

 
        

Measured memory_bytes: 151664
a = []
for _ in range(3):
  a = a + [int(i) for i in input().split()]
n = int(input())
a_bingo = [0] * 3 * 3
pos = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
for _ in range(n):
  b = int(input())
  if b in a:
    a_bingo[a.index(b)] = 1
for po in pos:
  if a_bingo[po[0]] == a_bingo[po[1]] == a_bingo[po[2]] == 1:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 9068
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c;
  cin >> k;
  ll ans = a + b + c + max(a,max(b,c))*pow(2, k) - max(a,max(b,c));
  print(ans);

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> x[2000];
vector<int> y[2000];
int h, w;
string s[2000];
int main()
{
    cin >> h >> w;
    rep(i, h)
    {
        cin >> s[i];
    }
    rep(i, h)
    {
        x[i].push_back(-1);
    }
    rep(i, w)
    {
        y[i].push_back(-1);
    }
    rep(i, h)
    {
        rep(j, w)
        {
            if (s[i][j] == '#')
            {
                x[i].push_back(j);
            }
        }
    }
    rep(i, w)
    {
        rep(j, h)
        {
            if (s[j][i] == '#')
            {
                y[i].push_back(j);
            }
        }
    }
    rep(i, h)
    {
        x[i].push_back(w);
    }
    rep(i, w)
    {
        y[i].push_back(h);
    }
    int ans = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            auto tw = lower_bound(x[i].begin(), x[i].end(), j);
            auto th = lower_bound(y[j].begin(), y[j].end(), i);
            ans = max(ans, (*tw - *(--tw) + *th - *(--th) - 2));
        }
    }
    cout << ans - 1 << endl;
}

Measured memory_bytes: 36480
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
string s[20];
int h[20],l[1010];
int n,m,cnt=0,k;  
int dp[20][1010];
int main()
{
	cin>>n>>m>>k;
  	rep(i,n)
  	{
  		cin>>s[i];
  	}
  	memset(dp,0,sizeof(dp));
  	forn(i,1,n)
  	{
    	forn(j,1,m)
   		{
    		dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+(s[i-1][j-1]=='1');
    	}
  	}
  	vi v;
  	int ans=1e9;
  	for(int mask=0;mask<(1<<(n-1));mask++)
  	{
	  	int now=0;
  		v.clear();
  		rep(i,n-1)
  		{
  	  		if(mask&(1<<i))	
  	  		{
  	  			now++;
  	  			v.pb(i);
	 		}
		}
		v.pb(n-1);
		bool flag=0;
		rep(i,m)
		{
			int la=-1;
			rep(j,v.size())
			{
				if((dp[v[j]+1][i+1]-dp[la+1][i+1]-dp[v[j]+1][i]+dp[la+1][i])>k)
				{				flag=1;
					}
				la=v[j];
			}
		}
		if(flag)continue;
		int last=-1,lasth=-1;
		rep(i,m+1)
		{
			last=-1;
			rep(j,v.size())
			{
				if((dp[v[j]+1][i+1]-dp[last+1][i+1])-(dp[v[j]+1][lasth+1]-dp[last+1][lasth+1])>k)
				{
					lasth=i-1;
					now++;
					break;
				}
				last=v[j];
			}
		}
		ans=min(ans,now);
  		}
  	cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, l, r) for(register long long i = (l), i##end = (long long)(r); i <= i##end; ++i)
using namespace std;
long long pos[300100];
int main () {
	long long n, a, b; cin >> n >> a >> b;
	if (a + b - 1 > n || a * b < n) return puts("-1"), 0;
	int val = n - a, cnt = 0; For (i, 1, a) pos[++cnt] = (++ val);
	val -= a; For (i, 1, b - 1) { int Block = min(val / (b - i), a); val -= Block; For (j, 1, Block) pos[++cnt] = (++val); val -= Block; }
	For (k, 1, n) printf ("%lld ", pos[k]); printf ("\n");
    return 0;
}


Measured memory_bytes: 4480
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  ll x,y,re=1e15;
  cin>>x>>y;
  rep(i,2){
    rep(j,2){
      if(x<=y) MN(re,y-x+i+j);
      y*=-1;
    }
    x*=-1;
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		for(int i = 0; i < w + 2;i++){
			System.out.print("#");
		}
		System.out.println();
		for(int i = 0 ; i < h;i++){
			String s = scan.next();
			System.out.print("#");
			for(int j = 0; j < w;j++){
				System.out.print(s.charAt(j));
			}
			System.out.println("#");
		}
		for(int i = 0; i < w + 2;i++){
			System.out.print("#");
		}
		System.out.println();
	}

}

Measured memory_bytes: 25892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

vector<vector<int>> g;
int dp[100100];

int rec(int x){
  if (dp[x] != -1) return dp[x];
  
  int res=0;
  for (auto v:g[x]){
      res = max(res,rec(v)+1);
  } 
  return dp[x]=res; 
}

int main(){
  int n,m;
  cin >> n >> m;
  g.resize(n,vector<int>());
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;y--;
    g[x].push_back(y);
  }
  int ans;
  ans=0;
  rep(i,n) dp[i] =-1;
  for (int i=0;i < n;i++){
    //printf(" %d path is %d\n",i+1,dp[i]);
    ans=max(rec(i),ans);
  }
  cout << ans << endl;
  return 0;
}

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


int N;
vector<int> a;

int alice, bob;

int main() {
	alice = 0;
	bob = 0;

	cin >> N;

	for (int i = 0; i<N; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.rbegin(), a.rend());

	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			alice += a[i];
		}
		else {
			bob += a[i];
		}
	}


	cout << alice-bob<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
X, N= map(int, input().split())
if N == 0:
  print(X)
else:
  p = input().split()
  i = 0
  while True:
    if (str(X-i) in p) == False:
      print(X-i)
      break
    elif (str(X+i) in p) == False:
      print(X+i)
      break
    else:
      i += 1

Measured memory_bytes: 9188
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int i, n;
   string c;
   cin>>c;
   if((c[2]==c[3]) && (c[4]==c[5]))
   {
       cout<<"Yes\n";
   }
   else
   {
       cout<<"No\n";
   }


    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var A, B, V, W, T int
	fmt.Scan(&A, &V, &B, &W, &T)

	A, B = 0, Abs(B-A)
	a := A + T*V
	b := B + T*W
	if a >= b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  int ans = 0;
  int temp = 0;
  int now;
  REP(i,n){
    if(i==0){
      now = a[i];
      temp = 1;
      continue;
    }
    if(now == a[i]){
      temp++;
      now = a[i];
      if(i == n-1){
        ans += temp/2;
      }
    }else{
      ans += temp/2;
      temp = 1;
      now = a[i];
      if(i == n-1){
        ans += temp/2;
      }
    }
  }
  cout<<ans<<endl;  
  return 0; 
}


Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  w,h,n,ni,i,j,a,x,y,sum:Integer;
  xy:array of array of Integer;
begin
  try
    { TODO -oUser -cConsole Main : ぬりえ }
    Read(w);
    Read(h);
    Readln(n);

    SetLength(xy,h,w);

    for i := 0 to h - 1 do
      for j := 0 to w - 1 do
        xy[i,j]:=0;

    for ni := 0 to n-1 do begin
      Read(x);
      Read(y);
      Readln(a);
      case a of
        1:begin
          for i := 0 to h - 1 do
            for j := 0 to x - 1 do
              xy[i,j]:=1;
        end;
        2:begin
          for i := 0 to h-1 do
            for j := x to w - 1 do
              xy[i,j]:=1;
        end;
        3:begin
          for i := 0 to y - 1 do
            for j := 0 to w - 1 do
              xy[i,j]:=1;
        end;
        4:begin
          for i := y to h - 1 do
            for j := 0 to w - 1 do
              xy[i,j]:=1;
        end;
      end;
    end;

    sum:=0;
    for i := 0 to h - 1 do
      for j := 0 to w - 1 do
        sum:=sum+(xy[i,j]xor 1 xor 0);

    Writeln(sum);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >>n>>m;
  if(n>=m){
    cout<<0<<endl;
    return 0;
  }
  vector<int>a(m);
  for(int i=0;i<m;i++)cin>>a[i];
  sort(a.begin(),a.end());
  priority_queue<int>q;
  long long kotae=0;
  for(int i=0;i<m-1;i++){
    int x=abs(a[i+1]-a[i]);
    //cout<<x<<" ";
    q.push(x);
    kotae+=x;
  }
  for(int i=0;i<n-1;i++){
    int y=q.top();q.pop();
    kotae-=y;
  }
  cout<<kotae<<endl;
  return 0;
}

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


int main() {
 int n,m;
 cin >> n >> m;
 int ans[n];
 memset(ans,-1,sizeof(ans));
 bool dp[n],j=false;
 memset(dp,false,sizeof(dp));
 for(int i=0;i<m;i++){
   int s,c;
   cin >> s >> c;
   if(!dp[s-1]) dp[s-1] =true;
   else{
     if(ans[s-1]!=c){
       j = true;
     }
   }
   if(s == 1 && ans[0] == 0) ans[0] = c; 
   ans[s-1] = c;
 }

if(n == 1  && ans[0] == 0|| n==1 && ans[0]==-1){
   cout <<0<< endl;
   return 0;
 }
 if(ans[0] == 0 || j){
   cout << -1 << endl;
   return 0;
 }
 int sum=0;
 for(int i=0;i<n;i++){
   if(!dp[i]){
     if(!i) ans[i] = 1;
     else ans[i]=0;
   }
   sum = sum*10 + ans[i];
 }
 cout <<sum<< endl;

 return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define ps(x) cout<<x;
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
int a,b,c,d,n,m,x,k,h,w,sum,mi,ma;
typedef vector<int> VI;
typedef vector<pair<int,int> > VP;

int main(void){
    cin>>x>>a;
    p(((x<a)?0:10));
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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



int main() {
	int n;
	cin >> n;
	vector<int>p(n), q(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> q[i];
	}
	vector<int>a(n);
	for (int i = 1; i <= n; i++) {
		a[i - 1] = i;
	}
	int p_n, q_n;
	int x = 0;
	do {
		bool is_p = true, is_q = true;;
		for (int i = 0; i < n; i++) {
			if (is_p) {
				if (a[i] != p[i])is_p = false;
			}
			if (is_q) {
				if (a[i] != q[i])is_q = false;
			}
		}
		if (is_p) {
			p_n = x;
		}
		if (is_q)q_n = x;
		x++;

	} while (next_permutation(a.begin(), a.end()));
	int ans = p_n - q_n;
	if (ans < 0)ans *= -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
<?php

while (true) {
	$n = trim(fgets(STDIN));
	if ($n == 0) {
		break;
	}
	$seq_before = explode(' ', trim(fgets(STDIN)));
	$seq_after = array();
	$count = 0;

	while(true) {
		$count++;
		$seq_after = transform($seq_before);
		if (array_equal($seq_before, $seq_after)) {
			break;
		}
		$seq_before = $seq_after;
	}
	echo $count - 1 . "\n";
	echo implode(' ', $seq_after) . "\n";
}

function transform($seq) {
	$result = array();
	foreach ($seq as $val) {
		$result[] = count(array_keys($seq, $val));
	}
	return $result;
}

function array_equal($a1, $a2) {
	if (count($a1) != count($a2)) {
		return false;
	}

	foreach ($a1 as $key => $value) {
		if (!isset($a2[$key])) {
			return false;
		}
		if ($value != $a2[$key]) {
			return false;
		}
	}
	return true;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
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, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll x, y; cin >> x >> y;
  cout << ((abs(x-y) > 1) ? "Alice" : "Brown") << endl;
  return 0;
}


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

using namespace std;

#define MAX_N 155
#define MAX_K 15
#define INF (1<<29)
typedef pair<int, int> pii;

struct State {
    int dng, x, y, m;
    State(){}
    State(int dng, int x, int y, int m) :
        dng(dng), x(x), y(y), m(m) {}

    bool operator < (const State &s) const {
        return dng > s.dng;
    }
};

int main()
{
    int N, M, K, x, d;
    while (cin >> N >> M, N) {
        vector<pii> G[MAX_N];
        for (int i = 0; i < N; i++) {
            cin >> K;            
            for (int j = 0; j < K; j++) {
                cin >> x >> d; 
                G[i].push_back(pii(x, d));
            }
        }
        G[N].push_back(pii(0, 0));
        
        int dn[MAX_N][MAX_K][MAX_N];
        for (int i = 0; i < MAX_N; i++) {
            for (int j = 0; j < MAX_K; j++) {
                for (int k = 0; k < MAX_N; k++) {
                    dn[i][j][k] = INF;
                }
            }
        }
        
        priority_queue<State> Q;
        for (int i = 0; i < 2; i++) {
            int size = G[i].size();
            int nm = (i == 1 ? M - 1 : M);
            for (int j = 0; j < size; j++) {
                Q.push(State(0, j, i, nm)); 
                dn[i][j][nm] = 0;
            }
        }
                
        while (!Q.empty()) {
            State s = Q.top(); Q.pop();
            int y = s.y, x = s.x, m = s.m;
            int dng = G[y][x].second;
            x = G[y][x].first;
            if (y == N) {
                cout << s.dng << endl;
                break;
            }

            for (int i = 1; i <= 2; i++) {
                int ny = y + i;
                if (ny > N) continue;                
                for (int j = 0; j < (int)G[ny].size(); j++) {
                    int nx = G[ny][j].first, nd = G[ny][j].second;
                    int nm = (i == 2 ? m - 1 : m);
                    int ncost = s.dng + (ny < N ? (dng + nd) * abs(x - nx) : 0);

                    if (nm >= 0 && ncost < dn[ny][j][nm]) {
                        dn[ny][j][nm] = ncost;
                        Q.push(State(ncost, j, ny, nm));
                    }
                }
            }
           
        }
    }
    return 0;
}

Measured memory_bytes: 4592
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int,int> pll;
const int maxn= 1e5+10;
const int p =1e9+7;
const double EPS = 1e-6;

LL quick_mod(LL a, LL b)
{
    LL ans = 1;
    a %= p;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a % p;
            b--;
        }
        b >>= 1;
        a = a * a % p;
    }
    return ans;
}

LL C(LL n, LL m)
{
    if(m > n)
        return 0;
    LL ans = 1;
    for(int i=1; i<=m; i++)
    {
        LL a = (n + i - m) % p;
        LL b = i % p;
        ans = ans * (a * quick_mod(b, p-2) % p) % p;
    }
    return ans;
}

LL Lucas(LL n, LL m)
{
    if(m == 0)
        return 1;
    return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,a,b;
    cin >> n >> a>> b;
    //cout << quick_mod(2,n) << " " << Lucas(n,a) << " " << Lucas(n,b) <<  endl;
    cout << ((quick_mod(2,n)-1-Lucas(n,a)+p)%p-Lucas(n,b)+p)%p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll A,B,C;
    cin >> A>>B>>C;
    ll shou = B / A;
    chmin(shou,C);
    cout << shou << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e18
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

const int maxn = 100005;
vl adj[maxn];
ll dp[2][maxn];

inline void mul(ll &a, ll b) {
	a = (a * b) % MOD;
}

void dfs(ll u, ll pv = -1)
{
	dp[0][u] = dp[1][u] = 1;
	
	for (int v : adj[u]) {
		if (v != pv) {
			dfs(v, u);
			mul(dp[0][u], dp[1][v]);
			mul(dp[1][u], dp[1][v] + dp[0][v]);
		}
	}
}

void solve() {
	ll n;
	cin >> n;

	rep(i, n - 1) {
		ll x, y;
		cin >> x >> y;
		x--, y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(0);
	cout << (dp[0][0] + dp[1][0] ) % MOD;
}

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


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

signed main() {

    int a, b;
    cin >> a >> b;
    if (a > b) cout << "safe" << endl;
    else cout << "unsafe" << endl;

}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;

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

	int n;
	cin >> n;
	int ans = 0;
	for(ll i = 1; i <= 1000000; i++) {
		for(ll j = 1; j <= 1000000 / i; j++) {
			if(i * j < n) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3692
program main
   
  implicit none
  integer :: n, i, j
  integer, allocatable :: s(:)
  character(10), allocatable :: names(:)
  
  read(*,*) n
  allocate( names(n) )
  do i = 1, n
    read(*,*) names(i)
  end do

  call quicksort1( names, 1, n ) 

  j = 0 
  do i = 1, n
    if( names(i) /= names(i+1) ) then
      j = j + 1
    end if 
  end do

  print*,j

end program main
recursive subroutine quicksort1( namec, first, last )

  implicit none
  character(10), intent(inout) :: namec(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  character(100)::x,t
  integer::i,j

  x = namec((first+last)/2)
  i = first
  j = last
  do
     do while ( LGT( x, namec(i) ) )
        i=i+1
     end do
     do while ( LGT( namec(j), x ) )
        j=j-1
     end do
     if (i >= j) exit
     t = namec(i)
     namec(i) = namec(j)
     namec(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1( namec, first, i-1  )
  if (j+1 < last)  call quicksort1( namec, j+1  , last )

  return

end subroutine quicksort1


Measured memory_bytes: 4756
def pre_c(n, mod):
    f = [0] * (n + 1)
    g = [0] * (n + 1)
    for i in range(n + 1):
        if i == 0:
            f[i] = 1
            g[i] = 1
        else:
            f[i] = (f[i - 1] * i) % mod
            g[i] = pow(f[i], mod - 2, mod)

    return f, g

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod = 10 ** 9 + 7
f, g = pre_c(n, mod)

ans = 0
for i in range(n - k + 1):
    min_temp = a[i] * f[n - i - 1] * g[k - 1] * g[n - i - 1 - k + 1] % mod
    max_temp = a[n - i - 1] * f[n - i - 1] * g[k - 1] * g[n - i - 1 - k + 1] % mod

    ans = (ans + (max_temp - min_temp) % mod ) %mod
print(ans)


Measured memory_bytes: 15248
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  
  if (b == 1) {
    cout << "0\n";
  } else {
    --a;
    int n = (b - 1) / a;
    int m = (b - 1) % a;
    if (m > 0)
      ++n;
    cout << n << endl;
  }
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
bool a[50][50], b[50][50];
int main() {
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i++) {
        string A;
        cin >> A;
        for(int j = 0; j < N; j++){
            a[i][j] = A[j] == '#';
        }
    }
    for (int i = 0; i < M; i++) {
        string B;
        cin >> B;
        for (int j = 0; j < M; j++) {
            b[i][j] = B[j] == '#';
        }
    }
    for(int y = 0; y <= N - M; y++) {
        for(int x = 0; x <= N - M; x++) {
            bool flag = true;
            for(int i = 0; i < M; i++) {
                for(int j = 0; j < M; j++) {
                    if(b[i][j] != a[y + i][x + j]) flag = false;
                }
            }
            if(flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

struct Graph{
    Graph(int n):d(n,vector<int>(n,INF)),N(n){
        for(int i=0;i<n;++i)d[i][i]=0;
    }
    vector<vector<int>>d;
    int N;
    void add_edge(int a,int b,int c){
        d[a][b]=c;
    }
    void warshallFloyd(){
        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]);
    }
};

main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V,E;
    cin>>V>>E;
    Graph G(V);
    for(int i=0;i<E;++i){
        int s,t,d;
        cin>>s>>t>>d;
        G.add_edge(s,t,d);
    }
    G.warshallFloyd();
    for(int i=0;i<V;++i)
        if(G.d[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    for(int i=0;i<V;++i){
        for(int j=0;j<V;++j)
            if(G.d[i][j]==INF) cout<<(j?" ":"")<<"INF";
            else cout<<(j?" ":"")<<G.d[i][j];
        cout<<endl;
    }
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b){
        swap(a,b);
    }
    int k;
    cin >> k;
    if(a<c){
        swap(a,c);
    }
    rep(i,k){
        a*=2;
    }
    cout << a+b+c <<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools

N = int(sys.stdin.readline())

count = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
    s = sys.stdin.readline().strip()
    if s[0] in count:
        count[s[0]] += 1

ans = 0
for perm in itertools.combinations(count.keys(), 3):
    tmp = 1
    for i in perm:
        tmp *= count[i]
    ans += tmp

print(ans)

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


int main(){
    string str;
    string divide[4] = {"dream", "dreamer", "erase", "eraser"};
    cin >> str;

    reverse(str.begin(),str.end());
    for(int i=0;i<4;i++) reverse(divide[i].begin(),divide[i].end());

    bool can = true;
    for(int i=0;i<str.size();){
        bool can2 = false;
        for(int j=0;j<4;j++){
            string d = divide[j];
            if(str.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(can2 == false){
            can = false;
            break;
        }
    }
    string ans = "NO";
    if(can){
        ans = "YES";
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
P_N = sorted(P)

# print(list(x != y for x, y in zip(P, P_N)))

S = sum(x != y for x, y in zip(P, P_N))
# print(S)
print('YES' if S == 0 or S == 2 else 'NO')


Measured memory_bytes: 3060
#include<iostream>
#include<list>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 60000
#define PRIME 0

int isprime[MAX];

int main()
{
    //memset(isprime,1,sizeof(isprime));
    isprime[0]=1;
    isprime[1]=1;
    for(int i=2;i<MAX;i++)
    {
        if(isprime[i]==PRIME)
        for(int j=2;j<MAX;j++)
        {
            if(i*j>=MAX) break;
            isprime[i*j] = 1;

        }
    }
    list<int> plist;
    for(int i=2;i<MAX;i++)
    {
        if(isprime[i]==0) plist.push_back(i);
    }
    int n;
    while(cin>>n)
    {
        int a,b;
        list<int>::iterator it = upper_bound(plist.begin(),plist.end(), n);
        b = *it;
        --it;
        if(*it<n) a= *it;
        else{--it;a= *it;}


        cout << a <<" "<< b <<endl;

    }
    
    return 0;
}

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

Measured memory_bytes: 1792
#pragma optimization_level 3
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int N;

long long M;
vector<int> p1, p2;
map<long long, int> T;

bool is_prime(long long x) {
  for (int i=2; i<=sqrt(x); i++) {
    if (x % i == 0) return false;
  }
  return true;
}

long long norm(long long x) {
  for (int k : p1) {
    while (x % (k*k*k) == 0) x /= k*k*k;
  }
  return x;
}

long long inv(long long x) {
  long long ret = 1;
  for (int k : p1) {
    int c = 0;
    while (x % k == 0) x /= k, c++;
    if (c > 0) {
      while (++c <= 3) {
        ret *= k;
        if (ret > M) return -1;
      }
    }
  }
  if (x == 1) return ret;

  // - p1^2  -> p1
  long long rt = sqrt(x);
  if (rt*rt == x) {
    ret *= rt;
    return ret>M?-1:ret;
  }

  auto it = lower_bound(p2.begin(), p2.end(), x);
  // - p1*p2 -> -1
  if (it == p2.end() || *it != x) return -1;
  // - p1 -> p1^2
  ret *= x; if (ret > M) return -1;
  ret *= x; if (ret > M) return -1;
  return ret;
}

int main() {
  cin >> N;
  for (int i=2; i<=2154; i++) {
    if (is_prime(i)) p1.push_back(i);
  }
  for (int i=2155; i<=100000; i++) {
    if (is_prime(i)) p2.push_back(i);
  }

  bool one = false;
  for (int i=0; i<N; i++) {
    long long s; cin >> s;
    long long n = norm(s);
    M = max(M, n);
    if (n == 1) one = true;
    else T[n]++;
  }

  int c = 0;
  for (auto p : T) {
    long long s = p.first;
    if (T[s] == 0) continue;
    long long v = inv(s);
    if (v == -1) c += p.second;
    else {
      c += max(T[v], p.second);
      T[v] = 0;
    }
  }
  cout << c + one << "\n";
  return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int ctoi(char c) {
	return c - 'a';
}

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

	int N;
	string S;
	cin >> N >> S;
	int res = 0;

	for (int i = 1;i <= N - 1;i++) {
		vector<bool> a(26, 0), b(26, 0);
		for (int j = 0;j < i;j++) a[ctoi(S[j])] = true;
		for (int j = i;j < N;j++) b[ctoi(S[j])] = true;
		int tmp = 0;
		for (int j = 0;j < 26;j++) {
			if (a[j] && b[j]) tmp++;
		}
		res = max(res, tmp);
	}
	cout << res << "\n";
	
	return 0;
}

Measured memory_bytes: 256
x,N=list(map(int,input().split()))
if N==0:
    print(x)
else:
    ps=list(map(int,input().split()))
    n=[0]*300

    for p in ps:
        n[p+100]+=1
    if n[x+100]==0:
        print(x)
    else:
        ans=0
        for i in range(1,200):
            if n[x-i+100]==0:
                ans=x-i
                break
            elif n[x+i+100]==0:
                ans=x+i
                break
        print(ans)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  cin >> s;
  
  if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
  
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    bool tmp=false;
    for(int i=1;i<=9;++i){
      for(int j=1;j<=9;++j){
        if(i*j==n) tmp=true;
      }
    }
    if(tmp) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

   return 0;
 }


Measured memory_bytes: 256
import Control.Applicative
import Data.List

main = do
  contents <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  let ans = fmap solve $ makeTuple contents []
  mapM_ output ans

makeTuple :: [[Int]] -> [([Int], [Int])] -> [([Int], [Int])]
makeTuple [] s = s
makeTuple all@(x:[]) s = s
makeTuple (x:y:ys) s = (x, y):makeTuple ys s

solve :: ([Int], [Int]) -> (Int, Int)
solve (x, y) = let hit = hitCount x y
                   blow = (blowCount x y) - hit
                     in (hit, blow)

hitCount :: [Int] -> [Int] -> Int
hitCount x y = length $ findIndices (== True) $ zipWith (==) x y

blowCount :: [Int] -> [Int] -> Int
blowCount x y = length $ findIndices (== True) $ fmap (\a -> elem a y) x

output :: (Int, Int) -> IO ()
output (x, y) = putStrLn $ (show x) ++ " " ++ (show y)

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

const int maxn=1e5+5;
vector<int>adj[maxn];
int visited[maxn];

void bfs(int v){
    visited[v]=1;
    queue<int>q;
    q.push(v);
    while(!q.empty()){
        int p=q.front();
        q.pop();
        for(auto u:adj[p]){
            if(!visited[u]){
                visited[u]=p;
                q.push(u);
            }
        }
    }
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);

    }
    bfs(1);
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++){
        cout<<visited[i]<<endl;
    }
}

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


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

using namespace std;
using ll = long long;
constexpr int INF = 1 << 29;

const int N = 101;
int main() {
    int n;
    int a[2][N];
    cin >> n;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            int x;
            scanf("%d", &x);
            a[i][j] = x;
        }
    }
    int m = 0;
    for (int i = 0; i < n; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            if (j < i) {
                sum += a[0][j];
            } else if (j > i) {
                sum += a[1][j];
            } else {
                sum += a[0][j] + a[1][j];
            }
        }
        m = max(m, sum);
    }
    cout << m << endl;

    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto s = readln.chomp;

    int plus = cast(int)s.count('+');
    writeln(plus - (4 - plus));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,kanou,ans;
  ans=0;
  cin>>n>>m;
  vector<pair<int,int> > vec(m);
  vector<int> nagare(n);
  for(int i=0; i<m; i++){
    cin>>vec.at(i).first;
    cin>>vec.at(i).second;
  }
  for(int i=0; i<n; i++){
    nagare.at(i)=i+1;
  }
  do {
    kanou=1;
    for(int i=0; i<n-1; i++){
      if(nagare.at(0)!=1){
        kanou=0;
        break;
      }
      for(int j=0; j<m; j++){
        if(nagare.at(i)==vec.at(j).first && nagare.at(i+1)==vec.at(j).second){
          break;
        }
        if(nagare.at(i)==vec.at(j).second && nagare.at(i+1)==vec.at(j).first){
          break;
        }
        if(j==m-1){
          kanou=0;
        }
      }
      if(kanou==0){
        break;
      }
    }
    if(kanou==1){
     
      
      ans=ans+1;
    }
  }
  while(next_permutation(nagare.begin(),nagare.end() ) );
  cout<<ans;
}
    

Measured memory_bytes: 256
#include<stdio.h>
int N,Q,X[10005],i,t,r=0;
int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",X+i);
	for(scanf("%d",&Q);Q--;)
	{
		scanf("%d",&t);
		for(i=0;i<N;i++)
			if(X[i]==t)
			{
				r++;
				break;
			}
	}
	return !printf("%d\n",r);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a;
    cin >> a;
    if(a == 'A') cout << 'T' << endl;
    if(a == 'T') cout << 'A' << endl;
    if(a == 'G') cout << 'C' << endl;
    if(a == 'C') cout << 'G' << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long[] arr = new long[sc.nextInt()];

		for (int i = 0; i < arr.length; i++) {
			arr[i] = sc.nextLong();
		}
		sc.close();

		System.out.println(lcd(arr));
	}

	private static long lcd(long[] arr) {

		if (arr.length == 1) {

			return arr[0];
		} else if (arr.length == 2) {

			return arr[0] * (arr[1] / gcd(arr[0], arr[1]));
		} else {

			long temp = arr[0] * (arr[1] / gcd(arr[0], arr[1]));

			for (int i = 2; i < arr.length; i++) {

				temp = temp * (arr[i] / gcd(temp, arr[i]));
			}

			return temp;
		}
	}

	private static long gcd(long m, long n) {

		if (m < n) {
			return gcd(n, m);
		}

		if (n == 0) {
			return m;
		}

		return gcd(n, m % n);
	}
}


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

int main(){
  int N;
  cin>>N;
  vector<tuple<string,int,int>> p(N); 
  for (int i=0; i<N; i++){
    int x;
    cin>>get<0>(p.at(i))>>x;
    get<1>(p.at(i))=-x;
    get<2>(p.at(i))=i+1;
  }
  sort(p.begin(),p.end());
  for (int i=0; i<N; i++){
    cout<<get<2>(p.at(i))<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int n; cin >> n;
  int F[50];
  F[0] = F[1] = 1;
  REP(i, 2, n) F[i] = F[i-1] + F[i-2];

  cout << F[n] << endl;

  return 0;
}





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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    set<int>s;
    int n;
    for(int i=0;i<3;i++)
    {
        cin>>n;
        s.insert(n);
    }
    if(s.size()==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
x = sorted(x)
ans = 100**3
for i in range(x[0],x[n-1]+1):
  cost = 0
  for j in range(n):
    cost += pow(x[j]-i,2)
  ans = min(ans,cost)
print(ans)


Measured memory_bytes: 3060
// #include<iostream>
// using namespace std;
// int main(){
//   int n;cin>>n;
//   int allice=0,bob=0,c;
//   for(int i=0;i<n;i++){
//     cin>>c;
//     if(i%2==0)allice+=c;
//     else if(i%!=0)bob+=c;
//   }
// }

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for( int i = 0; i < n1; i++ )L[i] = A[left + i];
  for( int i = 0; i < n2; i++ )R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for ( int k = left; k < right; k++ ){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right){
  if( left+1 < right){
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main(){
  int A[MAX], n, i;
  cnt = 0;cin>>n;
  for (i=0;i<n;i++)cin>>A[i];
  mergeSort(A, n, 0, n);
  int allice=0,bob=0;
  for(int i=n;i>=0;i-=2){
    allice+=A[i];
  }
  for(int i=n-1;i>=0;i-=2){
    bob+=A[i];
  }
  cout<<bob-allice<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
#include <stdio.h>
using namespace std;

int main(int argc, const char *argv[])
{   
    int N;
    cin>>N;
    vector<int> H(N,0);
    for(int i = 0; i < N ; i ++)
    {
        cin>>H[i];
    }
    int count = 0;
    int check = 1;
    for(int i = 0;i < N;i++)
    {
        check = 1;
        for(int j = 0; j <i ; j ++)
        {
            if(H[i] < H[j])
            {
                check = 0;
            }
        }
        if(check == 1)
        {
            count++;
        }
    }

    cout<<count;

    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(){
    ll N;
    cin >> N;
    if(N == 1){
        cout << "Hello World" << endl;
    }else{
        ll a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	int A,B;
	cin>>A>>B;
	if(B<10)A*=10;
	else if(B<100)A*=100;
	else A*=1000;
	int C = A+B;
	int D = (int)sqrt(C);
	if(D*D == C)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	return 0;
}

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

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;

int main() {
	int x, y;
	cin >> x >> y;
	bool flag = 0;
	if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))flag = 1;
	else if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))flag = 1;
	else if ((x == 2 && y == 2))flag = 1;
	if (flag) { print("Yes"); }
	else { print("No"); }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<set>
#include<numeric>
#include<functional>
#include<unordered_map>
using namespace std;

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int target = 100 * r + 10 * g + b;
    if (target % 4 == 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

Measured memory_bytes: 256