akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder171
{
    class Program
    {
        static void Main(string[] args)
        {

            var n = long.Parse(Console.ReadLine());

            var ans = string.Empty;

            while (true)
            {
                n--; // a-zの変換を0-25にするため
                var i = n % 26;
                ans = Convert.ToChar(0x61 + i) + ans;
                n = n / 26;
                if (n <= 0) break;
            }

            Console.WriteLine(ans);

        }
    }
}


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

#include <string.h>

#define MIN       (1)
#define MAX       (100)
#define INFTY (0x7FFFFFFF)

typedef enum
{
    ERROR  =-1,
    SUCCESS= 0
} ResultType;

static ResultType checkRangeOfNum(int, int, int);
static int getMinimumOfScalarMultiplication(int);

int R[MAX + 1];      // row and column table R[x], as follows;
                     // R[0]=row    of 1st Matrix "M1" (x=0)
                     // R[1]=column of 1st Matrix "M1" (x=1)
                     // R[2]=column of 2nd Matrix "M2" (x=2)
                     // R[3]=column of 3rd Matrix "M3" (x=3)
                     // ...

int C[MAX][MAX + 1]; // cost table C[i][i+j], which means 
                     // minimum of scalar multiplication (Mi * Mi+1 * ... Mi+j)
                     // (where i>=1, j>=1)
int main(void)
{

int x, y;
int N;

    ResultType eResult;

    /* input line 1 */
    scanf("%d",&N);
    eResult = checkRangeOfNum(N, MIN, MAX);
    if(eResult < SUCCESS)
    {
        printf("Err: %d is out of range.", N);
        return eResult;
    }

    /* input line 2 */
    for(x=0; x<=1; x++)
    {
        scanf("%d",&R[x]);
        eResult = checkRangeOfNum(R[x], MIN, MAX);
        if(eResult < SUCCESS)
        {
            printf("Err: %d is out of range.", R[x]);
            return eResult;
        }
    }

    /* input line from 3 to (N + 1) */
    for(y=2; y<N*2; y++)
    {
        x = (y+1)/2;
        scanf("%d",&R[x]);
        eResult = checkRangeOfNum(R[x], MIN, MAX);
        if(eResult < SUCCESS)
        {
            printf("Err: %d is out of range.", R[x]);
            return eResult;
        }
    }

    /* print minimum of scalar multiplication */
    printf("%d\n", getMinimumOfScalarMultiplication(N));

    return SUCCESS;
}

static ResultType checkRangeOfNum(int n, int nMin, int nMax)
{
    if((n < nMin) || (nMax < n))
    {
        return ERROR;
    }
    return SUCCESS;
}

static int getMinimumOfScalarMultiplication(int n)
{
    int i, j, k;
    int cost;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            C[i][j] = INFTY;
        }
    }
    
    for(i = 1; i <= n; i++)
    {
        C[i][i] = 0;
    }
    
    for(j = 1; j <= n - 1; j++)
    {
        for (i = 1; i <= n - j; i++)
        {
            for (k = i + 1; k <= i + j; k++)
            {
                // C[i][i+j] = min( C[i][i+j], 
                //                  C[i][k-1] + C[k][i+j] + R[i-1]*R[k-1]*R[i+j] );
                cost = C[i][k-1] + C[k][i+j] + R[i-1]*R[k-1]*R[i+j];
                if (cost < C[i][i+j])
                {
                    C[i][i+j] = cost;
                }
                
            }
        }
    }
    return C[1][n];
}



Measured memory_bytes: 2044
import collections
 
n=int(input())
 
li=[]
ma=0
an=[]
 
for i in range(n):
    li.append(input())
 
c=collections.Counter(li)
c2=c.most_common()
ma=c2[0][1]

for j in range(n):
    if c2[j][1]==ma:
        an.append(c2[j][0])
        
        if len(c2)==j+1:
            break
    else:
        break
 
an.sort()
 
for k in range(len(an)):
    print(an[k])

Measured memory_bytes: 47664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

pair<char,int> table[] = { { 'I', 1 }, { 'V', 5 }, { 'X', 10 }, { 'L', 50 },
{ 'C', 100 }, { 'D', 500 }, { 'M', 1000 } };
string s;
ll ans;
char c;
bool f = 0;

