akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    while (b) {
        ll x = a, y = b;
        a = y, b = x % y;
    }

    return a;
}

int main()
{
    ll N, M; cin >> N >> M;
    vll a(N);
    rep(i, N) {
        ll num; cin >> num; a[i] = num / 2;
    }

    while (a[0] % 2 == 0) {
        rep(i, N) {
            if (a[i] % 2) {cout << 0 << endl; return 0;}
            a[i] /= 2;
        }
        M /= 2;
    }

    rep(i, N) if (a[i] % 2 == 0) {cout << 0 << endl; return 0;}

    ll lcm = 1;
    rep(i, N) {
        lcm = lcm / gcd(lcm, a[i]) * a[i];
        if (lcm > M) {cout << 0 << endl; return 0;}
    }
    cout << (M / lcm + 1) / 2 << endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 200000+10;
const ll oo = numeric_limits<ll>::max();
ll tree[4*maxn],H[maxn],A[maxn],N;

void update(int node, int start, int end, int idx, ll val){
	if(start > idx || end < idx)return;
	if(start == idx && end == idx){
        tree[node] = val;
		return;
    }
    int mid = (start + end) / 2;
  	update(2*node, start, mid, idx, val);
  	update(2*node+1, mid+1, end, idx, val);
   	tree[node] = max(tree[2*node],tree[2*node+1]);
}
ll query(int node, int start, int end, int l, int r){
	if(r < start or end < l){
       	return -oo;
   	}
    if(l <= start and end <= r){
        return tree[node];
    }
    int mid = (start + end) / 2;
    ll p1 = query(2*node, start, mid, l, r);
    ll p2 = query(2*node+1, mid+1, end, l, r);
	return max(p1,p2);
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	forn(i,0,N){
		cin >> H[i];
		H[i]--;
	}
	forn(i,0,N)cin >> A[i];
	update(1,0,N-1,H[0],A[0]);
	forn(i,1,N){
		ll maxi = query(1,0,N-1,0,H[i]);
		update(1,0,N-1,H[i],maxi+A[i]);
	}
	cout << query(1,0,N-1,0,N-1) << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 8448
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] table = new int[r][c + 1];

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				table[i][j] = scan.nextInt();
				sum += table[i][j];
				System.out.printf(table[i][j] + " ");
			}
			table[i][c] = sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c + 1; i++) {
			int sum = 0;
			for(int j = 0; j < r; j++) {
				sum += table[j][i];
			}
			if(i != 0) {
				System.out.printf(" ");
			}
			System.out.printf(sum + "");
		}
		
		System.out.println();

		scan.close();
	}
}


Measured memory_bytes: 45568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int b[n];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<b[i]<<" ";	
	}
	return 0;
}


