akhauriyash/Code-Regression huggingface dataset:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N, W = map(int, input().split())
    weight, value = [0] * N, [0] * N
    for i in range(N):
        weight[i], value[i] = map(int, input().split())

    # この前段階で、荷物の数、ウェイトの上限、weightとvalueを敷き詰めた表は用意しておく。
    def knapsack(N, W, weight, value):

        dp = [[0]*(W + 1) for _ in range(N + 1)]

        for i in range(N):
            for w in range(W + 1):
                if w>=weight[i]:  # 荷物が加わる可能性がある
                    # max関数の第一引数だと、既存の荷物の方がましな場合。
                    # 第二引数だと、新入りを加えた方が良い場合。
                    dp[i + 1][w] = max(dp[i][w],dp[i][w - weight[i]] + value[i])
                else:  # 加わる可能性はない
                    dp[i + 1][w] = dp[i][w]

        return dp[N][W]

    print(knapsack(N,W,weight,value))

resolve()

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


int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector< pair<int, int> > v;
    for(int i = 0; i < a; i++) {
        int tmp;
        cin >> tmp;
        pair<int, int> p = make_pair(tmp, 0);
        v.push_back(p);
    }
    for(int i = 0; i < b; i++) {
        int tmp;
        cin >> tmp;
        pair<int, int> p = make_pair(tmp, 1);
        v.push_back(p);
    }
    for(int i = 0; i < c; i++) {
        int tmp;
        cin >> tmp;
        pair<int, int> p = make_pair(tmp, 2);
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    long long cnt0 = 0, cnt1 = 0, cnt2 = 0;
    long long ret = 0;
    for(int i = 0; i < v.size(); i++) {
        if(cnt0 + cnt1 + cnt2 == x+y) break;
        if(v[i].second == 0 && cnt0 < x) {
            ret += v[i].first;
            cnt0++;
        } else if(v[i].second == 1 && cnt1 < y) {
            ret += v[i].first;
            cnt1++;
        } else if(v[i].second == 2){
            ret += v[i].first;
            cnt2++;
        }
    }
    cout << ret << endl;
    return 0;
}

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


int main(){

  int a, b;

  cin >> a >> b;

  int ans = 0;
  for(int i = a; i <= b; i++){
    int s = i % 10, t = i / 10000 % 10;
    int u = i / 10 % 10, v = i /1000 % 10;

    if(s == t && u == v) ans++;
  }

  cout << ans << endl;



  return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define scan(n)     scanf("%lld", &n);
#define print(n)    printf("%lld\n", n);
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        100005
#define LOG         19
#define mod         1000000007
using namespace std;
// good approach
// yes


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i;
    cin>>n;
    ll a[n],b[n],c[n];
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dpa[n],dpb[n],dpc[n];
    for(i=0;i<n;i++){
        if(i==0){
            dpa[i]=a[i];
            dpb[i]=b[i];
            dpc[i]=c[i];
        }
        else{
            dpa[i]=a[i]+max(dpb[i-1],dpc[i-1]);
            dpb[i]=b[i]+max(dpa[i-1],dpc[i-1]);
            dpc[i]=c[i]+max(dpa[i-1],dpb[i-1]);
        }
    }
    cout<<max({dpa[n-1],dpb[n-1],dpc[n-1]});
}

Measured memory_bytes: 8300
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll x , y , z , k ; 
    cin >> x >> y >> z >> k ; 
    vector<ll> X(x) , Y(y) , Z(z) ; 
    for(ll i=0;i<x;i++){
    	cin >> X[i] ; 
    }
    for(ll i=0;i<y;i++){
    	cin >> Y[i] ; 
    }
    for(ll i=0;i<z;i++){
    	cin >> Z[i] ; 
    }
    sort(X.rbegin(),X.rend());
    sort(Y.rbegin(),Y.rend());
    sort(Z.rbegin(),Z.rend());
    vector<ll> ans ; 
    for(ll i=0;i<x;i++){
    	for(ll j=0;j<y;j++){
    		ans.push_back(X[i]+Y[j]);
    	}
    }
    sort(ans.rbegin(),ans.rend());
    ll n = (int) ans.size() ; 
    vector<ll> res ; 
    for(int i=0;i<min(k,n);i++){
    	for(int j=0;j<z;j++){
    		res.push_back(ans[i]+Z[j]);
    	}
    }
    sort(res.rbegin(),res.rend());
    for(int i=0;i<k;i++){
    	cout << res[i] << endl;
    }
    return 0 ;
}