int main(){
	while (cin>>s){
		s += "I";
		ans = 0;
		REP(i, s.size()){
			f = 0;
			REP(j, 7){
				if (s[i] == table[j].first){
					REP(k, 7){
						if (s[i + 1] == table[k].first){
							if (j < k){
								ans += table[k].second - table[j].second;
								f = 1;
							}
							else{
								ans += table[j].second;
							}
						}
					}
				}
			}
			if (f)i++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1180
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        sc.close();

        int tmp = N - K;
        if (K == 1){
            tmp = 0;
        }

        System.out.println(tmp);
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<vector>
typedef std::pair<int,int> P;
const int N=1e5+5;
int par[N],n,q,cnt;
long long m;
void init() {
    for(int i=0;i<n;i++) par[i]=-1;
    cnt=n;
}
int fd(int x) {
    return par[x]==-1?x:(par[x]=fd(par[x]));
}
void unite(int x,int y) {
    x=fd(x);y=fd(y);
    if(x==y) return;
    --cnt;
    par[x]=y;
}
int main() {
    scanf("%d%lld%d",&n,&m,&q);
    init();
    std::vector<P> g;
    for(int u,v,c;q--;) {
        scanf("%d%d%d",&u,&v,&c);
        if(c==0) unite(u,v);
        else g.push_back(P(u,v));
    }
    if(m==n-1) {
        printf("%s",g.size()>0?"No":"Yes");
        return 0;
    }
    for(auto &c:g) if(fd(c.first)==fd(c.second)) {
        printf("No");
        return 0;
    }
    printf("%s",m<=n-cnt+1LL*cnt*(cnt-1)/2?"Yes":"No");
    return 0;
}


Measured memory_bytes: 1784
#include<stdio.h>
int main()
{
    long long int h[10],i,j,temp;
    for(i=0;i<10;i++)
    {
        scanf("%lld", &h[i]);
    }
    for(i=9;i>0;i--)
    {
        for(j=0;j<i;j++)
        {
            if(h[j]<h[j+1])
            {
                temp=h[j];
                h[j]=h[j+1];
                h[j+1]=temp;
            }
        }
    }
    for(i=0;i<3;i++)
    {
        printf("%lld\n",h[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
    cin >> s >> t;
    int slen = s.length();
    int tlen = t.length();

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<int>());

    bool flg = false;
    int min = 0;

    if(slen > tlen) {
        min = tlen;
    }else {
        min = slen;
    }

    for(int i = 0; i < min; ++i) {
        if(s.at(i) < t.at(i)) {
            flg = true;
            break;
        }else if(s.at(i) > t.at(i)){
            break;
        }

        if(i == min-1) {
            if(s.at(i) < t.at(i)) {
                flg = true;
                break;
            }else if(s.at(i) > t.at(i)) {
                break;
            }else {
                if(slen < tlen) {
                    flg = true;
                    break;
                }
            }
        }
    }

    if(flg) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# わからなかったので､他の人の回答をパクりました｡
# リストの中身を金太郎飴みたいにその都度作って､
# 今まで作った飴と新しい飴が重複したときの番号を出力するやつは
# set()で作る｡

n = int(input())
a = set()
count = 0

a.add(n)

for i in range(2, 100000):

    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1

    if n in a:
        count = i
        break

    a.add(n)

print(count)


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

int main(){
  int n,k;
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    cin >> k;
    if(i % 2 == 0 && k % 2 == 1){
      cnt++;
    }
  }
  cout << cnt << endl;
}
  

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT

#define sz(x) ((int)x.size())

const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int maxn = 2*1000005;

#define FILENAME ""

vector <vector <ll>> g;
vector <char> used;
vector <ll> ans;
ll n, m;

void dfs(int v) {
    used[v] = true;
    for (int i = 0; i < g[v].size(); i++) {
        int to = g[v][i];
        if (!used[to]) {
            dfs(to);
        }
    }
    ans.pb(v);
}

void top_sort(){
    for (int i = 0; i < n; i++) {
        used[i] = false;
    }
    ans.clear();
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i);
        }
    }
    reverse(all(ans));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    g.resize(n);
    used.resize(n);
    for (int i = 0; i < m; i++) {
        ll x, y;
        cin >> x >> y;
        --x, --y;
        g[x].pb(y);
    }
    top_sort();
    vector <ll> dp(n);
    ll answ = 0;
    for (int i = 0; i < ans.size(); i++) {
        for (int j = 0; j < g[ans[i]].size(); j++) {
            int to = g[ans[i]][j];
            dp[to] = max(dp[to], dp[ans[i]] + 1);
            answ = max(answ, dp[to]);
        }
    }
    cout << answ;
    return 0;
}

Measured memory_bytes: 9588
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

ll a, b, k;

void input() {
    cin >> a >> b >> k;
}


void solve() {
    ll ca = a, cb = b;
    for (int i = 0; i < k; i++) {
        if (i % 2 == 0) {
            ca = a / 2;
            cb += ca;
        } else {
            cb = b / 2;
            ca += cb;
        }
        a = ca; b = cb;
    }
    cout << ca << ' ' << cb << endl;
}


int main() {
    input();
    solve();
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		sc.close();
		int count = 0;

		for (int i = 1; i <= K; i = i + 2) {
			for (int j = 2; j <= K; j = j + 2) {
				count++;
			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string s;
  cin >> s;
  int alpha[26];
  for (int i = 0; i < 26; i++) {
    alpha[i] = 0;
  }
  for (int i = 0; i < 4; i++) {
    alpha[s[i] - 65]++;
  }
  sort(alpha,alpha + 26);
  if (alpha[24] == 2 && alpha[25] == 2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def LinearSearch(A,n,key):
    i = 0
    A[n] = key
    while A[i] != key:
        i += 1
    return i != n

N = int(input())
S = [int(x) for x in input().split(" ")]
S.append(None)


q = int(input())
T = [int(x) for x in input().split(" ")]

count = 0

for key in T:
    if LinearSearch(S,N,key):
        count += 1
print(count)


Measured memory_bytes: 6556
#include<bits/stdc++.h>
#define fr(i,n) for(int i=0;i<(n);++i)
#define foor(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,n) for(int i=(n);i--;)
#define roof(i,b,a) for(int i=(b);i>=(a);--i)
#define all(x) x.begin(),x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define print(x) cout<<(x)<<endl
using namespace std;            typedef vector<int>  vi;
typedef long long ll;           typedef vector< ll>  vl;
typedef unsigned long long ull; typedef vector<ull>  vu;
typedef double dbl;             typedef vector<dbl>  vd;
typedef pair<int,int>pii;       typedef vector<pii>vpii; typedef map<int,int>mii;
typedef pair< ll, ll>pll;       typedef vector<pll>vpll; typedef map< ll, ll>mll;
typedef pair<dbl,dbl>pdd;       typedef vector<pdd>vpdd; typedef map<dbl,dbl>mdd;
typedef pair< ll,int>pli;       typedef vector<pli>vpli; typedef map< ll,int>mli;
typedef pair<dbl,int>pdi;       typedef vector<pdi>vpdi; typedef map<dbl,int>mdi;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T>multiset<T>&operator<<(multiset<T>&m,const T t){m.insert(t);return m;}
template<typename T>set<T>&operator<<(set<T>&s,const T t){s.insert(t);return s;}
template<typename T,typename U>PQ<T,vector<T>,U>&operator<<(PQ<T,vector<T>,U>&q,const T t){q.push(t);return q;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T>istream&operator>>(istream&s,vector<T>&v){fr(i,v.size()){s>>v[i];}return s;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto a:v){s<<a<<endl;}return s;}
const int MD=1e9+7;
vpli dijkstra(const int N,const vpli E[],const int s,const ll inf){vpli d;fr(i,N)d<<pli{inf,i};d[s].first=0;PQ<pli,vpli,greater<pli>>pq;pq<<(d[s]=pli{0,s});while(pq.size()){pli a=pq.top();pq.pop();int v=a.second;if(d[v].first>=a.first){for(pli e:E[v]){if(d[v].first+e.first<d[e.second].first){d[e.second]=pli{d[v].first+e.first,v};pq<<pli{d[v].first+e.first,e.second};}}}}return d;}
ll gcd(const ll a,const ll b){return a?gcd(b%a,a):b;}
ll pow(const ll a,const ll n,const int m){ll t;return n?(n&1?a>=0?a%m:~-m+~a%m:1)*(t=pow(a,n>>1,m),t*t%m)%m:1;}
ll C2(const int n){return(ll)n*~-n/2;}
// (int) * (int) => (int)
// (int) / (int) => (int)

vi E[2000];
int f(int p,int i,int d){
	if(!d)return 1;
	int x=1;
	for(int j:E[i])if(j!=p){
		x+=f(i,j,d-1);
	}
	return x;
}
main(){cin.tie(0);ios::sync_with_stdio(false);
	int N,K;
	cin>>N>>K;
	fr(i,N-1){
		int A,B;
		cin>>A>>B;
		E[--A]<<--B;
		E[B]<<A;
	}
	int z=0;
	if(K%2){
		fr(i,N){
			for(int j:E[i]){
				z=max(z,f(i,j,K/2)+f(j,i,K/2));
			}
		}
	}else{
		fr(i,N){
			z=max(z,f(i,i,K/2));
		}
	}
	print(max(0,N-z));
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int a, b, c, x, y, ans = INF, t = 0;
  cin >> a >> b >> c >> x >> y;
  int mx = max(x, y);

  for (int i = 0; i <= mx; ++i) {
    t = 2 * c * i;
    if (x - i > 0) t += a * (x - i);
    if (y - i > 0) t += b * (y - i);
    ans = min(ans, t);
  }

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


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

int main(void){
    char A,B;
    cin>>A>>B;
    if(A==B)
        cout<<"="<<endl;
    else if(A>B)
        cout<<">"<<endl;
    else if(A<B)
        cout<<"<"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 1;
		int min = sc.nextInt();
		for (int i = 1; i < N; i++) {
			int now = sc.nextInt();
			if (now <= min) {
				min = now;
				count++;
			}
		}
		System.out.println(count);
	}
}

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


int main() {
    int a, b;
    cin >> a >> b;
    if(a-b > 0){
        cout << a-b;
    }
    else{
        cout << 0;
    }   
    cout << endl;
}


Measured memory_bytes: 256
N,M,K = map(int,input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
direct = [0] * N
for i in range(M):
	A,B = map(int,input().split())
	direct[A-1] += 1
	direct[B-1] += 1
	uf.union(A-1,B-1)
ans = [0] * N
for i in range(K):
	C,D = map(int,input().split())
	if uf.same(C-1,D-1) :
		direct[C-1] +=1
		direct[D-1] +=1
for i in range(N):
	ans[i] = uf.size(i) - direct[i] -1
print(*ans)

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

int main(){
  ll x,y,a,b,c,i,ans;
  ans=0;
  cin >> x >> y >> a >> b >> c;
  ll p[a],q[b],r[c],s[x+y];
  for(i=0;i<a;i++){
    cin >> p[i];
  }
  sort(p,p+a,greater<ll>());
  for(i=0;i<b;i++){
    cin >> q[i];
  }
  sort(q,q+b,greater<ll>());
  for(i=0;i<c;i++){
    cin >> r[i];
  }
  sort(r,r+c,greater<ll>());
  for(i=0;i<x;i++){
    s[i]=p[i];
  }
  for(i=x;i<x+y;i++){
    s[i]=q[i-x];
  }
  sort(s,s+x+y);
  for(i=0;i<c;i++){
    if(s[i]<r[i]){
      s[i]=r[i];
    }
  }
  for(i=0;i<x+y;i++){
    ans+=s[i];
  }
  cout << ans;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
vi e[N];
int sz[N], f[N];
ll p[N];
void init() {
	rep(i, 0, N) e[i].clear();
}
void dfs(int u, int p) {
	f[u] = p;
	sz[u] = 1;
	for(auto v : e[u]) {
		if(v == p) continue;
		dfs(v, u);
		sz[u] += sz[v];
	}
}
ll inv(ll a, ll b) {
	return kpow(a, b-2);
}
int main() {
	while(~scanf("%d", &n)) {
		ll ans = 0;
		init();
		rep(i, 1, n) {
			int u, v; scanf("%d%d", &u, &v);
			e[u].pb(v);
			e[v].pb(u);
		}
		dfs(1, -1);
		rep(u, 1, n + 1) {
			if(sz(e[u]) == 1) continue;
			ll all = 1;
			int tot = 0;
			for(auto v : e[u]) {
				int m = sz[v];
				if(v == f[u]) m = n - sz[u];
				p[tot++] = (1ll - inv(kpow(2, m), mod) + mod) % mod;
				all *= ((1ll - p[tot - 1] + mod) % mod);
				all %= mod;
			}
			ll cur = all;
			rep(i, 0, tot) {
				cur += all * inv((1ll - p[i] + mod) % mod, mod) % mod * p[i] % mod;
				cur %= mod;
			}
			ans += (1 - cur + mod) * inv(2, mod) % mod;
			ans %= mod;
		}
		printf("%lld\n", ans);
	}
    return 0;
}


Measured memory_bytes: 21632
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int K,X; cin>>K>>X;
    REP(i,2*K-1){
        cout<<X-K+1+i<<" ";
    }
  cout<<endl;
}

Measured memory_bytes: 256
/* ex 7_1
   nnasy */

#include <stdio.h>

//指定された構造体
typedef struct point{
    int x_elem;
    int y_elem;
}point;

//複素数平面上の2点a,bについて、bから見てaを270度回転させた先の点cを返す関数
point rot_270_deg(point a, point b){
    point c;
    c.x_elem = b.x_elem + (a.y_elem - b.y_elem);
    c.y_elem = b.y_elem - (a.x_elem - b.x_elem);
    return c;
}

int main(void){
    //宣言
    point p1, p2, p3, p4;
    //入力
    scanf("%d %d %d %d", &p1.x_elem, &p1.y_elem, &p2.x_elem, &p2.y_elem);
    
    //座標(x3, y3)を求める
    p3 = rot_270_deg(p1, p2);
    //座標(x4, y4)を求める
    p4 = rot_270_deg(p2, p3);
    
    //出力
    printf("%d %d %d %d\n", p3.x_elem, p3.y_elem, p4.x_elem, p4.y_elem);
    
    return 0;
}

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

int main(){
   long long int A;
   std::string B;
   std::cin >> A >> B;
   long long int Ans;
   std::string newB;
   if (B.at(0) == '0'){
      newB = B.substr(2, 2);
   } else{
      newB = B.at(0) + B.substr(2, 2);
   }
   int intB = atoi(newB.c_str());
   std::cerr << newB << std::endl;
   Ans = intB * A / 100;
   std::cout << Ans << std::endl;
}



Measured memory_bytes: 3628
import heapq

# M日後までに得られる報酬
n, m = map(int, input().split())

# A日後に報酬B

task_list = []

for _ in range(n):
    a, b = map(int, input().split())
    task_list.append((a, b))

task_list = sorted(task_list,key=lambda x:x[0])

j = 0
hq = []
ans = 0

for i in range(1, m+1):
    # 残り1, 2, 3, 4...
    while j < n and task_list[j][0] <= i:
        heapq.heappush(hq, -task_list[j][1])
        j += 1
    if len(hq):
        ans += heapq.heappop(hq)

print(-ans)

Measured memory_bytes: 78296
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>

#define _USE_MATH_DEFINES
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999;

using namespace std;

int main() {

	int N, a, cnt = 0,ans = 1;
	int arr[100000] = { 0 };

	cin >> N;

	REP(i, N) {
		cin >> a;
		arr[a]++;
	}

	if (N % 2 == 0) {
		for (int i = 1; i < N; i += 2) {
			if (arr[i] == 2) cnt++;
		}
	}
	else {
		if (arr[0] == 1) cnt++;
		for (int i = 0; i < N; i += 2) {
			if (arr[i] == 2) cnt++;
		}
	}

	if (N % 2 == 0 && cnt == N / 2) {
		REP(i, N / 2) {
			ans *= 2;
			if (ans > 100000007)ans %= 1000000007;
		}
		cout << ans << endl;
	}
	else if (N%2 == 1 && cnt == N / 2 + 1){
		REP(i, N / 2) {
			ans *= 2;
			if (ans > 100000007)ans %= 1000000007;
		}
		cout << ans << endl;
	}
	else {
		cout << '0' << endl;
	}

	return 0;
}

Measured memory_bytes: 640
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,k;cin>>n>>k;
    vector<int>x(n);
    for(int i=0;i<n;i++)cin>>x[i];
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=min(2*(x[i]),2*(k-x[i]));
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from heapq import *

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pq = []
ans = 0

for i in range(X):
    heappush(pq, p[i])
    ans += p[i]

for i in range(Y):
    heappush(pq, q[i])
    ans += q[i]

r.sort(reverse=True)
now = ans

for i in range(C):
    now -= heappop(pq)
    heappush(pq, r[i])
    now += r[i]
    ans = max(ans, now)

print(ans)

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> va(n, vector<int>(m));
  vector<int> vc(n);
  for (int i = 0; i < n; ++i) {
    cin >> vc[i];
    for (int j = 0; j < m; ++j) {
      cin >> va[i][j];
    }
  }

  int ans = -1;
  for (int i = 0; i < (1 << n); ++i) {
    vector<int> vx(m, 0);
    int sum_price = 0;

    // 書籍 va_j, vc_j
    for (int j = 0; j < n; ++j) {
      if ((i & (1 << j)) == 0) {
        continue;
      }

      sum_price += vc[j];
      for (int k = 0; k < m; ++k) {
        vx[k] += va[j][k];
      }
    }

    int min_n = *min_element(vx.begin(), vx.end());
    if (min_n < x) {
      continue;
    }

    if (ans == -1 || sum_price < ans) {
      ans = sum_price;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
using namespace std; 
  
typedef long long LL; 
typedef pair<int, int> pii; 
typedef pair<LL, LL> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<string> vs;
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<LL> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
int INF = 100005; 
long long int mod=1000000007;
long long TES=1000007;
long long INFF = 1000000000000000005LL; 
double PI = acos(-1); 
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; 
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 }; 
  
#ifdef TESTING 
#define DEBUG fprintf(stderr, "====TESTING====\n") 
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
#define debug(...) fprintf(stderr, __VA_ARGS__) 
#else 
#define DEBUG 
#define VALUE(x) 
#define debug(...) 
#endif 
  
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) 
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) 
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) 
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) 
#define FOREACH(a, b) for (auto&(a) : (b)) 
#define rep(i, n) FOR(i, 0, n) 
#define repn(i, n) FORN(i, 1, n) 
#define MAX(a, b) a = max(a, b) 
#define MIN(a, b) a = min(a, b) 
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define TC(t) while (t--)

void solve()
{
    char c;
    cin>>c;
    if(islower(c))
    cout<<"a\n";
    else
    cout<<"A\n";
    return;
}
 
int main()
{
    IOS();
    solve();
    return 0;
}





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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK\n";
      return 0;
    }
  }
  cout << "NG\n";
  return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    int h, w, a, b;
    cin >> h >> w >> b >> a;
    for (int i = 0; i < h - a; i++) {
        for (int j = 0; j < w - b; j++) {
            cout << '0';
        }
        for (int j = 0; j < b; j++) {
            cout << '1';
        }
        cout << endl;
    }
    for (int i = 0; i < a; i++) {
        for (int j = 0; j < w - b; j++) {
            cout << '1';
        }
        for (int j = 0; j < b; j++) {
            cout << '0';
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include <stdio.h>
int main()
{
	int i;
	char s;
	int ans = 0;
	for(i = 1 ; i <= 3 ; i++)
	{
		scanf("%c", &s);
		if(s =='o')ans++;
	}
	printf("%d\n", 700 + ans * 100);
	return 0;
}

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

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

  int n, d;
  cin >> n >> d;
  vector<vector<int>> v(n, vector<int>(d));
  rep(i, 0, n) { rep(j, 0, d) cin >> v[i][j]; }

  int ans = 0;
  rep(i, 0, n) {
    rep(j, i + 1, n) {
      int sum_val = 0;
      rep(k, 0, d) {
        int t = v[i][k] - v[j][k];
        sum_val += t * t;
      }

      rep(k,0,sum_val + 1) {
        if (k * k == sum_val) ans++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

ll f(ll n, ll x) {
  if (n == -1) return 0;
  return n / x + 1;
}

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

Measured memory_bytes: 3676
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 0.00001;
const double pi = acos(-1);
const double inf = (int)1e5;

int main(void){
  double N;
  while(cin>>N,N!=-1){
    double q =1.0*N/2;
    int i = 0;
    while(abs(pow(q,3)-N)>eps*N&&i<10000){
      i++;
      //printf("%.10f\n",q);
      q=q-(pow(q,3)-N)/(3*pow(q,2));
    }
    printf("%.6f\n",q);
  }
}

Measured memory_bytes: 1236
import math
N, M = map(int, input().split())

div = M
for i in range(1, int(math.sqrt(M))+1):
    if M % i:
        continue
    i2 = M // i
    if i >= N:
        div = min(div, i)
    if i2 >= N:
        div = min(div, i2)

print(M//div)


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	int d;
	cin >> d;
	vector<int> c(26);
	rep(i,26) cin >> c[i]; 
	vector<vector<int>> s(d,vector<int>(26));
	rep(i,d) rep(j,26) cin >> s[i][j];

	// 最後に試合を行った日を保持する。
	vector<int> last_d(26,-1);
	ll ans = 0;
	rep(i,d){
		int index = 0;

		int m = 1e9+7;
		int sagaru = 0;
		rep(j,26){
			sagaru += (i - last_d[j]) * c[j];
		}

		rep(j,26){
			int now = sagaru - (i - last_d[j]) * c[j];
			if(chmin(m,now)){
				index = j;
			}
		}
		int game = index;
		last_d[game] = index;
		ans += s[i][game];
		rep(j,26){
			ans -= c[j] * (i - last_d[j]);
		}
		cout << index+1 << endl;
	}
}


Measured memory_bytes: 3672
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    D = int(readline())
    C = [int(i) for i in readline().split()]
    S = [[int(i) for i in readline().split()] for _ in range(D)]
    T = [int(readline()) for _ in range(D)]

    last = [0] * 26
    score = 0
    for i, t in enumerate(T):
        score += S[i][t-1]
        last[t-1] = i+1
        for j, c in enumerate(C):
            score -= c * (i+1 - last[j])

        print(score)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9412
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    string T;
    cin >> S >> T ;
    
    T.pop_back();
    if(S==T){ 
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}
    
    

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

int a[105];
int main(){
    int len;
    string str;
    cin >> len >> str;
    int ans = 0;
    for(int i = 1; i < len; i++){
        memset(a, 0, sizeof(a));
        for(int j = 0; j < i; j++){
            a[str[j] - 'a']++;
        }
        int cnt = 0;
        for(int j = i; j < len; j++){
            if(a[str[j] - 'a']){
                cnt++;
                a[str[j] - 'a'] = 0;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int n,a[200003],b[200003],x,y;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        a[i]=x+y,b[i]=x-y;
    }
    std::sort(a+1,a+1+n),std::sort(b+1,b+1+n);
    printf("%d\n",std::max(a[n]-a[1],b[n]-b[1]));
    return 0;
}

Measured memory_bytes: 3272
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

const int N=4000;
bitset<N>x,a[5],g,t,c;
char str[N*2];
inline void read(bitset<N> &bit) {
	scanf("%s",str);
	int n=strlen(str)-1;
	for (int i=0;i<=n;i++)
		bit[i]=str[n-i]-'0';
}
inline int deg(bitset<N> &bit) {
	for (int i=N;i--;) if (bit[i]) return i;
	return 0;
}
int p[N];
int main()
{
	int n=gi()-1,i,k,low;
	const int mod=998244353;
	read(x);read(g);
	for (i=0;i<n;i++) {
		read(t);
		while (1) {
			if (deg(g)<deg(t)) swap(g,t);
			low=deg(t);
			for (k=deg(g);k>=low;k--)
				if (g[k])
					g^=t<<(k-low);
			if (g.none()) { g=t; break; }
		}
	}
	for (i=p[0]=1;i<N;i++) p[i]=(p[i-1]<<1)%mod;
	k=deg(g);
	int ans=0;
	for (i=N-1;i>=k;i--) {
		if (x[i]) (ans+=p[i-k])%=mod;
		if (x[i]!=c[i]) c^=g<<(i-k);
	}
	for (i=k;~i;i--) {
		if (x[i]>c[i]) break;
		else if (x[i]<c[i]) { ans--; break; }
	}
	ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())

biglist1=[]
biglist2=[]

for i in range(n):
    nlist=[]
    nlist2=[]
    s=input()
    s=sorted(s)
    ln=len(s)
    before='0'
    for j in range(ln):
        if s[j]==before:
            nlist[-1][1]+=1
        else:
            nlist.append([s[j],1])
            nlist2.append(s[j])
        before=s[j]
    biglist1.append(nlist)
    biglist2.append(nlist2)

#print(biglist1)
#print(biglist2)
answer=""
for i in range(len(biglist1[0])):
    kaz=biglist1[0][i][1]
    for j in range(len(biglist1)):
        #print(biglist2[j], biglist2[0][i])
        #print(biglist2[j].index(biglist2[0][i]))
        if biglist2[0][i] in biglist2[j]:
            list3=biglist2[j]
            moji=biglist2[0][i]
            result=list3.index(moji)
            kaz=min(kaz, biglist1[j][result][1])
            pass
        else:
            kaz=0
    #print(kaz)
    answer+=biglist2[0][i]*kaz
print(answer)

Measured memory_bytes: 39664
#include<stdio.h>
#define maxs 10000001

int f[maxs]={};

int solve_1(int s){
	s=s*3+1;
	return s;
}

int solve_2(int s){
	s=s/2;
	return s;
}

int main(){
	int s;
	int ans=0,cnt=0;
	scanf("%d",&s);
	while(ans==0){
		cnt++;
		if(f[s]==0)f[s]=1;
		else ans=cnt;
		
		if(s%2==0)s=solve_2(s);
		else if(s%2==1)s=solve_1(s);
		
	}
	printf("%d",ans);
}



Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-13;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
char str[110];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	if(a+b>=c)printf("Yes\n");else printf("No\n");
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;
  vll a(n);
  REP(i, n)
    cin >> a[i];

  ll st = 0;
  ll ans = 0;
  REP1(i, n){
    if(st == 0){
      if(a[i]-a[i-1]>0)
        st = 1;
      else if(a[i]-a[i-1]<0)
        st = -1;
    }
    else{
      if(st*(a[i]-a[i-1])<0){
        ans++;
        st = 0;
      }
    }
  }

  ans++;

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num;
  int i;
  int pn[100000];
  int count=0;
  int output;
    
  cin >> num;
  for(i=0;i<num; i++)
    cin >> pn[i];  
  sort(pn, pn+num);
  
  output = pn[num/2] - pn[(num/2) - 1];
  cout << output;
}

Measured memory_bytes: 640
#include<cstdio>

	int main(){
		int a, b, c, d, S;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		if (a > b){
			S = b*c+(a-b)*d;
			printf("%d\n", S);
			}
		else if (a <= b){
			S = a*c;
			printf("%d\n", S);
			}
		return 0;
		}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

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

  long long all = 0;
  long long sub = 0;
  long long r = 0;
  long long g = 0;
  long long b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
    if (s[i] == 'G') g++;
    if (s[i] == 'B') b++;
  }
  all = r * g * b;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) continue;
      int k = 2 * j - i;
      if (k >= n || s[i] == s[k] || s[j] == s[k]) continue;
      sub++;
    }
  }

  cout << all - sub << endl;
}


Measured memory_bytes: 3204
import scala.io.StdIn

object Main extends App {
  val Array(h, w) = StdIn.readLine().split(' ').map(_.toInt)
  val matrix = Array.fill[String](h + 2, w + 2)("")

  (1 to h).foreach { i =>
    matrix(i) = (" " + StdIn.readLine() + " ").split("")
  }

  def judge(i: Int, j: Int): Boolean = {
    (matrix(i)(j) == "#" && matrix(i + 1)(j) == "#") ||
      (matrix(i)(j) == "#" && matrix(i)(j + 1) == "#") ||
      (matrix(i)(j) == "#" && matrix(i - 1)(j) == "#") ||
      (matrix(i)(j) == "#" && matrix(i)(j - 1) == "#")
  }

  var good = true
  var ti = 1
  while (good && ti <= h) {
    var tj = 1
    while (good && tj <= w) {
      good = if(matrix(ti)(tj) == "#") judge(ti, tj) else good
      tj += 1
    }
    ti += 1
  }

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

Measured memory_bytes: 25528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int B[N-1];
    for(int i = 0; i < N-1; i++){
        cin >> B[i];
    }
    int A[N];
    // A[0] = B[0];
    // for(int i = 1; i < N; i++){
    //     A[i] = (i==N-1) ? B[i-1] : min(A[i-1],B[i]);
    // }
    A[0] = B[0];
    for(int i = 1; i < N-1; i++){
        A[i] = min(B[i-1],B[i]);
    }
    A[N-1] = B[N-2];

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int INF32 = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);                
    string s;
    cin >> s;
    int sz = sz(s);
    map<char, int> cnt;
    for (char c : s)
        cnt[c]++;
    ll ans = 1;
    for (int i = 0; i < sz(s); i++) 
        ans += sz-- - cnt[s[i]]--;
    cout << ans;
    return false;                                                       
}

Measured memory_bytes: 720