akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
#define MP(n, m) make_pair(n, m);
#define COUT(d) cout<<std::setprecision(10)<<d<<endl;
#define CIN(n) getline(cin,n);
 
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
using ul = unsigned long;
 
typedef long long ll;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(VI& v){
  REP(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
 
int vtotal(VI& v){
  int total=0;
  REP(i,v.size()) total+=v[i];
  return total;
}
 
int ans=0;
int last=10;
int cnt=0;
 
void f(int x){
  int mod=x%10;
  ans+=x-mod;
  if(mod!=0){
      if(last>mod)last=mod;
      cnt++;
  }
}
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
	
  //init(); // mint初期化
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
 
  f(a);
  f(b);
  f(c);
  f(d);
  f(e);
 
  if(last!=10)ans+=last;
  if(cnt!=0)ans+=10*(cnt-1);
 
  cout<<ans<<endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll dp[100003];

int main() {
  ll n, ans = 0, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  rep(i, 100003) dp[i] = INF;
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; ++i) {
    for (int j = 1; i - j >= 0 && j <= k; ++j) {
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

        /*
        ひとつでも奇数のものがあれば first の勝ち？
        */
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a % 2 != 0) {
                System.out.println("first");
                return;
            }
        }
        System.out.println("second");
	}
}