Measured memory_bytes: 43112
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()

MOD = int(1e9) + 7
n = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

Tsa = [0]*n
Asa = [0]*n

if n == 1:
	if T[0] != A[0]:
		print(0)
	else:
		print(1)
elif T[-1] != A[0]:
	print(0)
else:
	##
	dai = T[0]
	shou = T[0]
	Tsa[0] = (shou, dai)

	for i in range(1, n):
		if T[i] == dai:
			Tsa[i] = (1, dai)
		else:
			dai = T[i]
			Tsa[i] = (dai, dai)

	##
	dai = A[-1]
	shou = A[-1]
	Asa[-1] = (shou, dai)

	for i in reversed(range(-n, -1)):
		if A[i] == dai:
			Asa[i] = (1, dai)
		else:
			dai = A[i]
			Asa[i] = (dai, dai)

	##
	ans = 1
	for i in range(n):
		d = max(Tsa[i][0], Asa[i][0])
		u = min(Tsa[i][1], Asa[i][1])

		if d > u:
			ans = 0
			break
		else:
			ans *= u - d + 1
			ans %= MOD
	print(ans)


Measured memory_bytes: 92260
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var g = Enumerable.Range(0, (int)N).Select(_ => new List<Tuple<long, long>>()).ToArray();
            for (var i = 0; i < N - 1; ++i)
            {
                var uvw = Sarray();
                var u = uvw[0] - 1;
                var v = uvw[1] - 1;
                var w = uvw[2];
                g[u].Add(Tuple.Create(v, w));
                g[v].Add(Tuple.Create(u, w));
            }
            var colors = Enumerable.Repeat(-1, (int)N).ToArray();
            colors[0] = 0;
            var q = new Queue<long>();
            q.Enqueue(0);
            while (q.Any())
            {
                var r = q.Dequeue();
                foreach (var e in g[r])
                {
                    var nr = e.Item1;
                    var w = e.Item2;
                    if (-1 == colors[nr])
                    {
                        if (w % 2 == 0)
                            colors[nr] = colors[r];
                        else
                            colors[nr] = (colors[r] + 1) % 2;
                        q.Enqueue(nr);
                    }
                }
            }
            foreach (var c in colors)
                WriteLine(c);
            Out.Flush();
        }
    }
}

Measured memory_bytes: 37016
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef struct _list_ {
	struct _list_ *prev;
	int value;
	struct _list_ *next;
}list;

int main(void) {
	int max, count;
	vector<list> x(2000000);
	string a;

	x[0].value = -1;
	x[1].value = -1;
	x[0].next = &x[1];
	x[1].prev = &x[0];

	count = 1;

	cin >> max;

	for (int i = 0; i < max; i++) {
		cin >> a;

		if (a == "insert") {
			count++;
			cin >> x[count].value;
			x[count].prev = &x[0];
			x[count].next = x[0].next;
			x[0].next->prev = &x[count];
			x[0].next = &x[count];
		}

		else if (a == "delete") {
			list *nextl = x[0].next;
			int b;
			cin >> b;
			for (;;) {
				if (nextl->value == b) {
					nextl->prev->next = nextl->next;
					nextl->next->prev = nextl->prev;
					break;
				}
				if (nextl->value == -1)
					break;
				nextl = nextl->next;
			}
		}

		else if (a == "deleteFirst") {
			x[0].next->next->prev = &x[0];
			x[0].next = x[0].next->next;
		}

		else if (a == "deleteLast") {
			x[1].prev->prev->next = &x[1];
			x[1].prev = x[1].prev->prev;
		}

	}

	list *nextl = x[0].next;

	if (nextl->value != -1) {
		cout << nextl->value;
		nextl = nextl->next;
	}

	for (;;) {
		if (nextl->value == -1)
			break;
		cout << " " << nextl->value;
		nextl = nextl->next;
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 49756
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

vi slidemax(const vi &a,int k){
	int n=a.size();
	deque<int>deq;
	vi res;
	rep(i,n){
		while(deq.size()&&a[deq.back()]<=a[i])deq.pop_back();
		deq.pb(i);
		res.pb(a[deq.front()]);
		if(i-k+1>=0){
			if(deq.front()==i-k+1)deq.pop_front();
		}
	}
	return res;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m,q;
	cin>>n>>m>>q;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi sm=in;
	rep(i,q-1){
		vi slide=slidemax(sm,m);
		for(int j=n-1;j>=0;j--){
			if(j<i+1)sm[j]=0;
			else sm[j]=(i+2)*in[j]+slide[j-1];
		}
	}
	int t=0;
	rep(i,n)cmax(t,sm[i]);
	cout<<t<<endl;
}


Measured memory_bytes: 3704
#include<stdio.h>
int bingo[3][3];
int answer[3][3] = {0,0};
void searchBingo(int);
int checkResult();
int main(void) {
  int n;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j< 3; j++) {
      scanf("%d", &bingo[i][j]);
    }
  }
  scanf("%d", &n);
  for (int k = 0; k < n; k++) {
    int tmp = 0;
    scanf("%d", &tmp);
    searchBingo(tmp);
  }
  if (checkResult() == 1) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

void searchBingo(int number) {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j< 3; j++) {
      if (bingo[i][j] == number) {
        answer[i][j] = 1;
      }
    }
  }
}

