akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  
  int n, m;
  cin >> n >> m;

  vector<vector<int>> g(n + 5);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;

    g[u].push_back(v);
  }

  auto calc = [&](vector<double> &d, int x) {
    for (auto to : g[x])
      d[x] += d[to];
    d[x] /= g[x].size();
    d[x]++;
  };

  vector<double> dp(n + 5, 0);
  for (int i = n - 1; i > 0; --i) {
    calc(dp, i);
  }

  double ans = dp[1];
  for (int i = n - 1; i > 0; --i) {
    if (g[i].size() == 1) continue;
    vector<double> cur(n + 5, 0);
    double mx = 0;
    for (auto to : g[i])  mx = max(mx, dp[to]);
    for (int j = n - 1; j > 0; --j) {
      if (j > i)  cur[j] = dp[j];
      else if (j == i)  {
        if (g[j].size() == 1) cur[j] = 0;
        else cur[j] = (dp[j] * g[j].size() - mx - 1) / (g[j].size() - 1);
      }
      else calc(cur, j);
    }
    ans = min(ans, cur[1]);
  }
  cout << ans << '\n';  
}  

Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,i,ans=1;
ll a[nmax],sum;
int main()
{
	//freopen("sol.in","r",stdin);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<n;i++)
	{
		sum+=a[i];
		if(a[i+1]>2*sum)ans=i+1;
	}
	cout<<n-ans+1<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, b, f[100005];
int find(int x){
	if(x == f[x]) return x;
	return f[x] = find(f[x]);
}
int main(){
	scanf("%d%d", &n, &m);
	for(i=1; i<=n; i++) f[i] = i;
	for(i=1; i<=m; i++){
		scanf("%d%d%*d", &a, &b);
		if(find(a) != find(b)){
			f[f[a]] = f[b], k++;
		}
	}
	printf("%d\n", n-k);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

using namespace std;
int main()
{
	int longNum = 0, shortNum = 0;
	char buffer[256];
	fgets(buffer, 256, stdin);
	if (sscanf(buffer, "%d %d", &longNum, &shortNum) > 0) {
		printf("%d %d\n", longNum * shortNum, (longNum + shortNum) * 2);
	}
	else {
		printf("error");
	}
}



Measured memory_bytes: 2576
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

int u[100001];

int find(int a)
{
	if (u[a] < 0) return a;
	return u[a] = find(u[a]);
}

bool merge(int a, int b)
{
	a = find(a), b = find(b);
	if (a == b) return false;
	if (abs(u[a]) < abs(u[b])) swap(a, b);
	u[a] += u[b], u[b] = a;
	return true;
}

int main(void)
{
	int n, m, a, b;
	scanf("%d %d", &n, &m);
	fill(u, u + n + 1, -1);
	while (m--)
	{
		scanf("%d %d", &a, &b);
		merge(a, b);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
		if (u[i] < 0)
			ans++;
			

	printf("%d", ans - 1);
	return 0;
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n,a[100000];
map<int,int> mp;
vector<P> v;

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

	cin>>n;
	REP(i,n) {
		cin>>a[i];
		mp[a[i]]++;
	}
	for(auto e:mp) v.pb(P(e.fi,e.se));
	bool flg;
	if(v.size()>2) flg=false;
	else if(v.size()==1&&(v[0].fi*2<=n||v[0].fi==n-1)) flg=true;
	else {
		//cout<<v[0].fi<<' '<<v[0].se<<' '<<v[1].fi<<' '<<v[1].se<<endl;
		if(v[0].fi-v[0].se>=0&&(v[1].fi-v[0].se)*2<=v[1].se) flg=true;
		else flg=false;
	}
	cout<<(flg?"Yes":"No")<<endl;

	return 0;
}


Measured memory_bytes: 6524
# ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    A = tuple(tuple(map(int, input().split())) for _ in range(M))
    S, D = set(), set()  # start, destination
    for a, b in A:
        if a == 1:
            S |= {b}
        if b == N:
            D |= {a}
    flg = S & D  # if the same X in both S & D -> possible
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N;

int main()
{
	scanf("%lld",&N);
	N++;

	vector<int> ans;
	deque<bool> d;
	{
		ll c = N;
		while(c > 1){
			if(c & 1){
				d.push_back(true);
				ans.push_back(int(ans.size()) + 1);
			}
			d.push_back(false);
			ans.push_back(int(ans.size()) + 1);
			c >>= 1;
		}
	}

	FOR(i,0,d.size()) if(d [i] == false){
		ans.push_back(i + 1);
	}
	for(int i = int(d.size()) - 1;i >= 0;i--) if(d [i]){
		ans.push_back(i + 1);
	}

	printf("%lu\n",ans.size());
	FOR(i,0,ans.size()){
		printf("%d%s",ans [i],i == ans.size() - 1 ? "\n" : " ");
	}

	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = tuple(int(input()) for _ in range(N))

    num = dict()
    for n in A:
        num[n] = num.get(n, 0) + 1

    ans = 0
    for v in num.values():
        ans += v % 2

    print(ans)

main()


Measured memory_bytes: 16272
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 200000;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

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

    vi v(n);
    forn(i, n)
        cin >> v[i];

    int val = 0, res = 1;
    forn(i, n) {
        val += v[i];
        if(val <= x) {
            res++;
        }
    }

    cout << res << endl;

    return 0;
}


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

ABs = []
for _ in range(N):
    A, B = map(int, input().split())
    ABs.append((A, B))

ABs = sorted(ABs, key=lambda t: t[0])

cost = 0
count_drink = 0
for A, B in ABs:
    if count_drink + B >= M:
        cost += A * (M - count_drink)
        break

    cost += A * B
    count_drink += B
print(cost)


Measured memory_bytes: 18952
[a, v] = raw_input().split()
[b, w] = raw_input().split()
t = int(raw_input())
if int(v) <= int(w):
    print 'NO'
else:
    if int(a) > int(b):
        m = int(a) - int(b)
    else:
        m = int(b) - int(a)
    s = int(v) - int(w)
    if s * t >= m:
        print 'YES'
    else:
        print 'NO'


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

vector<int> a;
vector<int> b;
vector<int> used;
int ans = 0;
int verp = 1;
int n;

void bfs(int x){
	if(verp==n){
		ans++;
		return;
	}
	for(int i = 0;i<a.size();i++){
		if(a[i]==x&&used[b[i]]==0){
			used[b[i]]=1;
			verp++;
			bfs(b[i]);
			used[b[i]]=0;
			verp--;
		}else if(b[i]==x&&used[a[i]]==0){
			used[a[i]]=1;
			verp++;
			bfs(a[i]);
			used[a[i]]=0;
			verp--;
		}
		
	}
	return;
	
}


int main(){
	int m;
	cin>>n>>m;
	
	for(int i = 0; i < m;i++){
		int tmpa,tmpb;
		cin>>tmpa>>tmpb;
		tmpa--;
		tmpb--;
		a.push_back(tmpa);
		b.push_back(tmpb);
		used.push_back(0);
	}
	
	used[0]=1;
	bfs(0);
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 500000

int A[N],R[N/2+2],L[N/2+2];
int c;
void merge(int*,int,int,int);
void mergeSort(int*,int,int);

int main(){

  int n,i,j;
  int left,right;

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

  left = 0;
  right = n;

  mergeSort(A,left,right);

  for(i=0; i<n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);

  printf("%d\n",c);

  return 0;
}

void merge(int* A,int left,int mid,int right){

  int n1,n2,i,j,k;

  n1 = mid - left;
  n2 = right - mid;

  for(i=0; i<n1; i++){
    L[i] = A[left+i];
  }

  for(i=0; i<n2; i++){
    R[i] = A[mid+i];
  }
  L[n1] = 2000000000;
  R[n2] = 2000000000;

  i=0;
  j=0;

  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      c++;
    }
    else{
      A[k] = R[j];
      j++;
      c++;
    }
  }

}

void mergeSort(int* A,int left,int right){

  int mid;

  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

Measured memory_bytes: 4504
mod=1000000007
h,w=map(int,input().split())
grid=[]
for _ in range(h):
    s=list(input())
    grid.append(s)

dp=[[0 for i in range(w)] for j in range(h)]
dp[0][0]=1
for i in range(h):
    for j in range(w):
        if grid[i][j]=='#':
            continue
        if i>0:
            dp[i][j]+=dp[i-1][j]%mod
        
        if j>0:
            dp[i][j]+=dp[i][j-1]%mod
        
print(dp[h-1][w-1]%mod)

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> quest;
    int ans = 0;

    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        quest.push_back({b,a});
    }   

    sort(quest.begin(),quest.end());
    int now_end = quest[0].first;
    ans++;
    for(int i = 1; i < m; i++){
        if(quest[i].second >= now_end){
            now_end = quest[i].first;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1528
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
int n;
map<string,int> ma;
string s;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) cin>>s,ma[s]++;
	printf("AC x %d\n",ma["AC"]);
	printf("WA x %d\n",ma["WA"]);
	printf("TLE x %d\n",ma["TLE"]);
	printf("RE x %d\n",ma["RE"]);
}

Measured memory_bytes: 3796
V,E = list(map(int,input().split()))
STD = [list(map(int,input().split())) for _ in range(E)]

D = [[float('inf')]*V for _ in range(V)]

for i in range(V):
    D[i][i] = 0

for std in STD:
    D[std[0]][std[1]] = std[2]

for k in range(V):
    for i in range(V):
        for j in range(V):
            D[i][j] = min(D[i][j], D[i][k]+D[k][j])

for i in range(V):
    if D[i][i] < 0:
        print('NEGATIVE CYCLE')
        exit()

for d in D:
    print(*list(map(lambda x: str(x) if x != float('inf') else 'INF', d)))


Measured memory_bytes: 7628
s = list(input())
i = 0
while i < len(s):
    if s[i] == 'C':
        j = i + 1
        while j < len(s):
            if s[j] == 'F':
                print('Yes')
                exit(0)
            j = j + 1
    i = i + 1

print('No')

Measured memory_bytes: 3060
#include<stdio.h>
int t[101],c[100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<=a;i++) scanf("%d",t+i);
		for(int i=0;i<=a;i++){
			int I=0;
			for(int j=0;j<=a;j++)if(i!=j)c[I++]=t[j];
			bool ok=1;
			for(int j=1;j<a;j++)if(c[1]-c[0]!=c[j]-c[j-1])ok=false;
			if(c[1]<=c[0])ok=0;
			if(ok){
				printf("%d\n",t[i]);
				break;
			}
		}
	}
}