Measured memory_bytes: 1536
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int A[100000],n,q;
bool bis(int x){
	int mid,l=0,r=n;
	while (l<r){
		mid=(l+r)/2;
		if (A[mid]==x) return true;
		else if (A[mid]<x) l=mid+1;
		else r=mid;
	}
	return false;
}
int main(){
	int x,cnt=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for (int i=0;i<q;i++){
		scanf("%d",&x);
		if (bis(x)) cnt++;
	}
	printf("%d\n",cnt);
} //By Vlgd



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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector <ll> a(n);
    vector <ll> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];

    }
    ll ans = 0;
    for(int i=n-1;i>=0;i--){
        ll s = a[i]+ans;
        ll d = b[i];
        if (s%d!=0){
            ans += (((s/d)+1)*d)-s;    
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define ll unsigned long long

int main() {
  ll n;
  cin >> n;
  string s = "";
  vector<char> l(26);
  l[0] = 'z';
  for (int i = 1; i <= 25; i++)
    l[i] = 96 + i;
  if (n <= 26) {
    cout << l[n % 26];
    return 0;
  }
  while (n > 0) {
    int mod = n % 26;
    s += l[mod];
    n = n / 26;
    if (mod == 0)
      n -= 1;
  }
  reverse(s.begin(), s.end());
  cout << s;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)

// エラトステネスの篩

vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(size_t j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;
}

int main(){
  sieve(200005);
  int n;cin>>n;
  reps(i,n,M){
    if(IsPrime[i]){
      cout<<i;return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,m,count=0;
    cin>>n;
    int s[n]={};
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    cin>>m;
    int t[m]={};
    for(int j=0;j<m;j++){
        cin>>t[j];
    }
    for(int i=0;i<m;i++){
        int a=0;
        s[n]=t[i];
        while(s[a]!=t[i]){
            a++;
        }
        if(a!=n){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 1e5 + 10;
int n, m, a[2][N], b[2][N];
char S[2][N];

int main() {
	scanf("%s", S[0] + 1); n = strlen(S[0] + 1);
	scanf("%s", S[1] + 1); m = strlen(S[1] + 1);
	for (int i = 1; i <= n; ++i) {
		a[0][i] = a[0][i - 1] + (S[0][i] == 'A');
		b[0][i] = b[0][i - 1] + (S[0][i] == 'B');
	}
	for (int i = 1; i <= m; ++i) {
		a[1][i] = a[1][i - 1] + (S[1][i] == 'A');
		b[1][i] = b[1][i - 1] + (S[1][i] == 'B');
	}

	int q; scanf("%d", &q);
	while (q--) {
		int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		int a1 = (((a[0][y1] - a[0][x1 - 1]) - (b[0][y1] - b[0][x1 - 1])) % 3 + 3) % 3;
		int a2 = (((a[1][y2] - a[1][x2 - 1]) - (b[1][y2] - b[1][x2 - 1])) % 3 + 3) % 3;
		if (a1 != a2) puts("NO"); else puts("YES");
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    long a,min=1e9,max=-1e9,sum=0;
    for(int i=0;i<n;++i){
        cin >> a;
        if(min>a) min=a;
        if(max<a) max=a;
        sum+=a;
    }
    cout << min << ' ' << max << ' ' << sum << endl;
    return 0;
}


Measured memory_bytes: 3104
XN = list(map(int, input().split(' ')))
if XN[1] == 0:
    print(XN[0])
else:
    p = list(map(int, input().split(' ')))
    count = [0] * 110
    for i in range(XN[1]):
        count[p[i] + 5] += 1
    for i in range(60):
        if count[XN[0] + 5 - i] == 0:
            print(XN[0] - i)
            break
        elif count[XN[0] + 5 + i] == 0:
            print(XN[0] + i)
            break


Measured memory_bytes: 62044
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;
/****************************** START ******************************/

signed main(){
  int N,X,M;
  cin >> N >> X >> M;
  map<int,int> A,index;
  
  A[1] = X;
  index[X] = 1;
  int start,end,last;
  int cnt = 1;
  int sum = 0;
  bool loop = false;
  repeq(i,1,N-1){
    A[i+1] = A[i] * A[i] % M;
    if (index[A[i+1]] > 0){
      start = index[A[i+1]];
      end = i;
      loop = true;
      break;
    } else {
      index[A[i+1]] = i+1;
    }
  }
  
  int ans = 0;
  if (loop){
    repeq(i,1,start - 1){
      ans += A[i];
    }
    
    repeq(i,start,end){
      sum += A[i];
    }
    cnt = (N - (start - 1))/(end - (start - 1)); 
    ans += sum * cnt;
    
    last = start + (end - (start - 1)) * cnt;
    repeq(i,start,N - (last - start)){
      ans += A[i];
    }
  } else {
    repeq(i,1,N){
      ans += A[i];
    }
  }
  cout << ans;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define MAX 100005
#define NIL -1
using namespace std;
using ll = long long;

struct Node {
    int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (i = 0, c = T[u].l; c != NIL; ++i, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
    int i, j, v, d, c, l, r;
    cin >> n;
    for (i = 0; i < n; ++i) T[i].p = T[i].l = T[i].r = NIL;
    for (i = 0; i < n; ++i) {
        cin >> v >> d;
       for (j = 0; j < d; ++j) {
                cin >> c;
                if (j == 0) T[v].l = c;
                else T[l].r = c;
                l = c;
                T[c].p = v;
        }
    }
    for (i = 0; i < n; ++i) {
        if (T[i].p == NIL) r = i;
    }
    rec(r , 0);
    for (i = 0; i < n; i++) print(i);
    return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> B(N - 1);
    for(int i = 0; i < N - 1; i++) cin >> B[i];

    int ans = 0;
    for(int i = 1; i < N - 1; i++){
        ans += min(B[i - 1], B[i]);
    }
    ans += B[0] + B[N - 2];

    cout << ans << endl;
}

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

const int N = 1010;
int n, X[N], Y[N];
char s[40];

int iabs(int x) { return x > 0 ? x : -x; }

int main() {
    scanf("%d", &n);
    int c = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &X[i], &Y[i]);
        if ((X[i] + Y[i]) & 1) c++;
        else c--;
    }
    if (iabs(c) != n) {
        puts("-1"); return 0;
    }
    int m = 31 + (c < 0);
    printf("%d\n", m);
    for (int i = 0; i <= 30; i++) printf("%d ", 1 << i);
    if (c < 0) printf("1 ");
    puts("");
    for (int i = 1; i <= n; i++) {
        int x = X[i], y = Y[i], sign = 0;
        if (c < 0) s[31] = 'R', x--;
        for (int j = 30; j >= 0; j--) {
            if (iabs(x) < iabs(y)) swap(x, y), sign ^= 1;
            if (x > 0) x -= 1 << j, s[j] = sign ? 'U' : 'R';
            else x += 1 << j, s[j] = sign ? 'D' : 'L';
        }
        printf("%s\n", s);
    }
    return 0;
}


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


int main(){
  int N ; 
  cin >> N ; 
  vector<int> A(N+1) , B(N+1) ; 
  
  for(int i = 1 ; i <= N ; i++){
    B.at(i) = 0 ; 
  }
  
  for(int i = 1 ; i <= N-1 ; i++ ){
    cin >> A.at(i) ;
    B.at(A.at(i))++ ; 
  }
  
  for(int i = 1; i <= N ; i++){
    cout  << B.at(i) << endl ; 
  }
  
}

Measured memory_bytes: 4768
#include <cstdio>
using namespace std;
int main(void){
    int n;
    long maxv, minv, buy, sell;
    scanf("%d", &n);
    scanf("%ld", &buy);
    scanf("%ld", &sell);
    maxv = sell - buy;
    if (buy > sell) buy = sell;
    for (int i = 2; i < n; i++){
        scanf("%ld", &sell);
        if (maxv < sell - buy) maxv = sell - buy;
        if (buy > sell) buy = sell;
    }
    printf("%d\n", maxv);
    return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,cnt=1;
    set<int>sad;
    cin>>n;
    sad.insert(n);
    while(1)
    {
        if(n%2==0)
        {
            n/=2;
            sad.insert(n);
        }
        else
        {
            n=(3*n)+1;
            sad.insert(n);
        }
        if(SZ(sad)==cnt)
        {
            break;
        }
        else
        {
            cnt++;
        }
    }
    cout<<SZ(sad)+1<<nl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  const int a[] = {1800, 1600, 1400, 1200, 1000, 800, 600, 400};

  int X;

  std::cin >> X;

  for (int i = 0; i < 8; i ++)
    if (X >= a[i]) {
      std::cout << i + 1 << std::endl;

      break;
    }

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){

  double xa,xb,c,a,b,h,m,z;;
    cin >>a>>b>>h>>m;
  
  z=h*60+m;

  if(xb>xa){c=a*a+b*b-2*a*b*cos(m*6*2/360*M_PI-z/2*2/360*M_PI);
    cout<<sqrt(c)<<endl;}
  else{c=a*a+b*b-2*a*b*cosl(z/2*2/360*M_PI-m*6*2/360*M_PI);
    cout<<fixed<<setprecision(20)<<sqrt(c)<<endl;}
}


Measured memory_bytes: 4140
import java.util.Scanner;

public class Main {

	static char[][]field;
	static char[]a={'o','x'};
	static int[]v1={-1,0,1,-1,1,-1,0,1};
	static int[]v2={-1,-1,-1,0,0,1,1,1};
	static int  turn;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		field=new char[8][];
		turn=0;
		for(int i=0;i<8;i++){
			field[i]=sc.next().toCharArray();
		}
		int pass=0;
		for(;;){
			
			int x=0,y=0,max=0;
			if(turn==0){
				max=0;
			}
			else{
				max=1;
			}
			boolean isPass=true;;
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++){
					int[] put =putCount(i,j,a[turn]);

					if(put==null)continue;
					if(turn==0){
						if(max<put[0]){
							max=put[0];
							x=i;
							y=j;
							isPass=false;
						}						
					}
					else{
						if(max<=put[0]){
							max=put[0];
							x=i;
							y=j;
							isPass=false;
						}
					}

				}
			}
			if(!isPass){
				put(x,y,a[turn]);
				pass=0;
			}
			else{
				pass++;
				if(pass==2){
					break;
				}
			}
			turn=1-turn;

			
			int cnt=0;
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++){
					if(field[i][j]!='.')cnt++;
				}
			}
			if(cnt==64)break;
//			System.out.println(pass);
//			System.out.println(isPass);
//			output();
		}
		
		output();
	}
	static void output(){
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++){
				System.out.print(field[i][j]);
			}
			System.out.println();
		}		
	}
	static void put(int x,int y,char c){
		field[x][y]=(char)c;
		for(int i=0;i<v1.length;i++){
			int xx=x+v1[i];
			int yy=y+v2[i];
			if(xx<0||yy<0||xx>=8||yy>=8)continue;
			if(field[xx][yy]==a[1-turn]){
				int u=uraCount(xx,yy,c,i);
				if(u!=-1){
					ura(xx,yy,c,i,u);
				}
			}
		}
	}
	static void ura(int x,int y,int c,int dir,int count){
		for(int i=0;i<count;i++){
			field[x][y]=(char)c;
			x+=v1[dir];
			y+=v2[dir];
		}
	}
	static int[] putCount(int x,int y,char c){
		
		// 個数、方向
		int[] re={0,0};
		if(field[x][y]!='.')return null;
		for(int i=0;i<v1.length;i++){
			int xx=x+v1[i];
			int yy=y+v2[i];
			if(xx<0||yy<0||xx>=8||yy>=8)continue;
			if(field[xx][yy]==a[1-turn]){
				int u=uraCount(xx,yy,c,i);
				if(u!=-1){
//					System.out.println(u);
					re[0]+=u;
				}
			}
		}
		return re;
	}
	static int uraCount(int x,int y,int c,int dir){
		int re=1;
		for(;;){
			x+=v1[dir];
			y+=v2[dir];
			if(x<0||y<0||x>=8||y>=8)break;
			if(field[x][y]==c){
				return re;
			}
			else if(field[x][y]==a[1-turn]){
				re++;
			}
			else{
				break;
			}
		}
		return -1;
	}
	
}

Measured memory_bytes: 18504
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type cake struct {
	x, y, z int
}

type cakes []cake

func (cs cakes) Len() int {
	return len(cs)
}

func (cs cakes) Swap(i, j int) {
	cs[i], cs[j] = cs[j], cs[i]
}

func (cs cakes) Less(i, j int) bool {
	return cs[i].x + cs[i].y + cs[i].z > cs[j].x + cs[j].y + cs[j].z
}

func main() {
	sc.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()
	c := make([][]cake, 8)
	for i := 0; i < 8; i++ {
		c[i] = make([]cake, n)
	}

	for i := 0; i < n; i++ {
		x, y, z := nextInt(), nextInt(), nextInt()
		c[0][i] = cake{x, y, z}
		c[1][i] = cake{x, -y, z}
		c[2][i] = cake{x, y, -z}
		c[3][i] = cake{x, -y, -z}
		c[4][i] = cake{-x, y, z}
		c[5][i] = cake{-x, -y, z}
		c[6][i] = cake{-x, y, -z}
		c[7][i] = cake{-x, -y, -z}
	}

	max := 0
	for i := 0; i < 8; i++ {
		sort.Sort(cakes(c[i]))
		sum := 0
		for j := 0; j < m; j++ {
			sum += c[i][j].x + c[i][j].y + c[i][j].z
		}

		if max < sum {
			max = sum
		}
	}

	fmt.Println(max)
}

Measured memory_bytes: 896
while line =gets
x = line.chomp.to_f
h = gets.chomp.to_f
break if x == 0 && h == 0
sx = (x / 2) ** 2
sy = h ** 2
sh = (sx + sy) ** 0.5
area= (x ** 2) +  (x * sh *0.5) * 4
puts sprintf("%#.6f",area)
end


Measured memory_bytes: 6924
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	String[] c = new String[h];
      	for(int i = 0; i < h ; i++){
        	c[i] = sc.next();
        }
      	for(int i = 0; i < h; i++){
        	System.out.println(c[i] + "\n" + c[i]);
        }
    }
}

