akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

struct SyntaxAnalysis {
  string s;
  int i;
  bool val;

  SyntaxAnalysis() {}
  SyntaxAnalysis(string s) { solve(s); }
 
  bool solve(string _s) {
    s = _s;
    i = 0;
    val = expr(i);
    return val;
  }

  bool expr(int &i) {
    bool res;
    switch(s[i]) {
      case '0': res = false; break;
      case '1': res = true; break;
      case '-': res = !expr(++i); break;
      case '(': res = factor(++i); break;
    }
    return res;
  }

  bool factor(int &i) {
    bool a = expr(i);
    bool en = s[++i] == '^';
    bool b = expr(++i);
    i++;
    if (en) return a ^ b;
    else return a & b;
  }
};

int dp[1<<16];

int main() {
  fill(dp, dp + (1<<16), INF);

  priority_queue<pii, vector<pii>, greater<pii> > pq;
  dp[0] = 1; pq.push(pii(1, 0));
  dp[(1<<16)-1] = 1; pq.push(pii(1, (1<<16)-1));
  REP(i, 4) {
    int curs = 0;
    REP(j, 1<<4) {
      if (j >> i & 1) curs |= 1 << j;
    }
    dp[curs] = 1;
    pq.push(pii(1, curs));
  }
  
  while (!pq.empty()) {
    pii cur = pq.top(); pq.pop();
    if (dp[cur.se] < cur.fi || cur.fi >= 16) continue;
    
    // -a
    int nexs = (1<<16)-1 ^ cur.se;
    if (chmin(dp[nexs], cur.fi + 1)) pq.push(pii(dp[nexs], nexs));

    // (a^b)
    REP(i, 1<<16) if (dp[i] != INF) {
      int nexs = i ^ cur.se;
      if (chmin(dp[nexs], cur.fi + dp[i] + 3)) pq.push(pii(dp[nexs], nexs));
    }

    // (a*b)
    REP(i, 1<<16) if (dp[i] != INF) {
      int nexs = i & cur.se;
      if (chmin(dp[nexs], cur.fi + dp[i] + 3)) pq.push(pii(dp[nexs], nexs));
    }
  }

  SyntaxAnalysis sa;
  string s;
  while (cin >> s, s != ".") {
    if (debug) putchar('@');

    int curs = 0;
    REP(i, 1<<4) {
      string cur = s;
      REP(j, cur.size()) {
        if (cur[j] >= 'a' && cur[j] <= 'd') {
          cur[j] = '0' + (i >> (cur[j]-'a') & 1);
        }
      }
      if (sa.solve(cur)) curs |= 1<<i;
    }
    cout << dp[curs] << endl;
  }


  return 0;
}


Measured memory_bytes: 7008
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 998244353;
//
bool used[200001]={},iro[200001]={};
  vector<int> hen[200001];
  void dfs(int a,bool x){
    iro[a]=x;
    for(int i=0;i<hen[a].size();i++){
      if(!used[hen[a][i]]){
        used[hen[a][i]]=true;
        dfs(hen[a][i],!x);
      }
    }
  }

        signed main() {
        int a,b,j,t,j0;
        cin>>a>>b;
        int ans=0;
        for(int i=a;i<=b;i++){
          j=i;t=10000;j0=0;
          for(int k=0;k<5;k++){j0+=(j%10)*t;j/=10;t/=10;}
          if(i==j0){ans++;}
        }
        cout<<ans;

        


      }


        


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for (int pw = 0; pw <= 999; ++pw) {
        vector<int> p;
        int pw_cp = pw;
        for (int i = 0; i < 3; ++i) {
            p.push_back(pw_cp % 10);
            pw_cp /= 10;
        }

        int idx = 0;
        for (int i = 0; i < n; ++i) {
            if (s[i] - '0' == p[idx]) {
                ++idx;
            }
            if (idx == 3) {
                ++cnt;
                break;
            }
        }
    }
    cout << cnt << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

#define MAXPOS 30010
#define MAXLEN 4
#define CURRENT 1000

//pos:どの桁をみたか
//len:何文字残す？
//current:現時点で残すと決めた部分の文字列


bool dp[MAXPOS][MAXLEN][CURRENT];