Measured memory_bytes: 2728
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

/*
まず状態を愚直に持つことを考える
例えば oxooxoxooxo (oが未使用, xが使用済み)
          ^
          |
このとき最後に使ったのが5番目だったとすると
s[i]が'>'なら次に使える数は3つあるとわかるし、'<'なら4つとわかる

そこで (最後に使ったやつの前に何個数が余っているか, 後ろに何個余っているか) だけを覚えておくことにするとこれで情報としては十分とわかる

ただ遷移を高速にするために (i個使った, 最後に使ったやつの前or後ろに何個余っているか) を覚えておくことになる
*/

const ll MOD = 1e9 + 7;

vector<ll> sumup(const vector<ll>& a) {
  int N = a.size();
  vector<ll> res(N + 1, 0);
  for (int i = 0; i < N; i++) res[i + 1] = (res[i] + a[i]) % MOD;
  return res;
}

int main() {
  int N;
  string s;
  while (cin >> N >> s) {
    s = "<" + s;
    vector<ll> dp(N + 1, 0);
    dp[N] = 1;
    for (int i = 0; i < N; i++) {
      int rem = N - i;
      assert(rem + 1 == dp.size());
      vector<ll> ndp(rem, 0);
      for (int r = 0; r <= rem; r++) {
        int l = rem - r;
        if (s[i] == '<') {
          (ndp[0] += dp[r]) %= MOD;
          if (r < rem) (ndp[r] += MOD - dp[r]) %= MOD;
        } else {
          if (r < rem) (ndp[r] += dp[r]) %= MOD;
        }
      }
      for (int r = 1; r < rem; r++) (ndp[r] += ndp[r - 1]) %= MOD;
      dp = ndp;
    }
    cout << dp[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=998244353;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m,k;
ll jc[N],inv[N],p[N],ans;

ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}

ll C(int x,int y) {return jc[x]*inv[y]%mod*inv[x-y]%mod;}


int main() {
	qr(n); qr(m); qr(k);
	jc[0]=1;for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
	inv[n]=power(jc[n]);for(int i=n;i;i--) inv[i-1]=inv[i]*i%mod;
	p[0]=1;for(int i=1;i<=n;i++) p[i]=p[i-1]*(m-1)%mod;
	
	for(int i=0;i<=k;i++)
		(ans += C(n-1,i)*p[n-1-i]) %= mod;
	pr2(ans*m%mod);
	return 0;
}



Measured memory_bytes: 7712
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
vector<int> edge[100001];
bool used[100001];

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  int ld, rd;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(i == 0){
      ld = a;
      rd = b;
    }
    edge[a].pb(b);
    edge[b].pb(a);
  }
  used[ld] = true;
  used[rd] = true;
  deque<int> q;
  // ld
  while(true){
    q.push_front(ld);
    used[ld] = true;
    int tmp = ld;
    for(int i = 0; i < edge[ld].size(); i++){
      if(used[edge[ld][i]])continue;
      ld = edge[ld][i];
      break;
    }
    if(ld == tmp)break;
  }
  // rd
  while(true){
    q.push_back(rd);
    used[rd] = true;
    int tmp = rd;
    for(int i = 0; i < edge[rd].size(); i++){
      if(used[edge[rd][i]])continue;
      rd = edge[rd][i];
      break;
    }
    if(rd == tmp)break;
  }
  cout << q.size() << endl;
  while(!q.empty()){
    int p = q.front(); q.pop_front();
    cout << p + 1;
    if(q.size() != 0)cout << " ";
    else cout << endl;
  }
	return 0;
}