Measured memory_bytes: 39676
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin >> d.at(i);
    }
    int sum=0;
  
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            sum += d.at(i)*d.at(j);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vb ans(n, false);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            a--;
            ans[a] = true;
        }
    }
    int cnt = 0;
    rep(i, n) if (!ans[i]) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3648
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
  fast();
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    while (x--) {
      int a;
      cin >> a;
      ++mp[a];
    }
  }
  int ans = 0;
  for (auto x : mp) {
    if (x.s == n) ++ans;
  }
  cout << ans;

  return 0;
}



Measured memory_bytes: 3628
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

matches = []
for i in range(0, 1000):
    if len(str(i)) == N:
        temp = True
        for s, c in sc:
            if str(i)[s - 1] != str(c):
                temp = False
        if temp: matches.append(i)
print(-1) if len(matches) == 0 else print(min(matches))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n];
    int c[n];
    for (int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    int dpa[n];
    int dpb[n];
    int dpc[n];
    dpa[0]=a[0];
    dpb[0]=b[0];
    dpc[0]=c[0];
    for (int i=1;i<n;i++){
        dpa[i]=max(dpb[i-1],dpc[i-1])+a[i];
        dpb[i]=max(dpa[i-1],dpc[i-1])+b[i];
        dpc[i]=max(dpb[i-1],dpa[i-1])+c[i];
    }
    if (dpa[n-1]>dpb[n-1]){
        cout<<max(dpa[n-1],dpc[n-1]);
    }
    else{
        cout<<max(dpb[n-1],dpc[n-1]);
    }
}


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

