akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    while (q--) {
        int k;
        cin >> k;
        cout << binary_search(all(a), k) << endl;
    }
}



Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5 ;
const int INF = 1e9 + 1e5 + 2;
const int mod= 1e9+7;
#define eps 1e-15
#define F first
#define S second
typedef long long ll;
int gcd (int a,int b)
{
    if (b==0)
        return a;
    return gcd (b,a%b);
}
int main()
{
    int n;
    cin>>n;

    int ans=0;
    for (int i=1; i<=n; ++i)
    {
        for (int j=1; j<=n; ++j)
        {
            int x=gcd(i,j);
            for (int k=1; k<=n; ++k)
                ans+=gcd(x,k);     
        }
    }
    cout<<ans;




    
}

Measured memory_bytes: 3636
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  long[] NH = readln.chomp.split.to!(long[]);
  long N = NH[0],
       H = NH[1];
  long[] a, b, ks;
  long ma;
  long idx;
  bool[long] isb;
  long ans;

  foreach (_; 0..N) {
    long[] ab = readln.chomp.split.to!(long[]);
    a ~= ab[0];
    b ~= ab[1];
  }

  a = a.sort!"a>b".array;
  ma = a[0];

  foreach (e; b) {
    if (e >= ma) {
      ks ~= e;
    }
  }
  ks = ks.sort!"a>b".array;

  while (H > 0) {
    if (idx < ks.length) {
      H -= ks[idx++];
      ans++;
    } else {
      long n = H / ma;
      H -= n * ma;
      if (H > 0) {
        H -= ma;
        n++;
      }
      ans += n;
    }
  }

  writeln(ans);
}


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

namespace ABC096_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] hw = Console.ReadLine().Split(' ');
            int H = int.Parse(hw[0]);
            int W = int.Parse(hw[1]);
            string[] s = new string[H];

            for (int i = 0; i < H; i++)
            {
                s[i] = Console.ReadLine();
            }

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    // Black
                    if (s[i][j].Equals('#'))
                    {
                        bool is_ok = false;
                        // Upper
                        if (IsBlack(s, i - 1, j))
                        {
                            is_ok = true;
                        }

                        // Lower
                        if (IsBlack(s, i + 1, j))
                        {
                            is_ok = true;
                        }

                        // Right
                        if (IsBlack(s, i, j + 1))
                        {
                            is_ok = true;
                        }

                        // Left
                        if (IsBlack(s, i, j - 1))
                        {
                            is_ok = true;
                        }

                        if (!is_ok)
                        {
                            Console.WriteLine("No");
                            return;
                        }
                    }
                }
            }
            Console.WriteLine("Yes");
        }

        static bool IsBlack(string[] a, int h, int w)
        {
            if (h < 0 || a.GetLength(0) <= h)
            {
                return false;
            }
            if (w < 0 || a[h].Length <= w)
            {
                return false;
            }
            if (a[h][w].Equals('#'))
            {
                return true;
            }
            return false;
        }
    }
}


Measured memory_bytes: 27336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
int h,w;
string a[8];

int dfs(int x, int y){
  int dep=-1000;
  int dep2=-1000;
  bool update=false;
  //  cout << a[0][1] << a[1][0] << endl;
  //  cout << x+1 << " " << w-1 << endl;
  if(x+1<=w-1){
    //    cout << " " << endl;
    if(a[y][x+1]=='#'){
      dep=dfs(x+1,y)+1;
      update=true;
      //      cout << a[0][1] << endl;
    }                                                                    
  }                                                                     
  if(y+1<=h-1){                                                          
    if(a[y+1][x]=='#'){                                                  
      dep2=dfs(x,y+1)+1;
      update=true;
    }                                                                    
  }
  if(x==w-1 && y==h-1){
    dep=0;
    update=true;
  }
  //  cout << x << " " << y << " " << max(dep,dep2) << endl;
  if(update) return max(dep,dep2);
  else return -100000;
}




int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  rep(i,h){
    cin >> a[i];
  }
  int c=0;
  rep(i,h) rep(j,w) {
    if(a[i][j]=='#') c++;
  }
  int reach=dfs(0,0)+1;
  if(reach==c){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  //  cout << reach << endl;
  /*rep(i,h) rep(j,w){
    cout << a[i][j];
    } */   
  /*  queue<pair<int, int> > q;
  q.push(mp(0,0));
  bool reach=false;
  while(!q.empty()){
    pair<int, int> t;
    t=q.front();q.pop();
    int x=t.first;
    int y=t.second;
    if(x==w-1 && y==h-1){
      reach=true;
      break;
    }
    if(x+1<=w-1){
      if(a[y][x+1]=='#'){
	q.push(mp(x+1,y));
      }
    }
    if(y+1<=h-1){
      if(a[y+1][x]=='#'){
	q.push(mp(x,y+1));
      }
    }
    }*/
  //  if(reach) cout << "Possible" << endl;
  //  else cout << "Impossible" << endl;
    
  
  return 0;
    

}