signed main(){

	dp[0][0][0]=true;

	lli n;
	cin>>n;
	string s;
	cin>>s;

	REP(i,0,n+1){
		dp[i][0][0]=true;
	}

	REP(i,0,n){
		lli now = s.at(i)-'0';
		if(DEBUG)cout<<"now="<<now<<endl;

		for(lli len=3;len>=0;len--){
			REP(current,0,1000){
				if(dp[i][len][current] && DEBUG)cout<<"i="<<i<<" len="<<len<<" current="<<current<<endl;
				
				if(dp[i][len][current]){
					if(len<=2)dp[i+1][len+1][current*10+now] = dp[i][len][current];
					dp[i+1][len][current] = dp[i][len][current];
				}
			}
		}
	}
	lli cnt=0;

	REP(i,0,CURRENT){
		if(dp[n][3][i]){
			if(DEBUG)cout<<"i="<<i<<endl;
			cnt++;
		}
	}
	cout<<cnt<<endl;
	
	return 0;
}

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

int main (){
    int n,w;
    cin >> n;
    cin >> w;
    int W[n];
    long long V[n];
    for(int i=0;i<n;i++){
        long long wi,v;
        cin >> wi >> v;
        W[i] = wi;
        V[i] = v;
     //   eff.at(i) = v/w;
    } 
    long long max_val[n][w+1];

    for(int j=0;j<w+1;j++){
        if(j>=W[0]){
            max_val[0][j] = V[0];
        }else{
            max_val[0][j] = 0;
        }
    }

    for(int i=1;i<n;i++){
        for(int j=0;j<w+1;j++){
            if(j-W[i]>=0){
                if(max_val[i-1][j]<max_val[i-1][j-W[i]]+V[i]){
                    max_val[i][j] = max_val[i-1][j-W[i]]+V[i];
                }else{
                    max_val[i][j] = max_val[i-1][j];
                }
            }else{
                max_val[i][j] = max_val[i-1][j];
            }
        }
    }

    cout << max_val[n-1][w] << endl;

    return 0;
}