vector<int> v(10, 0);
bool check(int n){
    while (n){
    int t1= n%10;
    if(v[t1]) return false;
    n /= 10;
  }
  return true;

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n,k;
  cin>>n>>k;
  
  while(k--){
    int temp;
    cin>>temp;
    v[temp] = 1;
  }

  for(int k = n ; k<1e10; k++){
    if(check(k)) {cout<<k; break;}
  }



  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            int n = int.Parse(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                string str = i.ToString();
                if (i % 3 == 0)
                {
                    Console.Write(" {0}", i);
                }
                else if (str.Contains("3"))
                {

                    Console.Write(" {0}", i);
                }
                    
                
            }
            Console.Write('\n');
        }
    }
}



Measured memory_bytes: 15960
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  cout << (n%k != 0) << endl;
  return 0;
}

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

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)

int now,n,k;


int main(){
  int ans=0;
  string s;cin>>s;
  n=s.length();
  vector<int> a(n);
  REP(i,n) {
    if (s[i]=='0')
      ans++;
  };
  
  ans=min(ans,n-ans)*2;



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

Measured memory_bytes: 896
#include <iostream>


int n;
int A[20];
int q;
int m[200];

bool solve(int i, int m) {
    if (m == 0) return true;
    else if (i >= n) return false;
    else {
        return solve(i + 1, m - A[i]) || solve(i + 1, m);
    }
}

int main(int argc, char **argv) {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> A[i];
    }
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        std::cin >> m[i];
    }
    for (int i = 0; i < q; i++) {
        if (solve(0, m[i])) {
            std::cout << "yes";
        }else {
            std::cout << "no";
        }
        std::cout << std::endl;
    }
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int N; cin >> N;
    vector<pair<ll, ll> > P(N);
    rep(i,N){
        ll A, B; cin >> A >> B;
        P[i] = make_pair(B, A);
    }
    sort(P.begin(), P.end());
    // rep(i,P.size()) cout << P[i].first << " " << P[i].second << endl;
    ll sum = 0; bool isComp = true;
    rep(i,P.size()){
        sum += P[i].second;
        if(sum > P[i].first){
            isComp = false;
            break;
        }
    }
    if(isComp) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
	int i,t,n,s,f;
	while(1){
		scanf("%d",&t);
		if(t==0){
			break;
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d%d\n",&s,&f);
			t-=(f-s);
		}
		if(t<=0){
			printf("OK\n");
		}else{
			printf("%d\n",t);
		}
	}
	return 0;
}

