akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second

/* STL */
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a)   reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n) i=1;i<=(n);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";

int main()
{

   Ezio
   ll t,m,n,x,a,b;
   string s;

   cin>>n>>s;
   m=x=0;

   fr(i,n){
       if(s[i]!=s[i-1]) m++;
   }
   cout<<m<<endl;
   return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 100011;
const ll INF = 5e16;
const ll P = 1e9 + 7;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll n, k, a[N];
	
	inline ll power ( ll a, ll b ) {
		ll res = 1;
		for (; b; b >>= 1, a = a * a % P) 
			res = (b & 1)? res * a % P: res; return res;
	}
	
	int main() {
		n = read(), k = read();
		For ( i, 1, n ) a[i] = read();
		
		ll A1 = 0;
		For ( i, 1, n ) For ( j, i + 1, n ) 
			if (a[i] > a[j]) ++A1;
		
//		ll A2 = 0;
//		For ( i, n + 1, 2 * n ) a[i] = a[i - n];
//		For ( i, 1, 2 * n ) For ( j, i + 1, 2 * n ) 
//			if (a[i] > a[j]) ++A2;
//			
//		ll A3 = 0;
//		For ( i, 2 * n + 1, 3 * n ) a[i] = a[i - n];
//		For ( i, 1, 3 * n ) For ( j, i + 1, 3 * n ) 
//			if (a[i] > a[j]) ++A3;
//		cout << "!" << A1 << " " << A2 << " " << A3 << endl;
//		if (k == 1) return wln(A1), 0;
//		if (k == 2) return wln(A2), 0;
		
		ll A = 0;
		For ( i, 1, n ) {
			ll now = 0;
			For ( j, 1, n ) now += a[i] > a[j];
			A += now;
		}
		ll inv2 = power(2, P - 2);
		ll Ans = k * A1 % P + 
			k * (k - 1) % P * A % P * inv2 % P;
		
		return wln(Ans% P), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*
1: A1
2: A1 + A1 + A
3: A1 + A1 + A + A1 + 2 * A
k * A1 + k * (k - 1) * A

1 * (A2 - A1)
2 * (A2 - A1)

(1 + 2 + 3 + ... + k - 1) * (A2 - A1)
*/






Measured memory_bytes: 256
#include<stdio.h>

#define INF 10000000

int c[101][101];
int d[101];
int f[101];
int a;

void abc(int);

int main()
{
    int i,j;
    int k,l,m,n;
    
    scanf("%d",&a);
    
    for(i=0;i<a;i++) d[i] = INF;
    for(i=0;i<a;i++)
        for(j=0;j<a;j++) c[i][j] = INF;
    
    for(i=0;i<a;i++){
        scanf("%d%d",&k,&l);
        for(j=0;j<l;j++){
            scanf("%d%d",&m,&n);
            c[k][m] = n;
        }
    }
    
    abc(0);
    
    for(i=0;i<a;i++){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}


void abc(int r)
{
    int i,j;
    
    d[r] = 0;
    
    while(1){
        int t=-1;
	
        for(i=0;i<a;i++){
            if(f[i]==0 && (t==-1 || d[i] < d[t])){
                t = i;
            }
        }
	
        if(t == -1) break;
	
        f[t] = 1;
	
        for(i=0;i<a;i++){
            int tmp = d[t]+c[t][i];
            d[i] = d[i] < tmp ? d[i] : tmp;
        }
    }
}



Measured memory_bytes: 2052
fun main(args: Array<String>) {
    val map = mutableMapOf<String, Int>()
    val n = readInteger()
    repeat(n) {
        val s = readLine()!!
        map[s] = if (map[s] == null) 1 else map[s]!! + 1
    }

    val maxNum = map.maxBy { it.value }!!.value
    val list = mutableListOf<String>()
    for (entry in map) {
        if (entry.value == maxNum) {
            list += entry.key
        }
    }

    println(list.sorted().joinToString("\n"))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 86036
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0 || a[i - 1] < a[i]) {
            bool f = true;
            for (int j = i + 1; j < n; j++) {
                if (a[j - 1] < a[j]) {
                    chmax(ans, j - i - 1);
                    f = false;
                    break;
                }
            }
            if (f) {
                chmax(ans, n - 1 - i);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key, null, null, null);
    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key, null, null, null);
      while (x !== null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      newNode.parent = y;
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  printByIneorder() {
    let str = '';
    let innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root)
    console.log(str);
  }

  printByPreorder(n = this.root) {
    let str = '';
    let innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root)
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.map((line) => line.split(' ')).forEach(function(cmd) {
    switch(cmd[0].charAt(0)) {
    case 'i': tree.insert(Number(cmd[1])); break;
    default: tree.print();
    }
  });

})();



Measured memory_bytes: 269300
# coding: UTF-8
from collections import deque
n,m = map(int,input().split())
link = [[] for _ in range(n)]
part = [-1 for _ in range(n)]
for _ in range(m):
  u,v = map(int,input().split())
  link[u].append(v)
  link[v].append(u)

searched = set()
queue = deque()
pindex = 0
for u in range(n):
  if u not in searched:
    queue.append(u)
    pindex += 1
    searched.add(u)
    while queue:
      v = queue.popleft()
      part[v] = pindex
      for w in link[v]:
        if w not in searched:
          part[w] = pindex
          queue.append(w)
          searched.add(w)

q = int(input())
answers = []
for _ in range(q):
  s,t = map(int,input().split())
  if part[s] == part[t]:
    answers.append("yes")
  else:
    answers.append("no")

for answer in answers:
  print(answer)


Measured memory_bytes: 29492
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

import collections
import numpy as np

# = input()
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
#

N = int(input())

yakusu = make_divisors(N)
yakusu.sort()
ans = np.inf
for y in yakusu:
  if y + N // y < ans:
    ans = (y + N // y) - 2

print(ans)


Measured memory_bytes: 12676
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    int N = S.length()-1;
    int n1 = (N)/2;
    int n2 = (N)/2+1;
    bool f=true;
    //cerr << N << " " << n1 << " " << n2 << endl;
    for(int i=0;i<N/2;i++){
        if(S[i]!=S[N-i]) f=false;
    }
    for(int i=0;i<n1/2;i++){
        if(S[i]!=S[n1-i-1]) f=false;
    }
    for(int i=0;i<N/2;i++){
        if(S[n2+i]!=S[N-i]) f=false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int n,m;cin>>n>>m;
  V<int> s(m);
  V<char> c(m);
  rep(i,0,m){
    cin>>s[i]>>c[i];
    s[i]--;
  }

  rep(i,0,1000){
    string now=to_string(i);

    if(n!=siz(now))continue;

    bool ok=true;
    rep(j,0,m){
      if(now[s[j]]!=c[j])ok=false;
    }

    if(!ok)continue;
    else{
      cout<<i<<ENDL;
      return 0;
    }
  }

  cout<<-1<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;
int main(){
  int N, m;
  cin >> N >> m;
  vector< bool > shop(N + 1, 0);
  for(int i = 0; i < m; ++i){
    int c, d;
    cin >> c >> d;
    fill( shop.begin() + c, shop.begin() + d, true);
  }
  cout << N + 1 + count(shop.begin(), shop.end(), true) * 2 << endl;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_S = 1000;
string s, t;
int S, T;
int dp[MAX_S+1][MAX_S+1];

int main()
{
  cin >> s >> t;
  S = s.size();
  T = t.size();

  erep(i, 0, S) erep(j, 0, T) dp[i][j] = INF;
  erep(i, 0, S) dp[i][0] = i;
  erep(j, 0, T) dp[0][j] = j;

  erep(i, 1, S) erep(j, 1, T){
    dp[i][j] = dp[i-1][j-1];
    if(s[i-1] != t[j-1]){
      minup(dp[i][j], min(dp[i-1][j], dp[i][j-1]));
      dp[i][j] += 1;
    }
  }

  cout << dp[S][T] << endl;

  return 0;
}

Measured memory_bytes: 5104
def main():
    import sys
    from collections import defaultdict
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, M, Q = [int(x) for x in input().strip().split()]
    abcd = [0] * Q
    for q in range(Q):
        abcd[q] = [int(x) for x in input().strip().split()]

    abcd.sort(key=lambda x:(x[0],x[1]))
    vecs = []

    def makevecs(n, vecs, A):
        if n == N:
            vecs.append(A)
            return None
        for b in range(A[-1], M+1):
            makevecs(n+1, vecs, A+[b])
        return None
        
    makevecs(1, vecs, [1])
    ans = 0
    for vec in vecs:
        ans_ = 0
        for q in range(Q):
            a, b, c, d = abcd[q]
            if vec[b-1] - vec[a-1] == c:
                ans_ += d
        
        ans = max(ans, ans_)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 16596
h,w,c,S,max,C,N;
int *_M;
int D(x,y){
	int r=1;
	_M[x+(w+2)*y]=N;
	if(_M[x-1+(w+2)*y]==C)r+=D(x-1,y);
	if(_M[x+1+(w+2)*y]==C)r+=D(x+1,y);
	if(_M[x+(w+2)*(y-1)]==C)r+=D(x,y-1);
	if(_M[x+(w+2)*(y+1)]==C)r+=D(x,y+1);
	return r;
}
E(int d,int *M){if(d<4||M[1+w+2]!=c){
	int *m=malloc(S);
	if(d==4){
		memcpy(_M=m,M,S);
		C=m[1+w+2],N=c;D(1,1);
		C=m[1+w+2],N=-1;int k=D(1,1);
		if(max<k)max=k;
	}else{
		int i=1;
		for(;i<7;i++)if(M[1+w+2]!=i){
			memcpy(_M=m,M,S);
			C=m[1+w+2],N=i;D(1,1);
			E(d+1,m);
		}
	}
	free(m);
}}
a[100];
main(i,j){for(;scanf("%d%d%d",&h,&w,&c),c;printf("%d\n",max)){
	memset(a,0,S=4*(w+2)*(h+2));
	for(j=1;j<h+1;j++)for(i=1;i<w+1;i++)scanf("%d",a+i+(w+2)*j);
	E(max=0,a);
}}

Measured memory_bytes: 620
#include <stdio.h>

int main(void){
    int N,M,C;
    scanf("%d %d %d",&N,&M,&C);
    int B[M],A[N][M];
    for(int i=0;i<M;i++)
    scanf("%d",&B[i]);
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            scanf("%d",&A[i][j]);
        }
    }    

    //////////////*確認用*///////////////////
    /*
    printf("------B行列------\n");
    for(int i=0;i<M;i++)
    printf("%d ",B[i]);
    printf("\n");
    printf("------A行列------\n");
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            printf("%d ",A[i][j]);
        }
        printf("\n");
    }
    */
    /////////////////////////////////////////
    int count=0;
    for(int i=0;i<N;i++){
        int sum=0;
        for(int j=0;j<M;j++){
            sum=sum+B[j]*A[i][j];
        }        
        sum=sum+C;
        //printf("sumは%d\n",sum);

        if(sum>0){
        count+=1;
        }
    }

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

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

using namespace std;

int N,M;
int pre[100005];

int main()
{
	cin >> N >> M;
	for (int i=1; i<=M; i++)
	{
		int L,R;
		cin >> L >> R;
		pre[L]++;
		pre[R+1]--;
	}
	for (int i=1; i<=N; i++) pre[i]+=pre[i-1];
	cout << count(pre+1,pre+N+1,M);
	return 0;
}

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

using namespace std;

int main(){
    int n,k,d,a[107];
    int cnt=0;
    cin>>n;
    cin>>k>>d;
    for(int i=0;i<n;i++){
        cin>>a[i];

        for(int j=1;j<=k;j+=a[i]){
            cnt++;
        }
    }
    cout<<cnt+d;
}


Measured memory_bytes: 256
from math import pow
from collections import deque, Counter
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())

def cal_score(N, K, records):
    sorted_recs = sorted(records, key=lambda x: -x[1])
    target_queue = deque(sorted_recs[0:K]) # only allow pop() action, so use dequeue
    compare_queue = deque(sorted_recs[K:])
    distinct_set = set()
    dup_queue = deque()
    score = 0
    for neta_point in target_queue:
        score += neta_point[1]
        if neta_point[0] not in distinct_set:
            distinct_set.add(neta_point[0])
        else:
            dup_queue.append(neta_point)

    cardinality = len(distinct_set)
    score += pow(cardinality, 2)
    score = int(score)
    new_scores = deque()
    new_scores.append(score)
    # start iteration and comparing gain and lost
    while compare_queue:
        comp = compare_queue.popleft()
        if comp[0] in distinct_set:
            continue
        elif len(dup_queue) < 1:
            break
        else:
            old = dup_queue.pop()
            inc = 2 * len(distinct_set) + 1
            dec = old[1] - comp[1]
            delta = inc - dec
            new_score = new_scores[-1] + delta
            new_scores.append(new_score)

            distinct_set.add(comp[0])
    # both queues are drained
    return max(new_scores)

N, K = li()
records = [tuple(li()) for i in range(N)]
score = cal_score(N, K, records)
print(score)


Measured memory_bytes: 22576
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
int r;
double dp[301][301];
void solve() {
	cin >> r;
	cout << 2.0*PI*r << endl;
}
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

Measured memory_bytes: 3776
#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() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    vector<int> sortp(n);
    rep(i, n) sortp[i] = p[i];
    sort(sortp.begin(), sortp.end());
    
    rep(i, n) {
        if (sortp[i] != p[i]) break;
        if (i == n-1) {
            cout << "YES" << endl;
            return 0;
        }
    }

    bool ok = false;
    rep(j, n)rep(i, j) {
        swap(p[i], p[j]);
        rep(k, n) {
            if (sortp[k] != p[k]) break;
            if (k == n-1) {
                cout << "YES" << endl;
                return 0;
            }
        }        
        swap(p[i], p[j]);
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
vector<int>g[1100];
vector<pair<int,int> >rev[1100];
int bfs[1100][2];
int use[1100];
int v[1100][2];
int main(){
	int a;
	while(scanf("%d",&a),a){
		int b,c,d;scanf("%d%d%d",&b,&c,&d);
		b--;c--;
		for(int i=0;i<a;i++){
			bfs[i][0]=bfs[i][1]=999999999;
			v[i][0]=v[i][1]=0;
			use[i]=999999999;
			g[i].clear();rev[i].clear();
		}
		for(int i=0;i<d;i++){
			int p,q;scanf("%d%d",&p,&q);
			p--;q--;
			g[p].push_back(q);
			rev[q].push_back(make_pair(p,i+1));
		}
		priority_queue<pair<pair<int,int>,pair<int,int> > >Q;
		Q.push(make_pair(make_pair(0,0),make_pair(b,0)));
		bfs[b][0]=0;
		while(Q.size()){
			int cost=-Q.top().first.first;
			int num=-Q.top().first.second;
			int at=Q.top().second.first;
			int st=Q.top().second.second;
			Q.pop();
			for(int i=0;i<g[at].size();i++){
				if(bfs[g[at][i]][st]>cost+1||(st&&bfs[g[at][i]][st]==cost+1&&use[g[at][i]]>use[at])){
					bfs[g[at][i]][st]=bfs[at][st]+1;
					if(st)use[g[at][i]]=use[at];
					Q.push(make_pair(make_pair(-cost-1,-num),make_pair(g[at][i],st)));
				}
			}
			if(!st){
				for(int i=0;i<rev[at].size();i++){
					if(bfs[rev[at][i].first][1]>cost+1||(bfs[rev[at][i].first][1]==cost+1&&use[rev[at][i].first]>rev[at][i].second)){
						bfs[rev[at][i].first][1]=bfs[at][st]+1;
						use[rev[at][i].first]=rev[at][i].second;
						Q.push(make_pair(make_pair(-cost-1,-use[rev[at][i].first]),make_pair(rev[at][i].first,1)));
					}
				}
			}
		}
		if(bfs[c][0]<=bfs[c][1])printf("%d 0\n",bfs[c][0]);
		else printf("%d %d\n",bfs[c][1],use[c]);
	}
}

Measured memory_bytes: 1496
S = input()
N = len(S)
ans = [0]*N
for i in range(N-1):
    if S[i] == 'R' and S[i+1] == 'L':
        p = i
        c = 0
        ans[i] += 1
        while p-1 >= 0 and S[p-1] == 'R':
            p -= 1
            ans[i if c else i+1] += 1
            c ^= 1
        q = i+1
        c = 0
        ans[i+1] += 1
        while q+1 < N and S[q+1] == 'L':
            q += 1
            ans[i+1 if c else i] += 1
            c ^= 1
print(*ans)

Measured memory_bytes: 6400
gets
ws = gets.strip.split(" ").map(&:to_i)

ans = 10001
0.upto(ws.size - 2) do |i|
  s1 = 0
  0.upto(i) do |j|
    s1 += ws[j]
  end

  s2 = 0
  (i + 1).upto(ws.size - 1) do |j|
    s2 += ws[j]
  end

  s = (s2 - s1).abs
  ans = s if s < ans
end

puts ans


Measured memory_bytes: 1788
(defun bishop ()
  (let ((h (read))
        (k (read))
        (ans 0))
    (if (or (= h 1) (= k 1))
        (setf ans 1)
        (if (zerop (rem (* h k) 2))
            (setf ans (floor (* h k) 2))
            (setf ans (+ (floor (* h k) 2) 1))))
        
    (format t "~d~%" ans)))


(bishop)

Measured memory_bytes: 15976
#棒の組み合わせを算出するためにitertoolsモジュールをインポートする
import itertools

# 棒の数を入力する
N = int(input())
# 棒の長さをスペース区切りで入力し、格納する
L = map(int,input().split())

#カウントを初期化する
count = 0
#　入力された棒から3本の組み合わせをxに代入してループさせる
for x in itertools.combinations(L,3) :
    #　そもそも同じ長さの棒が含まれていないことを確認する
    if x[0] != x[1] and x[0] != x[2] and x[1] != x[2]:
        # 三角形の辺の条件である2辺の和＞残りの1辺であるか判定する
        if x[0] + x[1] > x[2] and x[0] + x[2] > x[1] and x[1] + x[2] > x[0]:
            count = count + 1   
    
print(count)



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

using namespace std;
int main()
{
    int a,c;
    string b;
    cin>>a;
    cin>>b;
    c = b.size();
    if(c > a){
        b.resize(a);
        cout<<b<<"..."<<endl;
    }
    else{
        cout<<b;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;

int main(){
  int N; cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P.at(i);
  
  int res = 0;
  int now_min = INF;
  rep(i, N){
    if(now_min > P.at(i)) {
      now_min = P.at(i);
      res++;
    }
  }
  
  cout << res;
  
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define int ll

const int N = 2e5;
const int INF = 1e9;

int ta, ua, tp, ans;

main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> ua >> ta >> tp;
	ans += min(tp, ua);
	tp -= min(tp, ua);
	if(tp == 0) {
		cout << ans + ta;
		return 0;
	}
	int cost = min(tp, ta);
	ans += (cost * 2);
	tp -= cost;
	ta -= cost;
	if(tp == 0) {
		cout << ans + ta;
		return 0;
	}
	if(ta == 0) {
		cout << ans + 1;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
import copy
U = copy.copy(L)
for i in range (0, N):
	L[i]+=(i+1)
	U[i]= -U[i]+(i+1)


L = sorted(L)
U = sorted(U)

import bisect

count = 0
for i in range (0, N):
	count+= bisect.bisect_right(U, L[i])-bisect.bisect_left(U, L[i])
    
print(count)

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

int main(){
	int x, y;
	cin >> x >> y;
	if (x > y) 
		cout << "a > b" << endl;
	else if (x < y)
		cout << "a < b" << endl;
	else 
		cout << "a == b" << endl;
	return 0;
}

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

using namespace std;

int main() {
	int n;

	cin >> n;

	vector <int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.rbegin(), a.rend());

	long long int ans = a[0];
	int j = 2;

	for (int i = 1; i < n && j < n; i++) {
		ans = ans + a[i];
		j++;
		
		if (j == n) {
			break;
		}

		ans = ans + a[i];
		j++;
	}

	cout << ans << "\n";

	return 0;
}

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

int main() {
	int N, A, B, C, D;
	string S;
	cin >> N >> A >> B >> C >> D >> S;

	S = "#" + S + "#";

	auto can_reach = [&](int start, int end) {
		for (int i = start; i + 1 <= end; i++) {
			if (S[i] == '#' && S[i + 1] == '#') return false;
		}
		return true;
	};

	if (!can_reach(A, C) || !can_reach(B, D)) {
		cout << "No" << endl;
		return 0;
	}

	if (C > D) {
		bool snuke_can_over = false;
		for (int i = B; i <= D; i++) {
			if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
				snuke_can_over = true;
			}
		}
		if (!snuke_can_over) {
			cout << "No" << endl;
			return 0;
		}
	}	
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 772
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

#define int ll
template < class T >
vector< T > fzt(vector< T > a, bool toUpper) {
	int n = a.size();
	for (int i = 1; i < n; i <<= 1)
		for (int j = 0; j < n; j++)
			if ((j & i) == 0) {
				if (toUpper) {
					a[j] += a[j | i];
				}
				else {
					a[j | i] += a[j];
				}
			}
	return a;
}
template < class T >
vector< T > fmt(vector< T > a, bool toUpper) {
	int n = a.size();
	for (int i = 1; i < n; i <<= 1)
		for (int j = 0; j < n; j++)
			if ((j & i) == 0) {
				if (toUpper) {
					a[j] -= a[j | i];
				}
				else {
					a[j | i] -= a[j];
				}
			}
	return a;
}
template < class T >
vector< T > convOR(vector< T > a, vector< T > b) {
	a = fzt(a, 0);
	b = fzt(b, 0);
	for (size_t i = 0; i < a.size(); i++) a[i] *= b[i];
	return fmt(a, 0);
}
int m;
vector<int> kouho;
vector<pair<int,int>> vertexs[100];
//MODを取らない！(素振り)
vector<ll> dp[51];
int tmp[(1 << 20)] = {};
vector<int> go;
void dfs(int now, int back) {
	REP(q, (1 << m)) {
		dp[now].push_back(0);
	}
	int ok = 1;
	int maximum = 0;
	for (auto x : vertexs[now]) {
		if (x.first == back) continue;
		dfs(x.first, now);
		REP(i, (1 << m)) {
			go[i] = 0;
		}
		for (int q = (1 << m) - 1; q >= 0; --q) {
			if (dp[x.first][q] == 0) continue;
			go[q] += dp[x.first][q];
			go[q | x.second] += dp[x.first][q];
		}
		if (ok == 1) {
			REP(j, (1 << m)) {
				if (go[j] == 0) continue;
				dp[now][j] = go[j];
			}
			ok = 0;
		}
		else {
			dp[now] = convOR(go, dp[now]);
		}
	}
	if (ok == 1) {
		dp[now][0] = 1;
	}
	return;
}
int finding_target(int now, int back, int value, int adding) {
	if (now == value) {
		REP(q, vertexs[now].size()) {
			if (vertexs[now][q].first == back) {
				vertexs[now][q].second += adding;
			}
		}
		return 1;
	}
	for (int i = 0; i < vertexs[now].size();++i) {
		if (vertexs[now][i].first == back) continue;
		int next = finding_target(vertexs[now][i].first, now, value, adding);
		if (next == 1) {
			vertexs[now][i].second += adding;
			REP(q, vertexs[now].size()) {
				if (vertexs[now][q].first == back) {
					vertexs[now][q].second += adding;
				}
			}
			return 1;
		}
	}
	return 0;
}
void solve(){
	int n;
	cin >> n;
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		vertexs[a].push_back(mp(b, 0));
		vertexs[b].push_back(mp(a, 0));
	}
	cin >> m;
	REP(i, (1 << m)) {
		go.push_back(0);
	}
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		assert(finding_target(a, -1, b, (1 << i)) == 1);
	}
	dfs(0, -1);
	cout << dp[0][(1 << m) - 1] << endl;
}

#undef int
int main() {
	init();
	solve();
}

Measured memory_bytes: 434520
#include <bits/stdc++.h>
#include <string>
#include <vector>
#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(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> cnt(4);
    rep(i,n) {
        string s;
        cin >> s;
        rep(j,s.size()-1){  
            if(s[j]=='A'&&s[j+1]=='B') cnt[0]++;
        }
        if(s[0]=='B'){
            if(s[s.size()-1]=='A') cnt[1]++;
            else cnt[3]++;
        }else if(s[s.size()-1]=='A') cnt[2]++;
    }
    //rep(i,4) cout << cnt[i] << endl;
    if(cnt[1] >= 1){
        cnt[0] += cnt[1]-1;
        cnt[1] = 1;
    }
    if(cnt[2]+cnt[3]>0) cnt[0] += cnt[1]+min(cnt[2],cnt[3]);
    cout << cnt[0] << endl;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll i=1,c=1;
    char a;
    a=s[0];
    while(i<n)
    {
       if(s[i]==a)
       {
          a=a;
          c=c;
       }
       else
       {
          a=s[i];
          c=c+1;
       }
       i++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint p(n);
    rep(i, n) cin >> p[i];
    sort(rall(p));

    int ans = accumulate(all(p), 0) - p[0]/2;

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
	int n,t;
	while(cin >> n && n){
		int p[7]={0};
		for(int i=0;i<n;i++){
			cin >> t;
			if(t>60)t=60;
			p[t/10]++;
		}
		for(int i=0;i<7;i++){
			cout << p[i] << endl;
		}
	}
}

Measured memory_bytes: 864
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from statistics import median

n=int(input())
l1=[]
l2=[]
for i in range(n):
  a,b=nii()
  l1.append(a)
  l2.append(b)

m1=median(l1)
m2=median(l2)
ans=m2-m1

if n%2==0:
  ans*=2

print(int(ans+1))

Measured memory_bytes: 28816
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for( int i = 1; i <= n; i++)
    {
        for( int j = 1; j <= m; j++)
        {
            string s;
            cin >> s;
            if( s == "snuke")
            {
                printf("%c%d\n", j + 'A' - 1, i);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;
 
#define mod 1e9+7
 
typedef long long ll;
 

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

   	int len=ip.size();
   	string firstPart=ip.substr(0,(len-1)/2);
   	string secondPart=ip.substr((len+3)/2-1,len-1);


   	string temp1=firstPart,temp2=secondPart,temp3=ip;

   	reverse(temp1.begin(),temp1.end());
   	reverse(temp2.begin(),temp2.end());
   	reverse(temp3.begin(),temp3.end());


   	if((temp1==firstPart)&&(temp2==secondPart)&&(temp3==ip))
   		cout<<"Yes";
   	else
   		cout<<"No";


    return 0;
}
     

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int n;
void dfs(string s,int sum,char mx){
	if(sum==n){
		cout<<s<<endl;
		return ;
	}
	for(char c='a';c<=mx+1;c++){
		dfs(s+c,sum+1,max(mx,c)); 
	}
}
int main(){
	cin>>n;
	dfs("a",1,'a');
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n,r;cin >> n >> r;
    if(n>=10){
        cout << r << endl;
        return 0;
    }
    else{
        cout << r+(100*(10-n)) << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> c(h);
    rep(i,h){
            cin>>c[i];
    }
    int64_t ans=0;
  int64_t calc=0;
    vector<vector<bool>> visited_black(h,vector<bool> (w,false));
    //queue <pair<int,int>> q;
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    //cout << dis[sy][sx]<<endl;
    rep(k,h){
        rep(l,w){
            if(c[k][l]=='.' || visited_black[k][l])continue;
          bool ab=true;
          rep(t,4){
                    int ny = k + dy[t];
                    int nx = l + dx[t];
                    if(nx<0||ny<0||ny>=h||nx>=w){
                        continue;
                    }
            	if(c[ny][nx]=='.') ab=false;
          }
          if(ab) continue;
            int sy=k,sx=l;
            vector<vector<bool>> visited(h,vector<bool> (w,false));
            queue <pair<int,int>> q;
            q.push(make_pair(sy,sx));
            visited_black[sy][sx]=true;
            visited[sy][sx]=true;
            int times=1;
            int64_t cnt=0;
            while(!q.empty()){
                pair<int ,int> p = q.front();
                q.pop();
                //先頭の今決まってる座標を取り出す
                for(int i=0;i<4;i++){
                  calc++;
                    int ny = p.first + dy[i];
                    int nx = p.second + dx[i];
                    if(nx<0||ny<0||ny>=h||nx>=w){
                        continue;
                    }
                    else if(visited[ny][nx]){
                        continue;
                    }
                  else if(c[p.first][p.second]==c[ny][nx]){
                    continue;
                  }
                    else{
                 
                        visited[ny][nx]=true;
                        q.push(make_pair(ny,nx));
                        //新しく確定マスをキューに入れる 
                        if(c[ny][nx]=='.')cnt++;   
                        if(c[ny][nx]=='#' && !visited_black[ny][nx]){
                            times++;
                            //sy,sxから行けるところには今到達した黒(ny,nx)からもいける
                            visited_black[ny][nx]=true;
                        }
                    }
                }
            }
            ans += cnt*times;
        }
    }
    cout<<ans<<endl;
  //cout<<"計算"<<calc<<endl;
}


Measured memory_bytes: 3880
//Atcoder.jp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m; 
ll a[1005];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    ll m=1000;
    for(int i=2;i<=n;i++){
        if(a[i]>a[i-1]) m=m%a[i-1]+(m/a[i-1])*a[i];
    }
    printf("%lld",m);
	return 0;
}

Measured memory_bytes: 3752
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val a = Array(n){""}
    repeat(n) {
        a[it] = readLine()!!
    }
    val b = Array(m){""}
    repeat(m) {
        b[it] = readLine()!!
    }

    var ans = false
    for (k in 0..n-m) {
        for (l in 0..n-m) {

            var same = true
            for (i in 0 until m) {
                for (j in 0 until m) {
                    if (a[i+k][j+l] != b[i][j]) {
                        same = false
                        break
                    }
                }
                if (!same) break
            }
            if (same) {
                ans = true
                break
            }
        }
        if (ans) break
    }

    if (ans) println("Yes")
    else println("No")
}


Measured memory_bytes: 36332
s = input()

for i in range(len(s)):
    if i == 0:
        pass

    else:
        tmp = s[0 : len(s) - 2 * i]
        f = tmp[: len(tmp) // 2]
        l = tmp[len(tmp) // 2 :]
        if f == l:
            print(len(tmp))
            exit(0)


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

using namespace std;

int main(){
	int n;
	cin >> n;
	
	std::vector<int> d(n);
	for (int i = 0; i < n; ++i) {
		cin >> d.at(i);
	}
	
	sort(d.begin(), d.end());
	
	cout << d.at(n/2) - d.at(n/2 - 1) << endl;
	
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N)
    {
        cin >> A[i];
    }
    sort(ALL(A));

    ll maxP = (ll)1e18;
    ll ans = 1;
    REP(i, N)
    {
        if (ans == 0)
        {
            break;
        }
        if (ans > maxP)
        {
            ans = -1;
            break;
        }
        if (maxP % ans == 0)
        {
            if (A[i] > maxP / ans)
            {
                ans = -1;
                break;
            }
        }
        else
        {
            if (A[i] > maxP / ans + 1)
            {
                ans = -1;
                break;
            }
        }
        
        ans *= A[i];
    }

    if (ans > maxP)
    {
        ans = -1;
    }

    cout << ans << endl;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int A,B,C,D;
	cin>>A>>B>>C>>D;

	int flag = 1;


	while(C > 0)
	{
		C = C - B;

		if(C<=0)
		{
			flag = 1;
			break;
		}

		A = A - D;

		if(A <= 0)
		{
			flag = 0;
			break;
		}
	}

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

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
int Top=0; 
string X="CF";
int main(){
	string s; cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==X[Top]){
			Top++;
			if(Top==2){
				cout<<"Yes";
				return 0;
			}
		}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main()
{
    int n, k, v[105];
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> v[i];
    sort(v, v + n);
    int ans = 0, now = n - 1;
    while(k--)
    {
        ans += v[now];
        --now;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_H 400
#define MAX_W 400
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int h, w;
string s[MAX_H];

int color[MAX_H][MAX_W];

void dfs(int i, int j, int c){
  if(color[i][j] != 0) return;
  color[i][j] = c;
  int di[] = {0, -1, 0, 1};
  int dj[] = {1, 0, -1, 0};
  for(int k = 0; k < 4; k++){
    int ni = i + di[k];
    int nj = j + dj[k];
    if(!(ni >= 0 && ni < h && nj >= 0 && nj < w))
      continue;
    if((s[i][j] == '#' && s[ni][nj] == '.') ||
        (s[i][j] == '.' && s[ni][nj] == '#'))
      dfs(ni, nj, c);
  }
}

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

  cin >> h >> w;
  for(int i = 0; i < h; i++) cin >> s[i];

  int c = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(color[i][j] == 0){
        dfs(i, j, ++c);
      }
    }
  }

  ll counts[c][2];
  for(int i = 0; i < c; i++){
    fill(counts[i], counts[i] + 2, 0);
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#') counts[color[i][j] - 1][0]++;
      else if(s[i][j] == '.') counts[color[i][j] - 1][1]++;
    }
  }

  ll sum = 0;
  for(int i = 0; i < c; i++){
    sum += counts[i][0] * counts[i][1];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 26112
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    int n,p;
    cin >> n >> p;
    vector<int> a(n);
    int sum = 0;
    int odd = 0;
    int even = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
        if(a[i] % 2 == 0){
            even++;
        }else {
            odd++;
        }
    }   
    ll ans = 0;
    if(odd == 0){
        if(p == 0){
            ans = pow(2,n);
        }else{
            ans = 0;
        }
    }else{
        ans = pow(2,n-1);
    }
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();

        long sum = 0;
        for (long i = 1; i <= N; i ++) {
            if (i % 3 > 0 && i % 5 > 0) {
                sum += i;
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 35640