Measured memory_bytes: 48980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    while (a.at(i) % 2 == 0) {
      cnt++;
      a.at(i) /= 2;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 384
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void merge(lld brr[], lld arr[], lld l, lld m, lld r){
    lld i , j ,  k;
    lld n1 = m-l+1; 
    lld n2 = r - m;
    lld L1[n1], L2[n1];
    lld R1[n2], R2[n2];
    for (i = 0; i < n1; i++){
        L1[i] = arr[l + i];
        L2[i] = brr[l + i];
    }
    for (j = 0; j < n2; j++){
        R1[j] = arr[m+1+j];
        R2[j] = brr[m+1+j];
    }
    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L1[i] <= R1[j]){
            arr[k] = L1[i];
            brr[k] = L2[i];
            i++;
        }
        else{
            arr[k] = R1[j];
            brr[k] = R2[j];
            j++;
        }
        k++;
    }
        while (i   <   n1){
            arr[k] = L1[i];
            brr[k] = L2[i];
            i++;
            k++;
        }
        while (j   <   n2){
            arr[k] = R1[j];
            brr[k] = R2[j];
            j++;
            k++;
        }
}
void mergeSort(lld brr[], lld arr[], lld l, lld r){
    if (l < r)
    {
        lld m = l+(r-l)/2;
        mergeSort(brr, arr,l, m);
        mergeSort(brr,arr,m+1,r);
        merge(brr, arr, l, m, r);
    } 
} 
int main ()
{
      FastIO
      lld n, i;
      cin >> n;
      lld A[n];
      lld B[n];
      foi(i,n){
      	cin >> A[i] >> B[i];
      }
      mergeSort(A, B, 0, n - 1);
      lld t = 0;
      lld f = 1;
      for(i = 0; i < n; i ++){
      	t += A[i];
      	if (t > B[i])
      		f = 0;
      }
      if (f == 0)
      	cout <<  "No";
      else
      	cout << "Yes";
      return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

struct CHT {
  vector<pll> deq;              // first * x + second
  ll s,t;
  CHT(ll n) {
    deq.resize(n);
    s=0, t=0;
  }
  void add(ll a, ll b) {      // a : non increasing
    const pll p(a,b);
    while(s+1<t && check(deq[t-2],deq[t-1],p)) t--;
    deq[t++] = p;
  }
  ll incl_query(ll x) {            // x : non decreasing
    if (s==t) {
      return 1LL<<55;
    }
    while(s+1<t && f(deq[s], x) >= f(deq[s+1], x)) s++;
    return f(deq[s], x);
  }
  ll query(ll x) {           // without condition
    ll low = s-1, high = t-1;
    while(low+1<high) {
      ll mid = low+high>>1;
      if (isright(deq[mid], deq[mid+1], x)) low = mid;
      else high = mid;
    }
    return f(deq[high], x);
  }
private:
  bool isright(const pll &p1, const pll &p2, ll x) {
    return (p1.second-p2.second) >= x * (p2.first-p1.first);
  }
  bool check(const pll &p1, const pll &p2, const pll &p3) {
    return (p2.first-p1.first)*(p3.second-p2.second) >=
      (p2.second-p1.second)*(p3.first-p2.first);
  }
  ll f(const pll &p, ll x) {
    return p.first * x + p.second;
  }
};

ll p[10000];
ll c[10000];
ll dp[10001][101];

int main() {
  ll n,m,d,x;
  while(cin>>n>>m>>d>>x) {
    REP(i,n) {
      cin >> p[i];
    }
    REP(i,m) {
      int a, b;
      cin >> a >> b;
      if (b > 0) {
        // y = (x-a) + b = 0
        // x = a - b
        c[i] = a-b;
      } else {
        // y = -(x-a) + b = 0
        // x = a + b
        c[i] = a+b;
      }
    }
    sort(c,c+m);
    vector<CHT> cht(d+1, n);
    vector<ll> id(d+1,0);
    REP(i,n)REP(k,d+1)dp[i][k] = 1LL<<50;
    dp[0][0] = 0;
    while(id[0]<m&&c[id[0]]<p[0]) id[0]++;
    cht[0].add(m-id[0], dp[0][0]-p[0]*(m-id[0]));
    REP(i,n) {
      for (int k=d; k>=1; --k) {
        while(id[k]<m&&c[id[k]]+x*k<p[i]) id[k]++;
        dp[i][k] = cht[k-1].incl_query(p[i]);
        // cout << dp[i][k] << "," << m-id[k] << " " ;
        cht[k].add(m-id[k], dp[i][k]-p[i]*(m-id[k]));

      }
      // cout << endl;
    }
    cout << *min_element(dp[n-1], dp[n-1]+d+1) << endl;
  }
}

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

int main()
{
  int n;
  int b;
  cin>>n;
  vector<int> ar(n,0);
  vector<int> a(n,0);
    for (int k = 0; k < n ; k++){
        cin>>b;
        ar[k]=b;
    }
  int i;
  a[0]=0;
  a[1]=abs(ar[0]-ar[1]);
  i=2;
  	for (i; i < n; i++){
     if(abs(ar[i-1]-ar[i])+a[i-1]<abs(ar[i-2]-ar[i])+a[i-2]){
       a[i]=abs(ar[i-1]-ar[i])+a[i-1];
     }
      else{
        a[i]=abs(ar[i-2]-ar[i])+a[i-2];
      }
  	}
      cout<<a[n-1];
}


Measured memory_bytes: 1024
module Main (main) where

import Control.Applicative hiding (read)
import Data.List

main :: IO ()
main = do
  [x,y,z] <- (map read . words) <$> getLine :: IO [Integer]
  putStrLn $ fromList $ sort [x,y,z]

fromList :: [Integer] -> String
fromList [x,y,z] =
  (show x) ++ " " ++ (show y) ++ " " ++ (show z)

Measured memory_bytes: 3560
/*
http://blog.csdn.net/liuke19950717
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn= 999999+5;
ll prime[maxn];
int main()
{
	ll cnt=0;
	for(ll i=2;i<maxn;++i)
	{
		if(!prime[i])
		{
			prime[i]=++cnt;
			for(ll j=i*i;j<maxn;j+=i)
			{
				prime[j]=1;
			}
		}
		else
		{
			prime[i]=prime[i-1];
		}
	}
	ll n;
	while(~scanf("%lld",&n))
	{
		printf("%lld\n",prime[n]);
	}
	return 0;
}


Measured memory_bytes: 10532
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<vector>
#include <map>
#define I int
#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define P(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB(a) push_back(a)
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define ll long long 
using namespace std;
#define mx 500004
#define md 2000000000000000000ll
typedef pair<int, int >P;
typedef vector<ll>V;

////////define value/////

int main(){

   string s,t;
   cin>>s>>t;
   t+=s;
   cout<<t<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  if(S==U){
    cout<<A-1<<" "<<B<<endl;
  }
  else{
    cout<<A<<" "<<B-1<<endl;
  }
}

    

Measured memory_bytes: 256
H,W = map(int,input().split())
s = [input() for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == "#":
      if i != 0 and s[i-1][j] == "#":
        continue
      if i != H-1 and s[i+1][j] == "#":
        continue
      if j != 0 and s[i][j-1] == "#":
        continue
      if j != W-1 and s[i][j+1] == "#":
        continue
      print("No")
      exit()
print("Yes")


Measured memory_bytes: 3064
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t S, W;
    intmax_t ans = 0;

    scanf("%jd%jd", &S, &W);

    if (S > W) {
        puts("safe");
    } else {
        puts("unsafe");
    }

    return 0;
}


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

int main() {
  int N, l, r, sum;
  sum = 0;
  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,H,index;
    cin>>N;
    ll x[N],y[N],h[N];
    for(ll i=0;i<N;i++){
        cin>>x[i]>>y[i]>>h[i];
        if(h[i]) index=i;
    }
    for(ll i=0;i<=100;i++){
        for(ll j=0;j<=100;j++){
            ll cnt=0;
            bool f=true;
            H=abs(j-x[index])+abs(i-y[index])+h[index];
            for(ll k=0;k<N;k++){
                if(h[k]>0&&H!=abs(j-x[k])+abs(i-y[k])+h[k]) f=false;
                if(h[k]==0&&H>abs(j-x[k])+abs(i-y[k])) f=false;
            }
            if(f){
                cout<<j<<" "<<i<<" "<<H<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdio.h>
int cmp(const void *a,const void *b){
	return *(int *)b-*(int *)a;
}
int main(void){
	int n,m,i,j,a[1000],b,ans=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
		scanf("%d %d",&a[i],&b);
	qsort(a,m,sizeof(int),cmp);
	for(i=0;i<m-1;i++){
		if(a[i]<n)
			ans+=n-a[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 648
import kotlin.math.*
import java.util.*

const val mod = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (_a, _b) = readLine()!!.split(' ')
  val a = _a.toLong()
  val (b, c) = _b.split('.').map(String::toLong)
  println(a * b + a * c / 100)
}


Measured memory_bytes: 36060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // 計算量の見積もり間違ってた
    int n;
    cin >> n;
    int f[n][10];
    int p[n][11];
    rep(i, n) rep(j, 10) cin >> f[i][j];
    rep(i, n) rep(j, 11) cin >> p[i][j];
    int ans = -inf;
    rep(i, (1 << 10)) {
        if (i == 0) continue;
        int c[n]; fill_n(c, n, 0); // いくつ営業するか
        rep(j, 10) {
            if (i & (1 << j)) { // 営業する時間帯
                rep(k, n) {
                    if (f[k][j]) {
                        c[k]++;
                    }
                }
            }
        }
        int sum = 0;
        rep(j, n) {
            sum += p[j][c[j]];
        }
        // out(sum);
        chmax(ans, sum);
    }
    out(ans);
}



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

int main(){
  int k;
  cin>>k;
  queue<ll> g;
  rep(i,9) g.push(i+1);
  ll x;
  rep(i,k){
    x = g.front();
    if(x%10) g.push(10*x+x%10-1);
    g.push(10*x+x%10);
    if(x%10!=9) g.push(10*x+x%10+1);
    g.pop();
  }
  cout << x << endl;  
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int size, num, limit, start = 1, num_breack_bricks = 0;
    bool find_one = false;
    cin>> size;
    limit = size - 1;
    for (int i=1; i <= size; i++)
    {
        cin >> num;
        if(num!= start){
            num_breack_bricks++;
        }
        else if(num==start){
            find_one = true;
            start++;
        }
    }
    if(limit < num_breack_bricks || find_one==false)
        cout<< -1 << endl;
    else
        cout << num_breack_bricks << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  
  bool k = true;
  rep(i,n) if (s[i] != t[i]) k = false;
  
  if (k) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main()
{
    int n;
    cin >>n;
    vector<long long> l(100);
  	l.at(0)=2;
  	l.at(1)=1;
  	for(int i = 2; i <= n; i++){
      l.at(i) = l.at(i - 1) + l.at(i - 2);
    }
  	cout <<l.at(n) <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        for (int i = 0; i < A.length; i++) {
            int key = A[i];
            int j = i - 1;
            while (true) {
                if (j == -1 || key >= A[j]) {
                    A[j + 1] = key;
                    break;
                } else {
                    A[j + 1] = A[j];
                    j--;
                }
            }
            print(A);
        }
    }

    private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    }
}

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

#define MOD 1000000007

int main()
{
    int N, K; cin >> N >> K;
    vector<vector<int>> g(N+1);
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> c(N+1, -1);
    queue<int> q;
    q.push(1);
    c[1] = K;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        int colored = 1;
        for (int u : g[v]) {
            if (c[u] != -1) colored++;
        }
        for (int u : g[v]) {
            if (c[u] != -1) continue;
            q.push(u);
            c[u] = max(0, K-colored++);
        }
    }

    ll ans = 1;
    for (int i = 1; i <= N; i++) {
        ans = ans * c[i] % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6904
package main

import (
	"fmt"
	"sort"
	"strings"
)


func main() {
	var n int
	fmt.Scan(&n)
	S := make([]string, n)
	for i := 0; i<n;i++ {
		var c string
		fmt.Scan(&c)
		k:=strings.Split(c,"")
		sort.Strings(k)
		S[i]= strings.Join(k,"")
	}
	nums := map[string]int{}
	ans :=0
	for _,v := range S {
		ans += nums[v]
		nums[v]++
		
	}
	fmt.Println(ans)
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

long long search(const vector<vector<int>>& g, const vector<int>& col, int pos, int prev,
                                      vector<long long>& dec,
                                      vector<map<int, long long>>& mp,
                                      vector<int>& ref)
{
    int cnt = 1;
    for(auto t : g[pos]){
        if(t == prev) continue;
        auto res = search(g, col, t, pos, dec, mp, ref);
        auto& oppMp = mp[ref[t]];
        auto num = res;
        if(oppMp.count(col[pos])) num -= oppMp[col[pos]];
        dec[col[pos]] += num * (num + 1) / 2;
        if(mp[ref[pos]].size() < mp[ref[t]].size()) swap(ref[pos], ref[t]);
        for(auto& it : mp[ref[t]]){
            if(!mp[ref[pos]].count(it.first)) mp[ref[pos]][it.first] = 0;
            mp[ref[pos]][it.first] += it.second;
        }
        cnt += res;
    }
    mp[ref[pos]][col[pos]] = cnt;
    if(prev == -1){
        for(int i=0;i<dec.size();i++){
            long long num = dec.size();
            if(mp[ref[pos]].count(i)) num -= mp[ref[pos]][i];
            dec[i] += num * (num + 1) / 2;
        }
    }
    return cnt;
}

int main(){
    long long N; cin >> N;
    vector<int> c(N);
    for(auto& t : c){ cin >> t; --t; }
    vector<vector<int>> g(N);
    for(int i=0;i<N-1;i++){
        int a, b; cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<long long> dec(N, 0);
    vector<map<int, long long>> mp(N);
    vector<int> ref(N);
    for(int i=0;i<N;i++) ref[i] = i;
    search(g, c, 0, -1, dec, mp, ref);
    for(int i=0;i<N;i++){
        cout << N*(N+1)/2 - dec[i] << endl;
    }
}

Measured memory_bytes: 78856
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int A[3][3];
    REP(i, 3)
    {
        REP(j, 3)
        {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    bool B[3][3] = {false};

    REP(i, N)
    {
        int b;
        cin >> b;
        REP(j, 3)
        {
            REP(k, 3)
            {
                if (b == A[j][k])
                {
                    B[j][k] = true;
                }
            }
        }
    }
    // REP(i, 3)
    // {
    //     REP(j, 3)
    //     {
    //         cout << A[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    // REP(i, 3)
    // {
    //     REP(j, 3)
    //     {
    //         cout << B[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    bool flag = false;
    if (B[0][0] && B[0][1] && B[0][2])
    {
        flag = true;
    }
    else if (B[1][0] && B[1][1] && B[1][2])
    {
        flag = true;
    }
    else if (B[2][0] && B[2][1] && B[2][2])
    {
        flag = true;
    }
    else if (B[0][0] && B[1][0] && B[2][0])
    {
        flag = true;
    }
    else if (B[0][1] && B[1][1] && B[2][1])
    {
        flag = true;
    }
    else if (B[0][2] && B[1][2] && B[2][2])
    {
        flag = true;
    }
    else if (B[0][0] && B[1][1] && B[2][2])
    {
        flag = true;
    }
    else if (B[0][2] && B[1][1] && B[2][0])
    {
        flag = true;
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a=0,b=0,c=0,d=0,m,n,min=100000,k,ans=0;
    string s,s2;
    cin >> a >> b >> k;
    for(int i=0;i<k;i++){
        if(a+i<=b)
            cout << a+i <<endl; 
    }
    if(b >= k){
        for(int i=k;i>0;i--){
            if(b-i+1>=a&&(a+k-1<b-i+1))
                cout << b-i+1 <<endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, l, h, w, ans = 0;
  scanf("%lld%lld", &h, &w);
  char s[h + 2][w + 10];
  for(i = 0; i < h + 2; ++i) for(j = 0; j < w + 2; ++j) s[i][j] = '#';
  for(i = 0; i < h; ++i) scanf("%s", s[i + 1] + 1);
  bool flg[h][w];
  queue< pair<pair<ll, ll>, ll> > q;
  pair<pair<ll, ll>, ll> p;
  for(i = 1; i <= h; ++i) for(j = 1; j <= w; ++j) if(s[i][j] == '.') {
    q.push(make_pair(make_pair(i, j), 0));
    for(k = 0; k < h; ++k) for(l = 0; l < w; ++l) flg[k][l] = true;
    flg[i - 1][j - 1] = false;
    while(q.size()) {
      p = q.front(), q.pop();
      if(p.second > ans) ans = p.second;
      for(k = -1; k < 2; k++) for(l = -1; l < 2; l++) if(!(k * l))
        if(s[p.first.first + k][p.first.second + l] == '.' && flg[p.first.first + k - 1][p.first.second + l - 1]) 
          q.push(make_pair(make_pair(p.first.first + k, p.first.second + l), p.second + 1)), flg[p.first.first + k - 1][p.first.second + l - 1] = false;
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
import itertools
from collections import Counter

def main():
    N = int(input())
    data = []
    common_data = []
    max_common_num = 0
    for _ in range(N):
        data.append( list(map(int, input().split())) )

    data.sort()

    if N == 1:
        return 1
    else:
        for obj in itertools.combinations(data, 2):
            # print(obj)
            common_data.append( str(obj[0][0] - obj[1][0]) + "_" + str(obj[0][1] - obj[1][1]) )

        # カウント
        counter = Counter(common_data)
        for word, cnt in counter.most_common():
            if cnt >= max_common_num:
                max_common_num = cnt

    # print(common_data)
    return N - max_common_num

if __name__ == '__main__':
    print( main() )


Measured memory_bytes: 3572
import java.util.*;
public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        String t = scan.nextLine();

        if(s.equals(t.substring(0,t.length()-1))){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
	ll n,k,q,temp;
  cin>>n>>k>>q;
  vector<pair<ll,ll>>v(n, std::make_pair(0, 0));
  for(ll i=0;i<q;i++){
    	cin>>temp;
    	v[temp-1].second++;
  }
  for(ll i=0;i<n;i++){
    if(v[i].second<=(q-k))
      cout<<"No"<<endl;
    else
      cout<<"Yes"<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void) {
	int n, s = 0;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		s += i;
		if (s >= n) {
			for (int j = 1; j <= i; j++) {
				if (s - n == j)
					continue;
				printf("%d\n", j);
			}
			break;
		}
	}
}

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

using namespace std;

const int NMAX = 3005;
int n, m, k;
char s[NMAX], t[NMAX], a[NMAX];
int dp[NMAX][NMAX];

int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> (s + 1);
	cin >> (t + 1);
	n = strlen(s + 1);
	m = strlen(t + 1);
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j)
		{
			if (s[i] == t[j])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	int i = n, j = m;
	k = dp[n][m];
	a[k + 1] = 0;
	while (k > 0)
	{
		if (s[i] == t[j])
		{
			a[k] = s[i];
			--k;
			--i;
			--j;
		}
		else
		{
			if (dp[i - 1][j] > dp[i][j - 1])
				--i;
			else
				--j;
		}
	}
	cout << (a + 1) << "\n";	
	return 0;
}

Measured memory_bytes: 35456
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long A = scan.nextLong();
			long B= scan.nextLong();
			
			ArrayList<Long>a = enum_div(A);
			ArrayList<Long>C = new ArrayList<Long>();
			ArrayList<Long>D = new ArrayList<Long>();
			ArrayList<Long>E = new ArrayList<Long>();
			StringBuffer sb = new StringBuffer();
			
			for(Long i:a) {//Aの約数の数分チェック
				if(B%i==0) {
					C.add(i);
				}
			}
			
			
			for(Long i:C) {
				//System.out.println(i);
				//D.add((long)1);
				sb.append(1);
			}
			//System.out.println(COM(170,85));
			
			if(C.size()==1) {
				System.out.println(1);
				return;
				
			}
			
			for(int i = 1;i<C.size()-1;i++) {
				long ki = C.get(i);
				for(int j = i+1;j<C.size();j++) {
					long che = C.get(j);
					if(che%ki==0) {
						sb.replace(j, j+1, "0");
					}
				}
			}
			
			int count = 0;
			
			for(int i=0;i<sb.toString().length();i++) {
				String s = sb.toString().substring(i, i+1);
				if(s.equals("1")) {
					count++;
				}
			}
			
			
				System.out.println(count);
				
			
			
			
			
			
			
		}
		
		
	}
	
	
	private static ArrayList<Long> enum_div(long n){//数字１〜ｎまでの約数を全部Allaylistに詰め込むメソッド
		ArrayList<Long> ret = new ArrayList<Long>();
		for(long i = 1;i*i<=n;i++) {
			if(n%i==0) {
				ret.add(i);
				if(i*i!=n){
					ret.add(n/i);
				}
			}
		}
		
		//ただここまでだと格納した約数はソートされてない
		
		Collections.sort(ret);//int型、Sting型くらいの格納した奴ならコレクションクラスのソートが使える。
		//ソートしてからcollections.reverseつかえば降順にもできる
		return ret;
		
		
		
	}
	
	

}


Measured memory_bytes: 23912
def solve(s: str) -> bool:
  if len(s) % 2 == 1:
    return False
  if len(s) == 0:
    return True

  i = 0
  j = len(s) // 2
  while i < len(s) // 2:
    if s[i] != s[j]:
      return False
    i += 1
    j += 1
  return True


n = int(input().strip())
s = input().strip()
if solve(s):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
x,y,z,k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

x = 0
y = 0
z = 0
cakes = []
for x, a in enumerate(A):
    for y, b in enumerate(B):
        for z, c in enumerate(C):
            
            if (x+1)*(y+1)*(z+1) > k:
                break
                
            cakes.append(a+b+c)
    
cakes.sort(reverse=True)      
for cake in cakes[:k]:
    print(cake)

Measured memory_bytes: 8712
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    int N,W;cin>>N>>W;
    vector<int> v(N+1);
    vector<int> w(N+1);
    vector<int> dp(W+1,0);
    for(int i=1;i<N+1;i++) cin>>v[i]>>w[i];
    for(int now_w=0;now_w<W+1;now_w++){
        for(int i=1;i<N+1;i++){
            if(now_w-w[i]>=0) dp[now_w] = max(dp[now_w],dp[now_w-w[i]]+v[i]);
        }
    }
    int ans=0;
    for(int i=0;i<=W;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    vector<int> a;
    int n, k, count, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> k;
        a.push_back(k);
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < a.size();){
        k = a[i];
        count = 0;
        for( ; a[i] == k; i++){
            count += 1;
        }
        ans += (k <= count ? count - k : count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
const int maxn = 300001;
int n, m, s[11][11], slen[11], p[11], ans;
int ok(int light){
	for(int i = 0;i < m;++i){
		int cnt = 0;
		for(int j = 0;j < slen[i];++j){
			cnt += (bool)(light & (1 << s[i][j]));
		}
		if(p[i] != (cnt & 1))return false;
	}
	return true;
}
int main(){
	cin >> n >> m;
	for(int i = 0;i < m;++i){
		cin >> slen[i];
		for(int j = 0;j < slen[i];++j){
			cin >> s[i][j];
			--s[i][j];
		}
	}
	for(int i = 0;i < m;++i)cin >> p[i];
	for(int light = 0;light < (1 << n);++light){
		ans += ok(light);
	}
	cout << ans << '\n';
}


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

int main() {
    int N, C;
    cin >> N >> C;
    vector<vector<int>> R0(C, vector<int>(100000, 0));
    rep(i, N) {
        int s, t, c;
        cin >> s >> t >> c;
        ++R0[c - 1][s - 1];
        --R0[c - 1][t];
    }
    vector<vector<int>> R1(C, vector<int>(100000, 0));
    rep(i, C) R1[i][0] = R0[i][0];
    rep(i, C) REP(j, 100000) R1[i][j] = R1[i][j - 1] + R0[i][j];
    int ans = 0;
    rep(i, 100000) {
        int cnt = 0;
        rep(j, C) {
            if (R1[j][i]) ++cnt;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24184
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<fstream>

#define rep(i,a,N) for(int i=0+a;i<N;i++)
#define lint long long int
#define SIZE 100005
#define pb push_back
#define MP make_pair

using namespace std;

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	double Water[31]={};
	double Sugar[3001]={};
	double W=0,S=c,Wmax=0,Smax=0;
	double per=0;
	double p,q;
	for(int i=0;i<=30;i++){
		if(i*a>30)break;
		for(int j=0;j<=30;j++){
			if((i*a+j*b)>30)break;
			Water[i*a+j*b]=1;
		}
	}
	for(int i=0;i<=f;i++){
		if(i*c>f)break;
		for(int j=0;j<=f;j++){
			if((i*c+j*d)>f)break;
			Sugar[i*c+j*d]=1;
		}
	}
	for(int i=1;i<31;i++){
		if(Water[i]==1){
		int Emax=i*e;
		for(int j=min(f-i*100,Emax);j>0;j--){
			if(Sugar[j]==1){
				p=i,q=j;
				if(per<(q*100/(p*100+q))&&((p*100+q)<=f)){
					per=(q*100/(p*100+q));
					Smax=j;
					Wmax=i;
					break;
				}

			}
		}
		}
	}
	if(Wmax==0&&Smax==0)Wmax=a;
	cout<<Wmax*100+Smax<<" "<<Smax<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,count=0;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
   if(i/10000==i%10&&(i/1000)%10==(i/10)%10){
     count++;
   }
  }
    cout<<count<<endl;
  }

Measured memory_bytes: 256
n=int(input())
a=list(map(str,input().split()))
if n%2!=1:
    s=list(reversed(a[1::2]))+a[::2]
else:
    s=list(reversed(a[::2]))+a[1::2]
c=""
for i in range(n):
    c+=s[i]+" "
print(c)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  set<int> st;
  for(int i=0;i<3;i++){
    int t;cin>>t;
    st.insert(t);
  }
  if(st.size()==2){
    cout<<"Yes"<<endl;
  }
  else{
    puts("No");
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char s[60],t[60];
   vector<int>p;
   vector<string>ss;
   p.clear();
   ss.clear();
   int i,j,k,cnt,pan,pp=0,pos;
   scanf("%s%s",s,t);
   int lens=strlen(s),lent=strlen(t);
  for(i=lens-1;i>=0;i--)
  {
     if(s[i]==t[lent-1]||s[i]=='?')
     {   pan=0;
        for(k=i,j=lent-1;j>=0;k--,j--)
        {
           if(s[k]!=t[j]&&s[k]!='?') {pan++;break;}
        }
        if(pan==0) {pp++;pos=i-lent+1;p.push_back(pos);}
     }
  }
  vector<int>::iterator it;
 // for(it=p.begin();it!=p.end();it++) printf("%d\n",*it);
  if(pp==0) printf("UNRESTORABLE");
  else
  { vector<int>::iterator it;
  vector<string>::iterator it2;
  for(it=p.begin();it!=p.end();it++)
  {  pos=*it;//printf("%d",pos);
     string temp;
     for(i=0;i<lens;i++)
     { // printf("1");
         if(i==pos) {
         for(k=i,j=0;j<lent;k++,j++)
         {
            temp[k]=t[j];
         }
         i+=lent-1;
         }
         else
         {
            if(s[i]=='?') temp[i]='a';
            else temp[i]=s[i];
         }
     }
     string a;
     a="";
     for(i=0;i<lens;i++) a+=temp[i];
     //cout<<a<<endl;
     ss.push_back(a);
     }
     sort(ss.begin(),ss.end());
     it2=ss.begin();
    cout<<*it2;
  }
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    W = list(map(int, input().split()))

    S1 = 0
    S2 = sum(W)
    ans = 10 ** 18
    for i in range(N - 1):
        S1 += W[i]
        S2 -= W[i]
        diff = abs(S1 - S2)
        ans = min(ans, diff)

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
int dxy[5] = {0, 1, 0, -1, 0};
// assign

vector<string> board;
int h, w;

i_i move(int i, int j, int k)
{
    if (0 <= i + dxy[k] && i + dxy[k] < h && 
            0 <= j + dxy[k+1] && j + dxy[k+1] < w && 
            board[i+dxy[k]][j+dxy[k+1]] == '1') {
        return i_i(-1, -1);
    }
 //   cout << " ( " << i << " , " << j << " ) " << endl;
    while (0 <= i + dxy[k] && i + dxy[k] < h && 
            0 <= j + dxy[k+1] && j + dxy[k+1] < w) {
        i += dxy[k]; j += dxy[k+1];
        if (board[i][j] == '3') {
            return i_i(i, j);
        } else if (board[i][j] == '1') {
            return i_i(i-dxy[k], j-dxy[k+1]);
        }
    }
    return i_i(-1, -1);
}

int solve(int i, int j, int cnt)
{
//    cout << i << " " << j << endl;
/*
    rep(lop, h) {
        if (lop == i) {
            rep(loop, w) {
                if (loop == j) {
                    cout << 'x';
                } else {
                    cout << board[i][j];
                }
            }
            cout << endl;
        } else {
            cout << board[i] << endl;
        }
    }
*/
    if (cnt == 10) {
        return 11;
    }
    int ans = 11;
    rep(k, 4) {
        i_i pos = move(i, j, k);
        if (pos.fir == -1) {
            continue;
        } else if (board[pos.fir][pos.sec] == '3') {
            ans = min(ans, cnt+1);
        } else {
            board[pos.fir+dxy[k]][pos.sec+dxy[k+1]] = '0';
            ans = min(ans, solve(pos.fir, pos.sec, cnt+1));
            board[pos.fir+dxy[k]][pos.sec+dxy[k+1]] = '1';
        }
    }
    return ans;
}