Measured memory_bytes: 81704
#include <iostream>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int* L = new int[N];
    int* R = new int[N];
    L[0] = A[0]; R[N-1] = A[N-1];
    for (int i = 1; i < N; i++) {
        L[i] = gcd(L[i-1], A[i]);
    }

    for (int i = N-2; i >= 0; i--) {
        R[i] = gcd(R[i+1], A[i]);
    }
    
    int ans = R[1];
    for (int i = 1; i < N-1; i++) {
        ans = max(ans, gcd(L[i-1], R[i+1]));
    }
    ans = max(ans, L[N-2]);


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<iostream>
using namespace std;
int search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key)i++;
	return i!=n;
} 
int main(){
	int n,A[10000+1],q,key;
	int sum=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",&key);
		if(search(A,n,key))sum++;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3260
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
N, K = map(int, input().split())
# 横
A = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0
tmp = 0

for i, a in enumerate(A) :
    for aa in range(i + 1, N) :
        if a > A[aa] :
            ans += 1

for a in A :
    for aa in A :
        if a > aa :
            tmp += 1

print(((int((K*(K-1))//2)%MOD)*tmp+ans*K)%MOD)


Measured memory_bytes: 41708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    vector<int> a;
    rep(i,N){
        int tmp;
        cin>>tmp;
        a.push_back(tmp);
    }
    //Nが偶数⇒その数を除くと奇数個なので、a1^a2^a3^...a^nはx1^x2^x3...^xnに等しい（偶数回で0につぶれるため）
    //まずx1^x2...^xnを求める
    int allxor=0;
    rep(i,N){
        allxor=allxor^a[i];
    }
    //さて、x1=allxor^a1なのでそれでOK?
    vector<int> ans;
    rep(i,N){
        ans.push_back(allxor^a[i]);
    }
    rep(i,N){
        cout << ans[i];
        cout << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    vector<int> cnt(26, 0);
    REP(i, s.size()) {
        if ( isalpha(s[i]) ) {
            cnt[s[i]-'a']++;
        }
    }
    map<int, vector<char>> m;
    REP(i, 26) {
        if (cnt[i] > 0) {
            m[cnt[i]].pb('a'+i);
        }
    }
    vector<string> kou;
    EACH(p, m) {
        int coe; vector<char> v; tie(coe, v) = p;
        string str = "";
        EACH(c, v) {
            if (str != "") str += "+";
            str += c;
        }
        if (coe > 1) {
            if (v.size() > 1) {
                str = "(" + str + ")";
            }
            str = to_string(coe) + "*" + str;
        }
        kou.pb(str);
    }
    string ans = "";
    EACH(str, kou) {
        if (ans != "") ans += "+";
        ans += str;
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 2000000
#define MOD 1000000007
using Graph=vector<vector<int>>;

int dfs(Graph &G,int v,int p,vector<int> &number){
  int ans=0;
  for(auto nv:G.at(v)){
    if(nv==p){
      continue;
    }
    dfs(G,nv,v,number);
    ans+=1;
  }
  return number.at(v)=ans;
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  Graph G(N);
  for(int i=1;i<N;i++){
    cin>>A.at(i);
    A.at(i)--;
    G.at(i).push_back(A.at(i));
    G.at(A.at(i)).push_back(i);
  }

  vector<int> number(N);
  dfs(G,0,-1,number);

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


Measured memory_bytes: 31352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

double toRad(const double deg){
    return (deg / 360) * 2 * PI;
}

double toDeg(const double rad){
    return (rad / 2 / PI) * 360;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a,b,x;
    cin>>a>>b>>x;
    double ans = 0;
    
    LL times = 1e6;
    double low = 0;
    double high = PI/2;
    if(a * a * b / 2 < x){
        REP(i,times){
            double mid = (low + high)/2;
            double v = a * a * (b - (a * tan(mid))/2);
            if(v == x) {
                low = high = mid;
                break;
            }
            else if(v < x) {
                high = mid;
            }
            else {
                low = mid;
            }
        }
    }
    else {
        REP(i,times){
            double mid = (low + high)/2;
            double v = a * b * b * tan(PI/2 - mid) / 2;
            if(v == x) {
                low = high = mid;
                break;
            }
            else if(v < x) {
                high = mid;
            }
            else {
                low = mid;
            }
        }
    }
    ans = (high + low)/2;
    printf("%.9f\n", toDeg(ans));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

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

int sumd(int x)
{
  int ret = 0;
  while(x)
  {
    ret+= x%10;
    x/=10;
  }
  return ret;
}


int main()
{
  finp;
  int n;
  cin>>n;
  int ans = infs;
  afor(i,1,n-1)
  {
    ans = min(ans,sumd(i) + sumd(n-i));
  }
  cout<<ans;
  
return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());

        int ac = 0, wa = 0, tle = 0, re = 0;

        for(int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());
            String target = st.nextToken();

            switch (target) {
                case "AC" :
                    ac++;
                    break;
                case "WA" :
                    wa++;
                    break;
                case "TLE" :
                    tle++;
                    break;
                case "RE" :
                    re++;
                    break;
            }  
        }

        pw.println("AC x " + ac);
        pw.println("WA x " + wa);
        pw.println("TLE x " + tle);
        pw.println("RE x " + re);

        br.close();
        pw.close();
    }
}

Measured memory_bytes: 47772
N,W = map(int,input().split())
K = 10**5
dp = [[10**100 for i in range(K+1)] for j in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(K+1):
        dp[i][j] = dp[i-1][j]
        if j < v:
            continue
        else:
            dp[i][j] = min(dp[i-1][j-v] + w,dp[i-1][j])
for i in range(K+1):
    x = dp[N][-i-1]
    if x <= W:
        print(K-i)
        quit()


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

using namespace std;

const int N = 1234;

int col[N];
char s[N][N];

int main() {
  int h;
  scanf("%d", &h);
  int w = h;
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  bool any = false;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      any |= (s[i][j] == '#');
    }
  }
  if (!any) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        col[j]++;
      }
    }
  }
  int ans = (int) 1e9;
  for (int i = 0; i < h; i++) {
    int cur = 0;
    if (col[i] == 0) {
      cur++;
    }
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        cur++;
      }
    }
    for (int j = 0; j < w; j++) {
      if (col[j] < h) {
        cur++;
      }
    }
    ans = min(ans, cur);
  }
  printf("%d\n", ans);
  return 0;
}



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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int i = 0;
  while(i<n){
    for(int i = 0; i<s.size(); i++){
      if(s.at(i) != 'Z')
       s.at(i)++;
      else{
        s.at(i) = 'A';
      }
    }
    i++;
  }
  cout << s << endl;
}