int checkResult() {
  int flag = 0;
  for (int i = 0; i < 3; i++) {
    flag = 0;
    for (int j = 0; j< 3; j++) {
        flag += answer[i][j];
    }
    if (flag == 3) {
      return 1;
    }
  }

  for (int i = 0; i < 3; i++) {
    flag = 0;
    for (int j = 0; j< 3; j++) {
        flag += answer[j][i];
    }
    if (flag == 3) {
      return 1;
    }
  }
  
  flag = 0;
  for (int j = 0; j< 3; j++) {
      flag += answer[j][j];
  }
  if (flag == 3) {
    return 1;
  }
  
  flag = 0;
  for (int j = 0; j< 3; j++) {
      flag += answer[j][3-1-j];
  }
  if (flag == 3) {
    return 1;
  }
  
  return 0;
}

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

const int maxN = 1e5 + 10;
typedef long long ll;

int a[6] = {500, 5, 100, 50, 10, 1};

int main(){
    int x, p, q = 0;
    cin >> x;
    for(int i = 0; i < 6; i++){
        p = x / a[i];
        x = x - p*a[i];
        if(p){
            if(a[i] == 500) q = q + 1000*p;
            if(a[i] == 5) q = q + 5*p;
        }
    }
    cout << q << '\n';
}

Measured memory_bytes: 256
def main():
    num = int(input())
    data = list(input())

    left, righ = 0, 0
    for i in range(num):
        ele = data[i]
        if ele == '(':
            righ += 1
        else:
            if righ > 0:
                righ -= 1
            else:
                left += 1

    ans = ['(' for i in range(left)] + data + [')' for i in range(righ)]
    print(''.join(ans))






if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
s = list(input())

def check(a):
    n = len(a)
    m = len(a) // 2
    for i in range(m):
        if a[i] != a[n - i - 1]:
            return False
    else:
        return True

m_1 = (len(s) - 1) // 2
m_2 = m_1 + 1
ans = 'Yes' if check(s) and check(s[:m_1]) and check(s[m_2:]) else 'No'

print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    vi v(6);
    for (int i = 0; i < 6; i++) {
        cin >> v[i];
    }

    if (v[4] - v[0] > v[5]) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

int main()
{
  //入力
  int n;
  int d[3];
  cin >> n;
  char str[100100];

  for(int i=0; i<3; i++)cin >> d[i];

  string s;
  int a,b;

  vector<pair<int,int>> p;
  map<int,char> mp={{0,'A'},{1,'B'},{2,'C'}};
  for(int j=0; j<n; j++){
    cin >> s;
    if(s=="AB")p.emplace_back(0,1);
    else if(s=="AC")p.emplace_back(0,2);
    else p.emplace_back(1,2);
  }
  p.emplace_back(0,1);

  auto add = [&](int a, int b, int i){
    d[a]++;
    d[b]--;
    str[i] = mp[a];
  };

//a+b+c=0
  if(d[0]+d[1]+d[2]==0){
    cout << "No\n";
    return 0;
  }
//a+b+c=1
  else if(d[0]+d[1]+d[2]==1){
    for(int k=0; k<n; k++){
      a=p[k].first;
      b=p[k].second;
      if(d[a]==0 && d[b]==0){
        cout << "No\n";
        return 0;
      }
      else if(d[a]==0)add(a,b,k);
      else add(b,a,k);
    }
  }
//a+b+c>=2
  else{
    for(int i=0; i<n; i++){
      a=p[i].first;
      b=p[i].second;
      if(d[a]==0 && d[b]==0){
        cout << "No\n";
        return 0;
      }
      else if(d[a]==0)add(a,b,i);
      else if(d[b]==0)add(b,a,i);
      else{
        int an=p[i+1].first;
        int bn=p[i+1].second;
        if(an==a || bn ==a)add(a,b,i);
        else add(b,a,i);
      }
    }
  }
  cout << "Yes\n";
  for(int l=0; l<n; l++){
    cout << str[l] << endl;
  }

  return 0;
}