Measured memory_bytes: 6784
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  int n,k;
  int sum=0;
  int tmp=0;
  float ans=0;
  int sum_i=0;
  int tmp_i=0;
  scanf("%d %d",&n,&k);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<k;i++){
    sum+=a[i];
  }
  tmp=sum;
  for(int i=k;i<n;i++){
    tmp=tmp-a[i-k]+a[i];
    if(sum<=tmp){
      sum=tmp;
      //tmp_i=i-k+1;
    }else{
      //tmp_i=i-k+1;
    }
  }
  ans=(float)sum+(float)k;
  ans=ans/2.0;
  printf("%lf",ans);
  return 0;
}


Measured memory_bytes: 896
using System.Text;
using System;

public class BIT
{
    private int[] data;
    public BIT(int n)
    {
        data = new int[n + 1];
    }
    public int getSum(int i)
    {
        var s = 0;
        while (i > 0)
        {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
    public void addix(int i, int x, int n)
    {
        while (i <= n)
        {
            data[i] += x;
            i += i & -i;
        }
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var q = int.Parse(line[1]);
        getAns(n, q);
    }
    static void getAns(int n, int q)
    {
        var sb = new StringBuilder();
        var bit = new BIT(n);
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (line[0] == "0")
            {
                var x = int.Parse(line[1]);
                var y = int.Parse(line[2]);
                bit.addix(x, y, n);
            }
            else
            {
                var x = int.Parse(line[1]);
                var y = int.Parse(line[2]);
                if (x == 1) sb.Append(bit.getSum(y).ToString() + "\n");
                else sb.Append((bit.getSum(y) - bit.getSum(x - 1)).ToString() + "\n");
            }
        }
        Console.Write(sb);
    }
}



Measured memory_bytes: 22432
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
 
 
int main()
{
    fastio;
    
        ll n,k;
        cin>>n>>k;
        if(k>=n)
        cout<<"unsafe"<<endl;
        else
        cout<<"safe"<<endl;
        
}

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

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