Measured memory_bytes: 3596
const main = (args) => {
    const input = args.trim().split(' ');
    const A = input[0];
    const B = input[1];
    const H = input[2];
    const M = input[3];

    const c = (H / 12.0 + M / (12.0 * 60.0) - M / 60.0) * Math.PI * 2;
 
    const ans = Math.sqrt(Math.pow(A,2) + Math.pow(B,2) - (2 * A * B) * Math.cos(c));
    console.log(ans);

}
main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 29792
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
const int N=100005;
vector<int>adj[N];
int f[N];
int find(int x){
  return f[x]==x?x:f[x]=find(f[x]);
}
int n,m,rt=1,re=0;
int w[N];
void dfs(int u,int fa,int opt){
  w[u]=opt,f[u]=fa;
  for(auto v:adj[u]){
    if(v==fa)continue;
    dfs(v,u,-opt);
    w[u]+=w[v]; 
  }
}
int b[N],len;
int main(){
  n=read(),m=read();
  if(n&1){
    puts("-1"),exit(0);
  }
  for(int i=1;i<=n;i++)f[i]=i;
  for(int i=1;i<=m;i++){
    int u=read(),v=read();
    if(find(u)!=find(v)){
      f[find(u)]=find(v);
      adj[u].pb(v);
      adj[v].pb(u);
    }
    else{
      rt=u,re=v;
    }
  }
  memset(f,0,sizeof(f));
  dfs(rt,0,1);
  if(m==n-1){
    if(w[rt])puts("-1"),exit(0);
  }
  else{//基环树 
    for(int x=re;x;x=f[x])b[++len]=w[x];
    if(len&1){//奇环
      if(w[rt]&1)puts("-1"),exit(0);
      for(int x=re;x;x=f[x])w[x]-=w[rt]>>1;
    }else{//偶环 
      if(w[rt])puts("-1"),exit(0);
      sort(b+1,b+len+1);
      for(int x=re;x;x=f[x])w[x]-=b[len+1>>1];
    }
  } 
  ll ans=0;
  for(int i=1;i<=n;i++)ans+=abs(w[i]);
  printf("%lld\n",ans);
  return 0;
} 

Measured memory_bytes: 18168
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;


int main() {
	int H, W, x = 0, y = 0; cin >> H >> W;
	vector<string> S(H);
	int a[2001][2001] = { 0 }, b[2001][2001] = { 0 };
	for (int i = 0; i < H; i++) cin >> S[i];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				x = 0;
				while (j+x<W&&S[i][j + x] != '#') x++;
				while (j < W&&S[i][j] != '#') {
					a[i][j] = x;
					j++;
				}
			}
		}
	}
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {

			if (S[j][i] == '.') {
				x = 0;
				while (j+x<H&&S[j + x][i] != '#') x++;
				while (j<H&&S[j][i] != '#') {
					b[j][i] = x;
					j++;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, a[i][j] + b[i][j]);
		}
	}
	cout << ans-1 << endl;
}




Measured memory_bytes: 35712
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> b(n);
  for (ll i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<ll> ans;
  for (ll i = 0; i < n; i++) {
    for (ll j = n - 1 - ans.size(); j >= 0; j--) {
      if (b[j] == j + 1) {
        ans.push_back(b[j]);
        b.erase(b.begin() + j);
        break;
      }
    }
  }
  if (b.size() != 0) {
    cout << -1 << endl;
    return 0;
  }
  reverse(ans.begin(), ans.end());
  for (ll i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3660
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

 
/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 * Integer.valueOf(char)はダメ、(String)
 */
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.printf("%d %d %.5f", a/b, a%b, (double)a/b);
	}
}


Measured memory_bytes: 26404
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
temp_list = [T - h * 0.006 for h in H]

min_diff = float('inf')

for idx, temp in enumerate(temp_list):
    if min_diff > abs(temp-A):
        min_diff = abs(temp-A)
        min_idx = idx + 1
    # min_diff = min(min_diff, abs(temp-T))
# min_idx = temp_list.index(min_diff)
print(min_idx)