signed main()
{
    while (cin >> w >> h, w) {
        int stx, sty;
        board = vector<string>(h);
        rep(i, h) {
            rep(j, w) {
                Int(tmp);
                if (tmp == 2) { 
                    stx = i; sty = j;
                    tmp = 0;
                }
                board[i].pb(tmp + '0');
            }
        }
//        cout << stx << " " << sty << endl;
        /*
        rep(i, h) {
            cout << board[i] << endl;
        }*/
        int ret = solve(stx, sty, 0);
        if (ret == 11) {
            cout << -1 << endl;
        } else {
            cout << ret << endl;
        }
    }

    return 0;
}

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

int main() {
  int N;
  cin>>N;
  int K;
  cin>>K;
  int x=1;
  for(int i=0;i<N;i++){
  if(x<K)
    x+=x;
  else
    x+=K;}
  cout<<x<<endl;
  
    
}

Measured memory_bytes: 256
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()

    res = 0
    for i in range(1, n):
        if A[i] == A[i - 1]:
            A[i] = 0
            res += 1

    return res


print(main())


Measured memory_bytes: 3064
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>

using namespace std;

struct point{
  double x, y;
};

struct button{
  point ld,ru;
  string name;
};

struct page{
  string name;
  vector<button>btn;   
}; 