  int cnt=0, cnt1=0, res=0, res1=0;

  for(int i=0; i<s.size(); ++i){
    if(i == 0){
      res1++;
      if(s[i]  == 'R' || s[i] == 'U' || s[i] == 'D') cnt1++;
    }
    if(i%2 == 1){
      res++;
      if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') cnt++;
    }
    else if(i%2 == 0){
      res1++;
      if(s[i]  == 'R' || s[i] == 'U' || s[i] == 'D') cnt1++;
    }
  }
  if(cnt == res && cnt1 == res1) cout << "Yes";
  else cout << "No";
}

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

void arrange(int& i, int n) {
    if (i >= n) {
        i = 0;
    } else if (i < 0) {
        i = n - 1;
    }
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int** square = new int* [n];
        for (int i = 0; i < n; i++) {
            square[i] = new int [n];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                square[i][j] = 0;
            }
        }
        int x = n / 2;
        int y = 1 + n / 2;
        for (int i = 0; i < n * n; ) {
            arrange(x, n);
            arrange(y, n);
            if (square[y][x] == 0) {
                square[y++][x++] = i++ + 1;
            } else {
                x--;
                y++;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                printf("%4d", square[i][j]);
            }
            printf("\n");
        }
        for (int i = 0; i < n; i++) {
            delete[] square[i];
        }
        delete[] square;
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e3 + 5, MOD = 1e9 + 7;

int a[N][N], h, w, dp[N][N];

void solve(){
    cin >> h >> w;
    string a[h] = {string(w, '_')};
    for(int i = 0; i < h; ++i){
        cin >> a[i];
    }
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for(int i = 1; i < h; ++i){
        if(a[i - 1][0] != '#')
        dp[i][0] = 1;
        else
        break;
    }
    for(int j = 1; j < w; ++j){
        if(a[0][j - 1] != '#')
        dp[0][j] = 1;
        else
        break;
    }
    for(int i = 1; i < h; ++i){
        for(int j = 1; j < w; ++j){
            if(a[i - 1][j] != '#' && a[i][j - 1] != '#')
            dp[i][j] = ((dp[i - 1][j] % MOD) + (dp[i][j - 1] % MOD)) % MOD;
            else if(a[i - 1][j] != '#')
            dp[i][j] = dp[i - 1][j];
            else if(a[i][j - 1] != '#')
            dp[i][j] = dp[i][j - 1];
        }
    }
    cout << dp[h - 1][w - 1];
}

