akhauriyash/Code-Regression huggingface dataset:
/*
02:08 - 04:05
 */

#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<queue>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 2000
#define pow2(a) ((a)*(a))
#define EPS 1e-7
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

struct Point{
  double x,y;
  Point(double x=IINF,double y=IINF):x(x),y(y){}
  Point operator - (const Point& a)const { return {x-a.x,y-a.y}; }
};

struct Edge{
  int from,to;
  double dist;
  Edge(int from=IINF,int to=IINF,double dist=IINF):from(from),to(to),dist(dist){}
};

struct Data{
  int pre,cur,cost;
  double dist;
  Data(int pre=IINF,int cur=IINF,int cost=IINF,double dist=IINF):pre(pre),cur(cur),cost(cost),dist(dist){}
  bool operator < (const Data& a) const {
    if(equals(dist,a.dist))return cost > a.cost;
    return dist > a.dist;
  }
};

inline double getDist(Point a,Point b){ return sqrt(pow2(a.x-b.x)+pow2(a.y-b.y)); }
inline double cross(Point a,Point b){ return a.x*b.y-a.y*b.x; }

vector<Edge> G[MAX];
vector<Point> ps;
double mindist[MAX][MAX];//mindist[pre_node][cur_node] 
int    mincost[MAX][MAX];
int E,V,sp,gp;

void compute(){

  rep(i,V)rep(j,V){
    mindist[i][j] = IINF;
    mincost[i][j] = IINF;
  }
  priority_queue<Data> Q;
  rep(i,G[sp].size()){
    mindist[sp][G[sp][i].to] = G[sp][i].dist;
    mincost[sp][G[sp][i].to] = 2;
    Q.push(Data(sp,G[sp][i].to,2,G[sp][i].dist));
  }

  while(!Q.empty()){
    Data data = Q.top(); Q.pop();
    Point cp = ps[data.cur];
    Point pp = ps[data.pre];

    if(data.cur == gp){ cout << data.cost << endl; return; }

    rep(i,G[data.cur].size()){
      int next = i;
      Point np = ps[G[data.cur][next].to];
      if(G[data.cur][next].to == data.pre)continue;
      if(cross(cp-pp,np-pp) < -EPS)continue;
      double dist = G[data.cur][next].dist;
      if(equals(mindist[data.cur][next],data.dist+dist)){
	if(mincost[data.cur][G[data.cur][next].to] > data.cost+1){
	  mincost[data.cur][G[data.cur][next].to] = data.cost+1;
	  Q.push(Data(data.cur,G[data.cur][next].to,data.cost+1,data.dist+dist));
	}
      } else if(mindist[data.cur][G[data.cur][next].to] > data.dist+dist){
	mindist[data.cur][G[data.cur][next].to] = data.dist + dist;
	mincost[data.cur][G[data.cur][next].to] = data.cost + 1;
	Q.push(Data(data.cur,G[data.cur][next].to,data.cost+1,data.dist+dist));
      }
    }
  }

  cout << "impossible" << endl;

}

int main(){
  while(cin >> V >> E,V|E){
    unordered_map<string,int> getIndex;
    int x,y;
    string name,p,q;
    ps.clear();
    rep(i,V)G[i].clear();

    rep(i,V){
      cin >> name >> x >> y;
      getIndex[name] = (int)ps.size();
      ps.push_back(Point(x,y));
    }

    rep(i,E){
      cin >> p >> q;
      int node1 = getIndex[p], node2 = getIndex[q];
      G[node1].push_back(Edge(node1,node2,getDist(ps[node1],ps[node2])));
      G[node2].push_back(Edge(node2,node1,getDist(ps[node1],ps[node2])));
    }

    cin >> p >> q;
    sp = getIndex[p], gp = getIndex[q];

    compute();

  }
  return 0;
}