Measured memory_bytes: 38256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    bool accepted[100010] {};
    int cnt_wa[100010] {};
    int ac = 0;

    rep(i, M) {
        int p;
        string stat;
        cin >> p >> stat;

        if (stat == "AC") {
            if (!accepted[p]) {
                accepted[p] = true;
                ++ac;
            }
        } else {
            if (!accepted[p]) {
                ++cnt_wa[p];
            }
        }
    }

    int pe = 0;
    reps(i, 1, N) if (accepted[i]) pe += cnt_wa[i];

    print(ac, pe);

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main()
{
	int i,j,a[200]={0},n,count=0;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++)
	{
		int min=i;
		for(j=i;j<n;j++)
		{
			if(a[j]<a[min])
			min=j; 
		}
		if(min!=i)
		{
			int p=a[min];
			a[min]=a[i];
			a[i]=p;
			count++;
		}
	}
	for(i=0;i<n-1;i++) cout<<a[i]<<" ";
	cout<<a[n-1]<<endl;
	cout<<count<<endl;
	return 0;
}

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

typedef long long LL;

#define INF 1000000000
#define INF_LL_YJ 1145141919810364364

using namespace std;

#define MAX_N 100005

int N;
int A[MAX_N];
vector<int> AList[MAX_N];

void input()
{
  cin >> N;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    A[i]--;
    AList[A[i]].push_back(i);
  }
}

int solve(int pos = 0)
{
  int depth = AList[pos].size();
/*
  cerr << pos << " " << depth << ": ";
  for (int i = 0; i < AList[pos].size(); i++) {
    cerr << AList[pos][i] << " ";
  }
  cerr << endl;
*/
  vector<int> depList;
  for (int i = 0; i < AList[pos].size(); i++) {
    depList.push_back(solve(AList[pos][i]));
  }

  sort(begin(depList), end(depList));

  int ret = depth;

  for (int i = 0; i < depth; i++) {
    ret = max(ret, depth - i + depList[i]);
  }

  return ret;
}

int main()
{
  input();

  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 15488
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), ans = 0;
		if(a - b > 0) {
			ans = a - b;
		}else {
			ans = 0;
		}
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countMultiple(ll R, ll div, ll mod) { // [1,R] and x % div == mod
	if (R == 0) return 0;

	ll res = R / div;
	if (mod <= R % div and 0 < mod) res++;
	return res;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














ll A, B, C, D;
//---------------------------------------------------------------------------------------------------
ll f(ll x) {
	if (x == 0) return 0;

	ll lc = lcm(C, D);
	return x - (countMultiple(x, C, 0) + countMultiple(x, D, 0) - countMultiple(x, lc, 0));
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B >> C >> D;
	cout << f(B) - f(A - 1) << endl;
}







Measured memory_bytes: 384
S = input()
T = input()

replace_to =[]
flag = False
for i in range(len(S)):
    if S[i] != T[i]:
        if S[i] in replace_to or T[i] in replace_to:
            flag = True
            break
        else:
            S = S.replace(T[i], '0').replace(S[i], T[i]).replace('0', S[i])
            replace_to.append(S[i])

if flag:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 101744
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);


int main(){
    ll N; cin>>N;
    map<ll,ll> m;
    rep(i,N){
        ll t; cin>>t;
        m[t]++;
    }
    ll ans=0;
    for(auto x:m){
        if(x.b%2==1) ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 9824
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)

const ll LARGE = (ll)1e10;

int main(void)
{
	int n;
	cin >> n;
	vector<ll> as(n, 0);
	rep(i, n) {
		cin >> as[i];
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			sum += as[i];
		}
		else {
			sum -= as[i];
		}
	}
	vector<ll> bs(n, 0);
	bs[0] = sum;
	for (int i = 0; i < n-1; i++) {
		bs[i+1] = (as[i] - bs[i] / 2) * 2;
	}
	for (auto e : bs) {
		cout << e << " ";
	}
	cout << endl;
	return 0;
}

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