Measured memory_bytes: 256
N, T = map(int, input().split())
A = list(map(int, input().split()))

min_A = 10**10
max_A = 0
profit = []
for i in range(N):
    if A[i] <= min_A:
        profit.append(max_A - min_A)
        min_A = A[i]
        max_A = A[i]
    elif A[i] >= max_A:
        profit.append(max_A - min_A)
        max_A = A[i]
profit.append(max_A - min_A)        
        
max_profit = max(profit)
count = 0
for i in range(len(profit)):
    if profit[i] == max_profit:
        count += 1
        
print(count)

Measured memory_bytes: 15020
#include <stdio.h>
#define N 100
#define INF 100000

void MatrixChain(void);
int M[N][N],A[N];
int m;

int main(){
  int n,i,c;
  scanf("%d",&m);

  for(i=0;i<m;i++){
    scanf("%d %d",&A[i+1],&c);
      }
  A[i+1] = c;
  MatrixChain();

  return 0;
}

void MatrixChain(){
  int n,i,j,k,q,s;
  n = m;
  for(i=1;i<=n;i++){
    M[i][i]=0;
  }

  for(k=2;k<=n;k++){
    for(i=1;i<=n-k+1;i++){
      j = i+k-1;
      M[i][j] = INF;
      for(s=i;s<=j-1;s++){
	q = M[i][s]+M[s+1][j]+A[i]*A[s+1]*A[j+1];  
	if(q<M[i][j]){
	  M[i][j] = q;
	}
      }
    }
  }
  printf("%d\n",M[1][m]);
}

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

