akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <time.h>
#define l(x) x<<1
#define r(x) ((x<<1) | 1)
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int inf = 2*(1e9) + 10;
const long long MOD =998244353;
const int NMAX = 1000005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

vector<int> G[NMAX];
int viz[NMAX], color[NMAX];
bool bip;

int dfs(int v, int p){
    for(auto el: G[v]){
        if(el == p){
            continue;
        }
        if(viz[el]){
            if(color[el] != 1-color[v]){
                bip = 0;
            }
        } else {
            color[el] = 1 - color[v];
            viz[el] = 1;
            dfs(el, v);
        }
    }
}

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

    for(int i = 1; i<=m; ++i){
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    LL ans = 0;
    LL sum = 0;
    LL ons = 0;
    LL bp = 0;
    LL bm = 0;
    for(int i=1; i<=n; ++i){

        if(G[i].size() == 0){
            ons++;
            continue;
        }
        if(viz[i]){ continue;}
        bip = 1;
        viz[i] = 1;
        dfs(i, 0);
        if(bip){
            bp++;
        } else bm++;
    }
    cout<<2*ons*n - ons*ons + bm*bm + 2*bm*bp + 2*bp*bp<<"\n";

    return 0;
}


Measured memory_bytes: 37760
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    int N;
    int *count;
    scanf("%d",&N);
    count=(int *)malloc(sizeof(int)*N);
    for(int i=0;i<N;i++) count[i]=0;
    for(int i=1;i<N;i++){
        int a;
        scanf("%d",&a);
        count[a-1]++;
    }
    for(int i=0;i<N;i++) printf("%d\n",count[i]);

    

    return 0;
}

Measured memory_bytes: 2436
from collections import defaultdict

H, W = map(int, input().split())

S = [input() for _ in range(H)]




es = defaultdict(list)
# あるマスについて左右見なくても右に向かってみていけば逆もとれる
for i in range(H):
    for j in range(W):
        if j < W-1 and S[i][j] != S[i][j+1]:
            es[(i,j)].append((i,j+1))
            es[(i,j+1)].append((i,j))
        if i < H-1 and S[i][j] != S[i+1][j]:
            es[(i,j)].append((i+1, j))
            es[(i+1,j)].append((i, j))

checked = [[False for _ in range(W)] for H in range(H)]


ans = 0
for i in range(H):
    for j in range(W):
        if checked[i][j] == True:
            continue
        
        cnt_b = 0
        cnt_w = 0

        if S[i][j] == "#":
            cnt_b += 1
        else:
            cnt_w += 1
        checked[i][j] = True
        stack = es[(i,j)]

        while stack:
            new_stack = []
            for p,q in stack:
                if checked[p][q] == False:
                    checked[p][q] = True
                    if S[p][q] == "#":
                        cnt_b += 1
                    else:
                        cnt_w += 1

                    new_stack.extend(es[(p,q)])
            if len(new_stack) == 0:
                break
            else:
                stack = new_stack
        
        ans += cnt_b * cnt_w

print(ans)

Measured memory_bytes: 86584
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000
#define EMP '.'
#define W 'W'
#define B 'B'
#define FLG '-'

char mat[50][50];

