akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long 
#define mp make_pair
using namespace std;
inline int read()
{
	int x=0,fl=1;char st=getchar();
	while(st<'0'||st>'9'){ if(st=='-')fl=-1; st=getchar();}
	while(st>='0'&&st<='9') x=x*10+st-'0',st=getchar();
	return x*fl;
}
const int N=1e5+10;
int d[N],v[N],n;
struct skr
{
	int to,nxt,v;
}a[N<<1];
int head[N],cnt;
inline void add(int x,int y,int z)
{
	a[++cnt].to=y;a[cnt].nxt=head[x];head[x]=cnt;a[cnt].v=z;
//	printf("%d->%d %d\n",x,y,z);
}
priority_queue<pair<int,int> >q;
void dij()
{
	memset(d,0x3f,sizeof d);
//		memset(v,0,sizeof v);
	d[1]=0;
	q.push(mp(0,1));
	while(q.size())
	{
		int x=q.top().second;q.pop();
		if(v[x]) continue;
		v[x]=1;
		for(int i=head[x];i;i=a[i].nxt)
		{
			int y=a[i].to;
			if(d[y]>d[x]+a[i].v)
			{
				d[y]=d[x]+a[i].v;
				q.push(mp(-d[y],y));
			}
		}
	}
}
int main()
{
	n=read();
	for(int i=0;i<n;i++)
		add(i,(i+1)%n,1);
	for(int i=0;i<n;i++) add(i,10*i%n,0);
	dij();
	printf("%d\n",d[0]+1);
	return 0;
}


Measured memory_bytes: 4348
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;


void answer(){
    int n,ans=0,c=0,m1,c1=0;
    cin>>n>>m1;
    string s;
    vector<pair<int,string>> m;
    map<int,string> v;
    for(int i=0;i<m1;i++){
        cin>>n>>s;
        m.pb(mp(n,s));
        if(v[n]!="AC") v[n]=s;
    }
    for(int i=0;i<m1;i++){
        if(v[m[i].F] == "AC"){
            if(m[i].S=="WA") c++;
            else {v[m[i].F] = "WA"; c1++;}
        }
    }
    cout<<c1<<" "<<c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int q;
    //cin>>q; while(q--) 
                answer();
    return 0;
}

Measured memory_bytes: 17392
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

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

}

int main(void) {
	int n;
	int arr[200002];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}

	qsort(arr, n, sizeof(int), cmp);

	int er = 0;
	for (int i = 0; i < n-1; i++) {
		if (arr[i] == arr[i + 1]) {
			er = 1;
			break;
		}
	}

	if (er) printf("NO");
	else printf("YES");
	return 0;
}

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

int main() {
    int S;
    cin >> S;
    ll M = 1000000000+7;
    vector<ll> total(3, 0);
    ll n = 0;
    for(int i=3;i<=S;i++){
        n = (total[0] + 1) % M;
        total[0] = total[1];
        total[1] = total[2];
        total[2] = total[1] + n;
    }
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 3612
// This code was written in Qt
#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
inline long nano_time() {return chrono::high_resolution_clock::now().time_since_epoch().count();}
#ifndef CrafterKolyan
#define endl '\n'
#endif

int a[100000];
int sum[100000];
ll fenwick_tree[200001];

void init(int n) {
    memset(fenwick_tree, 0, sizeof(fenwick_tree));
}

ll get(int x) {
    ll ret = 0;
    for (;x > 0; x &= x + 1, --x) {
        ret += fenwick_tree[x];
    }
    return ret;
}

void inc(int x, int val = 1, int n = sizeof(fenwick_tree) / sizeof(*fenwick_tree)) {
    for (;x < n; x |= x + 1)
        fenwick_tree[x] += val;
}

bool check(int m, int n) {
    init(n);
    int cur = n;
    ll ans = 0;
    inc(cur);
    for (int i = 0; i < n; ++i) {
        if (a[i] >= m) ++cur;
        else --cur;
        ans += get(cur);
        inc(cur);
    }
    ll need = (ll) n * (n + 1) / 2;
    return 2 * ans >= need;
}

main() {
#ifndef CrafterKolyan
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    int l = INT_MAX, r = INT_MIN, m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        l = min(l, a[i]);
        r = max(r, a[i]);
    }
    ++r;
    while (r - l > 1) {
        m = (r + l) / 2;
        if (check(m, n)) {
            l = m;
        } else {
            r = m;
        }
    }
    cout << l << endl;
}


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int m[7][7][2] = {
  {{0,0},{6,300},{13,500},{18,600},{23,700},{43,1350},{58,1650}},
  {{6,300},{0,0},{7,350},{12,450},{17,600},{37,1150},{52,1500}},
  {{13,500},{7,350},{0,0},{5,250},{10,400},{30,1000},{45,1350}},
  {{18,600},{12,450},{5,250},{0,0},{5,250},{25,850},{40,1300}},
  {{23,700},{17,600},{10,400},{5,250},{0,0},{20,600},{35,1150}},
  {{43,1350},{37,1150},{30,1000},{25,850},{20,600},{0,0},{15,500}},
  {{58,1650},{52,1500},{45,1350},{40,1300},{35,1150},{15,500},{0,0}},
};
int main()
{
  int s,g,hs,ms,hg,mg,t,c;
  bool f;
  for(;;){
    cin >> s;
    if(s==0) break;
    cin >> hs >> ms;
    cin >> g;
    cin >> hg >> mg;
    f = false;
    t = hs * 60 + ms;
    if(1050<= t && t<=1170) f = true;
    t = hg * 60 + mg;
    if(1050<= t && t<=1170) f = true;
    if(m[s-1][g-1][0] > 40) f = false;
    c = m[s-1][g-1][1];
    if(f){
      c /= 2;
      if(c % 50 != 0) {
	c = c - (c % 50) + 50;
      }
    }
    cout << c << endl;
  }
  return 0;
}

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