int main(){
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool found = true;
    if(n&1){
        cout << "No" << endl;
    }else{
        //int mid = n/2;
        int x = 0, y = n/2;
        while(x < n/2 && y < n){
            //cout << s[x] << " " <<s[y] << endl;
            if(s[x] != s[y]){
                found = false;
                cout << "No" << endl;
                break;
            }
            x++, y++;
        } 
        
        if(found)cout << "Yes" << endl;
        
    }
    
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			String[] spl = br.readLine().split(" ");
			int a = Integer.parseInt(spl[0]);
			String op = spl[1];
			int b = Integer.parseInt(spl[2]);
			switch(op) {
			case "+":
				System.out.println(a + b);
				break;
			case "-":
				System.out.println(a - b);
				break;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	string s;
	int w;
	cin >> s >> w;
	for (int i: range(s.size())) {
		if(i%w==0)cout<<s[i];
	}
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
int main(){
    string s;
    cin>>s;
    REP(i,s.length()) cout<<"x";
    cout<<endl;
}

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

const long long p = 1000000007;

void printmat(const vector< int > &a)
{
  const int n = a.size();
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cerr << a[(i+n-j)%n] << " ";
    }
    cerr << endl;
  }
}

// caution: b = a * b
void mulBy(const vector< int > &a, vector< int > &b, int n)
{
  vector< int > r(n);
  for(int i = 0; i < n; i++) {
    r[i] = b[i];
  }
  for(int j = 0; j < n; j++) {
    long long c = 0;
    for(int k = 0; k < n; k++) {
      c += (a[k] * (long long)r[(j+n-k)%n]) % p; // b'[i][j] += a[i][k] * b[k][j];
    }
    b[j] = (int)(c % p);
  }
}
// b = b * b
void pow2(vector< int > &b, int n)
{
  vector< int > r(n);
  for(int i = 0; i < n; i++) {
    r[i] = b[i];
  }
  mulBy(r, b, n);
}
// mat = mat^x
void pow(vector< int > &mat, int n, int x)
{
  vector< int > r(n);
  // eye
  for(int j = 0; j < n; j++) {
    r[j] = 0 == j ? 1 : 0;
  }
  while(x > 0) {
    if((x & 1) != 0) {
      mulBy(mat, r, n);
    }
    pow2(mat, n);
    x >>= 1;
  }
  for(int j = 0; j < n; j++) {
    mat[j] = r[j];
  }
}

int main(int argc, char *argv[])
{
  for(;;) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> ps;
    for(int i = 0; i < m; i++) {
      int pi;
      cin >> pi;
      ps.push_back(pi);
    }

    // hist[i] .. possibilities of being on i
    // hist' = hist * mat
    //   where mat[i][j] is transition possibilities from i to j
    
    vector< int > mat(n);
    for(int j = 0; j < n; j++) {
      mat[j] = 0;
    }
    // kachi
    for(int j = 0; j < m; j++) {
      mat[(int)((ps[j]) % n)]++;
    }
    mat[0]++; // make
    //printmat(mat);
    pow(mat, n, k);
    for(int i = 0; i < n; i++) {
      cout << mat[i] << endl;
    }
    break;
  }
  return 0;
}