int main(){
  int Wi,H;

  while(scanf("%d %d\n", &Wi, &H), Wi|H){
    rep(i,H){
      rep(j,Wi){
	scanf("%c", &mat[i][j]);
      }
      getchar();
    }

    int aw=0,ab=0;
    rep(i,H){
      rep(j,Wi){
	if(mat[i][j]==EMP){
	  bool w=false, b=false;
	  int cnt=0;

	  queue<pii> q;
	  q.push(mp(i,j));
	  while(!q.empty()){
	    pii p = q.front(); q.pop();
	    int x = p.first, y=p.second;

	    if(mat[x][y]==W){
	      w=true;
	      continue;
	    } else if(mat[x][y]==B){
	      b=true;
	      continue;
	    } else if(mat[x][y]==FLG){
	      continue;
	    }
	    cnt++;
	    mat[x][y]=FLG;
	    int dx[]={-1,1,0,0}, dy[]={0,0,-1,1};
	    rep(k,4){
	      int nx=x+dx[k], ny=y+dy[k];
	      if(nx>=0 && nx<H && ny>=0 && ny<Wi && mat[nx][ny]!=FLG){
		q.push(mp(nx,ny));
	      }
	    }
	  }

	  if((w^b)==false) continue;
	  else {
	    if(w) aw+=cnt;
	    else  ab+=cnt;
	  }
	} // end if EMPTY
      } // end rep j
    } //end rep i

    cout << ab << " " << aw << endl;
  }
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N  = 1e6 + 69, INF = 1e9, mod = 1e9 + 7;

const ll INFLL = 1e18;

int n, K;
ll dp[N][2];

vector<int>gr[N];

void dfs(int x,int p){

        dp[x][0] = dp[x][1] = 1;

        for(int i = 0; i < gr[x].size(); i++){
                int to = gr[x][i];
                if(to == p) continue;
                dfs(to,x);
                dp[x][0] *= dp[to][0] + dp[to][1];
                dp[x][1] *= dp[to][0];
                dp[x][0] %= mod;
                dp[x][1] %= mod;
        }
}

int main(){

        cin >> n;
        for(int i = 1; i < n; i++){
                int x, y;
                cin >> x >> y;
                gr[x].pb(y);
                gr[y].pb(x);
        }

        dfs(1,0);

        cout << (dp[1][0] + dp[1][1]) % mod << endl;

}


Measured memory_bytes: 36992
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
  itn n; cin >> n;
  string s; cin >> s;
  rep(i,2*n){
    if((i%2==0)&&s[i]=='B') s[i]='W'; 
    else if((i%2==0)&&s[i]=='W') s[i]='B'; 
  }
  mint ans=1;
  itn w=0,b=0;
  rep(i,2*n){
    if(s[i]=='W') w++;
    if(s[i]=='B'){
      ans*=w-b;
      b++;
    }
  }
  if(b==0||(!(b==n&&w==n))){
    cout << 0 << endl;
    return 0;
  }
  rep1(i,n) ans*=i;
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, k, c;
	string s;
	cin >> n >> k >> c >> s;
	vector<int> bef(n), aft(n);
	int pos = 0;
	for ( int i = 0 ; i < k ; i++ ){
		while(s[pos] != 'o')
			pos++;
		bef[pos] = i + 1;
		pos += c + 1;
	}
	pos = n - 1;
	for ( int i = 0 ; i < k ; i++ ){
		while(s[pos] != 'o')
			pos--;
		aft[pos] = k - i;
		pos -= c + 1;
	}
	for ( int i = 0 ; i < n ; i++ ){
		if ( bef[i] == aft[i] && bef[i] )
			cout << i + 1 << "\n";
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(5); rep(i, 5) {  cin >> a[i]; if(a[i] == 0) cout << i+ 1 << endl;}
  
  // ll ans = 0;
  // bool ok = false;

  // cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,W[101];
	scan(N);
	int ans=INF;
	int wa=0;
	rep(i,N){
		scan(W[i]);
		wa+=W[i];
	}
	int sum=0;
	rep(i,N){
		sum+=W[i];
		ans=min(ans,abs(sum-(wa-sum)));
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
N,B = gets.chomp.split(" ").map(&:to_i)

div = 10**9 + 7
R = N-B
op = R+1
puts op
(2..B).each do |i|
    if i <= R+1 then
        op *= R-(i-2)
        op *= B-(i-1)
        op /= i
        op /= i-1
        puts op % div
    else
        puts "0"
    end
end

Measured memory_bytes: 2172
import copy
n = int(input())
t = list(map(int, input().split()))
m = int(input())
ans = []
for i in range(m):
    t1 = copy.copy(t)
    a, b = map(int, input().split())
    t1[a-1] = b
    ans.append(sum(t1))
for j in ans:
    print(j)

Measured memory_bytes: 3956
h, w, k = map(int, input().split())
cake = []
piece = []
flg = False
for _ in range(h):
    s = input()
    if flg and s.count("#") != 0:
        cake.append(piece)
        piece = [s]
        continue
    piece.append(s)
    if s.count("#") != 0:
        flg = True
cake.append(piece)

cnt = 0
for ps in cake:
    r = len(ps)
    oo = [0] * w
    for p in ps:
        st = p.count("#")
        if st == 0:
            continue
        cnt += 1
        for i, v in enumerate(p):
            oo[i] = cnt
            if v == "#":
                if st == 1:
                    pass
                else:
                    cnt += 1
                    st -= 1
    for _ in range(r):
        print(*oo)

Measured memory_bytes: 4220
#include <iostream>

int main(void) {

	int a, b;
	std::cin >> a >> b;

	int diff = b - a;
	int tall = 0;
	for (int v = 1; v <= diff; v++) {
		tall += v;
	}

	std::cout << (tall - b) << std::endl;

	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for a in range(min(N,K)+1):
    for b in range(min(N,K)+1-a):
        v=[]
        value=sum(V[:a])
        v.extend(V[:a])
        if b!=0:
            value=value+sum(V[-b:])
            v.extend(V[-b:])
        v.sort()
        for i in range(min(a+b,K-a-b)):
            if v[i]<0:
                value=value-v[i]
            else:
                break
        ans=max(ans,value)
print(ans)

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> s(h, vector<char>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> s[i][j];
        }
    }
    int ans = INF;
    for(int i = 0; i < (1 << (h - 1)); i++){
        int x = 0;
        map<int, int> m;
        int t = 0;
        for(int j = 0; j < h - 1; j++){
            m[j] = t;
            if(i >> j & 1){
                t++;
                x++;
            }
        }
        m[h - 1] = t;
        t++;
        vector<int> q(t);
        bool f = false;
        int j2 = -1;
        for(int j = 0; j < w; j++){
            for(int g = 0; g < h; g++){
                if(s[g][j] == '1'){
                    q[m[g]]++;
                    if(q[m[g]] > k){
                        if(j2 == j){
                            f = true;
                            break;
                        }
                        x++;
                        j2 = j;
                        j--;
                        for(int l = 0; l < t; l++){
                            q[l] = 0;
                        }
                        break;
                    }
                }
            }
            if(f){
                break;
            }
        }
        if(!f) ans = min(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500+j*100+k*50 == X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
from operator import itemgetter

A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = [[int(i) for i in input().split()] for _ in range(M)]

ans = float("inf")
for i in range(M):
	ans = min(ans, A[d[i][0]-1] + B[d[i][1]-1] - d[i][2])

A.sort()
B.sort()
ans = min(ans, A[0] + B[0])

print(ans)

Measured memory_bytes: 33056
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    t=LI()
    mv=LI()
    mv.append(0)
    
    
    
    #v0で始まってv1でおわる,最高vmまで出して良い,t廟の区間
    def calc(v0,v1,vm,t):
        vv = (t-abs(v1-v0))/2+max(v0,v1) #vmを気にしなければどこまで上がれるか
        
        if abs(v1-v0)==t:
            return (v0+v1)*t/2
        elif v1==vm or v0==vm:
            return (v1+v0)*abs(v1-v0)/2 +max(v1,v0)*(t-abs((v1-v0)))
        elif vv<vm:
            return (vv+v0)*(vv-v0)/2 + (vv+v1)*(vv-v1)/2
        else:
            return (v0+vm)*(vm-v0)/2 + vm*(t-(vm-v0)-(vm-v1)) + (vm+v1)*(vm-v1)/2 
         
         
    #区間端での速度,手前から決めていき，無理が生じたら手前を下げていく(Nが小さいので)
    v=[1000]*(N+1)
    v[0]=0
    v[-1]=0
    
    for i in range(N):
        v[i+1]=min(v[i]+t[i],mv[i],mv[i+1])
        if v[i]-v[i+1]>t[i]:#下げきれないなら
            j=i
            while v[j]-v[j+1]>t[j]:
                v[j]=v[j+1]+t[j]
                j-=1
                
                
    ans=0
    for i in range(N):
        ans+=calc(v[i],v[i+1],mv[i],t[i])
    print(ans)
 

main()




Measured memory_bytes: 38256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
int main() {
    cout.precision(15);
    cout << fixed;
    ll N;
    vector<ll> a;
    cin >> N;
    a.resize(N);
    REP(i,N)
        cin>>a[i];
    ll s=0;
    REP(i,N) {
        s^=a[i];
    }
    REP(i,N) {
        cout<<(s^a[i])<<endl;
    }
}


Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(long long i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long n;
    long long m;
    cin >> n >> m;
    long long a[n];
    long long b[n+1];
    map<long long,long long> mp;
    b[0] = 0;
    mp[0] = 1;
    rep(i,n){
        cin >> a[i];
        b[i+1] = (b[i] + a[i])%m;
        auto itr = mp.find(b[i+1]);
        if(itr != mp.end()){
            mp[b[i+1]]++;
        }
        else{
            mp[b[i+1]] = 1;
        }
    } 
    long long ans = 0;
    for(auto itr = mp.begin();itr!=mp.end();itr++){
        ans += itr->second*(itr->second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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



int main(){

    desperate_optimization(8);
    int n;cin >> n;
    double ans = 0,curr;
    string s;
    for(int i=0;i<n;i++){

        cin >> curr >> s;
        if(s == "BTC"){
            ans += (curr)*(380000.0);
        }
        else{
            ans += curr;
        }
    }
    cout << ans;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

    std::vector<int> list(9, 0);
    for(int i = 0; i < n; ++i){
        int val;
        std::cin >> val;
        int index = val / 400;
        if(index < 8){
            ++list.at(index);
        }else{
            ++list.at(8);
        }
    }

    int min = std::count_if(list.begin(), list.begin() + 8, [](auto i){
            return 0 < i;
            });

    std::cout << std::max(1, min) << " " << min + list.at(8) << std::endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll x,t;
    cin>>x>>t;
    ll ans=0;
    if(x-t > 0){
        ans = x-t;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define bitCount(num)  __builtin_popcount(num)
#define pb push_back
#define ll long long
#define bye return 0;
#define f(i,a,b) for( long long i=a;i<b;i++)
#define testCases long long t;cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define newLine <<"\n"
#define all(x) (x).begin(), (x).end()
#define vll vector<long long>

void showDP(vector<vector<ll>> dp)
{
	f(i,0,dp.size())
	{
		f(j,0,dp[i].size())
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
}




ll knapSack_Memo(vector<pair<int,ll>> p,vector<vector<ll>> &dp,int w, int currSum, int n)
{
     

	if(n==0|| currSum==0) 
		return dp[n][currSum]=0;


if(dp[n][currSum]!=-1) return dp[n][currSum];


  if(p[n-1].first<= currSum) 
  	{
  		ll ans1= p[n-1].second+knapSack_Memo(p,dp,w,currSum-p[n-1].first,n-1);
  		ll ans2=knapSack_Memo(p,dp,w,currSum,n-1);
  		return dp[n][currSum] =max(ans1,ans2);
  	}

  else return dp[n][currSum]=knapSack_Memo(p,dp,w,currSum,n-1);

}



int main()
{
    fast

    int n,w;
    cin>>n>>w;
    vector<pair<int,ll>> p(n);

    f(i,0,n)
    {
    	int a;
    	ll b;
    	cin>>a>>b;
    	p[i]={a,b};
    }
    // vector<pair<ll,ll>> p;

//     sort(p_.begin(),p_.end());
// // cout<<p.size()<<endl;
//     for(int i=n-1;i>=0;i--)p.pb(make_pair(p[i].first,p[i].second));
    // cout<<p.size()<<endl;
    vector<vector<ll>> dp(n+1, vector<ll>(w+1,-1));
    // cout<<knapSack_Memo(p,dp,w,w,n);
    // cout<<endl;
   for(int i=0;i<n+1;i++) dp[i][w]=0;
   for(int j=0;j<w+1;j++) dp[n][j]=0;

   	for(int i=n-1;i>=0;i--)
   	{
   		for(int j=w-1;j>=0;j--)
   		{
   			if(j+p[i].first<=w)
   			{
   				dp[i][j]= max((p[i].second+dp[i+1][j+p[i].first]), dp[i+1][j]);
   			}
   			else dp[i][j]=dp[i+1][j];
   			// cout<<dp[i][j]<<endl;
   		}
   	}
   	cout<<dp[0][0];





    // showDP(dp);




   
    bye
}

Measured memory_bytes: 83160
import itertools
n=int(input())
prime=[2]
d={2:0}
for i in range(3, 100):
    if all(i%p!=0 for p in prime):
        prime.append(i)
        d[i]=0
for i in range(1, n+1):
    tmp=i
    for p in prime:
        while tmp%p==0:
            d[p]+=1
            tmp//=p
cnt4=0
cnt2=0
cnt74=0
cnt14=0
cnt24=0
for p in prime:
    if d[p]>=4:
        cnt4+=1
    if d[p]>=2:
        cnt2+=1
    if d[p]>=74:
        cnt74+=1
    if d[p]>=14:
        cnt14+=1
    if d[p]>=24:
        cnt24+=1
print(max(0,(cnt4)*(cnt4-1)*(cnt2-2)//2)+max(0, cnt74)+max(0, cnt14*(cnt4-1))+max(0, cnt24*(cnt2-1)))  

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

int num_divisors(const int n)
{
    int counter = 0;
    for (int i = 1; i <= n; i++)
    {
        if (n % i == 0)
        {
            counter++;
        }
    }
    //cout << n << " " << counter << endl;

    return counter;
}

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

    int A, B, K;
    cin >> A >> B >> K;

    int smaller = (A >= B) ? B : A;

    int counter = 0;
    int answer = 9;
    for (int i = smaller; i >= 1; --i)
    {
        if (A % i == 0 && B % i == 0)
        {
            ++counter;
            if (counter == K)
            {
                answer = i;
            }
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(){
    ios_base::sync_with_stdio(false);
    srand(time(0));
    //freopen("input.txt", "r", stdin);
    int n, m, d;
    cin >> m >> n >> d;
    int val = 0;
    if (d == 0) val = m;
    else val = 2 * (m - d);
    cout << fixed << setprecision(10) << ((long double)(val) * (n - 1) / (1LL * m * m));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {	
	int t=1;
//	cin >> t;
	while (t--) {
	   int n;
	   cin>>n;
	    ll*arr=new ll[n];
	   for(int i=0;i<n;i++)
	   {
	   	 cin>>arr[i];
	   }
	   ll ans=0;
	   for(int i=0;i<n-1;i++)
	   {
	   	  if(arr[i+1]<arr[i])
	   	  {
	   	  	  ans+=arr[i]-arr[i+1];
	   	  	   arr[i+1]=arr[i];
			 }
	   }
	   cout<<ans<<endl;
	   
       
}
	    
	} 
	
	

Measured memory_bytes: 5176
import math

N, M = [int(x) for x in input().split()]
s, c = [], []

for i in range(M):
    s_i, c_i = [int(x) for x in input().split()]
    s.append(s_i)
    c.append(c_i)

for num in range(10 ** N):
    num = str(num)
    if len(num) != N:
        continue
    for i in range(M):
        if num[s[i] - 1] != str(c[i]):
            break
    else:
        print(int(num))
        exit()

print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a-1) * (b-1) << endl; 
  return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    flag = True
    cnt = 0
    for i in range(len(S)):
        if i == 0:
            if S[i] != 'A':
                print("WA")
                return
        else:
            if 2 <= i <= len(S)-2 and S[i] == 'C':
                cnt += 1
            elif S[i].isupper():
                print("WA")
                return
    if cnt == 1:
        print("AC")
    else:
        print("WA")
            
main()

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	if (N == 3) {
		printf("2 3 25\n");
		fflush(stdout);
		return 0;
	} else if (N == 4) {
		printf("2 3 4 9\n");
		fflush(stdout);
		return 0;
	}
	
	int i;
	printf("3 9");
	for (i = 2; i <= (N + 7) / 8; i++) printf(" %d %d", 3 * (i * 4 - 3), 3 * (i * 4 - 1));
	for (N -= (i - 1) * 2, i = 1; i <= (N + 2) / 3; i++) printf(" %d %d", 2 * (i * 3 - 2), 2 * (i * 3 - 1));
	for (N -= (i - 1) * 2, i = 1; i <= N; i++) printf(" %d", 6 * i);
	printf("\n");
	fflush(stdout);
	return 0;
}

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

int foo(int A, int j){
	int s = 0, count = 0;
	for(int i = j; s < A; i++){
		s += i;
		count++;
	}
	if(A == s && count >= 2) return 1;
	else return 0;	
}

int main(){
	while(1){
		int N, s = 0, i, j, c = 0;
		cin>>N;
		if(N == 0) break;
		
		for(j = 1; j < N; j++){
			if(foo(N, j) == 1) c++;
		}
		cout<<c<<endl;
	}
	return 0;
}



Measured memory_bytes: 3084
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#ifdef sahdsg
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...) (void)0
#endif // sahdsg
#define REP(r,x,y) for(register int r=(x); r<y; r++)
using namespace std;
typedef long long LL;
char pic[1007][1007];
inline char rein() {
    char x=getchar(); while(x<=' ') x=getchar(); return x;
}
typedef pair<int,int> pii;
const int d[][2]={{0,-1},{0,1},{1,0},{-1,0}};
queue<pii> q;
int main()
{
    int h,w;
    int cnt=0;
    scanf("%d%d", &h, &w);
    REP(i,0,h) REP(j,0,w) {
        pic[i][j]=rein();
        if(pic[i][j]=='#') q.push(pii(i,j)),cnt++;
    }
    int ans=0;
    DBG("!");
    while(cnt!=h*w) {
        int l=q.size();
        REP(i,0,l) {
            pii now=q.front(); q.pop();
            REP(j,0,4) {
                if(now.first+d[j][0]>=0)
                if(now.first+d[j][0]<h)
                if(now.second+d[j][1]>=0)
                if(now.second+d[j][1]<w)
                if(pic[now.first+d[j][0]][now.second+d[j][1]]=='.') {
                    pic[now.first+d[j][0]][now.second+d[j][1]]='#';
                    q.push(pii(now.first+d[j][0],now.second+d[j][1]));
                    cnt++;
                }
            }
        }
        ans++;
    }
    printf("%d\n", ans);
}


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

int main(int argc, char const *argv[])
{
	int A,B ;
	cin>>A>>B ;

	int K = (A + B) / 2 ;
	if(abs(A-K) == abs(B-K)) cout<<K ;
	else cout<<"IMPOSSIBLE" ;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    int x,y;
    int t[21][21]={};
    rep(i,n){
      cin >> x >> y;
      t[x][y]=1;
    }
    int m,g;
    x=10; y=10;
    cin >> m;
    char d;
    rep(i,m){
      cin >> d >> g;
      rep(j,g){
        if(d=='N') y++;
        if(d=='E') x++;
        if(d=='S') y--;
        if(d=='W') x--;
        if(t[x][y]==1) t[x][y]=0;
      }
    }
    bool flag = true;
    rep(i,21) rep(j,21) if(t[i][j]==1) flag = false;
    if(flag==true) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}




Measured memory_bytes: 3024
#include<iostream>
#include<vector>
using namespace std;
int N, G;
vector<int> p(100), c(100);

int calc(vector<bool>& b){
  int point = 0;
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(!b[i]){
      continue;
    }else{
      point += p[i] * (i + 1) * 100 + c[i];
    }
  }
  for(int i = 0; i < N; i++){
    if(b[i]) ans += p[i]; 
  }
  if(point >= G){
    //cout << ans;
    return ans;
  }else{
    int tmp = G - point;
    int f = 0;
    for(int i = N - 1; i >= 0; i--){
      if(b[i]) continue;
      for(int j = 0 ; j < p[i]; j++){
        tmp -= (i+1)*100;
        if(tmp <= 0){
          ans++;
          f = 1;
          break;
        }
        ans++;
      }
      if(f) break;
    }
    return ans;
  }
}

int dfs(int depth, vector<bool>& b){
  int tmp1 = 0, tmp2 = 0;
  if(depth >= N) return calc(b);
  else{
    b[depth] = true;
    tmp1 = dfs(depth + 1, b);
    b[depth] = false;
    tmp2 = dfs(depth + 1, b);
    return(min(tmp1, tmp2));
  }
}

using namespace std;
int main(){
  cin >> N >> G;
  vector<bool> b(N,false);
  for(int i = 0; i < N; i++){
    cin >> p[i] >> c[i];
  }
  int ans = dfs(0, b);
  cout << ans;
}

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

class Point {
public:
	double x, y, r;
};

int main()
{
	int n;
	Point p1,p2;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p1.x >> p1.y >> p1.r>> p2.x >> p2.y >> p2.r;
		double sumR = p1.r + p2.r;
		double l = sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
		
		if (p1.r > p2.r) {
			double subR = p1.r - p2.r;
			if (l < subR) {
				cout << "2" << endl;
			}
			else if (l <= sumR && l >= subR) {
				cout << "1" << endl;
			}
			else if (l > sumR) {
				cout << "0" << endl;
			}
		}
		else {
			double subR = p2.r - p1.r;
			if (l < subR) {
				cout << "-2" << endl;
			}
			else if (l <= sumR &&  l >= subR) {
				cout << "1" << endl;
			}
			else if (l > sumR) {
				cout << "0" << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 1e5 + 5;

int n;
int a[N];

int cnt[2][N];
vector <int> t[2];


bool cmp_even(int x, int y)
{
    return cnt[0][x] > cnt[0][y];
}
bool cmp_odd(int x, int y)
{
    return cnt[1][x] > cnt[1][y];
}

int ans = N;
void check(int even, int odd)
{
    if(even == odd)
        return;

    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i % 2 == 1)
            if(a[i] != odd)
                res++;
        if(i % 2 == 0)
            if(a[i] != even)
                res++;
    }

    ans = min(ans, res);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

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

    for(int i = 1; i < N; i++)
    {
        t[0].pb(i);
        t[1].pb(i);
    }

    sort(t[0].begin(), t[0].end(), cmp_even);
    sort(t[1]. begin(), t[1].end(), cmp_odd);

    check(t[0][0], t[1][0]);
    check(t[0][1], t[1][0]);
    check(t[0][0], t[1][1]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int main(){
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[0]==s[2]){
       cout<<"Yes"<<endl;
    }else if(s[3]==s[1]&&s[3]==s[2]){
       cout<<"Yes"<<endl;
    }else{
       cout<<"No"<<endl;
    }
	return(0);
}

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

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	int count = 0;
	for (size_t i=0; i<s.length(); ++i) {
		if (s[i] != t[i]) ++count;
	}
	cout << count << '\n';
}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    int roop = y-x + 1;
    vi d(n-1);
    rep1(i, n-1) for (int j=i+1; j<=n; j++) {
        int dist;
        if (i<=x) {
            if (j<=x) dist = j-i;
            else if (j>x&&j<=y) dist = (x-i) + min(j-x, roop-(j-x));
            else dist = (j-i) - (y-x) + 1;
        }
        else {
            if (i>=y&&j>=y) dist = j-i;
            else if (j<=y) dist = min(j-i, roop-(j-i));
            else dist = (j-y) + min(y-i, roop-(y-i));
        }
        d[dist-1]++;
    }
    rep(i, n-1) cout << d[i] << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi p(n);
    vector<ld> sum(n+1);
    rep(i, n) {
        cin >> p[i];
        sum[i+1] = sum[i] + (ld)(p[i]+1)/2;
    }

    ld ans = 0;
    rep(i, n-k+1) {
        ans = max(ans, sum[i+k]-sum[i]);
    }

    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 7096
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);

    rep(i, m){
        ll u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
    }
    ll s, t;
    cin >> s >> t;
    s--, t--;
    queue<pair<ll,ll>> q;
    vector<vector<ll>> dist(n, vector<ll>(3, INF));
    q.push({s, 0});

    while(!q.empty()){
        ll now = q.front().first;
        ll nowdist = q.front().second;
        q.pop();
        rep(i, g[now].size()){
            ll next = g[now][i];
            ll nextdist = nowdist + 1;
            if(dist[next][nextdist % 3] > nextdist){
                dist[next][nextdist % 3] = nextdist;
                q.push({next, nextdist});
            }
        }
    }

    cout << (dist[t][0]==INF?-1:(dist[t][0] / 3LL)) << endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>

#define REP(i, N) for(int i = 0; i < N; ++i)
#define FOR(i, M, N) for(int i = M; i < N; ++i)

using namespace std;

int main() {
	int N, T;

	int best = 1000;
	cin >> N >> T;
	
	bool check = false;
	REP(i, N) {
		int buf[2];
		cin >> buf[0] >> buf[1];
		if (buf[1] <= T && buf[0] <= best) {
			check = true;
			best = buf[0];
		}
	}

	if (check) cout << best << endl;
	else cout << "TLE" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	ll a[n];For(i,0,n) cin>>a[i];
	sort(a,a+n);
	ll l = n/2-1;
	ll r = n/2;

	cout<<(a[r]-a[l])<<endl;











	
}

Measured memory_bytes: 1024
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += gcd_list([a,b,c])

print(ans)


Measured memory_bytes: 74820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <fstream>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h> //works like magic, but at cost.
using namespace std;
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout<<x<<endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define fk(i, k, n) for(i=k; i<n; i++)
#define fn(i, n) for(i=n-1;i>=0;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lli long long int
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<lli, lli>	pl;
typedef vector<int>		vi;
typedef vector<lli>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

int main() {
    int N;
    cin>>N;
    string str;
    int AC=0,WA=0,TLE=0,RE=0;
    fo(i, N){
      cin>>str;
      if(str[0]=='A')
      AC++;
      if(str[0]=='W')
      WA++;
      if(str[0]=='T')
      TLE++;
      if(str[0]=='R')
      RE++;
     }cout<<"AC "<<"x "<<AC<<"\n";
     cout<<"WA "<<"x "<<WA<<"\n";
     cout<<"TLE "<<"x "<<TLE<<"\n";
     cout<<"RE "<<"x "<<RE<<"\n";
    
    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[] a = new int[1000];
	int sum = 0;
	int ans = 0;
	for(int i=0;i<1000;i++){
		a[i] = sc.nextInt();
		for(int k=1;k<=a[i]/2;k++){
			for(int m=k;m<=a[i];m++){
				sum = sum + m;
				if(sum==a[i]){
					ans = ans + 1;
				}
				if(sum>a[i]){
					break;
				}
			}
			sum = 0;
		}
		if(a[i]==0){
			break;
		}
		System.out.println(ans);
		ans = 0;
	}
}
}

Measured memory_bytes: 20044
#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>;
using vvi = vector<vector<int>>;

std::vector<std::vector<int>> iig(int vn, int en) {
	std::vector<std::vector<int>> res(vn);
        for(int i = 0; i < en; i++) {
                int s, t;
                std::cin >> s >> t;
                s--; t--;
                res[s].push_back(t);
                res[t].push_back(s);
        }
        return res;
}

void sep_pc(const std::vector<std::vector<int>>& g, std::vector<int>& p, std::vector<std::vector<int>>& c, const int root=0) {
	int n = g.size();
	std::vector<int> pt(n);
	std::vector<std::vector<int>> ct(n);
	std::function<void(int, int)> f = [&](int x, int parent) {
		pt[x] = parent;
		for(int y: g[x]) {
			if (y == parent) continue;
			ct[x].push_back(y);
			f(y, x);
		}
		return;
	};
	f(root, -1);
	p = std::move(pt);
	c = std::move(ct);
	return;
}

void iit(int n, std::vector<int>& p, std::vector<std::vector<int>>& c, const int root=0) {
	sep_pc(iig(n, n - 1), p, c, root);
}

std::vector<int> get_tsize(std::vector<std::vector<int>> &children, int root=0) {
	std::vector<int> res(children.size());
	std::function<int(int)> f = [&](int x) {
		int a = 1;
		for(int y: children[x]) {
			a += f(y);
		}
		res[x] = a;
		return a;
	};
	f(root);
	return res;
}

int n;
int c[200100];
long long tsize[200100];
vector<int> parent;
vvi children;

vvi categorize_v_by_color() {
	vector<vector<int>> res(n);
	rep(i, n) {
		res[c[i]].push_back(i);
	}
	return res;
}


long long *location[200100];
long long head[200100] = {};

void dfs(int x=0) {
	int color = c[x];
	*location[color] -= tsize[x];
	long long *prev_location = location[color];
	for(int y: children[x]) {
		location[color] = &tsize[y];
		dfs(y);
	}
	location[color] = prev_location;
}

long long comb2(long long x) {
	return (x + 1) * x / 2;
}

int main() {
	cin >> n;
	rep(i, n) {
		int t;
		cin >> t;
		c[i] = t - 1;
	}
	iit(n, parent, children);
	{
		auto tsize_tmp = get_tsize(children, 0);
		rep(i, n) tsize[i] = tsize_tmp[i];
	}
	rep(i, n) head[i] = n;
	rep(i, n) location[i] = head + i;
	dfs();
	auto v_catted = categorize_v_by_color();
	rep(i, n) {
		long long ans = comb2(n) - comb2(head[i]);
		for(int x: v_catted[i]) {
			for(int y: children[x]) {
				ans -= comb2(tsize[y]);
			}
		}
		cout << ans << endl;
	}
}


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

using namespace std;

int main(void)
{
	int n,m;

	cin >> n;
	string s[n];
	for(int i=1;i<=n;i++)
		cin >> s[i-1];

	cin >> m;
	string t[m];
	for(int i=1;i<=m;i++)
		cin >> t[i-1];
	
	int ans = 0;

	for(int i=1;i<=n;i++)
	{
		int tem = 1;
		for(int j=i+1;j<=n;j++)
			if(s[i-1]==s[j-1])tem++;
		for(int j=1;j<=m;j++)
			if(s[i-1]==t[j-1])tem--;

		ans = max(ans,tem);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256