Measured memory_bytes: 4344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a > b) {
			for (int i = 0; i < a; i++)  System.out.print(b);
		} else {
			for (int i = 0; i < b; i++)  System.out.print(a);
		}
		System.out.println();
	}
}

Measured memory_bytes: 21204
using System;
using System.Linq;

namespace Sample101
{
    class Program
    {
        static int[] insertionSort(int[] A, int N)
        {
            for (int i = 1; i < N; i++)
            {
                var temp = A[i];
                var j = i - 1;
                while (j >= 0 && A[j] > temp)
                {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = temp;

                Console.WriteLine(string.Join(" ", A));
            }
            return A;
        }

        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            Console.WriteLine(string.Join(" ", A));
            var result = insertionSort(A, N);
        }
    }
}


Measured memory_bytes: 18248
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String d = sc.next();
    String m = d.substring(5,7);
    if(4<Integer.parseInt(m)){
      System.out.println("TBD");
    }else{
      System.out.println("Heisei");
    }
  }
  

  
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;cin>>N>>K;
  vector<int> h(N);
  for(int i=0;i<N;i++)cin>>h[i];
  int m=1000000002;
  sort(h.begin(),h.end());
  for(int i=0;i<N-K+1;i++){
    m=min(m,h[i+K-1]-h[i]);
  }
  cout<<m<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	vector<pair<char, long long>> A;
	vector<pair<char, long long>> B;
	vector<pair<char, long long>> C;
	char c;
	while (cin >> c, c != '$') {
		int a;
		cin >> a;
		A.push_back({ c,a });
	}
	while (cin >> c, c != '$') {
		int a;
		cin >> a;
		B.push_back({ c,a });
	}
	while (cin >> c, c != '$') {
		int a;
		cin >> a;
		C.push_back({ c,a });
	}
	int clear = -1;
	REP(i, A.size() - B.size() + 1) {
		REP(j, B.size()) {
			if (A[i + j].first == B[j].first&&A[i + j].second >= B[j].second) {
				if (j != 0 && j != B.size()-1 && A[i + j].second > B[j].second)
					break;
				if (j == B.size() - 1) {
					clear = i;
					i = A.size();
				}
			}
			else
				break;
		}
	}
	vector<pair<char, long long>> ANS = A;
	if (clear != -1) {
		if (B.size() == 1) {
			ANS[clear].second -= B[0].second;
			REP(i, C.size())
			ANS.insert(ANS.begin() + clear+i, C[i]);
		}
		else {
			REP(i, B.size()) {
				ANS[clear+i].second -= B[i].second;
			}
			REP(i,C.size())
			ANS.insert(ANS.begin() + clear + 1+i, C[i]);
		}
		REP(i, ANS.size())
			if (ANS[i].second == 0) {
				ANS.erase(ANS.begin() + i);
				i--;
			}
		REP(i, ANS.size()-1)
			if (ANS[i].first ==ANS[i+1].first) {
				ANS[i].second += ANS[i + 1].second;
				ANS.erase(ANS.begin() + i+1);
				i--;
			}
	}

	REP(i, ANS.size()) {
		cout << ANS[i].first << " " << ANS[i].second << " ";
	}
	cout << "$" << endl;

}

Measured memory_bytes: 3196
using System;
using System.Linq;

namespace AGC009_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A = new long[N];
            var B = new long[N];
            for (long i = 0; i < N; i++)
            {
                var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
                A[i] = l[0];
                B[i] = l[1];
            }

            long c = 0;
            for (long i = N - 1; i >= 0; i--)
            {
                var t = (A[i] + c) % B[i];
                if (t != 0) c += B[i] - t;
            }
            Console.WriteLine(c);
        }
    }
}


