akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    int i = 0;
    for(int t = a; t <= b; t++) 
        if(c % t == 0)
            i++;
    cout << i << '\n';
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int dp[21][(1 << 21)], f[21][(1 << 21)];

int main ()
{
int n, k;
cin >> n >> k;
for(int i = 0 ; i <= n ; ++i){
	string s;
	cin >> s;
	for(int j = 0 ; j < s.size() ; ++j){
		if(s[j] == '1'){
			dp[i][j] = 1;
		}
	}
}
for(int i = 1 ; i <= n ; ++i){
	for(int j = 0 ; j < (1 << i) ; ++j){
		int u = (j >> (i - 1)) & 1;
		int br = 0;
		while(br < i && ((j >> (i - br - 1)) & 1) == u){
			br++;
		}
		if(br == i){
			f[i][j] = -1;
		}
		else{
			f[i][j] = br;
		}
	}
}
for(int i = 0 ; i <= n ; ++i){
	for(int j = i + 1 ; j <= n ; ++j){
		int mask = (1 << (j - i)) - 1;
		for(int w = 0 ; w < (1 << j) ; ++w){
			dp[i][w >> (j - i)] += dp[j][w];
			int x = f[j - i][w & mask];
			if(x != -1){
				dp[j - x][((w >> (j - i)) << (j - i - x)) | (w & ((1 << (j - i - x)) - 1))] += dp[j][w];
			}
		}
	}
}
int sol, vel = -1;
for(int i = 0 ; i <= n ; ++i){
	for(int j = 0 ; j < (1 << i) ; ++j){
		if(dp[i][j] >= k){
			if(i > vel){
				vel = i;
				sol = j;
			}
		}
	}
}
for(int i = vel - 1 ; i >= 0 ; --i){
	cout << ((sol >> i) & 1);
}

return 0;
}


Measured memory_bytes: 96704
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0;i<N;i++){
    cin >> l.at(i);
  }
  int s=0;
  sort(l.begin(),l.end());
  for(int i=0;i<K;i++){
    s+=l.at(N-1-i);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import itertools
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
nn = []
for i in range(1,n+1):
         nn.append(i)
zisyo = list(map(list,(itertools.permutations(nn))))
b = (-1)
for i in range(len(zisyo)):
         if zisyo[i] == p:
                  a = i
         elif zisyo[i] == q:
                  b = i
if b == (-1):
         print(0)
else:
         print(abs(a-b))


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

public class Main {
	
	public static void main(String[] args) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		bubbleSort(seq);
	}
	
	public static int[] bubbleSort(final int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printSequence(seq);
		System.out.println(count);
		return seq;
	}
	
	public static void printSequence(final int[] seq) {
		final StringBuilder p = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	}
	
	public static int[] getSequence() throws IOException {
		final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	}
}

Measured memory_bytes: 17048
s = input()
ans = [1] *len(s)

for i in range(len(s)-2):
    if s[i] == s[i+1] == "R":
        ans[i+2] += ans[i]
        ans[i] = 0
for i in range(len(s)-1,1,-1):
    if s[i] == s[i-1] == "L":
        ans[i-2] += ans[i]
        ans[i] = 0
print(*ans)

Measured memory_bytes: 6400
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    public static void Main()
    {
        int A = IntRead();
        int B = IntRead();
        int C = IntRead();
        int X = IntRead();
        int cou = 0;
        for (int x = 0; x <= A; x++) {
            for (int y = 0; y <= B; y++) {
                for (int z = 0; z <= C; z++) {
                    if (500 * x + 100 * y + 50 * z == X) cou++;
                }
            }
        }
        Console.WriteLine(cou);
    }
}

public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = StrReverce(ret);
        return ret;
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <algorithm>

using namespace std;

void check(vector<int>& values, vector<int>& checks, int value) {
  for (int i = 0; i < values.size(); ++i) {
    if (values[i] == value) {
      checks[i] = 1;
    }
  }
}

