akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n;
    cin >> n;
    vec a(n);
    loop(i, n) cin >> a[i];
    ll q;
    cin >> q;
    vec b(q), c(q);
    loop(i, q) cin >> b[i] >> c[i];
    vec count(100001); //
    loop(i, n) count[a[i]]++;
    ll S = Sum(a);
    loop(i, q)
    {
        ll siz = count[b[i]];
        count[b[i]] = 0;
        count[c[i]] += siz;
        S -= siz * b[i];
        S += siz * c[i];
        putout(S);
    }
    return 0;
}


Measured memory_bytes: 6372
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    D=defaultdict(int)
    for _ in range(M):
        a,b = MI()
        D[a]+=1
        D[b]+=1
    for v in D.values():
        if v&1:
            print("NO")
            return 
    print("YES")

if __name__ == '__main__':
    main()

Measured memory_bytes: 74840
implicit none
integer :: n,m,x
integer,allocatable :: a(:),c(:)
integer :: i,j
read *,n,m,x
allocate(a(m))
read *,(a(i),i=1,m)
allocate(c(0:n))
c(:) = 0
do i = 1, m
   c(a(i)) = 1
enddo
i = sum(c(0:x-1))
j = sum(c(x+1:n))
if (i < j) then
   write(6,'(i0)') i
else
   write(6,'(i0)') j
endif
end

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
     
    int i,n,max,min,a;
    long long int sum=0;
     
    max=-1000000;
    min=1000000;
     
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(a>max) max=a;
        if(a<min) min=a;
        sum+=a;
    }
     
    printf("%d %d %lld\n",min,max,sum);
     
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

const ll LAP_MAX=1e9;

int main(){
    ll N,L,T; cin >> N >> L >> T;
    vector<ll> X(N),pos(N);
    vector<int> W(N);
    rep(i,N){
        cin >> X[i] >> W[i];
        if (W[i]==1) pos[i]=(X[i]+T)%L;
        else pos[i]=(X[i]-T+LAP_MAX*L)%L;
    }
    ll now=0;
    rep2(i,1,3){
        ll j=3-i;
        if (W[0]==i){
            vector<ll> collision;
            rep(k,N) if (W[k]==j) collision.push_back(X[k]);
            ll cnt=collision.size();
            ll lap=2*T/L,rest=2*T-lap*L;
            if (i==1){
                now=(cnt*lap)%N;
                ll last=lower_bound(collision.begin(),collision.end(),X[0]+rest)-collision.begin();
                now=(now+last)%N;
            }
            else{
                now=(N-(cnt*lap)%N)%N;
                ll last=collision.end()-lower_bound(collision.begin(),collision.end(),X[0]-rest+L);
                now=(now-last+N)%N;
            }
        }
    }
    ll pos_now=pos[0];
    sort(pos.begin(),pos.end());
    ll start=lower_bound(pos.begin(),pos.end(),pos_now)-pos.begin();
    vector<ll> ans(N);
    rep(i,N) ans[(now+i)%N]=pos[(start+i)%N];
    rep(i,N) cout << ans[i] << endl;
}

Measured memory_bytes: 4080
// 'That's all it is. A leap of faith'

#include <bits/stdc++.h>

#define append push_back
#define L first
#define R second

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 998244353;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

template<typename Type>
long long sz(Type x) {
    return ll(x.size());
}

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

long long dp[N << 1], f[N << 1];

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, k; cin >> n >> k;

    vector<pair<long long, long long>> s(k);

    for(long long i = 0; i < k; i++) {
        cin >> s[i].L >> s[i].R;
    }

    sort(s.begin(), s.end());

    dp[1] = 1;
    for(long long i = 1; i <= n; i++) {
        (f[i] += f[i - 1]) %= MOD;
        (dp[i] += f[i]) %= MOD;
        for(long long j = 0; j < k; j++) {
            long long l = i + s[j].L, r = min(i + s[j].R, n) + 1;
            (f[l] += dp[i]) %= MOD;
            (f[r] += MOD - dp[i]) %= MOD;
        }
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 6696
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
    return ret


N, A, B = read_ints()
ab = A + B
syou, amari = divmod(N, ab)
print(syou * A + min(amari, A))


Measured memory_bytes: 3064
#include<stdio.h>

char map[10][10];

int main(){
  int i,j,k,ic=1,n,nx;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0,nx=1;i<n;i++){
      if(i%2){
	for(j=0;j<i+1;j++,nx++){
	  map[j][i-j]=nx;
	}
      }else{
	for(j=0;j<i+1;j++,nx++){
	  map[i-j][j]=nx;
	}
      }
    }
    nx=n*n;
    for(i=n-1;i>0;i--){
      if(i%2==n%2){
	for(j=n-1,k=i;j>i-1;j--,nx--,k++){
	  map[j][k]=nx;
	}	
      }else{
	for(j=n-1,k=i;j>i-1;j--,nx--,k++){
	  map[k][j]=nx;
	}
      }
    }
    printf("Case %d:\n",ic++);
    for(i=0;i<n;i++){
      for(j=0;j<n-1;j++){
	printf(" %2d",map[i][j]);
      }
      printf(" %2d\n",map[i][j]);
    }
  }while(1);
  return 0;
}

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