Measured memory_bytes: 18784
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
int a[10001],ans=0,bns=0,n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+2*n);   
    for(int i=1;i<=2*n;i+=2)
    {
        bns+=a[i];
    } 
    printf("%d\n",bns);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n, a[100000], count = 0, jud = 0, res = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        if (a[i] == jud) {
            count++;
        } else {
            jud = a[i];
            res += count % 2;
            count = 1;
        }
    }
    cout << res + count % 2 << endl;
}


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

int main(){
	string s;
	cin >> s;
	string ans = "";
	rep(i,s.size()){
		if('B' == s[i]){
          	if(!ans.empty()){
            	ans.pop_back();
            }
		}
		else{
			ans.push_back(s[i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <array>

using namespace std;

int main ()
{
	string str,ans1="",ans2="";
	map<string , int>d;
	while( cin >> str )
	{
		d[str]++;
	}

	int p = 0;
	for( auto x : d )
	{
		if( p < x.second )
		{
			p = x.second;
			ans1 = x.first;
		}
		if( ans2.length () < x.first.length() )
		{
			ans2 = x.first;
		}
	}
	cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

void prdmod(ll& src, const ll& tgt) {
  ll ret = ((src % MOD) * (tgt % MOD)) % MOD;
  if (ret < 0) ret += MOD;
  src = ret;
}

void addmod(ll& src, const ll& tgt) {
  ll ret = ((src % MOD) + (tgt % MOD)) % MOD;
  if (ret < 0) ret += MOD;
  src = ret;
}

// Sieve of Eratosthenes
// エラトステネスの篩
vector<int> sieve(int N) {
  vector<bool> e(N + 1, true);
  e[0] = false;
  e[1] = false;
  int sqrtN = ceil(sqrt(N)) + 1;
  rep(p, sqrtN) {
    if (!e[p]) continue;
    for (int i = pow(p, 2); i <= N; i += p) {
      e[i] = false;
    }
  }
  vector<int> ret;
  rep(i, N + 1) {
    if (e[i]) ret.push_back(i);
  }
  return ret;
}

int loga(int x, int a) {
  if (x == 0 || x == 1) return 0;
  int cnt = 0;
  while (x % a == 0) {
    x /= a;
    cnt++;
  }
  return cnt;
}

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

  // Nまでの素数列
  vector<int> prime = sieve(N);

  // 約数の数は N = p1 ^ c1 * p2 ^ c2 ... のとき (c1 + 1) * (c2 + 1) ...
  // https://juken-mikata.net/how-to/mathematics/number-of-divisor.html
  ll ans = 1;
  for (auto p : prime) {
    ll ans_i = 0;
    repi(i, 2, N + 1) {
      ll c = loga(i, p);
      addmod(ans_i, c);
    }
    prdmod(ans, ans_i + 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

ll x,y;
int main(){
  cin>>x>>y;
  if(abs(x-y)<=1)cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2,M = 1e9 + 7;
int dp[N][N],n,a,b,c,d,fact[N] = {1},inv[N];
void add(int &a,int b){
    a+=b;
    if(a >= M)a-=M;
}
int power(int base,int to){
    int ret = 1;
    while(to){
        if(to&1)ret = ret*1LL*base%M;
        to>>=1;
        base = base*1LL*base%M;
    }
    return ret;
}
int main(){
    //freopen("readin.txt","r",stdin);
    for(int i = 1;i < N;i++)fact[i] = fact[i - 1]*1LL*i%M;
    for(int i = 0;i < N;i++)inv[i] = power(fact[i],M - 2);
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    dp[a][0] = 1;
    for(int i = a;i <= b;i++)
        for(int j = 0;j <= n;j++){
            add(dp[i + 1][j],dp[i][j]);
            for(int k = c;k <= d;k++){
                if(j + i*k > n)break;
                int x = fact[n - j]*1LL*inv[n - j - i*k]%M;
                x = x*1LL*power(inv[i],k)%M;
                x = x*1LL*inv[k]%M;
                add(dp[i + 1][j + k*i],dp[i][j]*1LL*x%M);   
            }
        }
    printf("%d\n",dp[b + 1][n]);
}

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

using namespace std;

int main() {
	long long n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < m; i++) {
		long long x;
		cin >> x;
		sum += x;
		if (sum > n) {
			cout << -1;
			return 0;
		}
	}

	cout << n - sum;
}


Measured memory_bytes: 3576
#include <stdio.h>

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

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    ll K;
    cin >> S;
    cin >> K;

    ll current = 0;
    REP(i, S.length()) {
        if (S[i] == '1') {
            current += 1;
            if (current == K) {
                cout << '1' << endl;
                return 0;
            }
        } else {
            cout << S[i] << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 768
//SILENT KILLER
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
//vector<int>v;
int main()
{
   ll n;

    cin>>n;



    ll ara[n+23];

    for(ll i=0;i<n;i++)cin>>ara[i];


    ll sum=0;

    ll mn=ara[0];

    for(ll i=1;i<n;i++)
    {
        if(ara[i]<mn)
        {
            sum+=mn-ara[i];


        }
              mn=max(ara[i],mn);

    }



    cout<<sum<<endl;



}












Measured memory_bytes: 5112
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

s = input()
t = input()
ans = 0
for i in range(len(s)):
	if s[i]!=t[i]:
		ans+=1

print(ans)

Measured memory_bytes: 9720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

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

    int ans = 0;
    for(int i = 0; i < n.size(); i++){
        if(n[i] == '2'){ans++;}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<sstream>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define all(c) (c).begin(), (c).end()

using namespace std;
template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

int main() 
{
	int a,b;
	int ans;
	while(cin >> a >> b) {
		ans = a + b;
		string a_str = to_string(ans);
		cout << a_str.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
import java.awt.geom.Point2D;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){		
		new AOJ0079();
	}
		
	class AOJ0079{
		public AOJ0079() {
			Point2D list[] =new Point2D[20];
			int s;
			for(s=0;in.hasNext();s++){
				String input[] = in.next().split(",");
				list[s] = new Point2D.Double(Double.parseDouble(input[0]),Double.parseDouble(input[1]));
			}
			double sum=0;
			double nagasa[] = new double[s];
			for(int i=1;i<s;i++){
				nagasa[i-1] = list[i-1].distance(list[i]);
				sum+=nagasa[i-1];
			}
			nagasa[s-1]=list[0].distance(list[s-1]);
			double a = 0;
			for(int i=0;i<s;i++)a+=list[i].getX()*list[(i+1)%s].getY()-list[(i+1)%s].getX()*list[i].getY();
			System.out.println(Math.abs(a/2));
		}
	}


	class AOJ2503{
		int MAX = 0;
		public AOJ2503() {
			Scanner in = new Scanner(System.in);
			int n = in.nextInt();
			int m = in.nextInt();

			int[][] cost = new int[n][n];

			int[] dp = new int[n];
			for(int i=0;i<n*n;i++){
				cost[i/n][i%n]=MAX;
			}
			for(int i=0;i<m;i++){
				int a = in.nextInt();
				int b = in.nextInt();
				cost[a][b]=in.nextInt();
			}	
			//			TODO 一番大きいパスを0のポイントからn-1のポイントまでの

			for(int s=1;s<n;s++){
				for(int i=0;i<=s;i++){
					if(cost[i][s]==MAX)continue;
					dp[s]=Math.max(dp[s],dp[i]+cost[i][s]);
				}
			}
			for(int s=0;s<n;s++)for(int i=0;i<n;i++){
				if(cost[s][i]==MAX)continue;
				dp[i]=Math.max(dp[s]+cost[s][i],dp[i]);
			}
			for(int i=0;i<n;i++)System.out.print(dp[i]+" ");
			System.out.println();
			System.out.println(dp[n-1]);
		}
	}
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for(int x = 0; x <= K; x++) {
    for(int y = 0; y <= K; y++) {
      if (S - (x + y) <= K && S >= x + y)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int a, b;
  cin >> a >> b;
  cout << (a+b+1) / 2 << endl;
}

Measured memory_bytes: 256
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
/*STL Libs*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/*Boost*/
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#define REP(i, lower, upper) for (long long i = lower; i < upper; i++)
#define ALL(list) (list.begin()), (list.end())

using namespace std;
using bint = boost::multiprecision::cpp_int;
typedef long long ll;

constexpr int MOD = 10000007;

vector<long long> divisor(long long n) {
  vector<long long> head, tail;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

//--------------------------------

void execute() {
  ll a,b;
  cin>>a>>b;
  cout<<lcm(a,b)<<endl;
}

//--------------------------------

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

  execute();

  return (0);
}


Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
    ll n;
    cin>>n;
    vec(a,26);
    vector<ll>b(26,3000);
    vector<string>s(n);
    rep(i,n){
        cin>>s[i];
        rep(j,s[i].size()){
            a[s[i][j]-'a']++;
        }
        rep(j,26){
            b[j]=min(a[j],b[j]);
            a[j]=0;
        }
    }
    rep(i,26){
        rep(j,b[i]){
            cout<<(char)('a'+i);
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<sstream>
#define INF 999999
using namespace std;
int J(int x){
    stringstream ss;
    int LONG,plas=0,flg=0;
    char num[100];
    if(x<10)return 1;
    //itoa(x,num,10);
    ss<<x;
    ss>>num;
    LONG=strlen(num);
    if(LONG%2==0)plas=2;
    for(int i=0;i<(LONG-1+plas)/2;i++){
        if(num[i]!=num[LONG-1-i]){
            flg=1;
            break;
        }
    }
    if(flg==0)return 1;
    return 0;
}
int main(){
    int N;
    cin>>N;
    if(J(N)==1){cout<<N<<endl;return 0;}
    for(int i=1;;i++){
            if(J(N-i)==1){cout<<N-i<<endl;break;}
            if(J(N+i)==1){cout<<N+i<<endl;break;}
    }
    return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

vector<pair<ll,int>> prime_factor(ll n) {
  vector<pair<ll,int>>res;
  for(ll i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      int t = 1;
      n /= i;
      while(n%i==0){
        t++;
        n/=i;
      }
      res.push_back(pair<ll,int>(i,t));
    }
  }
  if(n != 1) res.push_back(pair<ll,int>(n,1));
  return res;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll d = gcd(a,b);
    auto mp = prime_factor(d);
    cout << mp.size() + 1<< endl;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<vector<char>> ss(2 * n, vector<char>(2 * n));
    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < n; j++) {
            cin >> ss[i][j];
            ss[i + n][j] = ss[i][j + n] = ss[i + n][j + n] = ss[i][j];
        }
    }

    i64 ans = 0;
    for (i64 i = 0; i <= 2 * n - 2; i++) {
        i64 ay = min(i, n - 1), ax = min(2 * n - 2 - i, n - 1);

        i64 err = 0;
        for (i64 ry = 0; ry < n; ry++) {
            for (i64 rx = ry; rx < n; rx++) {
                if (ss[ay + ry][ax + rx] != ss[ay + rx][ax + ry]) err++;
            }
        }
        if (!err) ans += min(ay, ax) + 1;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    while(true){
        string S;
        cin >> S;
        if(S == "0") break;

        int mods[2][11];
        memset(mods, 0, sizeof(mods));
        int cur = 0;
        int N = S.size();
        int ans = 0;
        for(int i=0;i<N;i++){
            int next = cur ^ 1;
            for(int j=0;j<11;j++){
                mods[next][(j * 10 + int(S[i] - '0')) % 11] = mods[cur][j];
            }
            if(S[i] != '0') mods[next][int(S[i] - '0')] += 1;
            ans += mods[next][0];
            cur = next;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3284
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while (a >= b)
    {
        ++cnt;
        b *= 2;
    }
    while (b >= c)
    {
        ++cnt;
        c *= 2;
    }
    cout << (cnt <= k ? "Yes" : "No") << endl;
}

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

using namespace std;
#define ll  long long
#define ld long double
struct graw {
 ll w;
 ll v;
};
int main()
{
 // freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    graw a[105] ={0};
    for(ll i =1;i<=n;i++) {
        cin>>a[i].w>>a[i].v;
    }
 ll ans [105][300005]={0};
 for(ll i =1;i<=n;i++) {

   for(ll j =0;j<=300000;j++) {
   if(j>=a[i].v) {
    if(ans[i-1][j-a[i].v]!=0 && ans[i-1][j-a[i].v]+a[i].w<=m) {
        if(ans[i-1][j] == 0) {
            ans[i][j] = ans[i-1][j-a[i].v]+a[i].w;
        } else ans[i][j] = min(ans[i-1][j],ans[i-1][j-a[i].v]+a[i].w);
    }
    else ans[i][j] = ans[i-1][j];
   } else ans[i][j] = ans[i-1][j];
   }
 if(a[i].w>m) continue;
 if(ans[i][a[i].v]==0) ans[i][a[i].v]=a[i].w; else
    ans[i][a[i].v] = min(ans[i][a[i].v],a[i].w);

 }
 ll an = 0;
 for(ll i =300000;i>=1;i--) {
     //   cout<<ans[n][i]<<" ";
    if(ans[n][i]!=0) {an = i; break;}
 }
 /*
 for(ll i =1;i<=3;i++) {
    for(ll j =1;j<=90;j++) {
        cout<<ans[i][j]<<" ";
    }
    cout<<endl;
 }
 */
 cout<<an;
}



Measured memory_bytes: 246400
n,d = map(int,input().split())
X = [list(map(int,input().split())) for i in range(n)]
res = 0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        dist = 0
        for k in range(d):
            dist += (X[i][k]-X[j][k])**2
        #print(dist)
        if int(dist**0.5) == dist**0.5:
            res += 1
print(res//2)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    double num;
    num = (a + b) / 2;
    if ((a+b) % 2 == 0) {
        cout << num << endl;
    } else {
        cout << int(num)+1 << endl;
    }

}

Measured memory_bytes: 256
n,m = map(int,input().split())
x,y,z = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    z.append(c)
def solve(x,y,z,m):
    ans = 0
    for bit in range(8):
        w = []
        for i in range(n):
            t = x[i]*(-1)**((bit>>2)&1)+y[i]*(-1)**((bit>>1)&1)+z[i]*(-1)**((bit>>0)&1)
            w.append(t)
        w.sort(reverse=True)
        ans = max(ans,sum(w[:m]))
    return ans

ans = solve(x,y,z,m)
print(ans)


Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
      int x,y;
      for(;;)
      {
            scanf("%d %d",&x,&y);
            if(x==0&&y==0)
            {
                 break;
            }
            if(x>y)
            {
                 printf("%d %d\n",y,x); 
            }
            else
            {
                 printf("%d %d\n",x,y);
            }
      }
      return 0;
}

Measured memory_bytes: 600
#include"stdio.h"
#include"stdlib.h"

typedef struct
{
  char M;
  int N;
}Card;
int partition(Card *A,int p,int r)
{
  int x=A[r].N;
  int i=p-1;
  int j;
  Card buf;
  for(j=p;j<r;j++)
    {
      if(A[j].N<=x)
        {
          i++;
          buf=A[i];
          A[i]=A[j];
          A[j]=buf;
        }
    }
  buf=A[i+1];
  A[i+1]=A[r];
  A[r]=buf;
  return i+1;
}
void quickSort(Card *A,int p,int r)
{
  int q;
  if(p<r)
    {
      q=partition(A,p,r);
      quickSort(A,p,q-1);
      quickSort(A,q+1,r);
    }
}
void Gudge(int n,Card *card,Card *A)
{
  int i,j,f;
  int c=0;
  for(i=1;i<n;i++)
    {
      if(A[i-1].N==A[i].N)
        {
          for(j=c;j<n;j++)
            {
              if(A[i-1].N==card[j].N)
                {
                  if(A[i-1].M==card[j].M)
                    {
                      for(f=j+1;f<n;f++)
                        {
                          if(A[i].N==card[f].N)
                            {
                              if(A[i].M==card[f].M)
                                {
                                  c=j+1;
                                  j=n;
                                  break;
                                }
                              else
                                {
                                  i=n;
                                  j=n;
                                  break;
                                }
                            }
                        }
                    }
                  else
                    {
                      i=n;
                      break;
                    }
                }
            }
        }
      else
        {
          c=0;
        }
    }
  if(i==n+1)
    {
      printf("Not stable\n");
    }
  else
    {
      printf("Stable\n");
    }
}
int main()
{
  int n;
  Card *A;
  Card *B;
  int i;
  int k;
  scanf("%d",&n);
  A=(Card*)malloc(sizeof(Card)*n);
  B=(Card*)malloc(sizeof(Card)*n);
  for(i=0;i<n;i++)
    {
      scanf("%s %d",&A[i].M,&A[i].N);
      B[i].M=A[i].M;
      B[i].N=A[i].N;
    }
  quickSort(A,0,n-1);
  Gudge(n,B,A);
  for(i=0;i<n;i++)
    {
      printf("%c %d\n",A[i].M,A[i].N);
    }
}


Measured memory_bytes: 3264