Measured memory_bytes: 612
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N + 1)]
AB = []
for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)
    AB.append((a, b))
C = list(map(int, input().split()))
C.sort()

for i, e in enumerate(edge[1:], start=1):
    if len(e) == 1:
        s = i
        break

node = [s]
memo = [-1] * (N + 1)
while node:
    s = node.pop()
    memo[s] = C.pop()
    for t in edge[s]:
        if memo[t] != -1:
            continue
        node.append(t)

ans = 0
for a, b in AB:
    ans += min(memo[a], memo[b])

print(ans)
print(*memo[1:])


Measured memory_bytes: 6792
a, b = map(int, input().split())
n = len(format(b, 'b'))


def bit_sum(x):
    bit = [0] * n
    x += 1
    for i in range(n):
        bit[i] = x // 2**(i + 1) * 2**i + max(0, x-1-x // 2**(i+1) * 2**(i+1) + 1 - 2**i)
    return reversed(bit)


a_bit = bit_sum(a-1)
b_bit = bit_sum(b)

ans = ''.join(str((i+j) % 2) for i, j in zip(a_bit, b_bit))
print(int(ans, 2))


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

#define REP(i, n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin() , (c).end()

struct P {
  int y, x;
  int num, up, hoge;
};

int dist[205][205][20][2][3];