Measured memory_bytes: 3264
import java.io.IOException;
import java.util.Scanner;

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

		int n = in.nextInt();
		for(int i=0;i<n;i++) {
			Point p1 = getPoint(in);
			Point p2 = getPoint(in);
			Point p3 = getPoint(in);
			Point p4 = getPoint(in);

			if(PointUtil.isParallel(p1, p2, p3, p4)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	public static Point getPoint(Scanner in) {
		double x = in.nextDouble();
		double y = in.nextDouble();
		return new Point(x, y);
	}
}

class Point {
	double x;
	double y;

	public Point(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public Point getMinus(Point p2) {
		double sx = this.x - p2.getX();
		double sy = this.y - p2.getY();
		return new Point(sx,sy);
	}

	public double len() {
		return x*x + y*y;
	}

	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}
}

class PointUtil {
	public static double EPS = 1e-10;
	/**
	 * angle of vec(p1-p) and vec(p2-p)
	 * @param p1
	 * @param p2
	 * @return
	 */
	public static double angleRad(Point p1, Point p2, Point p) {
		double a1 = p1.getX() - p.getX();
		double a2 = p1.getY() - p.getY();
		double b1 = p2.getX() - p.getX();
		double b2 = p2.getY() - p.getY();

		return Math.acos((a1*b1+a2*b2) / ( Math.sqrt(a1*a1 + a2*a2) * Math.sqrt(b1*b1 + b2*b2)));
	}

	public static boolean isParallel(Point a1, Point a2, Point b1, Point b2) {
		return EQ(cross(a1.getMinus(a2), b1.getMinus(b2)), 0.0);
	}

	public static double cross(Point a, Point b) {
		return a.getX()*b.getY() - a.getY()*b.getX();
	}

	public static boolean EQ(double left, double right) {
		if(Math.abs(left - right) <= EPS) {
			return true;
		}
		return false;
	}
}

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

int main()
{
    int sum = 0;
    char c;
    while((c=getchar()) != '\n'){
        sum += c - '0';
    }
    if(sum%9){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}

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

int n;

double parallel(vector<int> &A) {
    double sumDen = 0;
    for (int i = 0; i < n; i++) {
        sumDen += 1.0 / A[i];
    }

    double ans = 1.0 / sumDen;

    return ans;
}

int main() {
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    printf("%.10lf\n", parallel(A));

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題162


            int n = int.Parse(Console.ReadLine());

            string cc = Console.ReadLine();

            char[] c = new char[n];

            char[] kansei = new char[n];


            int w_to_r = 0;
            int r_to_w = 0;

            for (int i = 0; i < n; i++)
            {
                c[i] = cc[i];

                if (c[i] == 'R')
                {
                    r_to_w += 1;
                }
                kansei[i] = 'W';


            }

            int ans = Math.Max(w_to_r, r_to_w);



            int count = 0;


            for (int i = 0; i < n; i++)
            {
                if (c[i] == 'W')
                {
                    w_to_r += 1;
                }
                else
                {
                    r_to_w -= 1;
                }

                //for (int j = 0; j < i; j++)
                //{
                //    kansei[j] = 'R';
                //}

                //Console.WriteLine("aaaaaaaa");


                //foreach (var a in kansei)
                //{
                //    Console.WriteLine(a);
                //}

                //foreach (var a in c)
                //{
                //    Console.WriteLine(a);
                //}

                //for (int j = 0; j < n; j++)
                //{
                //    if (c[j] != kansei[j])
                //    {
                //        count++;
                //        //Console.WriteLine("test");
                //    }
                //}

                //Console.WriteLine(count);

                count = Math.Max(w_to_r, r_to_w);

                //Console.WriteLine(count);


                //count = (count + 1) / 2;

                ans = Math.Min(ans, count);

                count = 0;
                //ans = n;

                
            }


            Console.WriteLine(ans);


        }

    }





    
}


Measured memory_bytes: 29044
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 3456;
LL fac[MAXN], ifac[MAXN];
const LL MOD = (LL)1e9 + 7;

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

LL qpow(LL x, LL n) {
    LL ans = 1, base = x;
    while (n) {
        if (n % 2) ans = mul(ans, base);
        base = mul(base, base);
        n /= 2;
    }
    return ans;
}

LL C(LL n, LL m) {
    if (m > n) return 0;
    return mul(mul(fac[n], ifac[m]), ifac[n - m]);
}

void init() {
    fac[0] = ifac[0] = 1;
    for (int i = 1; i < MAXN; i++)
        fac[i] = mul(fac[i - 1], i);
    ifac[MAXN - 1] = qpow(fac[MAXN - 1], MOD - 2);
    for (int i = MAXN - 2; i >= 1; i--)
        ifac[i] = mul(ifac[i + 1], i + 1);
}