Measured memory_bytes: 28124
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
long long i,n,m;
vector<long long> v;
int main(){
	cin >> m >> n;
	for(i=1;i*i<=n;i++){
		if(n%i==0){
			v.push_back(i);
			if(i*i!=n){
				v.push_back(n/i);
			}
		}
	}
	
	sort(v.begin(),v.end());
	for(i=v.size()-1;i>=0;i--){
		if(n>=m*v[i]){
			cout << v[i] << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
S="012 345 678 036 147 258 048 246 "
A=[input().split()for i in range(3)]
B=A[0]+A[1]+A[2]
for b in [input()for i in range(int(input()))]:
  for l in range(9):
    S=S.replace(str([9,l][b==B[l]]),"")
print(["No","Yes"][S.find("  ")>-1])

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
void myswap(int *,int *);
int main(void){
	int abc[31],tate,yoko;
	cin>>tate>>yoko;
	for(int i=1;i<=tate;i++){
		abc[i]=i;
	}
	int pro1,pro2;
	char doll;
	for(int i=1;i<=yoko;i++){
		cin>>pro1>>doll>>pro2;
		myswap(&abc[pro1],&abc[pro2]);
	}
	for(int i=1;i<=tate;i++){
		cout<<abc[i]<<endl;
	}
	return 0;
}
void myswap(int *a,int *b){
	int c;
	c=*a;
	*a=*b;
	*b=c;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,cnt=0;
  cin>>n;
  vector<char>s(n);
  int l=0,r=0;
  rep(i,n)
  {
    char c;
    cin>>c;
    s[i]=c;
    if(c==')')
    {
      cnt--;
    }
    else
    {
      if(cnt<0){l+=-cnt;cnt=0;}
      cnt++;
    }
  }
  if(cnt<0)l+=-cnt;
  if(cnt>0)r=cnt;
  rep(i,l)cout<<'(';
  rep(i,n)cout<<s[i];
  rep(i,r)cout<<')';
  cout<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for (int i = (a); i < (b); i++)
#define N 1234567

int n, m, x, y, num[N], red[N];
int main() {
	scanf("%d %d", &n, &m);
	fo(i,0,n) num[i] = 1;
	red[0] = 1;
	fo(i,0,m) {
		scanf("%d %d", &x, &y); x--; y--;

		if (red[x]) red[y] = 1;
		if (num[x] == 1) red[x] = 0;
		num[x]--; num[y]++;
		//printf("%d %d %d %d\n", red[x], red[y], num[x], num[y]);
	}
	int ans = 0;
	fo(i,0,n) ans += red[i];
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int a[1000005]={0};
int main()
{
    int n,k,q,num;
    scanf("%d%d%d",&n,&k,&q);
    for(int i=0;i<q;i++){
        scanf("%d",&num);
        a[num]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]+k>q)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1024
class Segment_tree():
    def __init__(self, n, s):
        self.alphabet_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        self.key = dict()
        self.k = 1
        for value in self.alphabet_list:
            self.key[value] = self.k
            self.k *= 2
        self.inf = pow(2, 32)
        self.n = n
        self.s = s
        self.N = 1
        while self.N < self.n:
            self.N *= 2
        self.size = self.N * 2
        self.size -= 1
        self.N -= 1
        self.segment = [0]*(self.N) + [self.key[self.s[i]] for i in range(self.n)] + [0]*(self.size-self.N-self.n)
        for i in range(self.N-1, -1, -1):
            self.segment[i] = self.segment[2*i+1]|self.segment[2*i+2]

    def update(self, i, x):
        i += (self.N-1)
        self.segment[i] = self.key[x]
        while i > 0:
            i = (i-1)//2
            self.segment[i] = self.segment[2*i+1]|self.segment[2*i+2]
        
    def find(self, a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return self.segment[k]
        else:
            find_l = self.find(a, b, 2*k+1, l, (l+r)//2)
            find_r = self.find(a, b, 2*k+2, (l+r)//2, r)
            return find_l|find_r


n = int(input())
s = input()
segment = Segment_tree(n, s)
q = int(input())
N = 1
while N < n:
  N *= 2
for i in range(q):
    quer = [x for x in input().split()]
    if quer[0] == "1":
        i, c = int(quer[1]), quer[2]
        segment.update(i, c)
    else:
        l, r = int(quer[1]), int(quer[2])
        key = segment.find(l-1, r, 0, 0, N)
        ans = 0
        for i in range(26):
            if (key>>i)&1:
                ans += 1
        print(ans)

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

int digit_sum(int n){
   if(n < 10)  return n;
   return digit_sum(n/10) + n%10;
}

int main(void){
   
    int N,A,B,sum = 0;
    cin >> N >> A >> B;
    
    for(int i=1;i<=N;i++){
        int k = digit_sum(i);
        if(A <= k && k <= B) sum += i;
    }
    
    cout << sum <<endl;
}

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

using namespace std;

void solve() {
        int n;
        cin >> n;
        string s;
        cin >> s;

        int j = n - 1;
        int ans = 0;
        for (int i = 0; i < j; i++) {
                if (s[i] == 'R') continue;
                while (j > i && s[j] == 'W') j--;
                if (j == i) break;
                j--;
                ans++;
        }
        cout << ans << endl;
}


int main() {
#ifdef QWERTY
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
        ios_base::sync_with_stdio(false);


        int t = 1;
//        cin >> t;

        for (int i = 1; i <= t; i++) {
//                cout << "Case #" << i << ':' << endl;
                solve();
        }


        return 0;
}

Measured memory_bytes: 3784
MOD = 10**9 + 7
def main():
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  flag = True
  if N % 2 == 1:
    for i in range(N//2 + 1):
      if i == 0:
        if A[i] != 0:
          flag = False
          break
      else:
        if A[2*i-1] != 2*i or A[2*i] != 2*i:
          flag = False
          break
  else:
    for i in range(N//2):
      if A[2*i] != 2*i+1 or A[2*i+1] != 2*i +1:
        flag = False
        break
  if flag:
    print(pow(2, N//2, MOD))
  else:
    print(0)
if __name__ == "__main__":
  main()

Measured memory_bytes: 14008
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  priority_queue<long> q;
  for (int i=0; i<n; i++) {
    int a;
    cin >> a;
    q.push(a);
  }

  for (int i=0; i<m; i++) {
    int a = q.top();
    q.pop();
    q.push((int)((double)a/2.0));
  }

  long ans = 0;
  while(! q.empty()) {
    ans += q.top();
    q.pop();
  }

  cout << ans << endl;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day2/problems/F>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

struct edge{
    ll u,v,a,b;
    edge(ll u = 0,ll v = 0,ll a = 0,ll b = 0):u(u),v(v),a(a),b(b){}
};

ll N,M,S,G;
vector<vector<edge>> g;
vector<ll> dist;


ll check(ll t,ll a,ll b){
    if(a+t >= b) return t+1;
    ll ret = LINF;
    ll l = t, r = b;
    while(r-l>2){
        ll m1 = (r-l)/3 + l;
        ll m2 = (r-l)*2/3 + l;
        
        double c1 = m1 + (double)(b+m1+a-1)/(m1+a);
        double c2 = m2 + (double)(b+m2+a-1)/(m2+a);
        if(c1 < c2){
            r = m2;
        }else{
            l = m1;
        }
    }
    for(ll t = l; t <= r; t++){
        ret = min(ret,t+(b+t+a-1)/(t+a));
    }
    return ret;
}
ll solve(){
    ll res = 0;
    scanf("%lld %lld %lld %lld",&N,&M,&S,&G);
    S--; G--;

    g.resize(N); dist.resize(N);
    for(int i = 0; i < M;i++){
        ll U,V,A,B;
        scanf("%lld %lld %lld %lld",&U,&V,&A,&B);
        U--; V--;
        g[U].push_back(edge(U,V,A,B));
        g[V].push_back(edge(V,U,A,B));
    }
    
    
    fill(dist.begin(),dist.end(),LINF);
    dist[S] = 0;
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push({0,S});
    while(pq.size()){
        ll t,n; tie(t,n) = pq.top(); pq.pop();
        if(t > dist[n]) continue;
        if(n == G) break;
        
        for(const edge& e:g[n]){
            ll a = e.a, b = e.b;
            ll cost = check(t,a,b);
            if(dist[e.v] > cost){
                dist[e.v] = cost;
                pq.push({dist[e.v],e.v});
            }
        }
    }
    if(dist[G] == LINF) return -1;
    res = dist[G];
    return res;
}
int main(void) {
    //   cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  vector<ll> a(n+1);  rep(i, 0, n+1) cin >> a[i];
  vector<ll> b(n);  rep(i, 0, n) cin >> b[i];
  
  ll ans = 0;
  rep(i, 0, n) {
    if(a[i] > b[i]) {
      ans += b[i];
    }
    else {
      ans += a[i];
      b[i] -= a[i];
      if(a[i+1] > b[i]) {
        a[i+1] -= b[i];
        ans += b[i];
      }
      else {
        ans += a[i+1];
        a[i+1] = 0;
      }
    }
  }
    
  cout << ans << "\n";
}

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,A,B;
  cin >> N >> A >> B;
  ll ans=0;
  rep1(i,N){
    ll sum=0;
    ll tmp=i;
    while(1){
      sum+=tmp%10;
      tmp/=10;
      if(tmp==0) break;
    }
    if(sum>= A && B>= sum) ans+=i;
  }
  cout <<ans << endl;
  return 0;
    

}


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

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

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

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


using namespace std;

int dp[10][865][102] = {};

long long int saiki ( int n , int s , int x )
{
	if( n == 1 )
	{
		if( s <= x &&s >= 0 )return 1;
		else return 0;
	}
	long long int ans = 0;
	for( int i = min(x,s); i >= 0; i-- )
	{
		if( dp[n - 1][s - i][i - 1] == -1 )
		{
			dp[n - 1][s - i][i - 1] = saiki ( n - 1 , s - i , i - 1 );
		}
		ans += dp[n - 1][s - i][i - 1];
	}
	return ans;
}

int main ()
{
	int n , s;
	for( size_t i = 0; i < 10; i++ )
	{
		for( size_t j = 0; j < 865; j++ )
		{
			for( size_t k = 0; k < 102; k++ )
			{
				dp[i][j][k] = -1;
			}
		}
	}
	while( cin >> n >> s , n || s ) { 
		if( s > 864 )cout << 0 << endl;
		else cout << saiki ( n , s , min ( 100 , s ) ) << endl;
	}
}

Measured memory_bytes: 4604
#include <stdio.h>

int main(void){
    int A,B,C,D ;
    int l,r;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    l = A + B;
    r = C + D;
    if(l>r){
        printf("Left\n");
    }else if(l<r){
        printf("Right\n");
    }else{
        printf("Balanced\n");
    }
    return 0;
}

Measured memory_bytes: 128
object Main
  extends App {
  val N        = readInt
  val initList = readLine.split(" ").map(_.toInt).toList

  (0 until N).foldLeft(initList)((acc, h) => sortAndPrint(acc, h))

  def sortAndPrint(list: List[Int], i: Int): List[Int] = {
    val target = list(i)
    val left = list.take(i)
    val right = list.drop(i + 1)
    val insertIndex = left.dropWhileRight(target <= _).length
    val newList = left.take(insertIndex) ++ List(target) ++ left.drop(insertIndex) ++ right
    println(newList.mkString(" "))
    newList
  }

  implicit class RichList[A](l: List[A]) {
    def dropWhileRight(f: A => Boolean): List[A] = {
      l.reverse.dropWhile(f).reverse
    }
  }
}



Measured memory_bytes: 47292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
vector<ll> fac(4e5+4), ifac(4e5+4);

ll add(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod)%mod;
}

ll mul(ll a, ll b, ll mod = md) {
    return ((a%mod) * (b%mod))%mod;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    return res%mod;
}

ll C(ll n, ll r, ll mod = md) {
    if(n < r) return 0;
    return mul(fac[n], mul(ifac[r], ifac[n-r], mod), mod);
}

void cachefact(ll bound, ll mod = md) {
    fac[0] = 1;
    ifac[0] = power(1, mod-2)%mod;
    for(ll i = 1; i <= bound; i++) {
        fac[i] = (fac[i-1] % mod * i % mod)%mod;
        ifac[i] = power(fac[i], mod-2)%mod;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cachefact(4e5);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll sum = 0, subt = 0;
    for(int i = 0; i < n; i++) {
        sum = add(sum, mul(a[i], C(i, k-1)));
        subt = add(subt, mul(a[i], C(n-i-1, k-1)));
    }
    cout << add(sum, -subt) << "\n";
    return 0;
}


Measured memory_bytes: 10328
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int solve(int x, int n, std::vector<int>& values)
{
  std::sort(values.begin(), values.end());
  auto it = std::lower_bound(values.begin(), values.end(), x);
  if (it == values.end()) return x;
  if (*it != x) return x;

  auto x_left = x;
  auto it_left = it;
  auto x_right = x;
  auto it_right = it;

  while (it_left != values.begin()) {
    --it_left;
    --x_left;
    if (*it_left != x_left) break;
  }

  while (it_right + 1 != values.end()) {
    ++it_right;
    ++x_right;
    if (*it_right != x_right) break;
  }

  std::cerr << "left=" << x_left << ", right=" << x_right << std::endl;

  if (*it_left == x_left) --x_left;
  if (*it_right == x_right) ++x_right;

  return std::abs(x - x_left) <= std::abs(x - x_right) ? x_left : x_right;
}

int main()
{
  int x, n;
  std::cin >> x >> n;
  std::vector<int> values(n);
  for (auto& v : values) {
    std::cin >> v;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(x, n, values) << std::endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
int Prime(int X){
    int c=1,N,i;
    N=sqrt(X);
    for(i=2;i<=N;i++){
        if(X%i==0){
            c=-1;
            break;
        }
    }
    return c;
}
int main(void){
    int n,i,x,c,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        c=Prime(x);
        if(c==1){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print1(x) cerr << "x = " << x << endl;
#define print2(x, y) cerr<< "x,y = "  << x << "," << y << endl;
#define print3(x, y, z) cerr << "x,y,z = " << x << "," << y << "," << z << endl;
#define print4(x, y, z, w) cerr << "x,y,z,w = " << x << "," << y << "," << z << "," << w << endl;
#define MAX_V int(2e5 + 1)
const ll mod = ll(1e9+7);

struct edge{int to, cost;};

vector<edge> G[MAX_V];
vector<bool> seen;
vector<ll> bunshi;
int N;

// O(log n)
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

//ax + by = gcd(a, b) �𖞂��� x, y ��Ԃ�
ll extgcd (ll a, ll b, ll& x, ll& y){
    ll d = a;
    if (b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a/b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

// O(log n)
// ax == 1 (mod m)�𖞂��� x
ll mod_inverse(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

int dfs(int v) {
    // �s�����������C���N�������g���Ȃ��烁��
    int res, tot = 0; // �c��[����������
    ll x = 0, y = mod_pow(2, N - 1, mod);
    ll sum = 1;
    seen[v] = true; // v ��K��ςɂ���
    for (auto e: G[v]){
        if (seen[e.to]) continue; 
        res = dfs(e.to);
        
        (y += mod - mod_pow(2, res, mod)) %= mod;
        
        tot += res;
    }
    res = N - 1 - tot;
    if (res > 0){
        (y += mod - mod_pow(2, res, mod)) %= mod;
    }
    (y += G[v].size() - 1) %= mod;

    bunshi[v] = y;
    if (G[v].size() <= 1){
        bunshi[v] = 0;
    }
    return tot + 1;
}

////////////////////////////////////////

int main() {
    cin >> N;
    vector<int> A(N), B(N);
    
    rep(i, N - 1){
        cin >>  A[i] >> B[i];
        G[A[i] - 1].push_back((edge){B[i] - 1, 0});
        G[B[i] - 1].push_back((edge){A[i] - 1, 0});
    }
    
    seen.assign(N, false); // �S���_���u���K��v�ɏ�����
    bunshi.assign(N, 0); // �S���_��0�ɏ�����
    dfs(0);
    ll bunshi0 = 0;
    ll bunbo = mod_pow(2, N, mod);
    
    rep(i, N){
        //fprintf(stderr, "%d, %d/%d\n", i, bunshi[i], bunbo);
        bunshi0 += bunshi[i];
        bunshi0 %= mod;
    }
    //fprintf(stderr, "bunshi = %d, bunbo = %d\n", bunshi0, bunbo);
    // (bunbo) * x == 1 (mod m)�𖞂��� x
    ll x = mod_inverse(bunbo, mod);
    
    ll ans = bunshi0 * mod_pow(mod_inverse(2, mod), N, mod) % mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 23552
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll INF = 1e18;
int ans[100010];
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    ans[s] = 0;
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          if (d[e.to]%2==0) ans[e.to] = 0;
          else ans[e.to] = 1;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

int main() {
    int n; cin >> n;
    graph g(n);
    rep(i,n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g.add_edge(u,v,w);
        g.add_edge(v,u,w);
    }
    
    g.dijkstra(0);
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9088
from math import log2 as log

n = int(input())
n_lst = list(map(int,input().split()))
ans = 0
while True:
    for i in range(len(n_lst)):
        if n_lst[i]%2 == 1:
            print(ans)
            exit()
        else:
            n_lst[i] //= 2
    ans += 1


Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     factorial[0] = 1; 
    for (int i = 1; i <= 2001; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod; 
    }

    int s;
    cin>>s;
    int n = s/3;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        int p = s - 3*i;
        ans += nc(p+i-1,i-1,mod);
        ans%=mod;
        //cout<<ans<<nl;
        
    }
    cout<<ans%mod<<nl;
    


	return 0;
}


Measured memory_bytes: 3664
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
lli add(lli a, lli b) {
	return ((a % mod) + (b % mod)) % mod;
}
lli sub(lli a, lli b) {
	return ((a % mod) - (b % mod) + mod) % mod;
}
lli mul(lli a, lli b) {
	return ((a % mod) * (b % mod)) % mod;
}
lli fastPow(lli base, lli power) {
	lli ret = 1;
	while (power) {
		if (power & 1) {
			ret = mul(ret, base);
		}
		base = mul(base, base);
		power >>= 1;
	}
	return ret;
}
void solve() {
	lli n, k;
	cin >> n >> k;
	lli ret = 0;
	vi cnt(k + 1);
	for (lli i  = k; i >= 1; i--) {
		lli num = k / i;
		cnt[i] = add(fastPow(num, n), cnt[i]);
		for (lli j = i + i; j <= k; j += i) {
			cnt[i] = sub(cnt[i], cnt[j]);
		}
		ret = add(ret, mul(cnt[i], i));
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}


Measured memory_bytes: 4008
#include <cstdio>
#include <cstdlib>
#include <cstring>

char s[100010];
char ts[100010];
int ix[100010];
int n2;

void solve()
{
	int i, j;
	int len = strlen(s);
	for(i=0; i<len; i++){
		if(s[i]!='x')
			break;
	}
	if(i==len){
		printf("0\n");
		return ;
	}
	j = 0;
	for(i=0; i<len; i++){
		if(s[i]!='x'){
			ts[j] = s[i];
			ix[j] = i;
			j ++;
		}
	}
	for(i=0; i<j/2; i++){
		if(ts[i] != ts[j-1-i])
			break;
	}
	if(i<j/2){
		printf("-1\n");
		return ;
	}
	n2 = j;
	int res = 0;
	res += abs(ix[0] - (len-1-ix[n2-1]) );
	for(i=1; i<n2/2; i++){
		j = n2-1-i;
		res += abs(ix[i]-ix[i-1] - (ix[j+1]-ix[j]) );
	}
	if(n2>1 && n2%2==1){
		j = i;
		res += abs(ix[i]-ix[i-1] - (ix[j+1]-ix[j]) );
	}
	printf("%d\n", res);
}

int main()
{
	scanf("%s", s);
	solve();
	return 0;
}

Measured memory_bytes: 768
import math
import itertools

N,D= map(int,input().split())
X = []
count=0
for x in range(N):
    X.append(list(map(int,input().split()))) 

listArray = list(itertools.combinations(X, 2))

for X in listArray:
    sumX = 0
    for x in range(D):
        subX = X[0][x] - X[1][x]
        sumX += subX**2
     
    if math.sqrt(sumX).is_integer():
        count += 1
    
print(count)

    

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;

int main(){
    int n;
    cin >> n;
    vector<lli> a(n+1, 0);
    for(int i=0; i<n; i++){
        cin >> a[i+1];
    }
    for(int i=0; i<n; i++){
        a[i+1] += a[i];
    }
    lli ans = 0;
    map<lli, lli> nums;
    for(int i=0; i<n+1; i++){
        ans += nums[a[i]];
        nums[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17228
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

s = 0

for i in range(n):
    s += b[a[i]-1]
    if i > 0 and a[i-1] + 1 == a[i]:
        s += c[a[i-1]-1]

print(s)

Measured memory_bytes: 61800
def gcd(x, y):
  if(x == 0):
    return y
  elif(y == 0):
    return x
  else:
    while(x % y != 0 and y % x != 0):
      if(x > y):
        x = x % y
      else:
        y = y % x
    if(x > y):
      return y
    else:
      return x
  
N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+2) #L[i]:= 1, 2, ..., i-1番目までの最大公約数
R = [0]*(N+2) #R[i]:= i, i+1, i+2, ..., N番目までの最大公約数
M = [0]*N
L[0] = 0
R[N+1] = 0
for i in range(N):
  L[i+1] = gcd(L[i], A[i])
for i in range(N, 0, -1):
  R[i] = gcd(R[i+1], A[i-1])
for i in range(N):
  M[i] = gcd(L[i], R[i+2])
print(max(M))

Measured memory_bytes: 14080
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=400+2,VMAX=1e9+1;
const ll INF=1e15;
ll n,a[NMAX],dp[NMAX][NMAX],prefix[NMAX];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	prefix[0]=0;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		prefix[i]=prefix[i-1]+a[i];
		//cout << prefix[i] << ' ';
	}
	//cout << endl;
	for(int ecart=0;ecart<n;ecart++){
		for(int i=1;i<=n;i++){
			int j=i+ecart;
			
			if(j<=n){
				
				if(j==i){
					dp[i][j]=0;
				}
				else{
					ll minimum=INF;
					
					for(int k=i;k<j;k++){
						minimum=min(minimum,dp[i][k]+dp[k+1][j]);
					}
					dp[i][j]=minimum+prefix[j]-prefix[i-1];
				}
			}
			//cout << i << ' ' << j << ' ' << prefix[j]-prefix[i-1] << endl;
		}
	}
	
	cout << dp[1][n] << '\n';
			
}


Measured memory_bytes: 1536
#include <stdio.h>
#define MAX 100

int z(int a){return a>0 ? a : -a;}

int main(){
  int cx,cy,ch,chu,dh,n,x[MAX],y[MAX],h[MAX],i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d%d%d",&x[i],&y[i],&h[i]);
  
  for(cx=0;cx<=100;cx++){
    for(cy=0;cy<=100;cy++){
      if(h[0]==0){
        ch = 0;
        chu = z(x[0]-cx) + z(y[0]-cy);
      }else{
        ch = h[0] + z(x[0]-cx) + z(y[0]-cy);
      }
      for(i=1;i<n;i++){
        dh = h[i]+z(x[i]-cx)+z(y[i]-cy);
        if(h[i]==0){
          if(ch==0){
            if(dh < chu)
              chu = dh;
          }else{
            if(dh < ch)break;
          }
        }else{
          if(ch==0){
            if(chu < dh)
              break;
            else
              ch = dh;
          }else{
            if(dh != ch)break;
          }
        }
      }
      if(i==n){
        if(ch==0 && chu==1)ch=1;
        if(ch >= 1){
          printf("%d %d %d\n",cx,cy,ch);
          return 0;
        }
      }
    }
  }
  
  return 1;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

int n;
vector<int> a(1000100);
vector<int> cnt(1000100);

int main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        cnt[a[i]]++;
        cnt[a[i]+1]++;
        if(a[i]>0) cnt[a[i]-1]++;
    }
    sort(cnt.begin(),cnt.end(),greater<int>());
    cout<<cnt[0]<<"\n";
    return 0;
}

Measured memory_bytes: 10936
#include<queue>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;
 
struct A{
	int x,y;
};
 
queue<A>Q;

char a[810][810];
int vis[810][810],in[810][810],n,m,K;
 
void bfs(int x,int y){
	Q.push((A){x,y});
	vis[x][y]=0;
	while(!Q.empty()){
		A p=Q.front();Q.pop();int x,y,d=vis[p.x][p.y];in[p.x][p.y]=0;
		x=p.x-1;y=p.y;if(x>0&&y>0&&x<=n&&y<=m&&d+1<=K&&d+1<vis[x][y]&&a[x][y]!='#'){vis[x][y]=d+1;if(!in[x][y]){Q.push((A){x,y});in[x][y]=1;}}
		x=p.x+1;y=p.y;if(x>0&&y>0&&x<=n&&y<=m&&d+1<=K&&d+1<vis[x][y]&&a[x][y]!='#'){vis[x][y]=d+1;if(!in[x][y]){Q.push((A){x,y});in[x][y]=1;}}
		x=p.x;y=p.y-1;if(x>0&&y>0&&x<=n&&y<=m&&d+1<=K&&d+1<vis[x][y]&&a[x][y]!='#'){vis[x][y]=d+1;if(!in[x][y]){Q.push((A){x,y});in[x][y]=1;}}
		x=p.x;y=p.y+1;if(x>0&&y>0&&x<=n&&y<=m&&d+1<=K&&d+1<vis[x][y]&&a[x][y]!='#'){vis[x][y]=d+1;if(!in[x][y]){Q.push((A){x,y});in[x][y]=1;}}
	}
}
 
int Que(int x,int y){
	return min(min(x-1,y-1),min(n-x,m-y));
}
 
int main(){
	int x,y;
	scanf("%d %d %d",&n,&m,&K);
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
		for(int j=1;j<=m;j++){
			if(a[i][j]=='S')x=i,y=j;
		}
	}memset(vis,63,sizeof(vis));
	bfs(x,y);
	int minn=1<<30;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(vis[i][j]!=vis[0][0])minn=min(minn,Que(i,j));
		}
	}if(minn==0)printf("1\n");
	else printf("%d\n",1+(minn-1)/K+1);
	return 0;
}

Measured memory_bytes: 6016
/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1600&lang=jp
	Entrance Examination
*/

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// 標準入力を取得するScannerのインスタンスを作成
var scanner = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込みintとして返す

func readLine() int {
	if scanner.Scan() {
		number, _ := strconv.Atoi(scanner.Text())
		return number
	}
	return 0
}

func main() {
	// 改行から空白区切りに変更
	scanner.Split(bufio.ScanWords)

	// 0 0 0の行に到達するまでループする
	for {
		// 合格者、不合格者の境目=ギャップ
		m := readLine()   // 受験者の人数
		min := readLine() // 合格者の最小人数
		max := readLine() // 合格者の最大人数

		// 0 0 0の行に到達したのでループを抜け終了する
		if m == 0 && min == 0 && max == 0 {
			break
		}

		// 得点を格納するsliceを初期化
		ps := make([]int, 0, m)

		// sliceに得点を格納する
		for i := 0; i < m; i++ {
			ps = append(ps, readLine())
		}

		tmp := 0    // ギャップを一時的に保存
		gap := 0    // ギャップの最大値を保存
		answer := 0 // ギャップが最大になった時のindex(合格人数)を保存

		// 合格者の最小人数〜最大人数のギャップを計算する
		for i := min; i <= max; i++ {
			tmp = ps[i-1] - ps[i]

			// ギャップの最大値が更新された場合、最大値と合格人数を更新する
			// ギャップが同じ値だった場合も合格人数を更新する
			// (合格人数が多い方が優先されるので後から現れた値が優先される)
			if tmp >= gap {
				gap = tmp
				answer = i
			}
		}
		fmt.Println(answer)
	}
}



Measured memory_bytes: 1480
from math import sin, cos, pi, sqrt
a, b, h, m = map(float, input().split())
A = [a * cos(2 * pi * (h * 60 + m) / 720), a * sin(2 * pi * (h * 60 + m) / 720)]
B = [b * cos(2 * pi * m / 60), b * sin(2 * pi * m / 60)]
print("{:.15f}".format(sqrt((A[0] - B[0])**2 + (A[1] - B[1])**2)))


Measured memory_bytes: 9516
//#include <climits>
#include <vector>
#include <iostream>
//#include <sstream>
// #include <string>
using namespace std;


//char H[M][L]
//　→ charだから2次元配列になっているが、
//   stringだとH[M]の1次元配列で良い

class MyHash{
    private:
        static const int HASH_SIZE = 1046527;
        // static const int HASH_SIZE = 10000;
        string H[HASH_SIZE];
        int h1(int key);
        int h2(int key);
        int getHash(int key, int i);
        int getChar(char c);
        long long getKey(string str);
    public:
        MyHash();
        int find(string str);
        int insert(string str);
};


MyHash::MyHash() {
    for (int i = 0; i < HASH_SIZE; ++i)
    {
         H[i] = "";
    }
}


int MyHash::h1(int key) {
    return key % HASH_SIZE;
}

int MyHash::h2(int key) {
    return 1 + (key % (HASH_SIZE - 1));
}

long long MyHash::getKey(string str) {
    long long sum = 0;
    long long p = 1;

    for (long long i = 0; i < str.size(); ++i)
    {
        sum += p * getChar(str[i]);
        p *= 5;
    }

    return sum;
}

int MyHash::getChar(char c) {
    switch(c) {
        case 'A' :
            return 1;
        case 'C' :
            return 2;
        case 'G' :
            return 3;
        case 'T' :
            return 4;
        default :
            return 0;
    }
}



int MyHash::getHash(int key, int i) {
    return (h1(key) + i * h2(key)) % HASH_SIZE;
}

int MyHash::find(string str) {
    for (long long i = 0; ; ++i)
    {
        long long key  = getKey(str);
        long long hash = getHash(key, i);
        //ある
        if(H[hash] == str) {
            return 1;
        }
        //ない
        if(H[hash].size() == 0) {
            return 0;
        }
    }

    return 0;
}

int MyHash::insert(string str) {
    for (long long i = 0; ; ++i)
    {
        long long key  = getKey(str);
        long long hash = getHash(key, i);
        //既にあるとき
        if(H[hash] == str) {
            return 1;
        }
        //insertするとき
        if(H[hash].size() == 0) {
            H[hash] = str;
            return 0;
        }
    }

    return 0;
}



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

    vector<string> command(n);
    vector<string> str(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> command[i] >> str[i];
    }


    MyHash myhash;
    for (int i = 0; i < n; ++i)
    {
        if(command[i] == "insert") {
            myhash.insert(str[i]);
        } else { //find
            if(myhash.find(str[i])) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }

        }
    }

    return 0;
}



Measured memory_bytes: 126692
#include<iostream>
using namespace std;
int n,k;
char c[51];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(i==k){
			c[i]=char(int(c[i])+32);
		}
	}
	for(int i=1;i<=n;i++){
		cout<<c[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(VI::iterator it=(v).begin();it!=(v).end();++it)


int main() {
  int C[3][3];
  REP(i, 3) {
    REP(j, 3) {
      int c;
      cin >> c;
      C[i][j] = c;
    }
  }
  int sum_row[3], sum_column[3];
  fill(sum_row, sum_row+3, 0);
  fill(sum_column, sum_column+3, 0);
  REP(i, 3) {
    REP(j, 3) {
      sum_row[i] += C[i][j];
      sum_column[j] += C[i][j];
    }
  }
  cout << ((sum_column[0] - sum_column[1]) % 3 == 0 &&
           (sum_column[1] - sum_column[2]) % 3 == 0 &&
           (sum_column[0] - sum_column[2]) % 3 == 0 &&
           (sum_row[0] - sum_row[1]) % 3 == 0 &&
           (sum_row[1] - sum_row[2]) % 3 == 0 &&
           (sum_row[0] - sum_row[2]) % 3 == 0 ? "Yes" : "No") << endl;

  return 0;
}


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

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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

    vector<string> v;
    for(int i = 0 ; i < s.size() ; i++){
        string tmp = s.substr(i,1);

        if(tmp=="B") {if (v.size()>0)v.pop_back();}
        else v.push_back(tmp);
    }

    for(int i = 0 ; i < v.size() ; i++){
        cout << v.at(i);
    }
    cout << endl;
} 

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

using namespace std;

int main() {
    
    int n, st;
    cin>>n>>st;
    int t[n];
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
    }
    int s=0;
    for(auto i=1;i<n;i++)
    {
        if(t[i]-t[i-1] < st)
        {
            s+=t[i]-t[i-1];
        }
        else
            s+=st;
    }
    s+=st;
    cout<<s;
    
    return 0;
}

Measured memory_bytes: 1024
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    read!(usize);
    let S = rl().chars().collect::<Vec<_>>();

    let mut count = 0;
    let mut l = 0;
    let mut r = 1;

    while r <= S.len() {
        if r == S.len() || S[r] != S[l] {
            count += 1;
            l = r;
            r = l + 1;
            continue;
        }

        r += 1;
    }

    println!("{}", count)
}


Measured memory_bytes: 4352
class Combination():
    def __init__(self, n, mod):
        self.mod = mod
        self.fac = [1]*(n+1)
        for i in range(1,n+1):
            self.fac[i] = self.fac[i-1] * i % self.mod
        self.invfac = [1]*(n+1)
        self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
        for i in range(n-1, 0, -1):
            self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod
    
    def combination(self, n, r):
        return self.fac[n] * self.invfac[r] % self.mod * self.invfac[n-r] % self.mod
    
    def factorial(self, i):
        return self.fac[i]
    
    def invfactorial(self, i):
        return self.invfac[i]


class Rerooting(Combination):
    def __init__(self, adjacent, n, mod):
        super(Rerooting, self).__init__(n, mod)
        self.n = n
        self.adj = adjacent   # 0-indexedの配列で用意！
        # DFSで行きがけ順を記録
        self.order = []
        stack = [0]
        self.parent = [-1]*(n)
        while stack:
            node = stack.pop()
            self.order.append(node)
            for child in self.adj[node]:
                if self.parent[node] == child:
                    continue
                stack.append(child)
                self.parent[child] = node
    
    def merge(self, parent, child):
        # childの値をparentに統合する処理
        self.size[parent] += self.size[child]
        self.dp[parent] *= self.combination(self.size[parent]-1,self.size[child])
        self.dp[parent] %= self.mod
        self.dp[parent] *= self.dp[child]
        self.dp[parent] %= self.mod
        return self.dp[parent]

    def remerge(self, parent, child):
        # childの値が根となるときの統合処理
        self.dp[child] = self.size[child]*self.dp[parent]
        self.dp[child] *= pow(self.n-self.size[child], self.mod -2, self.mod)
        self.dp[child] %= self.mod
        return self.dp[child]

    def calc_subtree(self):
        # 帰りがけ順で木DPを行う
        # 根が0の時の値を算出
        self.dp = [1]*(self.n)
        self.size = [1]*(self.n)
        for node in self.order[::-1]:
            if self.parent[node] == -1:
                continue
            self.merge(self.parent[node], node)

    def root_subtree(self):
        # 行きがけ順で
        for node in self.order[1:]:
            p = self.parent[node]
            self.remerge(p, node)
        return self.dp
        

def main():
    import sys
    input = lambda: sys.stdin.buffer.readline().rstrip()
    n = int(input())
    mod = 10**9 + 7
    adj = [[] for i in range(n)]
    for i in range(n-1):
        a, b = map(lambda x: int(x)-1, input().split())
        adj[a].append(b)
        adj[b].append(a)

    r = Rerooting(adj, n, mod)
    r.calc_subtree()
    dp = r.root_subtree()

    for ans in dp:
        print(ans)


if __name__ == '__main__':
    main()

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


int main(){

    string O,E;
    cin >> O >> E;
    int n = O.length()-E.length();

    if(n == 0){

        for(int i = 0;i < O.length();i++){
            cout << O[i] << E[i];
        }
        cout << endl;
    }else{

        for(int i = 0;i < O.length()-1;i++){
            cout << O[i] << E[i];
        }
        cout << O[O.length()-1] << endl;


    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())

if abs(A-B) % 2 == 0:
  print(abs(A-B) // 2)
  exit()
  
if abs(A-B) == 1:
  print(min(max(A-1,B-1),max(N-A,N-B)))
  exit()
  
print(min(min(A-1,B-1),min(N-A,N-B))+1+(abs(A-B)-1)//2)

Measured memory_bytes: 9052