bool bingo(vector<int>& c) {
  auto testrow = [&](const int idx) {
    return c[idx*3] == 1 && c[idx * 3] == c[idx*3 + 1] && c[idx*3] == c[idx*3 + 2];
  };
  bool rows = testrow(0) || testrow(1) || testrow(2);

  auto testcol = [&](const int idx) {
    return c[idx] == 1 && c[idx] == c[idx + 3] && c[idx] == c[idx + 6];
  };
  bool cols = testcol(0) || testcol(1) || testcol(2);
  bool naname0 = c[0] == 1 && c[0] == c[4] && c[0] == c[8];
  bool naname1 = c[2] == 1 && c[2] == c[4] && c[2] == c[6];
  
  return rows || cols || naname0 || naname1;
}

int main() {
  vector<int> values(9);
  vector<int> checks(9);
  int tmp, N;
  for (int i = 0; i < 9; ++i) {
    cin >> tmp;
    values[i] = tmp;
    checks[i] = 0;
  }

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    check(values, checks, tmp);
    if (bingo(checks)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 2*acos(0)
#define ll long long
#define pii pair<int,int>
#define mx 100005
using namespace std;
int A[3][mx],dp[mx][3],vis[mx][3],N;
int f(int pos,int last)
{
    if(pos==N+1) return 0;
    if(vis[pos][last]) return dp[pos][last];
    vis[pos][last]=1;
    int ans=0;
    for(int i=0;i<3;i++){
        if(i!=last) ans=max(ans,A[i][pos]+f(pos+1,i));
    }
    return dp[pos][last]=ans;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N;
    for(int i=1;i<=N;i++) cin>>A[0][i]>>A[1][i]>>A[2][i];
    cout<<max(max(f(1,0),f(1,1)),f(1,2))<<endl;
    return 0;
}


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

using namespace std;

int main(void)
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());

	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += a[i];
	}
	cout << ans << endl;

	return 0;
}

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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				double q = double.Parse(s);
				if (q == -1) break;

				double x = q / 2;
				while (true)
				{
					x = x - (Math.Pow(x, 3.0) - q) / (3 * x * x);
					if (Math.Abs(Math.Pow(x, 3.0) - q) < 0.00001 * q) break;
				}
				Console.WriteLine("{0:0.000000}", x);
			}
		}
	}
}

Measured memory_bytes: 5744
#include <iostream>


using namespace std;

int main(){
  int w, a, b;
  cin >> w >> a >> b;
  int ret = 0;
  if(a <= b) {
    ret = max(0, (b-(a+w)));
  } else {
    ret = max(0, (a-(b+w)));
  }
  cout << ret << endl;
  return 0;
} 


Measured memory_bytes: 3564
#include <iostream>

using namespace std;