int main() {
  int table1[20][3] = {{4,1,5},{0,2,6},{1,3,7},{2,4,8},{3,0,9},
                       {11,10,0},{12,11,1},{13,12,2},{14,13,3},{10,14,4},
                       {9,5,15},{5,6,16},{6,7,17},{7,8,18},{8,9,19},
                       {16,19,10},{17,15,11},{18,16,12},{19,17,13},{15,18,14}};
  int table[20][2][3][3];
  REP(i, 20) {
    REP(j, 3) {
      REP(k, 3) {
        table[i][0][j][k] = table1[i][(j+k)%3];
      }
    }

    // int t = table1[i][0];
    // table1[i][0] = table1[i][1];
    // table1[i][1] = t;
    swap(table1[i][0], table1[i][1]);
    //cout << table1[i][0] << " " << table1[i][1] << endl;
    REP(j, 3) {
      REP(k, 3) {
        table[i][1][j][k] = table1[i][(j+k)%3];
      }
    }
  }
  // REP(i, 2) {
  //     REP(j,3) {
  //         REP(k, 3) {
  //             printf("(%d,%d,%d) ",i,j,k);
  //             cout << table[1][i][j][k] << endl;;
  //         }
  //     }
  // }
  int dx[] = {1,-1};
  int dy[] = {-1,1};

  int x, y, n;
  while(cin>>x>>y>>n,x||y||n) {
    queue<P> Q;
    Q.push((P){0, 0, 0, 1, 0});
    memset(dist, -1, sizeof(dist));
    dist[100][100][0][1][0] = 0;
    int ans = -1;
    while(!Q.empty()) {
      P now = Q.front(); Q.pop();
      // printf("(%d,%d) %d %d\n", now.x, now.y, now.num, dist[now.y+100][now.x+100][now.num][now.up][now.hoge]);
      // if (dist[now.y+100][now.x+100][now.num][now.up][now.hoge]>2) break;
      if (now.x == x && now.y == y && now.num == n) {
        ans =  dist[now.y+100][now.x+100][now.num][now.up][now.hoge];
        break;
      }

      REP(leftright, 2) {
        int yy = now.y;
        int xx = now.x + dx[leftright];
        int tmp = table[now.num][now.up][now.hoge][leftright];
        REP(i, 3) {
          if (table[tmp][!now.up][i][!leftright] == now.num) {
            if (dist[yy+100][xx+100][tmp][!now.up][i] == -1) {
              dist[yy+100][xx+100][tmp][!now.up][i] = dist[now.y+100][now.x+100][now.num][now.up][now.hoge] + 1;
              P next = (P){yy, xx, tmp, !now.up, i};
              Q.push(next);
            }
          }
        }
      }
      int yy = now.y+dy[now.up];
      int xx = now.x;
      int tmp = table[now.num][now.up][now.hoge][2];
      REP(i, 3) {
        if (table[tmp][!now.up][i][2] == now.num) {
          if (dist[yy+100][xx+100][tmp][!now.up][i] == -1) {
            dist[yy+100][xx+100][tmp][!now.up][i] = dist[now.y+100][now.x+100][now.num][now.up][now.hoge] + 1;
            P next = (P){yy, xx, tmp, !now.up, i};
            Q.push(next);
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 20000
N = gets.chomp.to_i

ans = Array.new(10_050, 0)

n = Math.sqrt(10_050)
(1..n).each do |x|
  (1..n).each do |y|
    (1..n).each do |z|
      v = x**2 + y**2 + z**2 + x * y + y * z + x * z
      ans[v] += 1 if v < 10_050
    end
  end
end

(1..N).each do |i|
  puts ans[i]
end

Measured memory_bytes: 14260
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>
#include <cstring>
#include <unordered_map>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


ll mod_pow(ll n, ll p) {
    if (p == 0) return 1;
    ll res = mod_pow(n*n%MOD, p / 2);
    if (p % 2 == 1) res = res * n % MOD;
    return res;
}

ll Combination(int n, int r) {//階乗は英語でFactorial
    vector<ll> fct(n + 1, 1); // fact[n] = n! の mod
    for (int i = 1; i <= n; i++) {
        fct[i] = i * fct[i - 1] % MOD;
    }

    vector<ll> invfct(n + 1, 1); // invfact[n] = 1/n! の mod
    invfct[n] = mod_pow(fct[n], MOD - 2) % MOD;// 1/n!を繰り返し二乗法で求める
    for (int i = n - 1; i >= 1; i--) {
        invfct[i] = (i + 1)*invfct[i + 1] % MOD;
    }
    // Combination(n,r)を計算
    ll Co = (fct[n] * invfct[r] % MOD)*invfct[n - r] % MOD;
    return Co;
}

int main() {
    int N, M, K;
    cin >> N >> M >> K;

    ll ans = 0;
    for (int dx = 1; dx < M; dx++) {
        ll A = (N*N*(M - dx)) % MOD;
        ans = (ans + A * dx % MOD) % MOD;
    }
    for (int dy = 1; dy < N; dy++) {
        ll A = (M*M*(N - dy)) % MOD;
        ans = (ans + A * dy % MOD) % MOD;
    }

    cout << ans * (Combination(N*M - 2, K - 2) % MOD) % MOD << endl;
}

Measured memory_bytes: 3328
/*
 © 2020-02-19 19:47:11 crystaalroo All Rights Reserved
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for(int i = (a); i <(b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define sz(x) (int) (x).size()
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long lli;
typedef pair<lli,lli > ii;
#define ENDL '\n'
#define deb(x) cout << #x": " << (x) << endl;
const lli INF=1e14;
const lli mod = 1e6;
const lli N = 1e4;


int main(){_
  int n;
  cin>>n;
  vector<double>v(n);
  fore(i,0,n)cin>>v[i];
  double dp[n+1][n+1];
  fore(i,0,n+1)fore(j,0,n+1)dp[i][j]=0;
  fore(j,n/2 + 1,n+1)dp[n][j]=1;
  for(int i=n-1;i>=0;i--)for(int j = n; j>=0; j--)dp[i][j] = v[i]*dp[i+1][j+1] + (1-v[i])*dp[i+1][j];
  cout<<dp[0][0]<<ENDL;


}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int a=0,b=0,i=0,j=0;
  while(i<N){
    a+=i;
    i++;
  }
  while(j<M){
    b+=j;
    j++;
  }
  cout<<a+b<<endl;
  
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        int M;
        Task[] tasks;
        PriorityQueue<Task> queue1 = new PriorityQueue<>(1,new TaskComparator1());
        PriorityQueue<Task> queue2 = new PriorityQueue<>(1,new TaskComparator2());

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            M = sc.nextInt();
            tasks = new Task[N];
            for (int i = 0; i < N; i++) {
                int a = sc.nextInt();
                int b = sc.nextInt();
                tasks[i] = new Task(a, b);
            }
        }
        for(Task t :tasks){
            queue1.add(t);
        }

        Task[] daySortTask = new  Task[N];
        for (int i = 0; i < N; i++) {
            daySortTask[i] = queue1.poll();
        }
        long result = 0;
        //日付を増やしていく
        int c = 0;
        //最後の日から逆算していく
        for(int d = 1; d <= M;d++){
            //dまでいれて
            while(true){
                if(!(c < N)){
                    break;
                }
                Task t = daySortTask[c];
                if(t.a <= d){
                    queue2.add(t);
                }else{
                    break;
                }
                c++;
            }
            //先頭(一番稼げるやつ)をとりだす
            Task t = queue2.poll();
            if( t !=null){
                result += t.b;
            }
        }

        System.out.println(result);
        return;
    }

    static class Task{
        int a;
        int b;

        public Task(int a,int b){
            this.a = a;
            this.b = b;
        }
    }
    static class TaskComparator1  implements Comparator{
        @Override
        public int compare(Object o1, Object o2) {
            Task x = (Task)o1;
            Task y = (Task)o2;
            if (x.a > y.a) {
                return 1;
            } else if (x.a < y.a) {
                return -1;
            } else{
                return 0;
            }
        }
    }
    static class TaskComparator2  implements Comparator{
        @Override
        public int compare(Object o1, Object o2) {
            Task x = (Task)o1;
            Task y = (Task)o2;
            if (x.b > y.b) {
                return -1;
            } else if (x.b < y.b) {
                return 1;
            } else{
                return 0;
            }
        }
    }
}


Measured memory_bytes: 87492
#include <stdio.h>

int main(void) {
	double a, b, c, d, e, f;
	double na, nb, nc, nd, ne, nf;
	double x, y;
	char instr[80];
	
	while (fgets(instr, sizeof(instr), stdin) != NULL) {
		sscanf(instr, "%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f);
		
		na=a*d; nb=b*d; nc=c*d;
		nd=d*a; ne=e*a; nf=f*a;
		
		na-=nd; nb-=ne; nc-=nf;
		
		y = nc/nb;
		x = (c - b*y)/a;
		
		printf("%.3f %.3f\n", x, y);
	}
	
	return 0;
}

Measured memory_bytes: 656
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005;
int n,m,cnt,h[N],siz[N],fa[N],dep[N],x,y,a[N];
struct edge{int v,n;} e[N<<1];
typedef long long LL;
LL ans;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void addedge(int u,int v)
{
	e[cnt]=(edge){v,h[u]},h[u]=cnt++;
	e[cnt]=(edge){u,h[v]},h[v]=cnt++;
}

void dfs(int x,int f,int tp)
{
	siz[x]=tp,dep[x]=dep[f]+1,fa[x]=f;
	for(int i=h[x]; i!=-1; i=e[i].n)
		if(e[i].v!=f)
		{
			if(dep[e[i].v]) ::x=e[i].v,y=x;
			else dfs(e[i].v,x,-tp),siz[x]+=siz[e[i].v];
		}
}

int main()
{
	n=getint(),m=getint();
	memset(h,-1,sizeof(h));
	rep(i,1,m) addedge(getint(),getint());
	dfs(1,0,1);
	if(m==n-1)
	{
		if(siz[1]) return puts("-1"),0;
		rep(i,1,n) ans+=abs(siz[i]);
		return printf("%lld\n",ans),0;
	}
	if((dep[x]^dep[y])&1)
	{
		if(siz[1]) return puts("-1"),0;
		rep(i,1,n) ans+=abs(siz[i]);
		*a=1;
		while(x!=y) dep[x]>dep[y]?(a[++*a]=siz[x],x=fa[x]):(a[++*a]=-siz[y],y=fa[y]);
		int mid=(*a)+1>>1;
		nth_element(a+1,a+mid,a+1+*a);
		rep(i,1,*a) ans+=-abs(a[i])+abs(a[i]-a[mid]);
		printf("%lld\n",ans);
	}
	else
	{
		if(siz[1]&1) return puts("-1"),0;
		int c=siz[1]>>1;
		ans=abs(c);
		while(x) siz[x]-=c,x=fa[x];
		while(y) siz[y]-=c,y=fa[y];
		rep(i,1,n) ans+=abs(siz[i]);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  int c = 0;
  int d = 0;
  rep(i,n) {
    if (s[i] == '0') c++;
    else d++;
  }
  cout << 2 * min(c, d) << endl;
}

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

Measured memory_bytes: 3748
import operator
class SegmentTree:
    def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size

def resolve():
    N = int(input())
    S = input()
    Q = int(input())

    seg = SegmentTree(N, fn=operator.or_)
    for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

    for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1"))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 84820
#include<iostream>

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;

  if (a < b) {
    cout << "a < b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else{
    cout << "a == b" << endl;
  }

  return 0;
}


Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
struct P {
    ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//??£??\???????????¨???
    ll to, cost;
};
struct S {//???????????±?????\???????????°
    int from, to, cost;
};
struct H {
    int x, y;
};
ll gcd(ll i, ll j) {//?????§??¬?´???°
    if (i > j) swap(i, j);
    if (i == 0) return j;
    return gcd(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
    return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad?????§?¨???????2??????????????¢
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main(){
	string a="AKIHABARA",s;
	cin>>s;
	if(s=="KIHBR"||s=="KIHBRA"||s=="KIHBAR"||s=="KIHBARA"||s=="KIHABR"||s=="KIHABRA"||s=="KIHABAR"||s=="KIHABARA"||
	s=="AKIHBR"||s=="AKIHBRA"||s=="AKIHBAR"||s=="AKIHBARA"||s=="AKIHABR"||s=="AKIHABRA"||s=="AKIHABAR"||s=="AKIHABARA"){
		cout<<"YES\n";
	}
	else{
		cout<<"NO\n";
	}
    getchar(); getchar();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,bool> mp;
int num,n,x;
int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&x);
		if(mp[x]){
			num--;
			mp[x] = false;
		}
		else{
			num++;
			mp[x] = true;
		}		
	}
	printf("%d\n", num);
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
map<string, int> mp;

int main() {
    int n, m;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string p;
        cin >> p;
        mp[p]++;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        string p;
        cin >> p;
        mp[p]--;
    }
    int ans = 0;
    for (const auto& i : mp) {
        if (i.second > ans) {
            ans = i.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256