int32_t main(){
    IOS;
    int t = 1;
    bool test = 0;
    if(test) cin >> t;
    for(int i = 1; i <= t; ++i)
    solve();
    return 0;
}

/*

  
*/
  

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

using namespace std;

void solve() {
    int n,m;
    cin >> n >> m;
    int f[n+1], l[n+1];
    for (int i=0; i<n+1; ++i) {
        f[i] = l[i] = 0;
    }
    for (int i=0; i<m; ++i) {
        int ai, bi;
        cin >> ai >> bi;
        if (ai == 1) {
            f[bi] = 1;
        }
        if (bi == n) {
            l[ai] = 1;
        }
    }
    for (int i=0; i < n+1; ++i) {
        if (f[i] == 1 && l[i] == 1) {
            cout << "POSSIBLE";
            return;
        }
    }
    cout << "IMPOSSIBLE";
}

int main() {

	solve();
    return 0;
}


Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int A[10];
    
    for(int i=1;i<=9;i++){
        cin >> A[i];
    }
    
    int N;
    cin >> N;
    
    int b[N];
    for(int i=0;i<N;i++){
        cin >> b[i];
        for(int k=1;k<=9;k++){
            if(b[i] == A[k]) A[k] = 0;
        }
    }
    
    int cnt = 0;
    
    int x[8] = {1,4,7,1,2,3,1,3};
    int y[8] = {2,5,8,4,5,6,5,5};
    int z[8] = {3,6,9,7,8,9,9,7};
    
    for(int i=0;i<8;i++){
        if(A[x[i]]+A[y[i]]+A[z[i]]==0) cnt++;
    }
    
    if(cnt != 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;
	int *s = new int[n];
	int minNum = 101;
	int sum = 0;
	rep(i,n){
		cin>>s[i];
		sum += s[i];
		if(s[i] % 10 != 0){
			minNum = min(minNum,s[i]);
		}
	}
	if( sum % 10 == 0 && minNum == 101){
		cout<<0<<endl;
	}else if( sum % 10 == 0 && minNum != 101){
		cout<<sum-minNum<<endl;
	}else{
		cout<<sum<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
n = int(input())
table = [input() for _ in range(n)]
d = dict()
for s in table:
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 0
m = max(d.values())
l = [key for key, value in d.items() if value == m]
l.sort()
print(*l, sep = "\n")

Measured memory_bytes: 35600
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  int odd = 0,even = 0;
  srep(i,1,N+1) {
    if(i % 2 == 0) {
      even++;
    } else{
      odd++;
    }
  }
  cout << setprecision(30) <<  (double)odd/(double)N << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <tgmath.h>
#include <time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

ll i, j, x;

ll nyan(ll a){
    return a*a*a*a*a;
}

main(){
    scanf("%lld", &x);
    for(i=-200;i<=200;i++){
        for(j=-200;j<=200;j++){
            if(nyan(i) - nyan(j) == x){
                printf("%lld %lld\n",i,j);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long 
#define pb push_back
int main(){	
	fast;
	ll c=0;
	ll a[3][3],b[3][3]={0};
	for(ll i=0;i<3;i++){
	for(ll j=0;j<3;j++){
		cin>>a[i][j];
		}}
	ll n; cin>>n;
	while(n--){
		ll x,f=0; cin>>x;
		for(ll i=0;i<3;i++){
		for(ll j=0;j<3;j++){
			if(a[i][j]==x){
				b[i][j]=1;
				f=1;
				break;}
			}
		if(f){
			break;}
			}
			}
	for(ll i=0;i<3;i++){
	if(b[i][0]==1 && b[i][1]==1 && b[i][2]==1){
		c=1;
		break;
		}}
	for(ll i=0;i<3;i++){
	if(b[0][i]==1 && b[1][i]==1 && b[2][i]==1){
		c=1;
		break;
		}}
	if(b[0][0]==1 && b[1][1]==1 && b[2][2]==1) {
		c=1;
		}
	
	if(b[0][2]==1 && b[1][1]==1 && b[2][0]==1) {
		c=1;
		}
	if(c==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	}	
	

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
 int  s,x,i,z=0;
 int a[101]={0};
 cin>>s;
 for(i=1;i<=s;i++)
 {
 cin>>x;
 a[x]=1;
 }
 for(i=1;i<=100;i++)
 z+=a[i];
 cout<<z;
  return 0;
}

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

int main()
{

	string s;
	cin>>s;
	if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])
		cout<<"Yes"<<endl;
	else if(s[0]==s[2] && s[1]==s[3] && s[1]!=s[2])
		cout<<"Yes"<<endl;
	else if(s[0]==s[3] && s[1]==s[2] && s[1]!=s[3])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;		

}

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

int main(){
  uint64_t A,B,N;
  uint64_t ans=0;
  uint64_t num;
  cin >> A >> B >> N;
  if(N<=1000000){
    for(uint64_t i=1; i<=N; i++){
      num = (A*i)/B - A*(i/B);
      ans = max(ans,num);
    }
  } else {
    if(B<=1000000){
      for(uint64_t i=1; i<=B; i++){
      num = (A*i)/B - A*(i/B);
      ans = max(ans,num);
    }
    } else {
      if(B>N){
        ans = (A*N)/B - A*(N/B);
      } else {
        // ここが違う
        ans = (A*(B-1))/B - A*((B-1)/B);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
 
int main(void) {
	int a, b;
	int count = 0;
 
	cin >> a >> b;
	count = a - 1;
	if (a <= b) {
		count++;
	}
	cout << count << endl;
 
 
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
struct str
{
	long long p,q;
}a[N];
bool cmp( str x, str y)
{
	return x.p<y.p;
}
int main()
{
	long long m,n,i;
	cin>>m>>n;
	for(i = 0; i < m; i++){
		cin>>a[i].p>>a[i].q;
	}
	sort(a,a+m,cmp);
	long long sum = 0;
	for(i = 0; i < m; i++){
		sum += a[i].q;
		if(sum >= n){
			cout<<a[i].p<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
import re
S = input().replace('?', '.')
T = input()
n = len(T)
for i in range(len(S) - n, -1, -1):
    if re.match(S[i:i+n], T):
        S = S.replace('.', 'a')
        print(S[:i] + T + S[i+n:])
        exit()
print('UNRESTORABLE')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

//Graph in adjcency matrix
class Graph{
private:
    int N;
    vector<vector<ll>> matrix;
public:
    Graph(int n, ll a) : N(n), matrix(n, vector<ll>(n,a)){
        for(int i=0; i<n; i++){
            matrix[i][i] = 0;
        }
    }

    void setEdge(int v1, int v2, ll d){
        matrix[v1][v2] = d;
    }
    
    void WarshallFloyd(){
        for(int k=0; k<N; k++){
            for(int i=0; i<N; i++){
                for(int j=0; j<N; j++){
                    ll d = matrix[i][k] + matrix[k][j];
                    if(d < matrix[i][j]){
                        matrix[i][j] = d;
                    }
                }
            }
        }
    }

    void solve(){
        auto matrix2 = matrix;
        WarshallFloyd();
        ll ans = 0;
        for(int i=0; i<N; i++){
            for(int j=i+1; j<N; j++){
                if(matrix2[i][j] < INF && matrix[i][j] != matrix2[i][j]){
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }

};

int main(){
    int n, m;
    cin >> n >> m;
    Graph G(n, INF);
    REP(i, m){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        G.setEdge(a-1, b-1, c);
        G.setEdge(b-1, a-1, c);
    }
    G.solve();
    return 0;
}

Measured memory_bytes: 384
N = gets.to_i
As = gets.split.map(&:to_i)
answer = nil
correct_pattern = true

# ありえるパターンかどうかのチェック
array = As.dup.sort
if N.even?
  # Nが偶数の場合、1, 1, 3, 3, ....., N-1, N-1となる
  num = 1
  until num > N - 1
    2.times do
      correct_pattern = false unless array.shift == num
    end
    if correct_pattern
      num += 2
    else
      break
    end
  end
  correct_pattern = false unless array.empty?
else
  # Nが奇数の場合、0, 2, 2, 4, 4, ...., N-1, N-1となる
  correct_pattern = false unless array.shift == 0
  num = 2
  until num > N - 1
    2.times do
      correct_pattern = false unless array.shift == num
    end
    if correct_pattern
      num += 2
    else
      break
    end
  end
  correct_pattern = false unless array.empty?
end

if correct_pattern
  # パターンとして適切なので、並び順を数え上げる
  pair_num = N / 2 # 0が1つ混じっていても影響なし
  # 各数字のペアに対して並べ方が2種類ある
  answer = 2 ** pair_num % (10 ** 9 + 7)
else
  # ありえないパターンなので、0が答えとなる
  answer = 0
end

puts answer


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

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

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

    s.erase(unique(s.begin(), s.end()), s.end());

    vector<int> v(5, 0);
    for(int i = 0; i < s.size(); i++) {
        if(s[i][0] == 'M') v[0]++;
        if(s[i][0] == 'A') v[1]++;
        if(s[i][0] == 'R') v[2]++;
        if(s[i][0] == 'C') v[3]++;
        if(s[i][0] == 'H') v[4]++;
    }

    int ans = 0;
    for(int i = 0; i < (1 << 5); i++) {
        if(__builtin_popcount(i) == 3) {
            int tmp = 1;
            for(int j = 0; j < 5; j++) {
                if(i & (1 << j)) tmp *= v[j];
            }
            ans += tmp;
        }
    }

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


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
	scanf("%s", s);
	if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') printf("Yes\n");
	else printf("No\n");
}

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


bool checkTest(int a, int b, int c)
{
  if (a != b) return false;
  if (a != c) return true;
  
  return false;
}

int main()
{
  vector<int> a{0, 0, 0};
  
  cin >> a[0] >> a[1] >> a[2];
  
  if (checkTest(a[0], a[1], a[2]))
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (checkTest(a[1], a[2], a[0]))
  {
    cout << "Yes" << endl;
    return 0;
  }
  if (checkTest(a[0], a[2], a[1]))
  {
    cout << "Yes" << endl;
    return 0;
  }
 	
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;

        ll pow(ll base, ll q, ll mod){
            ll answer = 1;
            while(q > 0){
                if(q & 1LL)
                    answer = (answer * base) % mod;

                q = q >> 1LL;
                base = (base*base) % mod;
            }
            return answer % mod;
        }

        ll factorial(ll n, ll mod){
            ll answer = 1;
            for(int i=2; i<=n; i++){
                answer = (answer * i) % mod;
            }
            return answer % mod;
        }

        ll inverse(ll base, ll mod){
            return pow(base, mod-2, mod) % mod;
        }

        /*ll C(ll n, ll m, ll mod){
            return (factorial(n, mod) * inverse(factorial(m,mod) * factorial(n-m, mod)%mod, mod) ) % mod;
        } */  

        

        void solve(){
            ll answer = 1;
            for(int i=1; i <= 5; i++){
                cin >> a;
                if(!a) answer = i;
            }
            cout << answer << endl;
        }

       
    


        int main(){
            ios_base::sync_with_stdio(false);


            

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

Measured memory_bytes: 3648
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<String>();
    let ans = n.chars().filter(|&x| x == '2').count();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    printf("%f %d\n",(double)w*(double)h/2.0, x+x==w&&y+y==h);
}   


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0 ; i < n ; i++){
        cin >> h[i];
    }
    int max = 0;
    int cnt = 0;
    for(int i = 1 ; i < n ; i++){
        if(h[i-1] >= h[i]){
            cnt++;
        }else if(max < cnt){
            max = cnt;
            cnt = 0;
        }else{
            cnt = 0;
        }
    }
    if(max < cnt){
        max = cnt;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 640
import collections

n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    tmpb,tmpc = map(int,input().split())
    b.append(tmpb)
    c.append(tmpc)

dic = collections.Counter(a)
val = 0
for key, value in dic.items():
    val +=key * value
for i in range(q):
    tmp = 0
    if b[i] in dic:
        if c[i] not in dic:
            dic[c[i]] = 0
        tmp = (c[i] - b[i]) * dic[b[i]]
        dic[c[i]] += dic[b[i]]
        dic[b[i]] = 0
        val = val + tmp
    print(val)

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

using namespace std;

int main()
{

	string input;

	cin >> input;

	int red_num = 0;
	int blue_num = 0;

	for (int i = 0; i < input.size(); ++i)
	{
		if (input[i] == '0')
			++red_num;
		else
			++blue_num;
	}

	int fewer_num = red_num < blue_num ? red_num : blue_num;

	cout << fewer_num * 2 << "\n";

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)
typedef long long ll;

const int N=20;
const ll INF=1e18;

int n; ll a[N];

ll dfs(int l,int r,ll x,ll y){
	if(r-l<=1) return a[l]*x+a[r]*y;
	ll ans=INF;
	lor(i,l+1,r-1) ans=min(ans,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)-a[i]*(x+y));
	return ans;
}

int main(){
	scanf("%d",&n); lor(i,1,n) scanf("%lld",&a[i]);
	printf("%lld\n",dfs(1,n,1,1));

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define S(v) sort(v.begin(), v.end())
#define SS(v) sort(v.begin(), v.end(), greater<int>())
#define print(v) for(auto i:v)cout<<i<<" "


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// freopen("in.txt","r", stdin);
	ll t=1;
	// cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		cout<<(s[s.size()-1]=='s'?s+"es":s+"s");

	}
	
} 





Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(s.substr(i, 3) == "ABC"){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int c[m],d[m];
  for(int i=0;i<m;i++){
    cin>>c[i]>>d[i];
  }
  for(int i=0;i<n;i++){
    int ma=1000000000,mb;
    for(int j=0;j<m;j++){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<ma){
        ma=abs(a[i]-c[j])+abs(b[i]-d[j]);
        mb=j+1;
      }
    }
    cout<<mb<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,k;
    cin>>n>>k;
    ll p=1000000007;
    ll ans=(1+n*(n-1))%p;
    ll dp[200001];
    ll factdp[200001];
    ll fact[200001];
    dp[0]=1;
    dp[1]=1;
    fact[0]=1;
    fact[1]=1;
    factdp[0]=1;
    factdp[1]=1;
    for(ll i=2;i<=200000;i++)
    {
        fact[i]=fact[i-1]*i%p;
        dp[i]=dp[p%i]*(p-p/i)%p;
        factdp[i]=factdp[i-1]*dp[i]%p;
    }
    for(ll m=2;m<=min(n-1,k);m++)
    {
        ans+=((fact[n])*fact[n-1]%p)*factdp[n-m]%p*factdp[n-m-1]%p*factdp[m]%p*factdp[m]%p;
    }
    cout<<ans%p;
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		System.out.println(((r * 100 + g * 10 + b) % 4 == 0) ? "YES" : "NO");

	}

}




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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	ll n; std::cin >> n;
	ll x = 1;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0)
			x = i;
	}
	ll y = n / x;
	std::cout << abs(y - 1) + abs(x - 1) << "\n";
}


Measured memory_bytes: 256
n = int(input())
dic ={}
for i in range(n):
    key = input()
    if key not in dic:
        dic[key] = 1
    if key in dic:
        dic[key] += 1
max_v = max(dic.values())
res = sorted(list(filter(lambda key:dic[key]==max_v,list(dic))))
for key in res:
    print(key)

Measured memory_bytes: 33112
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#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 <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

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

    int n, m, c;
    cin >> n >> m >> c;
    int b[105];
    for( int i = 0; i < m; ++i ) cin >> b[i];

    int res = 0;
    for( int i = 0; i < n; ++i ) {
        int sum = 0;
        for( int j = 0; j < m; ++j ) {
            int a;
            cin >> a;
            sum += a * b[j];

        }
        sum += c;

        if( sum > 0 ) ++res;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    count = 0
    for i in range(n):
        for div in divisors[a[i]]:
            if (div in hm and (div!=a[i] or hm[a[i]]>1)) or ((a[i] // div in hm) and (div!=1 or hm[a[i]]>1)):
                count -= 1
                break
        count += 1
    print(count)
    return


def get_divisors():
    divisors = [[] for _ in range(mxa+1)]
    for i in range(1, 10**3+1):
        for j in range(i, mxa+1, i):
            divisors[j].append(i)
    return divisors


n = RN()
a = RA()
mxa = max(a)
hm = {}
for ai in a:
    if not ai in hm:
        hm[ai] = 0
    hm[ai] += 1
divisors = get_divisors()
solve()


Measured memory_bytes: 311980
#include <stdio.h>
#include <stdlib.h>

typedef struct weight_
{
    int Num;
    int Wei;
    double OneNum;
    int flg;
}wgt;

void swap(wgt *X,wgt *Y)
{
    wgt wk; wk=*X; *X=*Y; *Y=wk;
}

void quicksort(int first,int last,wgt *X)
{
    int i,j;
    double pivot;
    if(first<last)
    {
        pivot=X[(first+last)/2].OneNum;
        i=first;
        j=last;
        while(i<=j){
            while(X[i].OneNum<pivot) i++;
            while(X[j].OneNum>pivot) j--;
            if(i<=j) swap(&X[i++],&X[j--]);
        }
        quicksort(first,j,X);
        quicksort(i,last,X);
    }
}

int main()
{
    int N,W,cnt;
    double d1,d2,tmp=0;
    scanf("%d %d",&N,&W);
    wgt box;
    wgt *X = malloc(sizeof(wgt)*N);
    for(int i=0;i<N;i++)
    {
        scanf("%lf%lf",&d1,&d2);
        X[i].Num = d1;
        X[i].Wei = d2;
        X[i].OneNum = d1/d2;
    }
    quicksort(0,N-1,X);
    for(int i=N-1;0<=i;i--)
    {
        //printf("i=%d Num=%d Weight=%d OneNum=%lf\n",i,X[i].Num,X[i].Wei,X[i].OneNum);
        if(X[i].Wei < W)
        {
            tmp = tmp + (X[i].Wei * X[i].OneNum);
            W = W - X[i].Wei;
        }
        else
        {
            tmp = tmp + (X[i].OneNum * W);
            break;
        }
    }
    printf("%lf\n",tmp);
}


Measured memory_bytes: 4128