int main() {
	int w,h;

	while (cin >> h >> w) {
		if (h == 0 && w == 0) {
			break;
		}
		for (int i = 0; i < h; i++) {
			cout << '#' << flush;
			for (int j = 1; j < w-1; j++) {
				if (i != 0 && i != h-1) {
					cout << '.' << flush;
				} else {
					cout << '#' << flush;
				}
			}
			cout << '#' << flush;
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
/*
0	>	10	1
1	>>	210	3
2	>>>	3210	6

 0	<	01	1
 1	<<	012	3
 2	<<<	0123	6

 0	<>	010
 1	<<>	0120
 1	<<>>	01210
 1	<<>>>	013210
*/

const ll INF = 1LL << 60;

int main() {
  string S0,S;
  cin >> S0;

  int N = S0.length();
  if (S0[0] == '>') S = '<' + S0;
  else S = S0;
  if (S0[N-1] == '<') S += '>';
  S += '@';
//  cout << S0 << endl;;
//  cout << S << endl;;
  N = S.length();
  
  ll total = 0;
  ll l = 0;
  ll r = 0;
  REP(i,N-1) {
    if (S[i] == '<') {
      l++;
    } else {
      r++;
      if (S[i+1] != '>' ) {
//        cout << " " << l << " " << r << " : " << l * (l-1) / 2 << " " << r * (r-1) / 2 << " " << ((l > r)?l:r) << endl;
        total += l * (l-1) / 2;
        total += r * (r-1) / 2;
        if (l > r)
          total += l;
        else
          total += r;
        l = r = 0;
      }
    }
  }
  cout << total << endl;
  
}


    
    


Measured memory_bytes: 1796
#include <stdio.h>

int main (void)
{
  int n , min = 10000 , max = 0;
  scanf("%d",&n);
  int a[n];
  for(int i = 0;i < n; i ++){
    scanf("%d",&a[i]);
    if(min>a[i]){
      min = a[i];
    }
    if(max<a[i]){
      max = a[i];
    }}
  
 printf("%d",max - min);
 return 0;
 }
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

vector<pair<int, int>> v[200005]; //min - max
pair<int, int> IN[200005];

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

    rep(i,m){
        cin >> IN[i].first >> IN[i].second;
        IN[i].second--;
    }
    sort(IN, IN + m);

    rep(i,m){
        int y = IN[i].second;
        //show(IN[i].first)
        //show(y)
        int s = y, t = y + 1;
        if(y != n - 2){
            if(not v[y + 1].empty()){
                s = min(v[y + 1].back().first, s);
                t = max(v[y + 1].back().second, t);
            }
        }
        if(y != 0){
            if(not v[y - 1].empty()){
                s = min(v[y - 1].back().first, s);
                t = max(v[y - 1].back().second, t);
            }
        }
        //show(s)
        //show(t)
        //show(y)
        v[y].emplace_back(make_pair(s,t));
    }

    rep(i,n){
        if(i) cout << ' ';
        if(i == 0) {
            if(v[i].empty()) cout << 1;
            else cout << v[i].back().second - v[i].back().first + 1;
        } else if(i == n - 1) {
            if(v[i - 1].empty()) cout << 1;
            else cout << v[i - 1].back().second - v[i - 1].back().first + 1;
        } else{
            if(v[i].empty() && v[i - 1].empty()) cout << 1;
            else if(v[i].empty()) cout << v[i - 1].back().second - v[i - 1].back().first + 1;
            else if(v[i - 1].empty()) cout << v[i].back().second - v[i].back().first + 1;
            else cout << v[i].back().second - v[i - 1].back().first + 1;
        }
    }
    cout << endl;
}

Measured memory_bytes: 11696
X, Y = map(int, input().split(' '))
if X == 1 and Y == 1:
    print(1000000)
elif X == 1:
    if Y == 2:
        print(500000)
    elif Y == 3:
        print(400000)
    else:
        print(300000)
elif X == 2:
    if Y == 1:
        print(500000)
    elif Y == 2:
        print(400000)
    elif Y == 3:
        print(300000)
    else:
        print(200000)
elif X == 3:
    if Y == 1:
        print(400000)
    elif Y == 2:
        print(300000)
    elif Y == 3:
        print(200000)
    else:
        print(100000)
else:
    if Y == 1:
        print(300000)
    elif Y == 2:
        print(200000)
    elif Y == 3:
        print(100000)
    else:
        print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++){
  	cout << s.at(i);
    if(i == 3){
    	cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int x,a,b,c,d;
    while(cin>>x)
    {
        a=x/1000;
        b=(x/100)%10;
        c=(x/10)%10;
        d=x%10;
        if(a+b+c+d==7)
            {cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;break;}
        if(a+b+c-d==7)
            {cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;break;}
            if(a+b-c+d==7)
            {cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;break;}
            if(a-b+c+d==7)
            {cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;break;}
            if(a+b-c-d==7)
            {cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;break;}
            if(a-b+c-d==7)
            {cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;break;}
            if(a-b-c+d==7)
            {cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;break;}
            if(a-b-c-d==7)
            {cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;break;}

    }
}


Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
solve(int A, int B, int C, int X)
{
  int ret = 0;
  for (int a = 0; a <= A && a <= X / 500; a++)
  {
    int ax = X - 500 * a;
    for (int b = 0; b <= B && b <= ax / 100; b++)
    {
      int bx = ax - 100 * b;
      if (bx % 50 == 0 && bx / 50 <= C)
      {
        ret++;
      }
    }
  }
  return ret;
}

int
main()
{
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  cout << solve(A, B, C, X) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
using namespace std;

int main() {
    FIO;
    char arr[10];
    cin >> arr;
    if(arr[2] == arr[3] && arr[4] == arr[5]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#C
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(3)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    dp[0][i+1] =  chmax(dp[1][i]+abc[i+1][0],dp[2][i]+abc[i+1][0])
    dp[1][i+1] =  chmax(dp[0][i]+abc[i+1][1],dp[2][i]+abc[i+1][1])
    dp[2][i+1] =  chmax(dp[1][i]+abc[i+1][2],dp[0][i]+abc[i+1][2])


ans = chmax(dp[0][N-1],dp[1][N-1])
ans = chmax(ans,dp[2][N-1])
    
print(ans)

Measured memory_bytes: 66648
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 200002;
const int M = 1e9 + 7;
const int oo = INT_MAX;
int n,m;
vi g[N];
bool vis[N];
int dfs(int u){
    vis[u]=true;
    int c=0;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(!vis[v]){
            c+=dfs(v);
        }
    }
    return 1+c;
}
int main(){
    cin>>n>>m;
    for(int a,b,i=0;i<m;i++){
        cin>>a>>b;
        g[--a].pb(--b);
        g[b].pb(a);
    }
    int mx=-oo;
    for(int i=0;i<n;i++)
        if(!vis[i])
            mx=max(mx,dfs(i));
    
    cout<<mx;
}


Measured memory_bytes: 20572
#include<iostream>
#include<string>
#include<cstring>

#define rep(i, n) for(int i = 0; i < n; i++)
using ll = long long;

using namespace std;

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    char s1[n / 2 + 1] = {'\0'}, s2[n / 2 + 1] = {'\0'};

    if(n % 2){
        cout << "No" << endl;
    }
    else{
        for(int i = 0; i < (n / 2); i++){
            s1[i] = s[i];
            s2[i] = s[n/2 + i];
        }
        
        if(strcmp(s1, s2)){
            cout << "No";
        }
        else{
            cout << "Yes";
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
int main() {
    int n, m, a, b, c; cin >> n >> m >> a >> b >> c;
    vector<vector<int> > g(n);
    repeat (i,m) {
        int u, v; cin >> u >> v;
        -- u; -- v;
        g[u].push_back(v);
    }
    vector<vector<bool> > ag, bg, cg; {
        vector<vector<bool> > x(n, vector<bool>(n)); // adjacency matrix
        repeat (i,n) {
            for (int j : g[i]) {
                x[i][j] = true;
            }
        }
        vector<vector<bool> > y = x;
        repeat (t, max(a,max(b,c))) {
            if (a == t+1) ag = y;
            if (b == t+1) bg = y;
            if (c == t+1) cg = y;
            vector<vector<bool> > z(n, vector<bool>(n));
            repeat (i,n) {
                repeat (j,n) {
                    repeat (k,n) {
                        z[i][j] = z[i][j] or (y[i][k] and x[k][j]);
                    }
                }
            }
            y = z;
        }
    }
    set<int> goals;
    goals.insert(n-1);
    for (int turn = 1; ; ++ turn) {
        vector<int> new_goals;
        repeat (i,n) if (not goals.count(i)) {
            bool ok_a = false; repeat (j,n) if (ag[i][j] and goals.count(j)) ok_a = true;
            bool ok_b = false; repeat (j,n) if (bg[i][j] and goals.count(j)) ok_b = true;
            bool ok_c = false; repeat (j,n) if (cg[i][j] and goals.count(j)) ok_c = true;
            if (ok_a and ok_b and ok_c) {
                new_goals.push_back(i);
            }
        }
        if (new_goals.empty()) {
            cout << "IMPOSSIBLE" << endl;
            break;
        }
        goals.insert(new_goals.begin(), new_goals.end());
        if (goals.count(0)) {
            cout << turn << endl;
            break;
        }
    }
    return 0;
}

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

int main() {

  int N;
  cin >> N;
  int count;
  int result;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    count = 0;
    while (A % 2 == 0) {
      count ++; 
      A /= 2;
    }
    if ( i == 0 ) {
      result = count;
    }
    if (result > count) {
      result = count;
    }
  }
  cout << result << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    int x,a,b,n; cin >> x >> a >> b >> n;
    for(int i=0;i<n;i++){
        string s; cin >> s;
        if(s=="nobiro"){
            x+=a;
        }
        else if(s=="tidime"){
            x+=b;
        }
        else{
            x=0;
        }
        x=max(x,0);
    }
    cout << x << endl;
}



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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

vector<int> g[N];

int t[N], c[N];
int l[N], r[N];

void dfs(int u,int p)   {
    c[u] = t[u];
    r[u] = 0;

    int Rmax = 0;
    int Lmax = 0;

    for(int v : g[u])   if (v != p) {
        dfs(v,u);

        c[u] += c[v];
        r[u] += r[v] + c[v];

        if (Rmax < r[v] + c[v])
            Rmax = r[v] + c[v],
            Lmax = l[v] + c[v];
    }
    if (Lmax + Rmax <= r[u])
        l[u] = r[u] % 2;
    else
        l[u] = Lmax + Rmax - r[u];
}

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;

    for(int i = 1 ; i <= n ; ++i)   {
        char c; cin >> c;
        t[i] = (c == '1');
    }

    for(int i = 2 ; i <= n ; ++i)   {
        int x;  cin >> x;
        int y;  cin >> y;

        g[x].pb(y);
        g[y].pb(x);
    }

    int ans = 1e9 + 7;

    for(int i = 1 ; i <= n ; ++i)   {
        dfs(i,0);

        if (l[i])   continue;
        if (ans > r[i] / 2)
            ans = r[i] / 2;
    }
    if (ans == 1e9 + 7)
        ans = -1;

    cout << ans << endl;
}

Measured memory_bytes: 6272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0061
{
    public class Program

    {
        public static void Main(string[] args)
        {
            Dictionary<int, int> teams = new Dictionary<int, int>();
            while (true)
            {
                int[] items = RIntAr(',');
                if (items.Sum() == 0) break;
                teams.Add(items[0], items[1]);
            }

            Dictionary<int, int> ranks = new Dictionary<int, int>();
            int before = int.MaxValue;
            int rank = 0;
            foreach (var item in teams.OrderByDescending(x => x.Value))
            {
                if (before != item.Value) rank++;
                ranks.Add(item.Key,rank);
                before = item.Value;
            }
    
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;
                Console.WriteLine(ranks[int.Parse(line)]);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 16436
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
 
	public static void main(String[] args) {
 
		long N = in.nextLong();
		long A = in.nextLong();
		long B = in.nextLong();

		long l = A + B;

		long count = N / l;
		long answer = A * count;
		long amari = N % l;
		long a = amari - A;
		answer += a >= 0 ? A : A + a;
		System.out.println(answer);
	}

	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}

}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

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

    int N;
    cin >> N;

    vector<int> C, V;
    for (int i = 0, v; i < N; ++i) {
        cin >> v;
        V.push_back(v);
    }
    for (int i = 0, c; i < N; ++i) {
        cin >> c;
        C.push_back(c);
    }

    int ans = -1e8;
    for (unsigned s = 0; s < (1 << N); ++s) {
        int X = 0, Y = 0;
        for (int i = 0; i < N; ++i) {
            if ((s >> i) & 1) {
                X += V[i];
                Y += C[i];
            }
        }
        ans = max(ans, X - Y);
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
const int MOD=1e9+7;
int n,o,g[SZ],f[605][605],e[SZ];
ll w[SZ];
int main()
{
	memset(g,-1,sizeof g);
	scanf("%d%d",&n,&o); n*=2;
	for(int i=1,a,b;i<=o;++i)
		scanf("%d%d",&a,&b),g[a]=b,g[b]=a;
	w[0]=1;
	for(int i=2;i<=n;i+=2)
		w[i]=w[i-2]*(i-1)%MOD;
	for(int i=1;i<=n;++i)
		e[i]=e[i-1]+(g[i]==-1);
	ll ans=0;
	for(int t=1;t<=n-1;t+=2)
	{
		for(int l=1;l+t<=n;++l)
		{
			int r=l+t,ok=1;
			for(int s=l;s<=r&&ok;++s)
				ok&=g[s]==-1||(g[s]>=l&&g[s]<=r);
			if(!ok) continue;
			int u=e[r]-e[l-1]; f[l][r]=w[u];
			for(int k=l+1;k<r;k+=2) if(f[l][k])
				f[l][r]=(f[l][r]-f[l][k]*w[e[r]-e[k]])%MOD;
			ans=(ans+f[l][r]*w[e[n]-u])%MOD;
		}
	}
	ans=(ans%MOD+MOD)%MOD;
	cout<<ans<<"\n";
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        int[][] nums = new int[input][2];
        for (int i = 0; i < input; i++) {
            for (int j = 0; j < 2; j++) {
                nums[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int count = 0;
        for(int[] a:nums){
            if(a[0]== a[1]){
                count++;
                if(count ==3){
                    System.out.println("Yes");
                    return;
                }
            }else{
                count = 0;
            }
        }

        System.out.println("No");

    }

}


Measured memory_bytes: 35996
s = input()

for i in range(len(s)//2):
    if s[i] == s[-i-1]:
        continue
    else:
        print("No")
        exit()
        
s_f = s[:len(s)//2]
s_b = s[len(s)//2 + 1:]


for i in range(len(s_f)//2):
    if s_f[i] == s_f[-i-1]:
        pass
    else:
        print("No")
        exit()
    
    if s_b[i] == s_b[-i-1]:
        pass
    else:
        print("No")
        exit()
else:
    print("Yes")

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

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

int n, m;
ll a[100005];
ll A[100005];

void Input() {

    cin >> n >> m;
}



void Solve() {


    for(int i = 1; i <= m; i++) {

        int t;
        cin >> t;
        A[t] = 1;
    }

    a[1] = (A[1] ? 0 : 1);
    a[2] = a[1] + (A[2] ? 0 : 1);

    for(int i = 3; i <= n; i++) {

        a[i] = ((A[i-1] ? 0 : a[i-1]) + (A[i-2] ? 0 : a[i-2])) % MOD;
        a[i] %= MOD;
    }

    cout << a[n] << endl;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
int a[200000],b[200000];
int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		scanf("%d%d",&a[i],&b[i]);a[i]--;b[i]--;
	}
	UnionFind uf(n);
	ll ans=n*(ll)(n-1)/2;
	vector<ll>v;
	for(int i=m-1;i>=0;i--){
		v.push_back(ans);
		if(uf.same(a[i],b[i]))continue;
		ans-=uf.size(a[i])*(ll)uf.size(b[i]);
		uf.unite(a[i],b[i]);
	}
	reverse(v.begin(),v.end());
	for(ll i:v){
		printf("%lld\n",i);
	}
}

Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define M 10000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, K, p[100];
int dp[128][4][4];

int check(){
  int c = 0;
  int n = p[0];
  rep(i, N){
    if(n == p[i]) c++;
    else{ c = 1; n = p[i]; }
    if(c >= 3) return 0;
  }
  if(c >= 3) return 0;
  rep(i, N) printf("%d ", p[i]); puts("");
  return 1;
}

int dfs(int n, int p2, int p1){
  if(N == n) return 1;
  if(dp[n][p2][p1]) return dp[n][p2][p1];

  if(p[n]){
    if(p2 == p1 && p1 == p[n]) return 0;
    return dfs(n+1, p1, p[n]);
  } else {
    int res = 0;
    REP(i, 1, 4){
      if(p2 == p1 && p1 == i) continue;
      p[n] = i;
      res += dfs(n+1, p1, i);
      res = res % M;
      p[n] = 0;
    }
    return dp[n][p2][p1] = res;
  }
  return 1;
}
int main(){
  scanf("%d%d", &N, &K);
  int A, B;
  rep(i, K){
    scanf("%d%d", &A, &B); A--;
    p[A] = B;
  }
  printf("%d\n", dfs(0, 0, 0));
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<int,vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int A,B,C,K;
    cin >>A>> B >> C>> K;

    int D = max(A,max(B,C));
    int E = D;
    rep(i,K) E*=2;
    out(A+B+C+E-D);


    return 0;
}


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

int main() {
    int N, n = 30;
    cin >> N;

    rep (i, N) { //数字の数だけ繰り返す
        int a;
        cin >> a;
        rep (j, n) { //各数字が2で割れる回数を数えてnに戻す
            if (a % 2 == 0){
                a /= 2;
            }

            else {n = j;
            break;
            }
        }
    }
    //nが最小値に収束
    cout << n << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

struct Edge{int to,weight; Edge(int t, int w) : to(t), weight(w) {}};
using DirectedGraph = vector<vector<Edge>>;
using UndirectedGraph = vector<vector<int>>;

vector<bool> seen,finished;
int pos = -1;
stack<int> hist;

void dfs(const UndirectedGraph &G,int v,int p){
    seen[v] = true;
    hist.push(v);
    for(auto nv:G[v]){
        if(nv==p) continue;
        if(finished[nv]) continue;
        if(seen[nv] && !finished[nv]){
            pos = nv;
            return;
        }

        dfs(G,nv,v);
        if(pos != -1) return;
    }
    hist.pop();
    finished[v] = true;
}

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

    UndirectedGraph G(N);
    REP(i,N){
        int a,b;
        cin>>a>>b;
        --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(N,false);
    finished.assign(N,false);
    pos = -1;
    dfs(G,0,-1);
    set<int> cycle;
    while(!hist.empty()){
        int t = hist.top();
        cycle.insert(t);
        hist.pop();
        if(t==pos) break;
    }
    int Q;cin>>Q;
    REP(i,Q){
        int a,b;
        cin>>a>>b;
        --a,--b;
        if(cycle.count(a) && cycle.count(b)) cout<<2<<endl;
        else cout<<1<<endl;
    }
}



Measured memory_bytes: 19172
#include <iostream>

using namespace std;

int main()
{
    char c1;
    char c2;
    char c3;
    cin>>c1>>c2>>c3;
    if(c1==c3)
    {
        cout <<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;

signed main()
{
  int X, Y;
  cin >> N >> X >> Y;
  cout << min(X,Y) << " " << max((int)0, (X+Y)-N) << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 
void solve(){
    ll n;
    ll a[100010];
    ll b[100010]={1};
    cin>>n;
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    ll now=0;
    rep(i,n){
        if(b[now]){
            if(now==a[now]) break;
            b[now]=0;
            b[a[now]]++;
            now=a[now];
            if(b[1]){
                cout<<i+1<<endl;
                return;
            }
        }
        else break;
    }
    cout<<-1<<endl;

    
} 
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

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

const long long MOD = 1000000007LL;

long long dp[100005][13];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    string s; cin >> s;
    int n = s.size();

    dp[n][0] = 1;

    int ten_rem = 1;

    for(int i = n - 1; i >= 0; --i){
        for(int rem = 0; rem < 13; ++rem){
            if(s[i] != '?'){
                dp[i][(rem + (s[i] - '0') * ten_rem) % 13] = dp[i + 1][rem];
                dp[i][(rem + (s[i] - '0') * ten_rem) % 13] %= MOD;
            } else {
                for(int dig = 0; dig < 10; ++dig){
                    dp[i][(rem + dig * ten_rem) % 13] += dp[i + 1][rem];
                    dp[i][(rem + dig * ten_rem) % 13] %= MOD;
                }
            }
        }
        ten_rem = ten_rem * 10 % 13;
    }

    cout << dp[0][5] << "\n";


    return 0;

}


Measured memory_bytes: 10704
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {

	int N, M, A[100], B[100],C[100],D[100];

	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &A[i], &B[i]);
	}
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &C[i], &D[i]);
	}

	for (int i = 0; i < N; i++) {
		int man = abs(C[0]-A[i]) + abs(D[0]-B[i]);
		int temp = 0;
		for (int j = 1; j < M; j++) {
			if (abs(C[j] - A[i]) + abs(D[j] - B[i]) < man) {
				man = abs(C[j] - A[i]) + abs(D[j] - B[i]);
				temp = j;
			}
		}
		printf("%d\n", temp+1);





	}










}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double pi = 4*atan(1);
  h += m/60;
  h *= 5;
  double c2 = a*a + b*b - 2*a*b*cos((h-m)*2*pi/60);
  cout << setprecision(20) << sqrt(c2) << endl;
}

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

int main(){
  char b;
  cin>>b;
  if(b=='A'){
    cout<<"T"<<endl;
  }
  else if(b=='T'){
    cout<<"A"<<endl;
  }
  else if(b=='G'){
    cout<<"C"<<endl;
  }
  else if(b=='C'){
    cout<<"G"<<endl;
  }
}
  
  

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
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 EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A[10010],B,C;
    std::string S,T;

    ll ans=0;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>S>>T;
    string s=S;
    REP(i,3)S+=s;
    int a=T.size();
    bool F=false;
    REP(i,a){
        if(T==S.substr(i,a)){
            F=true;
            break;
        }
    }
    cout<<(F?"Yes":"No")<<endl;

    //cout<<A<<endl<<B;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
 while(1){
  int H,W;
  scanf("%d %d", &H,&W);
  if(H==0 && W==0){break;}
  int i,j;
  for(i=0; i<H; i++){
   for(j=0; j<W; j++){
    printf("#");
   }
   printf("\n");
  }
  printf("\n");
 }
return 0;
}

Measured memory_bytes: 572
N = int(input())
h = list(map(int, input().split()))

dp = [10**9+10] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,N):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int a,b;
    cin>>a>>b;
    int p,q,r;
    cin>>p>>q>>r;
    double kai=p*b;
    double ans=0.0;
    if(a<b){
        kai=kai-(b-a)*q;
        ans+=b;
    }
    else{
        kai=kai-(a-b)*r;
        ans+=a;
    }
    ans+=kai/(q+r);
    printf("%lf\n",ans);
}




Measured memory_bytes: 3196
n = int(input())
a = list(map(int,input().split()))
b = a[::2]
c = a[1::2]
if n %2 == 0:
    c.reverse()
    ans =c + b
else:
    b.reverse()
    ans = b + c
for i in range(n):
    print(ans[i], end =' ')

Measured memory_bytes: 26020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll N,K;
  cin >> N >> K;

  for (int i = 1; i <= K; ++i) {
    cout << ((COM(N-K+1, i) * COM(K-1, i-1)) % mod) << endl;
  }
}

Measured memory_bytes: 15592
// 0と1が共存する限り操作は行える.
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  int cnt0=0,cnt1=0;
  for(int i=0;i<s.size();++i){
    if(s[i]=='0') cnt0++;
    else cnt1++;
  }
  cout << min(cnt0,cnt1)*2 << endl;
  return 0;
}

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

int main() {
  int k, r = 0, gcd_ij;
  
  cin >> k;
  
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        gcd_ij = gcd(i, j);
        r += gcd(gcd_ij, l);
      }
    }
  }
  
  cout << r << endl;
}

int gcd(int i, int j) {
  int n = 0, r, big, small, reminder;
  
  if (i > j) {
    big = i;
    small =j;
  } else {
    big = j;
    small = i;
  }
  
  // 念のために100を設定
  while (n < 100) {    
    if (small == 0) {
      return big;
    }
    
    reminder = big % small;
    big = small;
    small = reminder;
    
    n++;
  }
  
  return -1;
}


Measured memory_bytes: 3620
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
hMin = 10**9
for i in range(n - k + 1):
    if h[k + i - 1]-h[i] < hMin:
        hMin = h[k + i - 1]-h[i]
print(hMin)


Measured memory_bytes: 8280
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	string s, t;
	std::cin >> s >> t;

	map<char, vll> dic;
	rep(i, 0, s.size()) {
		dic[s[i]].push_back(i);
	}


	ll cnt = 0;
	ll pre_pos = -1;
	rep(i, 0, t.size()) {
		auto itr=std::upper_bound(dic[t[i]].begin(), dic[t[i]].end(), pre_pos);
		if (itr != dic[t[i]].end()) {
			pre_pos = *itr;
		}
		else if(dic[t[i]].size()>0) {
			pre_pos = dic[t[i]][0];
			cnt++;
		}
		else {
			std::cout << -1 << endl;
			return 0;
		}
	}

	std::cout << s.size()* cnt + pre_pos + 1 << endl;

	return 0;
}


Measured memory_bytes: 4596