int main()
{
	const int range[] = { 0, 10, 20, 30, 40, 50, 60, 1000 };

//	cut here before submit 
//	freopen ("testcase.tsuruga", "r", stdin );

	while (1){
		int n;
		cin >> n;
		if (n == 0){
			break;
		} // end if

		vector <int> hist (7, 0 );
		int i,j;
		for (i = 0; i < n; ++i){
			int age;
			cin >> age;
			for (j = 0; j < 7; ++j){
				if (age >= range[j] && age < range[j+1] ){
					++hist[j];
					break;
				} // end if
			} // end for
		} // end for
		for (j = 0; j < 7; ++j){
			cout << hist[j] << endl;
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 904
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;

int main() {
	int n,f[6]={};
	float h;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>h;
		
		if(h<165.0)++f[0];
		else if(h<170.0)++f[1];
		else if(h<175.0)++f[2];
		else if(h<180.0)++f[3];
		else if(h<185.0)++f[4];
		else ++f[5];
	}
	
	for(int i=0;i<6;++i){
		cout<<i+1<<":";
		for(int j=0;j<f[i];++j){
			cout<<"*";
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int main(){

	int c[10][10];

	int H,W,A,res;

	cin >> H >> W;

	for(int i = 0;i < 10;i++){
		for(int j = 0;j < 10;j++){
			cin >> c[i][j];
		}
	}

	for(int k = 0; k < 10;k++){
		for(int i = 0;i < 10;i++){
		    for(int j = 0;j < 10;j++){
		        if(c[i][j]  > c[i][k] + c[k][j]){
		        	c[i][j] = c[i][k] + c[k][j];
		        }
		    }
		}
	}

	for(int i = 0;i < H;i++){
		for(int j = 0;j < W;j++){
			cin >> A;
			if(A >=0)res += c[A][1];
		}
	}

	cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
A = int(input()) #500
B = int(input()) #100
C = int(input()) #50
X = int(input())
count = 0 #初期値
           
#全件走査
maxA = X // 500 if 500 * A > X else A
for i in range(maxA + 1):
  maxB = (X - 500 * i) // 100 if 100 * B > (X - 500 * i) else B
  for j in range(maxB + 1):
    q,mod = divmod (X - 500 * i - 100 * j ,50)
    if mod == 0 and q <= C:count += 1    
print(count)


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int oldm0 = 0, oldm1 = 0;
	size_t maxIdx = 0;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			vector<int>::iterator mIdx = max_element(a.begin() + 1, a.end());
			maxIdx = distance(a.begin(), mIdx);
			int max0 = *mIdx;
			cout << max0 << endl;
			oldm0 = a[0];
			oldm1 = max0;
			continue;
		}
		int m0 = oldm0;
		if (oldm0 < a[i - 1])
			m0 = a[i - 1];
		int m1 = oldm1;
		if (i == maxIdx && oldm1 != a[i + 1])
		{
			vector<int>::iterator mIdx = max_element(a.begin() + i + 1, a.end());
			maxIdx = distance(a.begin(), mIdx);
			m1 = *mIdx;
		}
		if (m0 > m1)
			cout << m0 << endl;
		else
			cout << m1 << endl;
		oldm0 = m0;
		oldm1 = m1;
	}
	return 0;
}

Measured memory_bytes: 2432
S = input().strip()

L = len(S) - 1
i = 2 ** L - 1

ans = 0

while i >= 0:
    tmp = str(S[0])
    for l in range(L):
        if i >> l & 1:  # "+"
            ans += int(tmp)
            tmp = S[l+1]
        else:
            tmp += str(S[l+1])
    ans += int(tmp)
    i -= 1
print(ans)


Measured memory_bytes: 39664
n = int(input())
a = list(map(int, input().split()))

a.sort()
cnt = 1
ans = 0
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        cnt += 1
        continue

    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    cnt = 1
if cnt >= a[-1]:
    ans += cnt - a[-1]
else:
    ans += cnt
print(ans)


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

using namespace std;

int main() {
	string s, t;
	cin>>s>>t;
	int ma=1e9;
	for(int i=0; i<s.size(); i++){
		if(i+t.size()>s.size()){
			break;
		}
		int jum=0;
		for(int j=0; j<t.size(); j++){
			if(s[j+i]!=t[j]){
				jum++;
			}
		}
		ma=min(ma, jum);
	}
	cout<<ma<<endl;
	
	
    return 0;
}

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

int main()
{
	int H,W;
	while(true){
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3088
A,B,C,X,Y = map(int, input().split())
money = 0
if A+B <= 2*C:
        money += A*X + B*Y
        
else:
    
    if X >= Y:
        money += C*2*Y
        if A <= 2*C:
            money += A*(X-Y)
        else:
            money += 2*C*(X-Y)
    else:
        money += C*2*X
        if B <= 2*C:
            money += B*(Y-X)
        else:
            money += 2*C*(Y-X)

print(money)
            

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int imosA[5002][5002] = {};
int imosB[5002][5002] = {};
int imos[5002][5002] = {};

int main(){
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a,b,x;
        cin >> a >> b >> x;
        a--; b--;
        imosA[a][b]++;
        imosA[a+x+1][b]--;
        imosB[a][b+1]--;
        imosB[a+x+1][b+x+2]++;
    }

    for(int i=0; i<N+1; i++){
        int now = 0;
        for(int j=0; j<N-i+1; j++){
            now += imosA[i+j][i];
            imos[i+j][i] += now;
        }
    }
    for(int i=0; i<N+1; i++){
        int now = 0;
        for(int j=0; j<N-i+1; j++){
            now += imosB[i+j][j];
            imos[i+j][j] += now;
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        int now = 0;
        for(int j=0; j<i+1; j++){
            now += imos[i][j];
            if(now > 0) ans++;
        }
    }
    cout << ans << endl;

    /*cout << endl;
    for(int i=0; i<N; i++){
        for(int j=0; j<i+1; j++){
            cout << imos[i][j] << " ";
        }
        cout << endl;
    }*/

    return 0;
}


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

const ll MOD = 1e9 + 7;

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

  vector<ll> cnt(26, 0);
  rep(i, n) ++cnt[s[i] - 'a'];
  ll ans = 1;
  rep(i, 26) ans = ans * (cnt[i] + 1) % MOD;
  --ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <cmath>
#include <cstdio>
#include <algorithm>
#define rg register
#define llint long long
using namespace std;

struct ios{
	template <typename _tp>
	inline ios operator >> (_tp &x){
		char c = getchar();int f = 1;
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c>='0'&&c<='9';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x){
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x)
			++dgt,s[dgt] = x%10+'0',x /= 10;
		while(dgt)
			putchar(s[dgt]),--dgt;
		return *this; 
	}
}io;

int n,cnt; 

int main()
{
	io >> n;
	for(rg int i=1;i<=n;++i){
		if((i/1<10&&i/1>0)||(i/100<10&&i/100>0)||(i/10000<10&&i/10000>0)||(i/1000000<10&&i/1000000>0))
			++cnt; 
	}
	io << cnt;
	return 0;
}

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

int *A, H;

void maxHeapify(int *, int);


int main() {
  int id;

  scanf( "%d" , &H );
  A = malloc((H+1) * sizeof(int));
  for ( id=1; id<=H; id++ ) scanf( "%d" , &A[id] );

  for ( id=H/2; id>=1; id-- ) maxHeapify(A, id);

  for ( id=1; id<=H; id++ ) printf( " %d" , A[id] );
  printf( "\n" );
  
  return 0;
}


void maxHeapify(int *A, int i) {
  int temp, l, r, largest;
  
  l = i*2;
  r = i*2+1;

  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if ( (l <= H) && (A[l] > A[i]) ) largest = l;
  else largest = i;
  if ( (r <= H) && (A[r] > A[largest]) ) largest = r;
  if ( largest != i ) { // i の子の方が値が大きい場合
    temp = A[i];
    A[i] =  A[largest];
    A[largest] = temp;
    maxHeapify(A, largest); // 再帰的に呼び出し
  }
}



Measured memory_bytes: 3696
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    if(S.at(5) == '0'
        &&  (S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' || S.at(6) == '4' ))
       { 
        cout << "Heisei" << endl;
       }
       else{
           cout << "TBD" << endl;
       }
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){
    int W, H ,i, r, z;
    for(;;){
        scanf("%d%d", &H , &W);
        if( W == 0 && H == 0 ){
            break;
        }

        for( i = 0; i < H; i++ ){
           if( i % 2 == 0 ){
               for( r = 0; r < W; r++ ){
                   if( r % 2 == 0 ){
                       printf("#");
                   }else{
                       printf(".");
                   }
               }
           }
           else{
               for( z = 0; z < W; z++ ){
                   if( z % 2 == 0 ){
                       printf(".");
                   }else{
                       printf("#");
                   }
               }
           }
           printf("\n");
        }
        printf("\n");
    }
    return 0;
}

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

int main()
{
  int A, B;
  cin >> A >> B;
  int ans;
  if (((A+B) % 2) == 0 ) {
    cout << (A + B) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
use strict;

my ($h, $w) = get_array_from_stdin();

my $table;
for (my $th = 1; $th <= $h; $th++) {
  my $row = get_array_from_stdin();
  my @tmp = split //, $row;
  for (my $tw = 1; $tw <= $w; $tw++) {
    $$table[$th][$tw] = shift @tmp;
  }
}

my $nh = 1;
my $nw = 1;
while (1) {
#  print "table $nh $nw is $$table[$nh][$nw]\n";

  my $matched_column = 0;
  my $matched_row = 0;

  for (my $th = $nh+1; $th <= $h; $th++) {
#    print "(2)table $th $nw is $$table[$th][$nw]\n";
    if ($$table[$th][$nw] eq "#") {
      $matched_column = 1;
#      last;
    }
  }
  for (my $tw = $nw+1; $tw <= $w; $tw++) {
#    print "(3)table $nh $tw is $$table[$nh][$tw]\n";
    if ($$table[$nh][$tw] eq "#") {
      $matched_row = 1;
#      last;
    }
  }

  if ($matched_column == 1 and $matched_row == 1) {
    print "Impossible\n";
    last;
  } elsif ($matched_column == 1) {
#    print "D: move down\n";
    $nh++;
  } else {
#    print "D: move right\n";
    $nw++;
  }

  if ($nh == $h and $nw == $w) {
    print "Possible\n";
    last;
  }
} 

exit;

### common sub routine ###

sub get_array_from_stdin {
  my $input = <STDIN>;
  chomp($input);
  if (wantarray) {
    return split /\s+/, $input;
  } else {
    return $input;
  }
}


Measured memory_bytes: 512
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
if (m == 0) and (n != 1):
  print(10**(n-1))
  exit()
elif (m == 0) and (n == 1):
  print(0)
  exit()
elif (n == 1) and (sc.count([1,0]) == m):
  print(0)
  exit()
for i in range(10**(n-1),1000):
  i = str(i)
  for j in range(m):
    try:
      if i[sc[j][0] - 1] ==  str(sc[j][1]):
        pass
      else:
        break
    except:
      break
    if j == m-1:
      print(i)
      exit()
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>

typedef long long ll;
const ll INF = 1e12;

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  std::vector< ll > va(n, 0);
  for (ll i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  ll ans = -INF;
  for (ll i = 0; i < n-1; i++) {
    for (ll j = 1; j < n; j++) {
      ans = std::max(ans, (ll)std::fabs(va[i] - va[j]));
    }
  }

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


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

int n;
long int combination = 0;

int main() {
  cin >> n;
  vector<long int> in_v(n);
  vector<long int> comb(n + 1,0);
  for (size_t i = 0; i < n; i++) {
    cin >> in_v.at(i);
  }
  for (size_t i = 0; i < n; i++) {
    comb.at(in_v.at(i))++;
  }
  for (size_t i = 0; i < n + 1; i++) {
    combination += (comb.at(i) * (comb.at(i) - 1)) / 2;
  }
  for (size_t i = 0; i < n; i++) {
    cout << combination - comb.at(in_v.at(i)) + 1 << endl;
  }
  return 0;
}


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

int main(){
    ll a,b,n,d;
    scanf("%lld%lld",&n,&d);
    int cnt=0;
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&a,&b);
        if(a*a+b*b<=d*d){
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 3824
#include <stdio.h>
#define INF 100000000

int n,M[101][101];
 
void dijkstra(){
  int minv,i,v,u;
  int d[101],color[101];
 
  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=0;
  }
   
  d[0]=0;
  color[0]=1;
  while(1){
    minv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=2){
    u=i;
    minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=2;
    for(v=0;v<n;v++){
      if(color[v]!=2 && M[u][v]!=INF){
    if(d[v] > d[u]+M[u][v]){
      d[v]=d[u]+M[u][v];
      color[v]=1;
    }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF){
      printf("1\n");
    }
      else   printf("%d\n",d[i]);
     
  }
}
 
int main(){
  int i,j,u,k,v,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v]=c;
    }
  }
   
  dijkstra();
  return 0;
}

Measured memory_bytes: 640
a,b=map(int,input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
  
x = Base_10_to_n(a, b)

print(len(x))



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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							 \
			cout.tie(0);
#define PI 3.141592654
#define all(v) v.begin(), v.end()
using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
void add(ll& x, ll v) { x = (x + v) % MOD; if (x < 0) x += MOD; }
//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }

void test_case() {

}

const int mxN = 1e5 + 1;


int main() {
	fastio;
	ll n;
	cin >> n;
	string ans;


	while (n > 0) {
		n--;
		int d = n % 26;
		ans += char('a' + d);
		n /= 26;
	}

	reverse(all(ans));
	cout << ans;

	return 0;
}

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

int main() {
  while(1) {
    int e;
    cin >> e;
    if(e == 0) break;
    int min = -1;
    for(int z = 0; z*z*z <= e; z++) {
      for(int y = 0; y*y <= e; y++) {
	int x = e - (y*y + z*z*z);
	if(x < 0) break;
	int m = x + y + z;
	if(min == -1 || m < min) min = m;
      }
    }
    cout << min << endl;
  }
  return 0;
}

Measured memory_bytes: 868
#include<stdio.h>
int main(void)
{
   int H[300],W[300],i,j,k,flag=1,cnt=0;
   do{
      scanf("%d %d",&H[cnt],&W[cnt]);
      if(H[cnt]==0&&W[cnt]==0){
         flag=0;
      }
      cnt++;
   }while(flag);
   for(i=0;i<cnt-1;i++){
      for(j=0;j<H[i];j++){
         for(k=0;k<W[i];k++){
            printf("#");
         }
         printf("\n");
      }
      printf("\n");
   }
   return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5 + 5;
int v[N];
int gcd(int a,int b){
	return !b ? a : gcd(b,a % b);
}
int main(){

//	freopen("in.txt","r",stdin);

	int n,k,mx=0,g=0;
	cin >> n >> k;
	for(int i=0;i < n;i++){
		scanf("%d",&v[i]);
		if(v[i] == k){
			puts("POSSIBLE");
			return 0;
		}
		mx=max(mx,v[i]);
		if(!i) g=v[i];
		else g=gcd(g,v[i]);
	}
	if(mx >= k && k % g == 0){
		puts("POSSIBLE");
		return 0;
	}
	puts("IMPOSSIBLE");

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int h,w;
    while(1){
        int i,j;
        cin >> h >> w;
        if(h==0 && w==0){
            break;
        }
        else{
            for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    if(i==1||i==h||j==1||j==w){
                        cout << "#";
                    }
                    else{
                        cout<<".";
                    }
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3072
w = str(input())
List = [w[i] for i in range(len(w))]
lis = sorted(List)
#print(lis)
uni = list(set(lis))
#print(uni)
ans = []
q = 0
for i in range(len(uni)):
    p = lis.count(uni[i])
    ans.append(p)
for j in range(len(ans)):
    q += ans[j]%2
if q == 0:
    print("Yes")
else:
  print("No")


Measured memory_bytes: 38256
#include <cstdio>
#define mod 998244353
#define max_n 200000
#define max_k 10
using namespace std;
int /*dp[max_n+1],*/sum[max_n+1];
struct node{
	int l,r;
};
node a[max_k+1];
typedef const int& ci;
int cnt(int l,ci r){
	if(r<=0)
		return 0;
	l<=0&&(l=1);
	return sum[r]-sum[l-1]+mod;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0; ++i<=k; scanf("%d%d",&a[i].l,&a[i].r));
	sum[1]=1,sum[0]=0;
	long long num;
	for(int i=1; ++i<=n; sum[i]=(sum[i-1]+num)%mod)
		for(int j=num=0; ++j<=k; num+=cnt(i-a[j].r,i-a[j].l));
	num=sum[n]-sum[n-1];
	printf("%lld\n",num<0?(num+mod):num);
	return 0;
}

Measured memory_bytes: 2504
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    string s;
    cin >> s;
    map<char,int> m;
    rep(i,s.length())m[s[i]]++;
    if((m['N'] != 0 && m['S'] == 0) || (m['N'] == 0 && m['S'] != 0) || (m['E'] == 0 && m['W'] != 0) || (m['E'] != 0 && m['W'] == 0))cout << "No\n";
    else cout << "Yes\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
 
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector <ll> p(n);
	vector <ll> q(n);
	for (int z=0;z<n;z++){
		cin >> p[z];
	}
	for (int z=0;z<n;z++){
		cin >> q[z];
	}
	vector <ll> def(n);
	for (int z=1;z<=n;z++){
		def[z-1] = z;
	}
	bool ok = true;
	ll a=1,b=1;
	while (ok){
				ok = false;
		for (int z=0;z<n;z++){
			if (def[z] != p[z]) {
				ok = true;
				break;
			}
		}
				a++;
		
		next_permutation(def.begin(),def.end());
	}
	for (int z=1;z<=n;z++){
		def[z-1] = z;
	}
	ok = true;
	while (ok){
				ok = false;
		for (int z=0;z<n;z++){
			if (def[z] != q[z]) {
				ok = true;
				break;
			}
		}
				b++;
		
		next_permutation(def.begin(),def.end());
	}
	//cout << a << " " << b << endl;
	cout << abs(a-b) << endl;
}

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

int main() {
  int A , B , C , D ;
  cin >> A >> B >> C >> D ;
  if ( A + B > C + D ) {
    cout << " Left " << endl;
  } else if ( A + B == C + D ) {
    cout << " Balanced " << endl;
   } else {
    cout << " Right " << endl;
   }
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct bipartite_matching{
    static const int MAX_V=2010;
    vector<int>G[MAX_V];
    int match[MAX_V];
    bool used[MAX_V];

    void add_edge(int u,int v){
        G[u].push_back(v);
        G[v].push_back(u);
    }

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

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

int N,M,L;
const int INF=1001001001001001001;
int dist[100][100];
void solve(){
    fill_n(*dist,100*100,INF);
    rep(i,N)dist[i][i]=0;

    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        chmin(dist[a][b],c);
        chmin(dist[b][a],c);
    }
    rep(k,N)rep(i,N)rep(j,N)chmin(dist[i][j],dist[i][k]+dist[k][j]);

    vpint qs;
    rep(i,L){
        int a,b;
        cin>>a>>b;
        qs.pb(pint(b,a));
    }

    sort(all(qs));

    bipartite_matching bm;
    for(int i=0;i<L;i++){
        for(int j=i+1;j<L;j++){
            if(dist[qs[i].se][qs[j].se]<=qs[j].fi-qs[i].fi){
                bm.add_edge(i*2+1,j*2);
            }
        }
    }
    cout<<L-bm.matching()<<endl;
}

signed main(){
    while(cin>>N>>M>>L,N||M||L)solve();
    return 0;
}

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

using namespace std;


int main()
{
  int p, q, r;
  cin >> p >> q >> r;
  int ans = 0;
  if (p < q)
    {
      ans = p + min(q, r);
    }
  else
    {
      ans = q + min(p, r);
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
kpsk_list = [list(map(int, input().split())) for _ in range(N)]
#print(kpsk_list)
dp = [[0]*(W+1) for _ in range(N+1)]
#print(dp)
for n in range(1, N+1): #何個目までのアイテムを考慮するか
  for w in range(W+1): #各重さでの価値の最大値を求める.
    #print(f"n:{n},w:{w}")
    if w - kpsk_list[n-1][0] < 0: 
      dp[n][w] = dp[n-1][w]
    else:
      dp[n][w] = max(dp[n-1][w], dp[n-1][w - kpsk_list[n-1][0]] + kpsk_list[n-1][1])
    #print(dp)

print(dp[N][W])
#dp[n]について各重さsum_w(=0~W)の時の最大価値をdpテーブルに保存していく.


Measured memory_bytes: 120172
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int a[200004],b[200004];
vector<int>ans;
int main(){
    ans.clear();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=n;i>=1;i--){
        int sum=0;
        for(int j=i+i;j<=n;j+=i){
            sum+=b[j];
        }
        if((sum&1)!=a[i]){
            b[i]=1;
            ans.push_back(i);
        }
    }
    printf("%d\n",ans.size());
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)printf("%d ",ans[i]);
    puts("");
    return 0;
}


Measured memory_bytes: 2936
n,k=map(int,input().split())
mod=998244353
lr=[]
for i in range(k):
    lr.append(list(map(int,input().split())))
d=[0]*(n+1)
d[0]=1
for i in range(n): 
    for l,r in lr:
        r+=1
        d[min(n,i+l)]+=d[i]
        d[min(n,i+r)]-=d[i]
    if i!=0:
        d[i+1]+=d[i]
    d[i+1]%=mod
#print(d)
print(d[n-1]%mod)


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

using namespace std;

int main()
{
  int R, C;
  string S[128];
  int hash[1 << 16];
  for(int i = 0; i < 1 << 16; i++) hash[i] = __builtin_popcount(i);

  cin >> R >> C;
  for(int i = 0; i < R; i++) cin >> S[i];

  vector< int > latte(1 << C, -1);
  latte[0] = 0;
  const int mask = (1 << C) - 1;
  for(int y = 0; y < R; y++) {
    for(int x = 0; x < C; x++) {
      vector< int > malta(1 << C, -1);
      for(int j = 0; j < 1 << C; j++) {
        if(latte[j] == -1) continue;

        auto ch = [&](int &a, int b)
        {
          a = max(a, b);
        };

        const int beet = hash[j & ((1 << x) - 1)];
        if(beet + C - x > S[y].size()) ch(malta[j & ~(1 << x)], latte[j]);
        if(beet < S[y].size()) {
          int point = 0;
          if(x && (j >> (x - 1)) & 1) {
            if(beet && S[y][beet] == S[y][beet - 1]) ++point;
          }
          if(y && (j >> x) & 1) {
            int pos = (int) S[y - 1].size() - hash[j >> x];
            if(pos >= 0 && S[y - 1][pos] == S[y][beet]) ++point;
          }
          ch(malta[j | (1 << x)], latte[j] + point);
        }
      }
      latte.swap(malta);
    }
  }
  cout << *max_element(begin(latte), end(latte)) * 2 << endl;
}

Measured memory_bytes: 3708
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    [a,b,c,d,e,f] <- getLine
    putStrLn $ if c==d && e==f then "Yes" else "No"


Measured memory_bytes: 380
object Main extends App {
  import scala.annotation.tailrec

  def high(x: Int): Int = x * x
  def rectangle(y: Int, d: Int): Int = y * d
  def area(d: Int): Int =
    d.until(600, d).foldLeft(0)((acc, n) => acc + rectangle(high(n), d))

  @tailrec
  def loop() {
    val line = scala.io.StdIn.readLine()
    if (line == null) return
    else {
      val d = line.toInt
      println(area(d))
      loop()
    }
  }

  loop()
}

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

int main(){
int N,i=0;
cin>>N;
int *a = new int[N]();
while(i<N){
     cin>>a[i++];
}

int odd_num = 0;
for(int i=0; i< N; i++){
    if(a[i]%2!=0)
        odd_num++;
}

if(odd_num%2==0)
    cout<<"YES";
else
    cout<<"NO";

delete[] a;
return 0;

}

Measured memory_bytes: 640
import math
n=int(input())
for a in range(math.ceil(n/4),3501):
    q=4/n-1/a
    if q==0:continue
    for b in range(math.ceil(q),3501):
        if not 4*a*b==b*n+a*n:
            t=a*b*n/(4*a*b-b*n-a*n)
            if t>0 and t%1==0:
                print(a,b,int(t))
                exit()
    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];

    int ret = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                vector<int> v{l[i], l[j], l[k]};
                sort(v.begin(), v.end());
                if (v[0] != v[1] && v[1] != v[2] && v[0] + v[1] > v[2]) {
                    ret++;
                }
            }
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>

using namespace std;

struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

//双方向リストの要素の探索
Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

//双方向リストの初期化
void init(){
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key, n;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for(int i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){
            insert(key);
            np++;
            size++;
        } else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
        }
        size--;
    }
    
    printList();
    
    return 0;
}


Measured memory_bytes: 34456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

static const int INF = 1 << 28;

#define D(x) cout << x << endl;
#define d(x) cout << x;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;

int main() {
  int n;
  cin >> n;
  ll p = 1;
  for (int i = 1; i <= n; i++) {
    p *= i;
    p %= 1000000007;
  }

  D(p);
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll n,k;
char matrix[2000][2000];

string func(ll i,ll j)
{
	string ans;
	ll x=i,y=j;
	while(x<n || y<n)
	{
		    	if(x==n-1)
    			{
    				ans.pb(matrix[x][y+1]);
    				y++;
    				continue;
    			}
    			if(y==n-1)
    			{
    				ans.pb(matrix[x+1][y]);
    				x++;
    				continue;
    			}
    	if(matrix[x+1][y]<matrix[x][y+1])
    	{
    		ans.pb(matrix[x+1][y]);
    		x++;
    	}
    	else if(matrix[x+1][y]>matrix[x][y+1])
    	{
    		ans.pb(matrix[x][y+1]);
    		y++;
    	}
    	else
    	{
    		ans.pb(matrix[x+1][y]);
    		string t=min(func(x+1,y),func(x,y+1));
    		ans+=t;
    		return ans;
    	}
	}
	return ans;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
    // freopen("alchemy_input.txt", "r", stdin);
 //    // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1,t=1;
   // cin>>tests;
    while(tests--)
    {
    	ll i,j,n,k;
    	cin>>n>>k;
    	vector<ll>h(n);
    	rep(i,0,n-1) cin>>h[i];
    	ll dp[n];
    	dp[0]=0;
    	dp[1]=abs(h[1]-h[0]);
    	for(i=2;i<n;i++)
    	{
    		dp[i]=(dp[i-1]+abs(h[i]-h[i-1]));
    		for(j=2;j<=k;j++)
    		{
    			if(i-j<0) break;
    			dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
    		}
    	}
    	cout<<dp[n-1];
    }

	return 0;
}

Measured memory_bytes: 4968
#include <bits/stdc++.h>
#define _for(i,n) for(int i = 0; i < n; i++)

using namespace std;
void dfs(int,vector<vector<int> >,int*);

int num_visited = 0;
int ans = 0;
int n,m;
int main() {
  cin >> n >> m;
  int a[m], b[m];
  _for(i,m) cin >> a[i] >> b[i];
  _for(i,m) {
    a[i]--;
    b[i]--;
  }
  int visited[n];
  _for(i,n) visited[i] = 0;
  vector<vector<int> > connected(n,vector<int>());
  _for(i,m) {
    connected[a[i]].push_back(b[i]);
    connected[b[i]].push_back(a[i]);
  }
  dfs(0,connected,visited);
  cout << ans << endl;  
  return 0;
}

void dfs(int current,vector<vector<int> > connected,int* visited) {
  visited[current] = 1;
  num_visited++;
  if (num_visited==n) ans++;
  else {
    _for(i,connected[current].size()) if (visited[connected[current][i]]!=1) {
      dfs(connected[current][i],connected,visited);
    }
  }
  visited[current] = 0;
  num_visited--;
}

Measured memory_bytes: 256
#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);

	int n;cin>>n;
	ll ans=0;
	unordered_map<int,int> umap;
	for(int i=0;i<n;i++){
		int t;cin>>t;
		ans+=t;
		if(umap.find(t)==umap.end()){
			umap[t]=1;
		}
		else{
			umap[t]++;
		}
	}

	int q;cin>>q;
	for(int i=0;i<q;i++){
		int b,c;cin>>b>>c;
		if(umap.find(b)==umap.end()){
			cout<<ans<<endl;
			continue;
		}
		int tmp=umap[b];
		ans=ans+tmp*(c-b);
		cout<<ans<<endl;

		umap.erase(b);

		if(umap.find(c)==umap.end())
			umap[c]=tmp;
		else
			umap[c]+=tmp;
	}

	return 0;
}

Measured memory_bytes: 6664
isExists = True
n,m = list(map(int,input().split()))
n1,n2,n3 = -1,-1,-1
for i in range(m):
  si,ci = list(map(int,input().split()))
  if si == 1:
    if n1 == -1 or n1 == ci:
      n1 = ci
    else:
      #print('p1')
      isExists = False
  elif si == 2:
    if n2 == -1 or n2 == ci:
      n2 = ci
    else:
      #print('p2')
      isExists = False
  elif si == 3:
    if n3 == -1 or n3 == ci:
      n3 = ci
    else:
      #print('p3')
      isExists = False
if (n == 2 or n == 3) and n1 == 0:
  #print('p4')
  isExists = False
if n1 == -1 and n == 1:
  n1 = 0
if n1 == -1 and n > 1:
  n1 = 1
if n2 == -1:
  n2 = 0
if n3 == -1:
  n3 = 0
if isExists == True:
  if n == 1:
    print(n1)
  elif n == 2:
    print(str(n1)+str(n2))
  elif n == 3:
    print(str(n1)+str(n2)+str(n3))
else:
  print(-1)

Measured memory_bytes: 3064
num = list(map(int, input().split()))
q = int(input())

class Dice():
    def __init__(self, t, s, e, w, n, b):
        self.a = [t, s, e, w, n, b]
    
    def shake(self, me):
        if me == 'S':
            self.b = [self.a[int(i)] for i in '402351']
            self.a = self.b
        elif me == 'N':
            self.b = [self.a[int(i)] for i in '152304']
            self.a = self.b
        if me == 'W':
            self.b = [self.a[int(i)] for i in '215043']
            self.a = self.b
        if me == 'E':
            self.b = [self.a[int(i)] for i in '310542']
            self.a = self.b  
    def get(self, dir):
        if dir == 't': return self.a[0]
        elif dir == 'f': return self.a[1]
        elif dir == 'e': return self.a[2]
        elif dir == 'w': return self.a[3]
        else: print('input err', dir)

d = Dice(*num)
for i in range(q):
    u, f = map(int, input().split())
    for j in range(50):
        if d.get('t') == u and d.get('f') == f:
            print(d.get('e'))
            break
        elif d.get('w') == f or d.get('e') == f or d.get('f') == f:
            d.shake('W')
        else:
            d.shake('S')


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[110000];
main(){
    ll a,b,k,ans=0;
    cin>>a>>b;
    if(a<b){
        rep(i,0,b)cout<<a;
    }
    else rep(i,0,a)cout<<b;
    //rep(i,0,n)cin>>a[i];
    
    
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    long double N, M, D;
    cin >> N >> M >> D;

    cout.precision(18);
    cout << ((D) ? 2 : 1) * (M - 1) * (N - D) / (N * N) << endl;
}

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

#define sz(o) ((int)o.size())
#define all(o) o.begin(), o.end()
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define repr(i, a, b) for(int i = (a); i >= (b); i--)
//#define vpal 100

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<int> vi;

void solve(int testcase) {
    int n;
    cin >> n;
    vll a(n);
    rep(i, 0, n-1) cin >> a[i];
    sort(all(a));
    ll val = (a[n-1]+1)/2;
    ll mini = 1e9+1, ans = 0;
    rep(i, 0, n-2){
        if(abs(val-a[i]) < mini){
            mini = abs(val-a[i]);
            ans = a[i];
        }
    }
    cout << a[n-1] << ' ' << ans;
}

int main() {
    #ifdef vpal
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(10);
    clock_t b = clock();
    int t = 1;
    //cin >> t;
    rep(tt, 1, t) solve(tt);
    clock_t e = clock();
    cerr << (double(e - b) / CLOCKS_PER_SEC) << " sec";
    return 0;
}

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

min_v = 10**10+1
max_p = -10**10+1
for i in range(n):
    val = int(input())
    p = val - min_v
    if p>max_p:
        max_p = p
    
    if val<min_v:
        min_v = val

print(max_p)
    


Measured memory_bytes: 5612
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 3003
#include <bits/stdc++.h>
using namespace std;



int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << 0; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    char c; cin >> c; ++c; cout << c;
}

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

Measured memory_bytes: 3544
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  for(int i=0;i<n;i++){
    if(i%2==0 && s[i]=='1')ans++;
    if(i%2==1 && s[i]=='0')ans++;
  }
  int anss=0;
  for(int i=0;i<n;i++){
    if(i%2==1 && s[i]=='1')anss++;
    if(i%2==0 && s[i]=='0')anss++;
  }
  cout<<min(ans,anss)<<endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		while ((line = br.readLine()) != null) {
			int a, b, gcm;
			a = Integer.parseInt(line.substring(0, line.indexOf(" ")));
			b = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
			gcm = getGCD(a, b);
			System.out.println(gcm + " " + getLCM(a, b, gcm));
		}
	}

	public static int getGCD(long a, long b) {

		int mod;
		int gt = (int) Math.max(a, b);
		int lt = (int) Math.min(a, b);

		do {
			mod = gt % lt;
			gt = lt;
			lt = mod;
		} while (mod != 0);

		return gt;
	}

	public static long getLCM(int a, int b, int gcm) {
		return (long) a * (long) b / gcm;
	}
}

Measured memory_bytes: 17020
n, m = map(int, input().split())
cake = [[int(i) for i in input().split()] for _ in range(n)]
ans = 0
for sign_x in [1, -1]:
    for sign_y in [1, -1]:
        for sign_z in [1, -1]:
            point = []
            for x, y, z in cake:
                v = (x * sign_x) + (y * sign_y) + (z * sign_z)
                point.append(v)
            point.sort(reverse=True)
            ans = max(sum(point[:m]), ans)
print(ans) 

Measured memory_bytes: 9312
import java.util.*;

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

      double a = (double)w*h;
      boolean flg = false;
      if((w == x*2) && (h == y * 2)) {
        flg = true;
      }
      if(flg) {
        System.out.println((a/ 2.0) + " 1");
      } else {
        System.out.println((a/ 2.0) + " 0");
      }      
    
    }
}

Measured memory_bytes: 23764