int main() {
    init();
    int S;
    scanf("%d", &S);
    LL ans = 0;
    for (int i = 1; i <= S; i++) {
        if (i * 3 > S) break;
        LL tmp = C(S - 3 * i + i - 1, i - 1);
        ans = (ans + tmp) % MOD;
    }
    printf("%lld\n", ans);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


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

using namespace std;

int main(){

	int a, b, c;

	cin>> a >> b;

	if(a<b){
		c=b;
		b--;
	}else{
		c=a;
		a--;
	}

	if(a<b){
		c+=b;
	}else{
		c+=a;
	}

	cout<< c << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 200000;
const int Mmax = 200000;
int N, M;
int A[Nmax], X[Mmax], Y[Mmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<M; i++){
		cin >> X[i] >> Y[i];
		X[i]--;
	}

	vector<int> l(N), n(N);
	int ans = 0;
	for(int i=0; i<N; i++){
		l[i] = i+1;
	}
	for(int i=0; i<N; i++){
		l[A[i]-1]--;
		if(l[A[i]-1] >= 0){
			n[l[A[i]-1]]++;
		}
	}
	for(int i=0; i<N; i++){
		if(n[i] == 0) ans++;
	}
	//for(int i=0; i<N; i++) cout << l[i] << (i==N-1?'\n':' ');
	//for(int i=0; i<N; i++) cout << n[i] << (i==N-1?'\n':' ');
	//cout << endl;

	for(int i=0; i<M; i++){
		int a = A[X[i]];
		if(l[a-1] >= 0){
			n[l[a-1]]--;
			if(n[l[a-1]]==0) ans++;
		}
		l[a-1]++;
		//for(int j=0; j<N; j++) cout << l[j] << (j==N-1?'\n':' ');
		//for(int j=0; j<N; j++) cout << n[j] << (j==N-1?'\n':' ');
		//cout << endl;

		l[Y[i]-1]--;
		if(l[Y[i]-1] >= 0){
			n[l[Y[i]-1]]++;
			if(n[l[Y[i]-1]]==1) ans--;
		}
		A[X[i]] = Y[i];
		//for(int j=0; j<N; j++) cout << l[j] << (j==N-1?'\n':' ');
		//for(int j=0; j<N; j++) cout << n[j] << (j==N-1?'\n':' ');

		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 5376
A, B, C, D = map(int, input().split())

def gcd(a, b):
	if 0 == a % b:
		return b
	return gcd(b, a % b)

def solve(n):
	return n - (n // C) - (n // D) + (n // (C * D // gcd(C, D)))

#print(solve(B))
#print(solve(A - 1))
print(solve(B) - solve(A - 1))


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

struct UnionFind{
    vector<int> data;
    //data[i] = -x ... iが根であり、サイズがx
    //data[i] = x ... iの親がx

    //最初は全員根
    UnionFind(int size): data(size,-1){}

    bool union_set(int x, int y){//サイズがx>yになるようにしてから、xにyをつなげる
        x=root(x);
        y=root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find_set(int x, int y){//ルートが一致するかどうかを返す
        return root(x) == root(y);
    }
    int root(int x){//根を見つける。ついでに深さ2にしちゃう
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main() {
    int N,K,L; cin >> N >> K >> L;
    UnionFind uf1(N);
    REP(i,K){
        int a,b; cin >> a >> b;
        a--;
        b--;
        uf1.union_set(a,b);
    }

    UnionFind uf2(N);
    REP(i,L){
        int a,b; cin >> a >> b;
        a--;
        b--;
        uf2.union_set(a,b);
    }

    vector<int> A(N);
    vector<int> B(N);
    map<pair<int,int>,int> C;
    REP(i,N){
        A[i] = uf1.root(i);
        B[i] = uf2.root(i);
        C[{A[i], B[i]}] ++;
    }

    REP(i,N){
        cout << C[{A[i], B[i]}] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 17632
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

public class Main {

    private enum right {
        y,
        u,
        i,
        o,
        p,
        h,
        j,
        k,
        l,
        n,
        m,
        ;
   }

    static String current = "";
    static int cnt = 0;
    static List<String> hands = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine().trim()) != null && !"#".equals(line)) {
            output(line);
            clear();
        }
    }

    public static void output(String line) {
        IntStream.range(0, line.length()).mapToObj(i->line.substring(i,i+1)).forEach(key -> {
            if(Arrays.stream(right.values()).map(e->e.name()).anyMatch(e->key.equals(e))) {
                hands.add("r");
            } else {
                hands.add("l");
            };
        });
        IntStream.range(0, hands.size()).mapToObj(i->hands.get(i)).forEach(hand -> {
            if(!current.isEmpty() && !current.equals(hand)) {
                cnt++;
            }
            current = hand;
        });
        System.out.println(cnt);
    }

    public static void clear() {
        hands.clear();
        current = "";
        cnt = 0;
    }
}


Measured memory_bytes: 35492
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,a,b;

int main(){
    cin >> n >> a >> b;
    if(abs(a-b)%2==0){
        put("Alice");
    }else{
        put("Borys");
    }
}


Measured memory_bytes: 256