int main()
{
	int N, K;

	scanf("%d", &N);
	scanf("%d", &K);

	long X = pow(K - 1,N-1);

	long Y = X * K;

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



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

int main() 
{
  int k, n;
  scanf("%d%d", &k, &n);
  int houses[n];
  for (int i = 0; i < n; i++)
    scanf("%d", &houses[i]);
  sort(houses, houses + n);
  long long ans = 0;
  for (int i = 1; i < n; i++)
    ans = max(ans, (long long) houses[i] - houses[i - 1]);
  long long dist = (k - houses[n - 1]) + houses[0];
  printf("%lld\n", dist > ans ? k - dist : k - ans);
  return (0);
}

Measured memory_bytes: 1024
import java.util.*;
public class Main
{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		char c[][] = new char[H+2][W+2];
		
		int i;
		int j;
		String s;
		
		for(i=0; i<H+2; i++){
			for(j=0; j<W+2; j++){
				c[i][j]='#';
			}
		}
		for(i=1; i<H+1; i++){
			s=sc.next();
			for(j=1; j<W+1; j++){
				c[i][j]=s.charAt(j-1);
			}
		}
		
		
		for(i=0;i<H+2;i++){
			System.out.println(c[i]);
		}
	}
}

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

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


    if (a > b){
        for (int i=0; i<a; i++){
            cout << b;
        }
    } else {
        for (int i=0; i<b; i++){
            cout << a;
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

Measured memory_bytes: 110144
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

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

    queue<i64> que;
    for(int i = 1; i < 10; i++) que.emplace(i);
    int k = 0;
    
    i64 ans = 1;
    while(k != K){
        i64 x = que.front(); que.pop();
        ans = x;
        k++;

        i64 m = x % 10;
        if(m != 0) que.push(x*10 + (m-1));
        que.push(x*10 + m);
        if(m != 9) que.push(x*10 + (m+1));
    }

    Cout(ans);
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

const int NMAX = 120, WMAX = 10020;
int dp[NMAX][WMAX];
int w[NMAX], v[NMAX];

int main() {
  int N, W;
  cin >> N >> W;
  REP(i, N) {
    cin >> v[i+1] >> w[i+1];
  }

  for (int m = 0; m <= W; m++) {
    for (int i = 1; i <= N; i++) {
      if (m - w[i] >= 0)
        dp[i][m] = max(dp[i-1][m], dp[i-1][m-w[i]] + v[i]);
      else
        dp[i][m] = dp[i-1][m];
    }
  }

  cout << dp[N][W] << endl;
}

Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
struct edge
{
  int u, v, cost;
  bool operator<(const edge& e) const
  {
    return(cost < e.cost);
  }
};
struct UnionFind
{
  vector< int > data;
  UnionFind(int size)
  {
    data.assign(size, -1);
  }
  int Find(int k)
  {
    if(data[k] < 0) return(k);
    else return(data[k] = Find(data[k]));
  }
  bool Unite(int x, int y)
  {
    x = Find(x), y = Find(y);
    if(x == y) return(false);
    if(data[y] < data[x]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }
  int Size(int k)
  {
    return(-data[Find(k)]);
  }
};


int main()
{
  int n;
  vector< edge > Edges;

  cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    Edges.push_back((edge){a, b, c});
  }
  sort(Edges.begin(), Edges.end());
  UnionFind uf(n);
  int64 ret = 0;
  for(edge e : Edges) {
    ret += 1LL * uf.Size(e.u) * uf.Size(e.v) * e.cost;
    uf.Unite(e.u, e.v);
  }
  cout << ret << endl;
}

Measured memory_bytes: 6028
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			long N = Long.parseLong(sc.next());
			long answer=1;
			for(long i=1;i<=N;i++){
				answer=(answer*i)%(1000000000+7);
			}
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 20820
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int grid[2000000] = {};
map<int, int> geko;
vector<pair<int, int>> wow;
vector<int>x;
int main() {
	int n;
	cin >> n;
	while (true) {
		for (int i = 0;i < 500000;++i) grid[i] = 0;
		REP(i, n) {
			int geko;
			cin >> geko;
			x.push_back(geko);
			wow.push_back(make_pair(geko, i + 1));
			if (grid[geko] != 0) {
				cout << "No" << endl;
				return 0;
			}
			grid[geko] = i + 1;
		}
		sort(wow.begin(), wow.end());
		//右側に設置
		int now_itr = n - 1;
		int now_filled = wow[now_itr].second;
		if (now_filled == n) {
			if (now_itr != 0) {
				now_itr--;
				now_filled = wow[now_itr].second;
			}
		}
		for (int i = n*n;i >= 1;--i) {
			if (grid[i] == false) {
				grid[i] = wow[now_itr].second;
				now_filled++;
			fo2:;
				if (now_filled == n) {
					if (now_itr == 0) {
						break;
					}
					now_itr--;
					now_filled = wow[now_itr].second;
					goto fo2;
				}
			}
		}
		now_itr = 0;
		now_filled = wow[now_itr].second - 1;
		if (now_filled == 0) {
			if (now_itr != n - 1) {
				now_itr++;
				now_filled = wow[now_itr].second - 1;
			}
		}
		for (int i = 1;i <= n*n;++i) {
			if (grid[i] == false) {
				grid[i] = wow[now_itr].second;
				now_filled--;
			fo1:;
				if (now_filled == 0) {
					now_itr++;
					if (now_itr == n) {
						break;
					}
					now_filled = wow[now_itr].second - 1;
					goto fo1;
				}
			}
		}
		for (int i = 1;i <= n*n;++i) {
			if (grid[i] == 0) {
				cout << "No" << endl;
				return 0;
			}
			geko[grid[i]]++;
			if (geko[grid[i]] == grid[i]) {
				if (i != x[grid[i] - 1]) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
		cout << "Yes" << endl;
		for (int i = 1;i <= n*n;++i) {
			cout << grid[i] << " ";
		}
		cout << endl;
		return 0;
	ok:;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int n = 26;
const ll INF = 1000000005;

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

    // 満足度が下がる値
    vector<int> bad(n);
    rep(i, n) cin >> bad[i];

    // そのコンテストをその日に開いた時の満足度
    vector<vector<int>> score(days+1, vector<int>(n));
    for(int d = 1; d <= days; d++){
        rep(i, n) cin >> score[d][i];
    }

    // 最後にそのコンテストが開かれたのが何日前か
    vector<vector<int>> preD(days+1, vector<int>(n, 0));

    // 日付毎で満足度が最大になるコンテストを開く
    vector<int> sats(days+1, 0), cons(days+1, 0);
    for(int d = 1; d <= days; d++){
        int maxSat = -INF, maxCon = 0;

        // d日のi番目のコンテストを開いたときの満足度を計算し、最大になるコンテストと満足度を記録する
        rep(i,n){
            int conSat = score[d][i] + sats[d-1];
            vector<int> copyPreD = preD[d-1];
            rep(j,n){
                if (i == j) continue;
                conSat -= bad[j] * copyPreD[j];
                copyPreD[j]++;
            }
            if (chmax(maxSat, conSat)){
                maxCon = i;
            }
        }

        // 最も良いスコアとコンテストを更新
        sats[d] = maxSat;
        cons[d] = maxCon+1;

        // 開いたコンテストの最終日を更新
        rep(i,n){
            if (i == maxCon) preD[d][i] = 0;
            else preD[d][i] = preD[d-1][i] + 1;
        }
    }
    
    for(int d = 1; d <= days; d++){
        cout << cons[d] << endl;
    }
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <utility>
#include <map>
using namespace std;

void BubbleSort(vector<string> V, int N)
{
    for (int i = N - 1; i > 0; i--)
    {
        bool flag = true;
        for (int j = 0; j < i; j++)
        {
            flag = false;
            if (V[j][1] - '0' > V[j + 1][1] - '0')
            {
                swap(V[j], V[j + 1]);
                flag = true;
            }
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << V[i];
        if (i < N - 1)
        {
            cout << " ";
        }
    }
    cout << endl;
    cout << "Stable" << endl;
}

void SelectionSort(vector<string> V, int N)
{
    map<string, int> mp;
    for (int i = 0; i < N; i++)
    {
        mp[V[i]] = i;
    }

    for (int i = 0; i < N; i++)
    {
        int min_idx = i;
        for (int j = i + 1; j < N; j++)
        {
            if (V[min_idx][1] - '0' > V[j][1] - '0')
            {
                min_idx = j;
            }
        }
        swap(V[min_idx], V[i]);
    }

    for (int i = 0; i < N; i++)
    {
        cout << V[i];
        if (i < N - 1)
        {
            cout << " ";
        }
    }
    cout << endl;

    for (int i = 0; i < N; i++)
    {
        int x = V[i][1] - '0';
        for (int j = i + 1; j < N; j++)
        {
            int y = V[j][1] - '0';
            if (x == y && mp[V[i]] > mp[V[j]])
            {
                cout << "Not stable" << endl;
                return;
            }
        }
    }
    cout << "Stable" << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<string> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    BubbleSort(A, N);
    SelectionSort(A, N);

    return 0;
}


Measured memory_bytes: 3228
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()

    def judge():
        for i in range(len(S)):
            if i % 2 == 0:
                if S[i] == "L":
                    return False
            else:
                if S[i] == "R":
                    return False
        return True

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


if __name__ == '__main__':
    main()


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

typedef long long int ll;

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif

int main()
{
	GO
	//fioe();
	string s;
	cin>>s;
	deque<char> d;
	for(ll i=0;i<s.size();i++){
		d.push_back(s[i]);
	}
	ll q;
	cin>>q;
	ll flag=0;
	while(q--){
		ll x;
		cin>>x;
		if(x==1){
			flag^=1;
		}
		else{
			ll f;char ch;
			cin>>f>>ch;
			if(flag==0){
				if(f==1){
					d.push_front(ch);
				}
				else{
					d.push_back(ch);
				}
			}
			else{
				if(f==2){
					d.push_front(ch);
				}
				else{
					d.push_back(ch);
				}
			}
		}
	}
	string ans;
	while(d.empty()==0){
		char ch=d.back();
		ans.push_back(ch);
		d.pop_back();
	}
	if(flag==0){
		reverse(ans.begin(),ans.end());
		cout<<ans<<endl;
	}
	else{
		cout<<ans<<endl;
	}	
	return 0;
}

Measured memory_bytes: 1368
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

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

	deque<ll> que;

	for(ll i = 1; i < 10; i++){
		que.push_back(i);
	}

	for(int i = 1; i < K; i++){
		auto now_number = que.front();que.pop_front();
		//cout<<now_number<<endl;
		if( now_number % 10 != 0){
			que.push_back( now_number * 10 + now_number % 10 - 1);
		}
		que.push_back( now_number * 10 + now_number % 10);

		if( now_number % 10 != 9){
			que.push_back( now_number * 10 + now_number % 10 + 1);
		}
	}

	ll answer = que.front();
	cout<<answer<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

int main(void) {
    int n;
    while (cin>>n && n) {
        vector<vector<int> > g(31);
        for (int i = 0; i < n; i++) {
            int m;
            cin >> m;
            for (int j = 0; j < m; j++) {
                int t; cin >> t;
                g[t].push_back(i);
            }
        }
        vector<set<int> > se(n);
        for (int i = 0; i < n; i++) se[i].insert(i);
        
        int ans = -1;
        for (int i = 1; i < 31; i++) {
            set<int> t;
            for (int j = 0; j < g[i].size(); j++) t.insert(se[g[i][j]].begin(), se[g[i][j]].end());
            for (int j = 0; j < g[i].size(); j++) se[g[i][j]] = t;
            if (ans == -1 && t.size() == n) ans = i;
        }
        cout << ans << endl;
    }
}

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

intmax_t divider = 1000000007;

intmax_t pow(int x, int y)
{
  intmax_t r = 1;
  for (int i = 0; i < y; i++)
  {
    r *= x;
    r %= divider;
  }
  return r;
}

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

  intmax_t r = pow(10, n) - pow(9, n) * 2 + pow(8, n);
  r %= divider;
  r = r < 0 ? r + divider : r;

  cout << r << endl;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define PI 3.14159265358979
#define int long long

double inner_product1(double x1, double y1, double x2, double y2) {
    return (x1 * x2 + y1 * y2);
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int x[110], y[110];
    rep(i, N) cin >> x[i] >> y[i];
    double ans = 0.0;
    rep(i, 200000) {
        int X = 0, Y = 0;
        rep(j, N) {
            double theta = PI/(i/100000.0);
            double xx = cos(theta);
            double yy = sin(theta);
            if (inner_product1(xx, yy, x[j], y[j]) >= 0) {
                X += x[j];
                Y += y[j];
            }
        }
        ans = max(ans, sqrt(X * X + Y * Y));
    }
    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = B[0]
for i in range(1,N):
    if A[i] - A[i-1] == 1:
        ans += C[A[i]-2]
    ans += B[i]

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int,int> par;

const int N=200010,P=1e9+7,inv2=P+1>>1;

int n,cnt,G[N],dpt[N];
struct edge{
  int t,nx;
}E[N];
struct tp{
  int x,y,z;
  tp(){}
  tp(int a,int b,int c):x(a),y(b),z(c){}
};

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
}

inline int Pow(int x,int y){
  int ret=1;
  for(;y;y>>=1,x=1LL*x*x%P) if(y&1) ret=1LL*ret*x%P;
  return ret;
}

deque<tp> f[N];

void dfs(int x){
  int mx=0,smx=0;
  for(int i=G[x];i;i=E[i].nx){
    dfs(E[i].t); int v=E[i].t;
    if(f[v].size()>mx) smx=mx,mx=f[v].size();
    else smx=max(smx,(int)f[v].size());
    if(f[v].size()>f[x].size()) swap(f[x],f[v]);
    for(int j=0;j<f[v].size();j++){
      tp cur;
      cur.x=(1LL*f[x][j].x*f[v][j].y+1LL*f[v][j].x*f[x][j].y)%P;
      cur.y=1LL*f[x][j].y*f[v][j].y%P;
      cur.z=(1LL*f[x][j].x*f[v][j].x+1LL*f[x][j].x*f[v][j].z+1LL*f[x][j].y*f[v][j].z+1LL*f[x][j].z*f[v][j].x+1LL*f[x][j].z*f[v][j].y+1LL*f[x][j].z*f[v][j].z)%P;
      f[x][j]=cur;
    }
  }
  for(int i=0;i<smx;i++){
    f[x][i].y=(f[x][i].y+f[x][i].z)%P;
    f[x][i].z=0;
  }
  f[x].push_front(tp(inv2,inv2,0));
}

int main(){
  scanf("%d",&n);
  for(int i=1,x;i<=n;i++)
    scanf("%d",&x),addedge(x,i);
  dfs(0); int ans=0;
  for(int i=0;i<f[0].size();i++)
    ans=(ans+f[0][i].x)%P;
  ans=1LL*ans*Pow(2,n+1)%P;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 234240
def factor(N):
    f = []
    for i in range(1,int(N**0.5)+1):
        if N%i == 0:
            f.append(i)
    return sorted(list(set(f)))

def f(A,B):
    return max(len(str(A)),len(str(B)))

N = int(input())
m = 1e9
for n in factor(N):
    m = min(f(n,N//n),m)

print(m)

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


void solve(std::string S, long long w){
    string ans;
    ll n=S.length();
    for(ll i=0; (i*w) <n; i++){
        ans.push_back(S[i*w]);
    }
    cout << ans << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    long long w;
    scanf("%lld",&w);
    solve(S, w);
    return 0;
}


Measured memory_bytes: 256
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 200005;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int X = 200005;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
ll a[X];
ll b[X];
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    for (int zz = 0; zz < t; zz++)
    {
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    int n,m;
    ll k;
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        cin>>a[i+1];
        a[i+1]+=a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i+1];
        b[i+1]+=b[i];
    }
    int ans=0;
    for(int i=0,j=m;i<=n;i++){
        if(a[i]>k)break;
        while(a[i]+b[j]>k)j--;
        ans=max(ans,i+j);
    }
    cout<<ans;
    return;
}



Measured memory_bytes: 6784
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var nm=Arr.shift().split(" ").map(Number);
   var n=nm[0];
   var m=nm[1];
   if(n==0 && m==0)break;
   var arr=[];
   for(var i=0;i<n;i++)arr.push(Arr.shift()-0);
   arr.push(0);
   var Q=[];
   for(var i=0;i<arr.length;i++){
     for(var j=i;j<arr.length;j++){
        if(arr[i]+arr[j]>m)continue;
        Q.push(arr[i]+arr[j]);
     }
   }
   Q.sort(function(a,b){return a-b;});
   var max=0;
   var k=Q.length-1;
   for(var i=0;i<Q.length;i++){
      while(Q[i]+Q[k]>m)k--;
      max=Math.max(max,Q[i]+Q[k]);
  }
  console.log(max);
}

Measured memory_bytes: 43028
#include<stdio.h>
int c[3001][3001];
int main(void)
{
    int n,m,k,i,a[3000],b[3000],j,s;
	scanf("%d %d %d",&n,&m,&k);
	for(i=0;i<n;i++){
	    scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<=n;i++){
	    for(j=0;j<=m;j++){
		    c[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
	    for(j=0;j<=m;j++){
		    if(c[i+1][j]<c[i][j]){
			    c[i+1][j]=c[i][j];
			}
		    if(j+b[i]<=m&&(j+b[i]<=k||j>=k)&&c[i+1][j+b[i]]<c[i][j]+a[i]){
			    c[i+1][j+b[i]]=c[i][j]+a[i];
			}
		}
	}
	s=-1;
	for(i=0;i<=m;i++){
	    if(s<c[n][i]){
		    s=c[n][i];
		}
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 37936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//素数判定
ll is_prime(ll n) {
  if (n == 1) return 0;
  if (n == 2) return 1;
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}

//約数列挙
//昇順
vll div(ll n) {
  vll vec(1, 1);
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) vec.push_back(i);
  }
  if (sqrt(n) == (ll)sqrt(n)) {
    for (ll i = vec.size() - 2; i >= 0; i--) {
      vec.push_back(n / vec[i]);
    }
  }
  else {
    for (ll i = vec.size() - 1; i >= 0; i--) {
      vec.push_back(n / vec[i]);
    }
  }
  return vec;
}


vll comdiv(ll a, ll b) {
  if (a > b) swap(a, b);
  vll vec1 = div(a);
  vll vec2(0);
  for (ll i = 0; i < vec1.size(); i++) {
    if (b % vec1[i] == 0) vec2.push_back(vec1[i]);
  }
  return vec2;
}

int main() {
  ll a, b;
  cin >> a >> b;
  vll vec = comdiv(a, b);
  ll cnt = 0;
  for (ll i = 0; i < vec.size(); i++) {
    if (is_prime(vec[i]) == 1) cnt++;
  }
  cout << cnt + 1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; long long m; cin >> n >> m;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	vector<long long> A(n + 1, 0);
	sort(a.begin(), a.end());
	for(int i = n - 1; i >= 0; i--) A[i] = A[i + 1] + a[i];
	auto f = [&](int x){
		long long ans = 0, sum = 0;
		for(int i = 0; i < n; i++){
			ans += n;
			int p = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin();
			ans -= p;
			sum += 1ll * (n - p) * a[i] + A[p];
		}
		return make_pair(ans, sum);
	};
	int lo = 0, hi = 1<<30, ans = 1<<30;
	while(lo <= hi){
		int mid = (lo+hi)>>1;
		if(f(mid).first < m) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	auto p = f(ans);
	cout << p.second + (m - p.first) * (ans - 1) << '\n';
	return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int n,k,h,ans;
vector<int> v;

signed main() {
    cin >> n >> k;
    rep(i,n) cin >> h, v.pb(h);
    sort(rall(v));
    repo(i,k,n) ans += v[i];
    cout << ans << endl;
}



Measured memory_bytes: 2420
#include <cstdio>
#include <algorithm>
using namespace std;

void proc() {
	long long n, m;
	scanf("%lld %lld", &n, &m);
	long long v = min(n, m / 2);
	long long ans = v;
	n -= v;
	m -= v * 2;
	if (m > 0) {
		ans += m / 4;
	}
	printf("%lld", ans);
}

int main() {
	//freopen("input.txt", "r", stdin);
	proc();
	return 0;
}

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

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int N = s.length();
    bool ok = true;
    map<char,char> ma,ima;
    rep(i,N){
        char u = s[i],v = t[i];
        if(ma.count(u))if(ma[u] != v)ok = false;
        if(ima.count(v))if(ima[v] != u)ok = false;
        ma[u] = v;ima[v] = u;
        
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

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

int main(void)
{
    int N, A, B;
    std::cin >> N >> A >> B;
    std::string S;
    std::cin >> S;

    int all = 0;
    int foregin = 0;
    rep(i, N)
    {
        bool isOk = false;

        if( S[i] == 'a')
        {
            if( all < A + B )
            {
                isOk = true;
                all++;
            }
        }
        else if( S[i] == 'b' )
        {
            if( all < A+B )
            {
                if( foregin < B )
                {
                    isOk = true;
                    all++;
                    foregin++;
                }
            }
        }

        if( isOk == true )
        {
            std::cout << "Yes" << std::endl;
        }
        else
        {
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	if(a>0) cout << "Positive" << endl;
	else if(a<=0 && b>=0) cout << "Zero" << endl;
	else{
		if((b-a)%2==1) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x, y, s=0, i, tmp, d1, d2, d4, d5;
	cin >> x >> y;
	for (i=x;i<=y;++i)
	{
		tmp = i;
		d5 = tmp / 10000;
		d4 = tmp / 1000 % 10;
		d2 = tmp / 10 % 10;
		d1 = tmp % 10;
		if(d5==d1&&d4==d2)
		{
			++s;
		}
	} 
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
int n, a[3010];
int dp[3010][3010];
bool cd[3010][3010];
int f(int x, int y) {
	if (cd[x][y])return dp[x][y];
	cd[x][y] = true;
	if (x == y)return dp[x][y] = a[x];
	return dp[x][y] = max(a[x] - f(x + 1, y), a[y] - f(x, y - 1));
}
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	cout << f(0, n - 1) << endl;
	return 0;
}


Measured memory_bytes: 78464
package main

import "fmt"

func main(){
  var N,M int
  fmt.Scan(&N, &M)
  if N==1 && M==1{
    fmt.Println(1)
  }else if N == 1{
    fmt.Println(M-2)
  }else if M ==1{
    fmt.Println(N-2)
  }else{
    fmt.Println((M-2)*(N-2))
  }
}


Measured memory_bytes: 512
#include <stdio.h>
#define MAX 25
#define NIL -1 /*use to show there no anything*/

typedef struct{
  int parent,left,right;
}Record;

void Preorder(int, Record*);
void Inorder(int, Record*);
void Postorder(int, Record*);

int main(){
  int i,num,id,root,lef,rig;
  Record data[MAX];
  scanf("%d",&num);
  for(i=0;i<num;i++) {
    data[i].parent=NIL;
    
  }
  
  for(i=0;i<num;i++){
    scanf("%d%d%d",&id,&lef,&rig);
    data[id].left=lef;
    data[id].right=rig;
      
    if(lef!=NIL) data[lef].parent=id;   
    
    if(rig!=NIL)  data[rig].parent=id;   
    
  }
  for(i=0;i<num;i++){
    if(data[i].parent==NIL){
      root=i;
      break;
    }
  }
  printf("Preorder\n");
  Preorder(root,data);
  printf("\n");

  printf("Inorder\n");
  Inorder(root,data);
  printf("\n");

  printf("Postorder\n");
  Postorder(root,data);
  printf("\n");

  return 0;
}

void Preorder(int x,Record* data){
  if(x==NIL) return ;
  printf(" %d",x);
  Preorder(data[x].left,data);
  Preorder(data[x].right,data);
}

void Inorder(int x,Record* data){
  if(x==NIL) return;
  Inorder(data[x].left,data);
  printf(" %d",x);
  Inorder(data[x].right,data);
}

void Postorder(int x,Record* data){
  if(x==NIL) return;
  Postorder(data[x].left,data);
  Postorder(data[x].right,data);
  printf(" %d",x);
}



Measured memory_bytes: 2148
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;
long long n,ans;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int cnt = 1;
    while (cnt < b) {
        ans++;
        cnt += a-1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans, n, t, x, a[3005], b[3005], dp[3005][3005];
vector<long long> preostali;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> t;
for (int i=1; i<=n; i++){
	cin >> a[i] >> b[i];
	for (int j=0; j<=t; j++){
		dp[i][j]=dp[i-1][j]; if (j>=a[i])
		dp[i][j]=max(dp[i-1][j], dp[i-1][j-a[i]]+b[i]);
	}
} x=t-1; 

for (int i=n; i>0; i--){
	if (dp[i][x]==dp[i-1][x]) preostali.push_back(b[i]);
	else x=x-a[i];
	
} sort(preostali.begin(), preostali.end());
if (preostali.empty()) cout << dp[n][t];
else cout << max(dp[n][t-1]+preostali[preostali.size()-1], dp[n][t]);
return 0;
}


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

int main(){
    int E, Y, AD;
    int wareki[5] = {0, 1867, 1911, 1925, 1988};
    cin >> E >> Y;
    AD = Y+wareki[E];

    if(E!=0)
        cout << AD << endl;
    else{
        if(AD > wareki[4])
            cout << "H" << Y-wareki[4] << endl;
        else if(AD > wareki[3])
            cout << "S" << Y-wareki[3] << endl;
        else if(AD > wareki[2])
            cout << "T" << Y-wareki[2] << endl;
        else
            cout << "M" << Y-wareki[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >> N;
	VV<bool> isEmpty(N,V<bool>(N,false));
	VV<int> d(N,V<int>(N,1e9));
	rep(i,N) rep(j,N){
		chmin(d[i][j],i);
		chmin(d[i][j],N-1-i);
		chmin(d[i][j],j);
		chmin(d[i][j],N-1-j);
	}
	int ans = 0;
	V<int> dx = {0,1,0,-1};
	V<int> dy = {1,0,-1,0};
	auto is = [&](int x,int y){
		return 0<=x&&x<N&&0<=y&&y<N;
	};
	show(d);
	rep(t,N*N){
		int Pt; cin >> Pt; Pt--;
		int sx = Pt/N, sy = Pt%N;
		ans += d[sx][sy];
		queue<int> qx,qy;
		qx.push(sx);qy.push(sy);
		isEmpty[sx][sy] = true;
		while(!qx.empty()){
			int x = qx.front(), y = qy.front(); qx.pop();qy.pop();
			rep(di,4){
				int nx = x+dx[di], ny = y+dy[di];
				if(!is(nx,ny)) continue;
				int nd = d[x][y] + (isEmpty[x][y] ? 0 : 1);
				if(d[nx][ny] > nd){
					d[nx][ny] = nd;
					qx.push(nx); qy.push(ny);
				}
			}
		}
		shows("------done",sx,sy);
		show(d);
	}
	cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  set<int> treat;
  for (int i = 0; i < K; i++) {
    int num;
    cin >> num;
    for (int j = 0; j < num; j++) {
      int tmp;
      cin >> tmp;
      treat.insert(tmp);
    }
  }
  cout << N - treat.size() << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int main(void){
    int count=700;
    string str;

    cin >> str;

    for(int i=0;i<str.size();i++){
        if(str[i]=='o'){
            count+=100;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



int main() {
    int N;
    cin >> N;
    vi V(N), C(N);
    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];
    int ans = 0;
    rep(i, N) {
        if (V[i] - C[i] > 0) ans += V[i] - C[i];
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1005][1005],pos[1005],n,ans,vis[1005],num;
queue<int> q;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=0;j<n-1;j++)
            cin>>a[i][j];
    for(int i=1;i<=n;i++) q.push(i);
    while(!q.empty()){
        ans++;int sz=q.size();
        for(int o=1;o<=sz;o++){
            int i=q.front();q.pop();
            int x=a[i][pos[i]];
            if(vis[x]==ans||vis[i]==ans) continue;
            if(a[x][pos[x]]==i){
                num++;pos[x]++;pos[i]++;
                if(pos[i]!=n-1) q.push(i);
                if(pos[x]!=n-1) q.push(x);
                vis[x]=ans;vis[i]=ans;
            }
        }
    }
    if(num==n*(n-1)/2) cout<<ans<<endl;
    else cout<<-1<<endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;

  if (abs(n-m) >= 2){
    cout << 0 << endl;
    return 0;
  }
  int64_t res = 1;
  for (int i = 1; i <= n; i++) {
    res *= i;
    res %= mod;
  }
  for(int i = 1; i <= m; i++){
    res *= i;
    res %= mod;
  }
  if (n == m) res *= 2;
  cout << res % mod << endl;
  return 0;
}

Measured memory_bytes: 3644
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp
# Combinatorial - Knapsack Problem

n, maxW = gets.split.map(&:to_i)
vw = Array.new
n.times do
  v, w = gets.split.map(&:to_i)
  vw << { v: v, w: w }
end

maxW += 1
dp = Array.new(n) { Array.new(maxW, 0) }

n.times do |i|
  (1...maxW).each do |j|
    if i == 0
      dp[i][j] = j / vw[i][:w] * vw[i][:v]
    else
      if j >= vw[i][:w]
        dp[i][j] = [dp[i - 1][j], dp[i][j - 1], dp[i][j - vw[i][:w]] + vw[i][:v]].max
      else
        dp[i][j] = [dp[i - 1][j], dp[i][j - 1]].max
      end
    end
  end
end

puts dp[n - 1][maxW - 1]



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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
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; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a, b; cin >> a >> b;
  
  //main
  ll ans = -1;
  for(double i=1; i<=1000; i++){
    if(floor(i*0.08)==a && floor(i*0.10)==b){
      ans = (ll)i;
      break;
    }
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void)
    {
        char a[201],b[200];
        int m,i,h,c,j;
        while(1)
        {
            scanf("%s",a);
            c=strlen(a);
            if(a[0]=='-')
            {
                break;
            }
            scanf("%d",&m);
            for(i=0;i<m;i++)
            {
                scanf("%d",&h);
                for(j=0;j<h;j++)
                {
                    b[j]=a[j];
                }
                for(j=h;j<c;j++)
                {
                    a[j-h]=a[j];
                }
                for(j=0;j<h;j++)
                {
                    a[c-h+j]=b[j];
                }
            }
        for(i=0;i<c;i++)
        {
            printf("%c",a[i]);
        }
        printf("\n");
    }
 
    return 0;
}


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

typedef long long ll;

int main()
{
    ll x, y;
    cin >> x >> y;
    for (ll i=1;;i++){
        if(y<x){
            cout << i-1 << endl;
            break;
        }
        x *= 2;
    }
        return 0;
}


Measured memory_bytes: 256