int main(void){
  int n;
  int w,h,b;
  point l,r;
  page in;
  vector<page> a;
  button tmp;

  while(cin >> n,n){
  
    a.clear();

    cin >> w >> h;
    
    for(int j=0;j<n;j++){
      in.btn.clear();
      cin >> in.name >> b;    
      
      for(int i=0;i<b;i++){
	cin >> tmp.ld.x >> tmp.ld.y >> tmp.ru.x >> tmp.ru.y >> tmp.name;
	in.btn.push_back(tmp);
      }
      a.push_back(in);
    }

    int m,now=0,fg=0;
    static page buf[1000000];

    cin >> m;
    buf[0]=a[0];

    for(int k=0;k<m;k++){
      string s;
      cin >> s;
      
      if(s=="click"){
	int c,d;
	cin >> c >> d;
	
	for(int i=0;i<buf[now].btn.size();i++){
	  int fg2=0;
	  if(buf[now].btn[i].ld.x <=c &&
	     buf[now].btn[i].ld.y <=d &&
	     buf[now].btn[i].ru.x >=c &&
	     buf[now].btn[i].ru.y >=d){
	    for(int j=0;j<a.size();j++){
	      if(buf[now].btn[i].name==a[j].name){
		buf[++now]=a[j];
		fg=0;
		fg2=1;
		break;
	      }
	    }
	    if(fg2)break;
	  }
	}
      }
      else if(s=="back" && now>0){
	now--;
	fg++;
      }
      else if(s=="forward" && fg>0 && now < 1000000)now++,fg--;
      else if(s=="show")cout << buf[now].name << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 19000
#include<bits/stdc++.h>
#define ll long long
#define Mx 3e3+5
using namespace std;
string s,t;
int dp[3005][3005];
int lcs(int i,int j)
{
    if(s[i]=='\0'||t[j]=='\0')
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    int ans = 0,ret1 = 0,ret2 = 0;
    if(s[i]==t[j])
        ans= 1+lcs(i+1,j+1);
    else
    {
        ret1 = lcs(i,j+1);
        ret2 = lcs(i+1,j);
        ans= max(ret1,ret2);
    }
    dp[i][j] = ans;
    return ans;
}
string ans;
void print_lcs(int i,int j)
{
    if(s[i]=='\0'||t[j]=='\0')
    {
        //cout<<ans<<endl;
        return;
    }
    if(s[i]==t[j])
    {
        cout<<s[i];
        print_lcs(i+1,j+1);
    }
    else
    {
        if(dp[i][j+1]>dp[i+1][j])
            print_lcs(i,j+1);
        else print_lcs(i+1,j);
    }
}
int main()
{
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    lcs(0,0);
    print_lcs(0,0);
}


Measured memory_bytes: 35840
import numpy as np
import sys
a_list = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
 
for _ in range(n):
    b = int(input())
    
    for a in a_list:
        for idx, aa in enumerate(a):
            if aa == b:
                a[idx] = 0

# 縦横対角
for i in range(3):
    if list(a_list[i, :]) == [0, 0, 0] or list(a_list[:, i]) == [0, 0, 0]:
        print("Yes")
        sys.exit()
    

# 斜め
if ([a_list[i, i] for i in range(3)] == [0, 0, 0]) or ([a_list[0, 2], a_list[1, 1], a_list[2, 0]] == [0, 0, 0]):
    print("Yes")
    sys.exit()

print("No")



        


Measured memory_bytes: 12496
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int n = 5;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int k;
  cin >> k;
  bool happy = true;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (abs(v[i] - v[j]) > k) {
	happy = false;
      }
    }
  }
  if (happy) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  return 0;
}


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

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

   bool flag = true;
   for (int i=0; i<S.size(); i++)
      if (i%2 == 0){
         if (!(S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D')){
            flag = false;
            break;
         }
      } else{
         if (!(S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D')){
            flag = false;
            break;
         }
      }

   if (flag)
      cout << "Yes" << endl;
   else
      cout << "No" << endl;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x,happy=0;
    cin >> x;
    while(x>=500){
        x-=500;
        happy+=1000;
    }
    while(x>=5){
        x-=5;
        happy+=5;
    }
    cout << happy << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll N;
    string S;
    cin >> N >> S;
    if (N % 2 == 1) {
        cout << "No\n";
        return 0;
    }
    string t1 = S.substr(0, N/2), t2 = S.substr(N/2, N/2);
    if (t1 == t2) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> primeList = getPrimeNum(10000);
		int limit;
		while((limit = Integer.parseInt(br.readLine())) != 0){
			System.out.println(getMaxTwinPrime(primeList,getLimitIndex(limit,primeList)));
		}
	}
	
	private static int getLimitIndex(int limit,List<Integer> primeList){
		int limitIndex;
		if((limitIndex = primeList.indexOf(limit)) != -1){
			return  limitIndex;
		}else{
			for(int i = 0 ; i < primeList.size() ; i++){
				if(primeList.get(i) > limit){
					return i - 1;
				}
			}
		}
		return primeList.size() - 1;
	}
	
	private static String getMaxTwinPrime(List<Integer> primeList,int limitIndex){
		for(int i = limitIndex ; 0 < i ; i--){
			for(int y = i - 1 ; 0 <= y ; y--){
				if(primeList.get(i) - primeList.get(y) == 2){
					return primeList.get(y) + " " + primeList.get(i);
				}else if(primeList.get(i) - primeList.get(y) < 2){
					continue;
				}else{
					break;
				}
			}
		}
		return null;
	} 
	
	private static List<Integer> getPrimeNum(int limit){
		List<Integer> primeList = new ArrayList<>();
		primeList.add(2);
		for(int i = 3 ; i <= limit ; i += 2){
			boolean primeFlag = true;
			for(int y = 2 ; y < i ; y++){
				if(i % y == 0){
					primeFlag = false;
					break;
				}
			}
			if(primeFlag){
				primeList.add(i);
			}
		}
		return primeList;
	}

}

Measured memory_bytes: 34820