int main() {

long X;
cin>>X;

for(int a=0;a<=1000;a++){
  for(int b=-1000;b<=1000;b++){
    if(a*a*a*a*a-b*b*b*b*b==X){
      cout<<a<<" "<<b<<endl;
      return 0;
    }
  }
}
cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
int isPrime(int);

main(){
  int len,i;
  int A[10000];
  int ans;
  int count=0;


  scanf("%d",&len);

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

 for(i=0;i<len;i++){
   ans=isPrime(A[i]);
   if(ans == 1){
     count+=1;
   }
 }
  
 printf("%d\n",count);
 return 0;
}



int isPrime( int x ){
  int i;
  if (x <= 1) return 0;


 for(i=2;i<=x/i;i++){
   if (x % i == 0)return 0;
}
 return 1;

}

Measured memory_bytes: 632
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
bool sortcol1(const vl &a, const vl &b)
{
	return a[0]+a[1]>b[0]+b[1];
}
bool sortcol2(const vl &a, const vl &b)
{
	return a[0]-a[1]>b[0]-b[1];
}
void solve()
{
    ll n;
    cin>>n;
    vector<vl> coo(n, vl(2, 0));
    forr(i, n)
    {
    	cin>>coo[i][0]>>coo[i][1];
    }
    sort(all(coo), sortcol1);
    ll dist=(ll)abs(coo[n-1][0]+coo[n-1][1]-coo[0][0]-coo[0][1]);
    sort(all(coo), sortcol2);
    dist=max(dist, (ll)abs(coo[0][0]-coo[0][1]-(coo[n-1][0]-coo[n-1][1])));
    cout<<dist<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

int c[64][64];

void paint(int y, int x) {
  if (y < 0 || y >= 50 || x < 0 || x >= 50) return;
  if (c[y][x] == 0) return;
  c[y][x] = 0;
  for (int dy = -1; dy <= 1; ++dy) {
    for (int dx = -1; dx <= 1; ++dx) {
      paint(y + dy, x + dx);
    }
  }
}

int main() {
  int H, W;
  while (cin >> W >> H, H) {
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        cin >> c[i][j];
      }
    }
    int res = 0;
    for (int y = 0; y < H; ++y) {
      for (int x = 0; x < W; ++x) {
        if (c[y][x] == 1) {
          ++res;
          paint(y, x);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3196
function main(input) {
  const formatted_input = input.split('\n')[0].split(' ').map( x => parseInt(x, 10) );

  const A = formatted_input.sort()[2];
  const B = formatted_input.sort()[1];
  const C = formatted_input.sort()[0];

  console.log(10*A + B + C);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    ll a,b,k;cin>>a>>b>>k;
    for(ll i=100;;i--){
	if(a%i==0&&b%i==0){
	    k--;
	    if(k==0){
		cout<<i<<endl;
		break;
	    }
	}
    }
    return 0;
}




Measured memory_bytes: 256
///Mn kotr el labawy mb2t4 nawy
#include<bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 2e5 + 5;
const int MOD =  998244353;
int n, k;
ll sum[N];
int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  return 0;
  cin >> n >> k;
  for(int i = 1; i <= n; i++){
    cin >>  sum[i];
    sum[i] += sum[i-1];
    sum[i]--;
  }
  map<ll, int> mp;
  ll out = 0;

  for(int i = 0; i <= n; i++){
    if(i >= k){
        mp[sum[i-k]%k]--;
    }
    out += mp[sum[i] % k];
    mp[sum[i]%k]++;
  }

  cout << out << endl;


}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
vector <int> v[100010];
int d1[100010],d2[100010];
int main()
{
    int n,sum1=0,sum2=0;
    cin>>n;
    for(int i=1;i<=n-1;++i)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }	
    memset(d1,63,sizeof(d1));
    memset(d2,63,sizeof(d2));
    queue <int> q1;
    queue <int> q2;	
    q1.push(1);
    d1[1]=0;
    while(!q1.empty())
    {
        int u=q1.front();
        q1.pop();
        for(int i=0;i<v[u].size();++i)
        {
            if(d1[v[u][i]]>1e8)
            {
                d1[v[u][i]]=d1[u]+1;
                q1.push(v[u][i]);
            }
        }
    }
    q2.push(n);
    d2[n]=0;
    while(!q2.empty())
    {
        int u=q2.front();
        q2.pop();
        for(int i=0;i<v[u].size();++i)
        {
            if(d2[v[u][i]]>1e8)
            {
                d2[v[u][i]]=d2[u]+1;
                q2.push(v[u][i]);
            } 
        }
    }
    for(int i=1;i<=n;++i)
    {
        if(d1[i]<d2[i])
            sum1++;
        if(d1[i]>d2[i])
            sum2++;
        if(d1[i]==d2[i])
            sum1++;
    }
    if(sum1>sum2)
        cout<<"Fennec"<<endl;
    else
        cout<<"Snuke"<<endl;
    return 0;
} 

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15

 int main(){

  long long l,r,cnt=0,i;
  cin>>l>>r;
 //cin>>i;

   for(int i=l;i<=r;i++){

     long long new0 = i,fact=1,result=0;
     vector<int>ans(0);

     while(new0){
        int rem = new0%10;
        ans.push_back(rem);
        new0 = new0/10;
     }

     vector<int>::iterator it;
       reverse(ans.begin(),ans.end());

     for(it = ans.begin();it!=ans.end();it++){
         result +=  *it*(fact);
        fact = fact*10;
     }

     if(result == i)
        cnt++;
  }

   cout<<cnt<<endl;


 return 0;
 }


Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];
ll d[1000000];

void bellmanFord(int s) {
    fill(d, d + V + 10, intmax);
    d[s] = 0;
    for (int i = 0; i < V - 1; i++) {
        bool update = false;
        for (int j = 0; j < V; j++) {
            for (int k = 0; k < G[j].size(); k++) {
                edge e = G[j][k];
                if (d[j] + e.cost < d[e.to]) {
                    d[e.to] = d[j] + e.cost;
                    update = true;
                }
            }
        }
        if (!update) {
            break;
        }
    }
}

int main() {
    int E, r;
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        edge e;
        e.to = t;
        e.cost = d;
        G[s].push_back(e);
    }
    bellmanFord(r);
    for (int i = 0; i < V; i++) {
        if (d[i] == intmax) {
            cout << "INF" << endl;
        } else {
            cout << d[i] << endl;
        }
    }
}



Measured memory_bytes: 33844
N, A, B, C = list(map(int, input().rstrip().split()))
l = [int(input()) for i in range(N)]

costs = []

for i in range(2 ** (2 * N)):
    i_bin = format(i, '0' + str(2 * N) + 'b')
    cost = 0
    a = b = c = 0
    for j in range(N):
        t = i_bin[j * 2 : j * 2 + 2]
        if t == '01':
            cost += 10
            a += l[j]
        elif t == '10':
            cost += 10
            b += l[j]
        elif t == '11':
            cost += 10
            c += l[j]
    if min(a, b, c) == 0:
        continue
    cost += abs(a - A) + abs(b - B) + abs(c - C) - 30
    costs.append(cost)

print(min(costs))

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

long long sums(long long sum,string s);

int main(){
  string S;
  cin >> S;
  cout << sums(0,S) << endl;
}

long long sums(long long prev,string s){
  int s_size = s.size();
  long long sum = 0;
  for(int i=1;i<=s_size;i++){
    string now_s = "", next_s = "";
    rep(j,i){
      now_s += s.at(j);
    }
    for(int j = i; j<s_size; j++){
      next_s += s.at(j);
    }
    if(next_s != ""){
      sum += sums(prev + stoll(now_s),next_s);
    }else{
      sum += prev + stoll(now_s);
    }

  }
  return sum;
}

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

int main() {
  string S;
  cin >> S;
  
  int ans = 0;
  
  int N = S.size();
  for (int i = 0; i < N-1; i++) {
    if (S[i] != S[i+1]) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3716
#include<iostream>
using namespace std;
string a;
int ans, i;
int main()
{
	cin >> a;
	for(i = 1; i < a.size(); i ++)
	{
		if(a.substr(i, 1) != a.substr(i - 1, 1)) ans ++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
  int width, height;
  
  while(true) {
    cin >> height >> width;
    
    if(height == 0 && width == 0) {
      break;
    }
    
    string rect(width, '#');
    for(int i = 0; i < height; i++) {
      cout << rect << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3068
#include <cstring>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    string S; cin >> S;
    long long ans = 0;
    for (int s = 0; s < 1<<n; s++) {
        string r, b;
        for (int i = 0; i < n; i++)
            if ((s >> i) & 1) b.push_back(S[i]);
            else r.push_back(S[i]);
        const int rl = r.size(), bl = b.size();
        long long dp[rl+1][bl+1];
        memset(dp, 0, sizeof dp);
        for (int i = 0; i <= rl; i++) {
            for (int j = 0; j <= bl; j++) {
                if (i == 0 && j == 0) { dp[0][0] = 1; continue; }
                const char c = S[2*n-i-j];
                long long tmp = 0;
                if (i > 0 && r[i-1] == c) tmp += dp[i-1][j];
                if (j > 0 && b[j-1] == c) tmp += dp[i][j-1];
                dp[i][j] = tmp;
            }
        }
        ans += dp[rl][bl];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from math import factorial
from sys import exit, stdin
N, T = [int(_) for _ in stdin.readline().rstrip().split()]
t_list = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(N-1):
    if t_list[i+1] - t_list[i] > T:
        ans += T
    else:
        ans += t_list[i+1] - t_list[i]
ans += T
print(ans)

Measured memory_bytes: 26832
from itertools import product

H, W, K = map(int, input().split())
C = [input() for _ in range(H)]

ans = 0
for selection in product([True, False], repeat=H + W):
    row_sel = selection[:H]
    col_sel = selection[H:]
    count = 0
    for i, j in product(range(H), range(W)):
        if C[i][j] == "#" and row_sel[i] and col_sel[j]:
            count += 1
    if count == K:
        ans += 1

print(ans)

Measured memory_bytes: 9216
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			char[] s = sc.next().toCharArray();
			int[] a = new int[10];
			for(int i=0;i<13;i++) a[(int)s[i]-48]++;
			
			ArrayList<Integer> ans = new ArrayList<Integer>();
			int[] b = new int[10];
			
			for(int i=1;i<=9;i++){
				for(int j=1;j<=9;j++){
					if(a[i]<4){
						b = a.clone();
						b[i]++;
						b[j]-=2;
						for(int k=1;k<=7;k++){
							if(b[k]<0){
								b[9]=-1;
								break;
							}
							if(b[k]==1 || b[k]==4){
								b[k]--;
								b[k+1]--;
								b[k+2]--;
							}else if(b[k]==2){
								b[k]-=2;
								b[k+1]-=2;
								b[k+2]-=2;
							}
						}
						if(b[8]>=0 && b[8]%3==0 && b[9]>=0 && b[9]%3==0){
							ans.add(i);
							break;
						}
					}
				}
			}
			
			if(ans.size()==0) System.out.println(0);			
			else{
				for(int i=0;i<ans.size();i++){
					if(i!=0) System.out.print(" ");
					System.out.print(ans.get(i));
				}
				System.out.println();
			}
		}
	}
}

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

using namespace std;

int main() {
 //freopen("input.txt","r",stdin);
 int n, k;
 cin >> n >> k;
 vector <int> a(n);
 for (int i = 0; i < n; i++) {
    cin >> a[i];
 }
 sort(a.begin(), a.end());
 int ans = 0;
 for (int i = 0; i < k; i++) {
    ans += a[i];
 }
 cout << ans;
 return 0;
}



Measured memory_bytes: 3596
void main(){
	int p, q, r;
	scanf("%d %d %d", &p, &q, &r);
	min(p+q, p+r, q+r).writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2520
//file_name:ABC106_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */


int main() {
    int n,m,q;cin>>n>>m>>q;
    int count[n+1][n+1];
    rep(i,n+1){
        rep(j,n+1){
            count[i][j] = 0;
        }
    }
    rep(i,m){
        int l,r;
        cin>>l>>r;
        count[l][r]++;
    }

    int ans[n+1][n+1];
    rep(i,n+1){
        rep(j,n+1){
            ans[i][j] = 0;
        }
    }

    int sumr[n+1] = {};

    drep(i,n+1){
        if(i==0)break;
        srep(j,i,n+1){
            if(j==i){
                ans[i][j] = count[i][j];
                sumr[j] += count[i][j]; 
            }else{
                ans[i][j] = ans[i][j-1] + sumr[j] + count[i][j];
                sumr[j] += count[i][j];
            }
        }
    }

    rep(i,q){
        int p,q;
        cin >> p >> q;
        cout << ans[p][q] << endl;
    }

    return 0;
}



Measured memory_bytes: 2944
#include <iostream>
#include <string>
using namespace std;
string s;
long long k;
int main(){
    cin>>s>>k;
    for(long long i=0;i<k;i++){
        if(s[i]!='1'){
            cout<<s[i];
            return 0;
        }
    }
    cout<<1;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double x1, y1, x2, y2, t1, t2;
  t1 = (h/6 + m/360) * M_PI;
  t2 = m / 30 * M_PI;
  x1 = a * sin(t1);
  y1 = a * cos(t1);
  x2 = b * sin(t2);
  y2 = b * cos(t2);
  double res = pow(pow(x1-x2, 2) + pow(y1-y2, 2), 0.5);
  cout << setprecision(20) << res << endl;
  return 0;
}

Measured memory_bytes: 4216
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const M : usize = 1000000007;

fn inv(a: usize) -> usize {
    let m = M as i64;
    let mut a = a as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    let mut tmp;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        tmp = a;
        a = b;
        b = tmp;
        u -= t * v;
        tmp = u;
        u = v;
        v = tmp;
    }
    u %= m;
    if u < 0 {
        u += m;
    }
    return u as usize;
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut f = vec![0; n + 1];
    f[0] = 1;
    for i in 1..n + 1 {
        f[i] = f[i - 1] * i % M;
    }
    let mut g = vec![0; n + 1];
    for i in 0..n + 1 {
        g[i] = inv(f[i]);
    }
    // println!("{:?}", f);
    // println!("{:?}", g);

    for i in 1..k + 1 {
        if i > n - k + 1 {
            println!("0");
        } else {
            let a = (f[n - k + 1] * g[n - k + 1 - i] % M) * g[i] % M;
            let b = (f[k - 1] * g[k - i] % M) * g[i - 1] % M;
            // println!("{} {}", a, b);
            println!("{}", a * b % M);
        }
    }

}


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

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int tmp = 0;
    vector<int> leng;
    vector<int> gain;
    
    // enumerating switching points
    leng.push_back(0);
    for(int i = 1; i < S.length(); i++){
        if(S[i] != S[i-1]) leng.push_back(i);        
    }
    
    // calculating gain depending on each element of leng
    for(int i = 0; i < leng.size(); i++){
        if(S[leng[i]] == '0') tmp = 2*K;
        else tmp = 2*K + 1;
        
        if(i+tmp >= leng.size()) gain.push_back(N-leng[i]);
        else gain.push_back(leng[i+tmp]-leng[i]);
    }

    cout << *max_element(gain.begin(), gain.end()) << '\n';
    
    return 0;
}

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

int main(){
	string s;
	int ans=0;
	while(cin>>s){
		int c=s.length()/2;
		int cc=s.length();
		bool flag=true;
		for (int i = 0; i < c; ++i) {
			if(s[i]!=s[cc-1-i]){flag=false;break;}
		}
		if(flag)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2992
#include <iostream>
#include <string>

using namespace std;

void dfs(string s,char mx,int n){
  if(s.length() == n){
    cout << s << endl;
  }else{
    for(char c='a';c<=mx;c++){
      dfs(s+c,((c == mx) ? (char)(mx+1):mx),n);
    }
  }
}

int main(){
  int n;
  cin >> n;
  dfs("",'a',n);
  return 0;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << n-k << endl;
  return 0;
}


Measured memory_bytes: 256
dx = [2,2,2,1,0,-1,-2,-2,-2,-1,0,1]
dy = [-1,0,1,2,2,2,1,0,-1,-2,-2,-2]
def solve(x,y,XY):
	xy = XY[:]
	if len(xy) == 0: return "OK"
	sx,sy = xy.pop(0),xy.pop(0)
	for i in range(12):
		try:
			if doa(x+dx[i],y+dy[i],sx,sy): 
				r = solve(x+dx[i],y+dy[i],xy)
				if r: return r
		except:
			pass

def doa(x,y,sx,sy):
	return True if abs(x-sx) < 2 and abs(y-sy) < 2 else False

while 1:
	x,y = map(int,raw_input().split())
	if x == y == 0: break
	n = input()
	xy = map(int,raw_input().split())
	ans = solve(x,y,xy)
	print ans if ans else "NA"

Measured memory_bytes: 4280
import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed.Mutable as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace



main :: IO ()
main = do
  [r,d,x] <- map read.words <$> getLine :: IO [Int]
  forM_ (drop 1 $ take 11 $ iterate (\y -> r*y - d) x) $ \ans -> do
    print $ ans


Measured memory_bytes: 508
while True:
	try:
		n = int(raw_input())
		ans = [i for i in range(n+1)]
		m = int(raw_input())
		for i in range(m):
			a, b = map(int, raw_input().strip().split(','))
			t = ans[a]
			ans[a] = ans[b]
			ans[b] = t
		ans = ans[1:]
		for x in ans:
			print x
	except EOFError:
		break

Measured memory_bytes: 6336
n,k=map(int,input().split())

if k%2==1:
    cnt0=n//k

    print(cnt0**3)
else:
    cnt0=n//k
    cnt1=(n-k//2)//k+1 if n>=k//2 else 0
    ans=cnt0**3+cnt1**3
    print(ans)


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int p,q,r; cin >> p >> q >> r;

  int ans1=INF,ans2=INF;
  ans1 = min(p+q,r+q);
  ans2 = min(r+p,q+p);
  int ans = min(ans1,ans2);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+1;
const ll p=1e9+7;
int main()
{
	int r,g,b;
	cin>>r>>g>>b;
	int ans=(r*100+g*10+b)%4;
	if(ans)printf("NO");
	else printf("YES");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N , M ;
	cin >> N >> M ;
	vector<int> vec(N,0);
	for (int i = 0 ; i < M ; i++){ 
		//M本の道路なのでM回サーチさせないとね。
		//1が出てきたら要素の0番目に1を足す
		int a , b ;
		cin >> a >> b ;

	//if ( a == 1   if (a==2ってやるとしんどいので、これもちょっと趣向を凝らしてみよう
	//aとｂで出てきた値をｘ、ｙ として vec.at(x)に＋１という風にすれば楽かな
	//そんなことするまでもない 俺がコードを見せてやる
	vec.at(a-1) ++;
	vec.at(b-1) ++;
	}
	for (int i = 0 ; i < N ; i++){
		cout << vec.at(i) <<endl;
	}
}


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

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

	int n, l;
	cin >> n >> l;

	vector<string>	V(n);
	rep(i, n)
		cin >> V.at(i);
	sort(V.begin(), V.end());
	rep(i, n)
		cout << V.at(i);
	cout << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int H,W,K;
int dp[105][15];
signed main(){
    scanf("%lld %lld %lld",&H,&W,&K);
    rep(h,H+1){
        rep(w,W){
            if(h==0&&w==0)dp[h][w]=1;
            dp[h][w]%=mod;
            rep(i,1<<(W-1)){
                //この掛け方がOKかどうかを試す
                int ifok=true;
                rep(j,W-2){
                    if( ( (i>>j)%2 ) & ( (i>>(j+1))%2 ) ){ifok=false;break;}
                }
                if(!ifok)continue;
                //この掛け方で現在の1からの位置がどこへ移るか
                if(w!=W-1&&(i>>w)%2==1){//右
                    dp[h+1][w+1]+=dp[h][w];
                    dp[h+1][w+1]%=mod;
                }else if(w!=0&&(i>>(w-1))%2==1){//左
                    dp[h+1][w-1]+=dp[h][w];
                    dp[h+1][w-1]%=mod;
                }else{//真ん中
                    dp[h+1][w]+=dp[h][w];
                    dp[h+1][w]%=mod;
                }
            }
            //printf("%lld ",dp[h][w]);
        }
        //printf("\n");
    }
    printf("%lld\n",dp[H][K-1]%mod);
}

Measured memory_bytes: 1748
#include <bits/stdc++.h>
#define Mod 1000000007
#define INF 9e8
#define INFL 9e18
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define N 500005
#define fs first
#define sc second 
#define UNIVISITED 0
#define EXPLORED 1
#define VISITED 2
using namespace std;
typedef  long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;

ll arr[N];

int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
ios::sync_with_stdio(false);
cin.tie(0);
cin>>arr[0]>>arr[1]>>arr[2];
sort(arr,arr+3);
if(arr[0]==arr[1])
cout<<arr[2]<<endl;
else
cout<<arr[0]<<endl;













return 0;


}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N; std::cin >> N;
  std::vector<int> A(N);
  std::priority_queue<int> B;
  for(int i=0; i<N; i++) {
    std::cin >> A[i]; B.push(A[i]);
  }

  int Amax = B.top(); B.pop();
  int A2nd = B.top();

  for(int i=0; i<N; i++){
    if (A[i] != Amax) std::cout << Amax << std::endl;
    else std::cout << A2nd << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3316
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
ll N;
int main() {
	cin>>N;

	for(int i=1;;i++){
		if(i*i>N){
			cout<<(i-1)*(i-1)<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

inline void swap(int &x, int &y)
{
  x ^= y;
  y ^= x;
  x ^= y;
}

int main()
{
  int a = 0, b = 0, c = 0;
  std::cin >> a >> b >> c;

  if (a > b) swap(a, b);
  if (b > c) swap(b, c);
  if (a > b) swap(a, b);

  std::cout << a << " " << b << " " << c << std::endl;

  return 0;
}

Measured memory_bytes: 1168
import numpy as np
N = int(input())
Hs = np.array([int(i) for i in input().split()])

Hs_diff = np.array([Hs[i]-Hs[i-1] for i in range(len(Hs))])
Hs_diff[0] = 0

Hs_bool = Hs_diff>0
indices = np.append([0], np.append(np.where(Hs_bool)[0], [len(Hs_bool)]))
indices_diff = np.array([indices[i]-indices[i-1] for i in range(len(indices))])

print(max(indices_diff-1))

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

int x[3];

int main()
{
    cin >> x[0] >> x[1] >> x[2];
    sort(x, x + 3);

    int cnt = 0;
    
    int a = (x[2] - x[1]) / 2;
    cnt += a;

    int b = (x[2] - x[1]) % 2;

    if (b % 2 != 0)
    {
        x[1]++;
        x[0]++;
        cnt++;
    }

    if ((x[2] - x[0]) % 2 == 0)
    {
        cnt += (x[2] - x[0]) / 2;
    }
    else
    {
        cnt++;
        cnt += (x[2] + 1 - x[0]) / 2;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


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

    int ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (i == j) continue;
                ans += d[i]*d[j];
        }
    }

    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 888
package main

import "fmt"

func main() {
	var O, E string
	fmt.Scan(&O, &E)
	s := make([]byte, len(O)+len(E))
	for i := 0; i < len(O); i++ {
		s[i*2] = O[i]
	}
	for i := 0; i < len(E); i++ {
		s[1+i*2] = E[i]
	}
	fmt.Println(string(s))
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl


int p,q;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());
  int N=b.size();

  int max=-1,min=INF;
  for(int i=0;i<n;i++){
    if(a[i]>max)max=a[i];
    if(a[i]<min)min=a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]==max)q++;
    else if(a[i]==min)p++;
  }
  bool flag=false;
  if(max==min){
    if(n-1==max || n>=max*2){
      flag=true;
    }
  }
  if(max==min+1){
    if((max>p)&&q>=2*(max-p))flag=true;
  }
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}

void init_comb(ll n_max) {
	//大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < n_max + 100; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}


}

ll comb(ll a, ll b) { //aCbをmod計算
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}

ll devi(ll a, ll b) {
	return comb(a - b  + b - 1, b - 1) % M;
}

int main()
{
	ll N, K;
	cin >> N >> K;
	init_comb(N + 100);

	vec ans(K + 1, 0);
	FOR(i, 1, K + 1) {
		if (N == K && i == 1) ans[i] += 1;
		if (i != 1 && N - K >= i - 1) {
			ans[i] += devi(N - K, i - 1);
		}
		// debug(ans[i]);
		if (N - K >= i + 1) {
			ans[i] += devi(N - K, i + 1 );
		}
		// debug(ans[i]);
		if (N - K >= i) {
			ans[i] += 2 * devi(N - K, i);
		}
		// debug(ans[i]);

		ans[i] *= devi(K, i) % M;
		ans[i] %= M;
		// debug(ans[i]);
		cout << ans[i] % M << endl;
	}
//
	// debug(comb(K, K));
	return 0;
}

Measured memory_bytes: 4992
// AOJ 2731 Shifting a Matrix
// 2018.2.11 bal4u

#include <stdio.h>
#include <ctype.h>

#define SIZE 1000

int N;
typedef struct { short r, c; } T;
T tbl[SIZE+2][101][101];
char s[1002], *p;
char used[SIZE+2];

char *seq(int res, char *s);

// malloc
int new() {	int i;
	for (i = 0; i < SIZE; i++) if (!used[i]) { used[i] = 1; break; }
	return i;
}

// free
void dis(int k) { used[k] = 0; }

char *in(int *res, char *p) { int n = 0;
	while (isdigit(*p)) n = (n<<3)+(n<<1) + (*p++ & 0xf); *res = n; return p;
}

void calc(int a, int b)
{
	int r, c;
	int tmp;

	tmp = new();
	for (r = 0; r < N; r++) for (c = 0; c < N; c++) {
		tbl[tmp][r][c] = tbl[a][tbl[b][r][c].r][tbl[b][r][c].c];
	}
	for (r = 0; r < N; r++) for (c = 0; c < N; c++) tbl[a][r][c] = tbl[tmp][r][c];
	dis(tmp);
}

char *ope(int a, char *s)
{
	int k, r, c;
	char x;

	x = *s++;
	s = in(&k, s), k--;
	for (r = 0; r < N; r++) for (c = 0; c < N; c++)
		tbl[a][r][c].r = r, tbl[a][r][c].c = c;

	if      (x == 'L') for (c = 0; c < N; c++) tbl[a][k][c].c = (c+1  ) % N;
    else if (x == 'R') for (c = 0; c < N; c++) tbl[a][k][c].c = (c-1+N) % N;
    else if (x == 'U') for (r = 0; r < N; r++) tbl[a][r][k].r = (r+1  ) % N;
	else               for (r = 0; r < N; r++) tbl[a][r][k].r = (r-1+N) % N;
	return s;
}

char *rep(int a, char *s)
{
	int n, r, c;
	int b;
	
	b = new();
	s = seq(b, s)+1;
	s = in(&n, s);
	for (r = 0; r < N; r++) for (c = 0; c < N; c++)
		tbl[a][r][c].r = r, tbl[a][r][c].c = c;

	while (n) {
		if (n & 1) calc(a, b);
		calc(b, b);
		n >>= 1;
	}
	dis(b);
	return s;
}

char *seq(int res, char *s)
{
	int r, c;
	int tmp;

	for (r = 0; r < N; r++) for (c = 0; c < N; c++)
		tbl[res][r][c].r = r, tbl[res][r][c].c = c;
	tmp = new();
	while (*s == '(' || isalpha(*s)) {
		if (*s == '(') s = rep(tmp, s + 1);
		else s = ope(tmp, s);
		calc(res, tmp);
	}
	dis(tmp);
	return s;
}

int main()
{
	int L, r, c;
	int ans;
	
	fgets(p=s, 16, stdin), p = in(&N, p), in(&L, p+1);
	fgets(s, 1002, stdin);

	ans = new();
	seq(ans, s);
	for (r = 0; r < N; r++) {
		printf("%d", N*tbl[ans][r][0].r + tbl[ans][r][0].c + 1);
		for (c = 1; c < N; c++)
			printf(" %d", N*tbl[ans][r][c].r + tbl[ans][r][c].c + 1);
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 28472
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll dp_digit[10][10];

int main()
{
    
    int i,j;
    int n;
    cin>>n;

    int power=1;
    for(i=1;i<=n;i++)

    {



        int d1,d2;
        d1=i%10;
        j=i;
        while((j/10))
        {

           j=j/10;

        }
        d2=j;

        if(d1!=0 && d2 !=0)
            dp_digit[d1][d2]++;





    }

    ll ans=0;

    for(i=1;i<=9;i++)
        for(j=1;j<=9;j++)
         ans=ans+dp_digit[i][j]*dp_digit[j][i];






    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

m = len(S)
n = len(T)

ans = n
for i in range(m - n + 1):
    d = 0
    for j in range(n):
        if S[i + j] != T[j]:
            d += 1
    if ans > d:
        ans = d
print(ans)

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

#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#define popCnt(x) (__builtin_popcountll(x))

typedef long long Long;
const int N = 505;
int dist[N][N];
bool vis[N][N];

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

void dfs(int i, int j, int d) {
    if (d >= dist[i][j]) return;
    dist[i][j] = d;
    d += !vis[i][j];
    for (int x = 0; x < 4; ++x) {
        dfs(i + dx[x], j + dy[x], d);
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            dist[i][j] = min(min(i - 1, j - 1), min(n - i, n - j));
        }
    }
    for (int i = 0; i <= n + 1; ++i) {
        vis[0][i] = vis[n + 1][i] = vis[i][0] = vis[i][n + 1] = true;
    }
    int res = 0;
    for (int i = 1; i <= n * n; ++i) {
        int c;
        cin >> c;
        --c;
        int x = c / n + 1, y = c % n + 1;
        assert(dist[x][y] == 0 || i + 1 < n * n);
        res += dist[x][y];
        vis[x][y] = true;
        for (int d = 0; d < 4; ++d) {
            dfs(x + dx[d], y + dy[d],
                dist[x][y]);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 20012