akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n,m; cin >> n >> m;
    vector<pair<ll,ll>> ab(m);
    rep(i,m) cin >> ab.at(i).first >> ab.at(i).second;
    vector<set<ll>> side(n);
    rep(i,m){
        ll x = --ab.at(i).first;
        ll y = --ab.at(i).second;
        side.at(x).insert(y);
        side.at(y).insert(x);       
    }
    vector<set<ll>> sidereset = side;
    ll ans = 0;
    rep(i,m){
        vector<bool> check(n,1);
        pair<ll,ll> dls = ab.at(i);
        side.at(dls.first).erase(dls.second);
        side.at(dls.second).erase(dls.first);
        check.at(0) = 0;
        queue<ll> q;
        q.push(0);
        while(q.size()){
            ll vtx = q.front();
            q.pop();
            for(auto x: side.at(vtx)){
                if(check.at(x)==0) continue;
                check.at(x) = 0;
                q.push(x);
            }
        }
        rep(j,n){
            if(check.at(j)){
                ans++;
                break;
            }            
        }
        side = sidereset;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  int H,W;
  int cnt=0;
  cin>>H>>W;
  char x[W+1][H+1];//////文字列あたりよくわからん
  string y[W+1][H+1];//うまくいかないのでstring yに入れていく
  
  for(int j=0;j<H;j++){//入力
  	for(int i=0;i<W;i++){
      cin>>x[i][j];
    }
  }
  
  
  for(int j=0;j<H;j++){
  	for(int i=0;i<W;i++){
      //#でなければ、左上左左下右上右右下を見て、数える。ただし、場外ならキャンセル
      if(x[i][j]=='.'){
        
        //メイン処理
        ///////////////////////////////////
        cnt=0;
        
      	if(i-1 >= 0){
          if(x[i-1][j]=='#'){//左
            cnt++;
          }
          if(j-1 >= 0){
            if(x[i-1][j-1]=='#'){//左上
              cnt++;
            }
          }
          if(j+1 <= H){
            if(x[i-1][j+1]=='#'){//左下
              cnt++;
            }
          }
        }
        if(i+1 <= W){
          if(x[i+1][j]=='#'){//右
            cnt++;
          }
          if(j-1>=0){
            if(x[i+1][j-1]=='#'){//右下
              cnt++;
            }
          }
          if(j+1<=H){
            if(x[i+1][j+1]=='#'){//右上
              cnt++;
            }
          }
        }
        if(j-1>=0){//下
          if(x[i][j-1]=='#'){
            cnt++;
          }
        }
        if(j+1<=H){//上
          if(x[i][j+1]=='#'){
            cnt++;
          }
        }
        ///////////////////////////////////
        
        
        y[i][j]=to_string(cnt);
      }
      else{
        y[i][j]="#";
      }
    }
  }
  
  
  for(int j=0;j<H;j++){//出力
  	for(int i=0;i<W;i++){
      cout<<y[i][j];
    }
    cout<<endl;
  }
} 

Measured memory_bytes: 384
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	string S;
	cin >> S;

	int cnt = 1;
	for (int i = 0; i < N - 1; i++) if (S[i + 1] != S[i]) cnt++;

	cout << cnt << "\n";

	return 0;
}

Measured memory_bytes: 512
from collections import deque

INF = int(1e10)

dh = [0, 0, 1, -1]
dw = [1, -1, 0, 0]

def main():
    from builtins import int, map
    H, W = map(int, input().split())
    Ch, Cw = map(lambda x: int(x) - 1, input().split())
    Dh, Dw = map(lambda x: int(x) - 1, input().split())
    S = [list(input()) for _ in range(H)]

    dist = [[INF] * W for _ in range(H)]
    dist[Ch][Cw] = 0
    queue = deque([(Ch, Cw)])

    while queue:
        (h, w) = queue.popleft()

        for i in range(4):
            dhi, dwi = dh[i], dw[i]
            nh, nw = h + dhi, w + dwi
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                if dist[h][w] < dist[nh][nw]:
                    dist[nh][nw] = dist[h][w]
                    queue.appendleft((nh, nw))
        
        # 5x5-grid
        for ddh in range(-2, 3):
            for ddw in range(-2, 3):
                if abs(ddh) + abs(ddw) <= 1:
                    continue
                nh, nw = h + ddh, w + ddw
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                    if dist[nh][nw] > dist[h][w] + 1:
                        dist[nh][nw] = dist[h][w] + 1
                        queue.append((nh, nw))

    if dist[Dh][Dw] == INF:
        print(-1)
    else:
        print(dist[Dh][Dw])

if __name__ == '__main__':
    main()


Measured memory_bytes: 132148
#include <stdio.h>

int main(void)
{
	int i;
	char str[11];
	
	scanf("%d",&i);
	scanf("%s",str);
	
	if (i >= 3200){
		printf("%s\n",str);
	}
	
	else {
		printf("red\n");
	}
	
	return (0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
signed main()
{
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r")) {
        freopen ("INPUT.txt" , "r" , stdin);
        // freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
//-----------------------------------------------------------------------------------------------------------
    string s, t;
    cin>>s>>t;
    long long arr[26];
    memset(arr, 0, sizeof(arr));
    for(auto i:s)
        arr[i-'a']++;
    for(auto i:t)
        if(arr[i-'a']==0)
        {
            cout<<-1;
            return 0;
        }
    int n=s.size(), m=t.size();;
    int next[n][26];
    for(int i=0;i<n;i++)
    for(int j=0;j<26;j++)
        next[i][j]=-1;
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(s[j]=='a'+i)
            {
                next[n-1][i]=j;
                break;
            }
        }
        for(int j=n-2;j>=0;j--)
        {
            if(s[j+1]=='a'+i)
            {
                next[j][i]=j+1;
            }
            else
            {
                next[j][i]=next[j+1][i];
            }
            
        }

    }
    long long cnt=0;
    int start=0;
    if(s[0]!=t[0])
        start=next[0][t[0]-'a'];
    cnt+=start+1;
    for(int i=1;i<m;i++)
    {
        int offset=next[start][t[i]-'a']-start+n;
        if(offset>n)
            offset%=n;
        cnt+=offset;
        start=next[start][t[i]-'a'];



    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 10704
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double n = (a + b) / 2;
		int m = (int) Math.ceil(n);
		System.out.println(m);
	}

}


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

int main(){

    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) {cin >> x[i];}

    int ans = INT_MAX;
    rep(i, 100) {
        int sum = 0;
        rep(j, n) {
            sum += pow(x[j]-(i+1), 2);
        }
        ans = min(sum, ans);
    }

    cout << ans << endl;

    return 0;
} 


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1
 
void testCase() {
    string s;
    cin >> s;
    int ans = 0;
    if (s == "RRR")
        ans = 3;
    else if (s == "RRS" || s == "SRR")
        ans = 2;
    else if (s == "SSS")
        ans = 0;
    else
        ans = 1;
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
    ll n; cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    n *= 2;

    vector<ll> check;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            check.emplace_back(i);
            if (n / i != i) check.emplace_back(n / i);
        }
    }

    ll ans = n - 1;
    for (int i = 0; i < (int)check.size(); i++) {
        ll x = check[i], y = n / x;
        auto change = crt({0ll, y - 1}, {x, y});
        if (change.second != 0 && change.first < ans) ans = change.first;
    }

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


Measured memory_bytes: 3696
fn main(){
    let R:i32 = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().parse().unwrap()
    };
    let G:i32= {
        let mut t = String::new();
        std::io::stdin().read_line(&mut t).unwrap();
        t.trim_right().parse().unwrap()
    };
    println!("{}", 2 * G - R);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int n; cin>>n;
    int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    vector<int> a(15,0);
    int cnt2=0,cnt4=0,cnt14=0,cnt24=0;
    rep(i,15){
        int p=prime[i],q=n;
        while(q>0){
            q/=p;
            a.at(i)+=q;
        }
        if(a.at(i)>=24)cnt24++;
        if(a.at(i)>=14)cnt14++;
        if(a.at(i)>=4)cnt4++;
        if(a.at(i)>=2)cnt2++;
    }
    int ans=0;
    ans+=max<int>(0,cnt24*(cnt2-1));
    ans+=max<int>(0,cnt14*(cnt4-1));
    ans+=max<int>(0,cnt4*(cnt4-1)*(cnt2-2)/2);
    if(a.at(0)>=74)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
List = []
for i in range(N):
    count = 0
    while i % 2 != 0:
        i = i // 2
        count += 1
    List.append(count)

maxcount = 0
for i in range(N):
    if maxcount <= List[i]:
        maxcount = List[i]
        ans = i+1
print(ans)


Measured memory_bytes: 2940
S = []

A = raw_input().split()

for i in range(len(A)):
    if A[i] == '+':
        S.append(int(S.pop()) + int(S.pop()))
    elif A[i] == '-':
        S.append(-int(S.pop()) + int(S.pop()))
    elif A[i] == '*':
        S.append(int(S.pop()) * int(S.pop()))
    else:
        S.append(A[i])

print S[0]

Measured memory_bytes: 6328
from itertools import accumulate
from collections import defaultdict
N,K = map(int, input().split())
Xs = list(accumulate([0] + [int(x) for x in input().split()]))
Xs = [(x-i)%K for i, x in enumerate(Xs)]
d,r=defaultdict(int),0
for i, x in enumerate(Xs):
    d[x]+=1
    if i >= K:
        d[Xs[i-K]] -= 1
    r += d[x]-1
print(r)


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

import sys
import copy

# input = sys.stdin.readline

# ---------------------------------------------------------

N, K = map(int, input().split())
S = input()

cnt = []
kind = []

i, j = 0, 0
while i < N:
    while j < N and S[i] == S[j]:
        j += 1
    cnt.append(j - i)
    kind.append(int(S[i]) - int('0'))
    i = j

ans = 0
sum = 0
zero = 0
L = len(cnt)
right = 0
for left in range(L):
    if left > right:
        right = left
    while right < L and zero <= K:
        if kind[right] == 0 and zero == K:
            break
        if kind[right] == 0:
            zero += 1
        sum += cnt[right]
        right += 1

    ans = max(ans, sum)
    sum -= cnt[left]
    if kind[left] == 0:
        zero -= 1

print(ans)


Measured memory_bytes: 5324
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Vs = list(mapint())

even = []
odd = []
for i in range(N):
    if i%2==1:
        even.append(Vs[i])
    else:
        odd.append(Vs[i])

from collections import Counter
ceven = Counter(even)
ans = 0
even_second = 0
for i, (num, cnt) in enumerate(ceven.most_common()):
    if i==0:
        even_most = cnt
        even_num = num
    if i==1:
        even_second = cnt
    ans += cnt
codd = Counter(odd)
odd_second = 0
for i, (num, cnt) in enumerate(codd.most_common()):
    if i==0:
        odd_most = cnt
        odd_num = num
    if i==1:
        odd_second = cnt
    ans += cnt

if even_num==odd_num:
    ans = min(ans-odd_most-even_second, ans-odd_second-even_most)
else:
    ans -= odd_most+even_most
print(ans)

Measured memory_bytes: 99224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	ll N;
  	cin >> N;
  	ll ans;
  	ans = N / 2;
  	if(N%2==0) ans--;
  	cout << ans << endl;
}


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

int main(){
	int a[5];
  int answer;
  for(int i = 0; i < 5; ++i) {
    cin >> a[i];
    if(a[i]==0) answer = i + 1;
  }
	cout << answer << endl;
  

  return 0;
}


Measured memory_bytes: 3580
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

int N;
vector<pll> seg;

priority_queue<ll> lpq, rpq;
ll loff = 0, roff = 0, mn = 0;

int main() {
	scanf("%d", &N);
	seg.resize(N + 1);
	seg[0] = pll(-1e15, 1e15);
	for(int i = 1; i <= N; i++) {
		scanf("%lld %lld", &seg[i].first, &seg[i].second);
	}

	lpq.push(-1e15);
	rpq.push(-1e15);

	for(int i = N - 1; i >= 0; i--) {
		ll lt = lpq.top() + loff;
		ll rt = -rpq.top() + roff;

		if(lt <= seg[i + 1].first && seg[i + 1].first <= rt) {
			lpq.push(seg[i + 1].first - loff);
			rpq.push(-(seg[i + 1].first - roff));
		}
		else if(seg[i + 1].first < lt) {
			lpq.push(seg[i + 1].first - loff);
			lpq.push(seg[i + 1].first - loff);
			ll lt1 = lpq.top() + loff; lpq.pop(); rpq.push(-(lt1 - roff));
			ll lt2 = lpq.top() + loff;
			mn += abs(lt2 - seg[i + 1].first) + lt1 - lt2;
		}
		else if(seg[i + 1].first > rt) {
			rpq.push(-(seg[i + 1].first - roff));
			rpq.push(-(seg[i + 1].first - roff));
			ll rt1 = -rpq.top() + roff; rpq.pop(); lpq.push(rt1 - loff);
			ll rt2 = -rpq.top() + roff;
			mn += abs(rt2 - seg[i + 1].first) + rt2 - rt1;
		}

		loff -= seg[i].second - seg[i].first;
		roff += seg[i + 1].second - seg[i + 1].first;
	}
	cout<<mn;
}

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

using namespace std;

int main(){
	int a ,b ,c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans1, ans2 , ans3;
	bool c_is_optimal = false;
	ans1 = min(x,y) * c * 2;
	int t = min(x,y);
	ans1 += (x - t)*a + (y - t)*b;
	ans2 = a * x + b * y;
	ans3 = max(x,y) *c * 2;
	cout << min(min(ans1,ans2),ans3);
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,a,b,i;
    cin>>n>>m;
    set<pair<int,int>> edge;
    for (i=0;i<m;i++)
    {
        cin>>a>>b;
        edge.insert(mp(a,b));
    }
    bool flag=false;
    for (i=2;i<n;i++)
    {
        if (edge.find(mp(1,i))!=edge.end() && edge.find(mp(i,n))!=edge.end())
        {
            flag=1;
            break;
        }
    }
    if (flag)
        cout<<"POSSIBLE\n";
    else
        cout<<"IMPOSSIBLE\n";
}

Measured memory_bytes: 9600
def diff(a, b):
	cnt = 0
	for i in range(len(a)):
		if a[i] == b[i]:
			cnt += 1
	return cnt

def solve(a, b):
	l = len(b)
	maxx = -1
	for i in range(len(a)-l+1):
		val = diff(b, a[i:i+len(b)])
		maxx = max(maxx, val)
	return l - maxx

a = input()
b = input()
print(solve(a, b))


Measured memory_bytes: 9136
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
ll n,k;
ll a[105],dp[N];
ll fun(ll x)
{
    if(dp[x]!=-1)
        return dp[x];
    ll fl=0;
    for(int i=1;i<=n;i++)
    {
        if(x==a[i])
        {
          dp[x]=1;
          return dp[x];
        }        
    }
    for(int i=1;i<=n;i++)
    {
        if(x-a[i]<0)
          continue;
        if(!fun(x-a[i]))
        {
            dp[x]=1;
            return 1;
        }
    }
    dp[x]=0;
    return 0;

}
void solve()
{
   cin>>n>>k;
   memset(dp,-1,sizeof(dp));
   for(int i=1;i<=n;i++)
    cin>>a[i];
   if(fun(k))
    cout<<"First"<<endl;
   else
    cout<<"Second"<<endl;

   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 9032
def solve():
    MOD = 1000000007

    N = int(input())
    S1 = input()
    S2 = input()

    patterns = []

    i = 0
    while i < N:
        if S1[i] == S2[i]:
            patterns.append(0)
            i += 1
        else:
            patterns.append(1)
            i += 2
    
    ans = 1
    for i in range(len(patterns)):
        c = 0
        if i == 0:
            if patterns[i] == 0:
                c = 3
            else:
                c = 6
            
            ans *= c
            ans %= MOD
            continue

        if patterns[i] == 0:
            if patterns[i-1] == 0:
                c = 2
            else:
                c = 1
        else:
            if patterns[i-1] == 1:
                c = 3
            else:
                c = 2
        
        ans *= c
        ans %= MOD
    
    print(ans)
    
if __name__ == '__main__':
    solve()


Measured memory_bytes: 62052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG


signed main() {
  int N, X, M; cin >> N >> X >> M;
  vector<int> a = {X};
  map<int,int> m; m[X]++;
  
  int x = X;
  int k = 0;
  while(true) {
    x *= x;
    x %= M;
    if(x == 0) {
      int ans = 0;
      rep(i, a.size()) ans += a[i];
      cout << ans << endl;
      return 0;
    }
    if(m[x] > 0) {
      rep(i, a.size()) if(x == a[i]) k=i;
      break;
    }
    else {
      m[x]++;
      a.push_back(x);
    }
  }
  
  int ans = 0;
  rep(i, k) {
    ans += a[i];
    N--;
  }
  vector<int> b(a.size()-k);
  copy(a.begin()+k, a.end(), b.begin());
  int s = b.size();
  rep(i, s) ans += b[i]*(N/s);
  rep(i, N%s) ans += b[i];
  
  cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    int max = 0;
    int streak = 0;
    int h[N+10] = {0};
    for(int i =0; i < N; i++){
        cin >> h[i + 1];
    }
    for(int i = 1; i <= N; i++){
        if(h[i -1] < h[i]){
            if(streak > max)max = streak;
            streak = 0;
            continue;
        }
        streak ++;
    }
    if(streak > max) max = streak;
    cout << max << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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; }

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}

int main(){
    string s; cin >> s;
    int n = s.size();
    vector<vector<int>> dp(n, vector<int>(2)); //dp[i][j]...i番目の文字列を長さj+1でとったときの最大
    dp[0][0] = 1;
    int ans = 0;
    for(int i = 1; i < n; i++){ 
        //今回は長さ2までしかとらない
        if(s[i-1] != s[i]){
            chmax(dp[i][0], dp[i-1][0]+1); // i-2|i-1|i
        }
        chmax(dp[i][0], dp[i-1][1]+1); // i-2 i-1|i
        if(i >= 2){
            chmax(dp[i][1], dp[i-2][0]+1); // i-2|i-1 i
            chmax( dp[i][1], dp[i-2][1]+1); // i-3 i-2 | i-1 i
        }
    }

    ans = max(dp[n-1][0], dp[n-1][1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11396
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
char s[N]; int n;
inline int check(int l,int r)
{	if(l>r) swap(l,r);
	for(rint i=l;i<r;i++) if(s[i]=='#'&&s[i+1]=='#') return 0;
	return 1;
}
inline int gao(int l,int r)
{	if(l>r) swap(l,r);
	for(rint i=l;i<r-1;i++) if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.') return 1;
	return 0;
}
inline int L(int _)
{for(int x=_;;){if(x>1&&s[x-1]=='.')x--;else if(x>2&&s[x-2]=='.')x-=2;else return x;}}
inline int R(int _)
{for(int x=_;;){if(x+1<=n&&s[x+1]=='.')x++;else if(x+2<=n&&s[x+2]=='.')x+=2;else return x;}}
int main()
{	int a,b,c,d; cin>>n>>a>>b>>c>>d; scanf("%s",s+1);
	if(a>b) swap(a,b),swap(c,d);
	if(!check(a,c)||!check(b,d)) return !printf("No");
	if(c>d) cout<<(gao(b-1,d+1)?"Yes":"No");
	else cout<<"Yes";
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n==0){
			System.out.println(0);
			sc.close();
			return;
		}		//0のとき自明に0
		String s="";
		int m = 1;		//数字の正負の回転
		while (n!=0){
			int d =0;
			if (Math.abs(n)%2==1) d = 1;
			s = d + s;
			n = (n - d*m )/2;		//-2,-8,-32などのときに、足していけばOKAY
			m*=-1;
		}
		System.out.println(s);
		sc.close();
	}

}


Measured memory_bytes: 23508
# -*- coding: utf-8 -*-
# 整数を一旦文字列として受け取り
n = input()
int_n = int(n)
result = int_n

# 超愚直にやって見る
for i in range(1, int_n+1):
    if len(str(i))%2 == 0:
        result -= 1

print(result)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, k;
    cin >> n >> k;
    vp sushi(n);
    rep(i, n){
        cin >> sushi[i].second >> sushi[i].first;
    }
    vll ans(100001, 0);
    vi cnt(100001, 0);
    sort(ALL(sushi));
    reverse(ALL(sushi));
    dump(sushi);
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    priority_queue<pll, vector<pll>, greater<pll>> pq2;
    ll tmp = 0;
    rep(i, k){
        if(cnt[sushi[i].second] == 0){
            pq2.emplace(sushi[i]);
        }else{
            pq.emplace(sushi[i]);
        }
        cnt[sushi[i].second]++;
        tmp += sushi[i].first;
    }
    rep(i, 20){
        dump(i, cnt[i]);
    }
    ans[pq2.size()] = tmp;
    ll j = k;
    while(j < n && SZ(pq2) < k){
        dump(pq.top().first, pq2.top().first);
        tmp -= pq.top().first;
        pq.pop();
            dump(j, cnt[sushi[j].second]);
        while(j < n && cnt[sushi[j].second]){
            j++;
        }
        if(j == n) break;
        pq2.emplace(sushi[j]);
        tmp += sushi[j].first;
        cnt[sushi[j].second]++;
        ans[pq2.size()] = tmp;
    }
    ll ansm = 0;
    rep(i, 100001){
        if(ans[i] > 0){
            chmax(ansm, ans[i]+i*i);
            dump(i, ans[i]);
        }
    }
    cout << ansm << endl;
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    while (n) {
        if (7==n%10) {
            cout<<"Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

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


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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] nm = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];

        var each_time = 1900 * m + 100 * (n - m);
        var ex_value = (long)Math.Pow(2,m);
        var ans = each_time * ex_value;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <list>
#include <cmath>

using namespace std;

struct Node {
    double x;
    double y;

    Node add(const Node& target)
    {
        return {x + target.x, y + target.y};
    }

    Node dist(const Node& target)
    {
        return {target.x - x, target.y - y};
    }

    void print()
    {
        printf("%.8f %.8f\n", x, y);
    }
};

const double PI = 3.14159265358979;
const double SIN_60 = sin(PI / 3);
const double COS_60 = cos(PI / 3);

void koch_curve(list<Node> nodes, list<Node>::iterator head, list<Node>::iterator tail, int count_down)
{
    if (count_down <= 0) return;

    Node all_diff = head->dist(*tail);
    Node diff = {all_diff.x / 3, all_diff.y / 3};
    Node b_diff;
    b_diff.x = diff.x * COS_60 - diff.y * SIN_60;
    b_diff.y = diff.x * SIN_60 + diff.y * COS_60;

    Node a = head->add(diff);
    Node b = a.add(b_diff);
    Node c = a.add(diff);

    nodes.insert(tail, a);
    nodes.insert(tail, b);
    nodes.insert(tail, c);

    list<Node>::iterator next_head, next_tail;
    next_head = head;
    next_tail = head;
    next_tail++;
    while (next_head != tail){
        koch_curve(nodes, next_head, next_tail, count_down - 1);

        next_head = next_tail++;
    }
}

int main()
{
    int n;

    cin >> n;

    list<Node> nodes{{0.0, 0.0}, {100.0, 0.0}};

    koch_curve(nodes, nodes.begin(), --nodes.end(), n);

    for (Node node : nodes){
        node.print();
    }

    return 0;
}




Measured memory_bytes: 3348
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    ll d,t,s;cin>>d>>t>>s;
    cout << (d <= t*s ? "Yes" : "No") << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int sg(int n,int k){
/*	if(k <= 32000){
		while(1){
			if(n % k == 0)return n / k;
			if(n < k)return 0;
			n = (int)(n * (k-1LL) / k);
		}
	}else{*/
		while(1){
			int hi = n / k, lo = n % k;
			if(lo == 0)return hi;
			if(hi == 0)return 0;
			if(lo < (hi + 1))
				n -= hi+1;
			else
				n = hi * k + lo % (hi + 1);
		}
//	}
}
int main(){
	int t,r=0;
	for(scanf("%d",&t); t--;){
		int n,k;
		scanf("%d%d",&n,&k);
		r^=sg(n,k);
	}
	puts(r?"Takahashi":"Aoki");
	return 0;
}


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

int main(){


int a[10000] , b[10000] ;
char op[10000] ;
int x[10000]; 



 	for (int i=1; i<=10000; i=i+1 )
 	{
 	 cin >> a[i] >> op[i] >> b[i] ;

		if( op[i] == '?' )
 		{
 		break;
 		}else{
         }

                if ( op[i] == '+' ){
                cout<< a[i] + b[i] << endl; // �a
                } else if ( op[i] == '-' ){
                cout<< a[i] - b[i] << endl; // ��
                } else if ( op[i] == '*' ){
                cout<< a[i] * b[i] << endl; // ��
                } else if ( op[i] == '/' ){
                cout<< a[i] / b[i] << endl; // ��
                } else {
                break ; // �ُ�I��
                }


 	}

 return 0;
 }





Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define Vsort(a) sort(a.begin(), a.end())
#define rep(i,a,b) for(int i = a; i < (b); i++)
#define ll long long
#define P pair<int, int>
using namespace std;

const ll mod = 1000000007;

int main() { 
  ll n, sum = 0, ans = 0, b;
  cin >> n;
  vector<ll> a(n);
  rep(i,0,n){
    cin >> a[i];
    sum += a[i];
  }
  rep(i,0,n-1){
    sum -= a[i];
    b = sum % mod;
    ans += a[i] * b;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4840
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;

int main()
{
	int a[3];
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	sort(a, a+3);
	if(a[2] == (a[0] + a[1]))
		printf("Yes\n");
	else
	    printf("No\n");
	return 0;	
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import heapq

def _solve(N, _list):
    n = len(_list)
    # Kの昇順
    _list.sort(key=lambda x: x[0])
    
    # まず、最低限得られるうれしさを求める
    base_score = sum([x[2] for x in _list])

    ni = 0
    S = []
    for j in range(N+1):
        # Ki = j であるラクダをSに追加
        while ni < n and _list[ni][0] == j:
            _, L, R = _list[ni]
            heapq.heappush(S, L - R)
            ni += 1
        # len(S) > j である場合、増えるうれしさの小さいものを削除する
        while len(S) > j:
            heapq.heappop(S)

    return base_score + sum(S)# + sum([x[1]-x[2] for x in _list[ni:]])

def solve(N, KLR):
    BigL = [] # L の方が大きいやつ
    BigR = [] # R の方が大きいやつ

    for i in range(N):
        K, L, R = KLR[3*i], KLR[3*i+1], KLR[3*i+2]
        # L の方が大きいやつと、 Rの方が大きいやつに分けて考える
        if L < R:
            # R の方が大きいやつは、LとRを逆転させて、
            # Lの方が大きいやつと同じように考えられるようにする
            BigR.append((N-K, R, L))
        else:
            # 番号が0から始まるようにする
            BigL.append((K, L, R))

    return _solve(N, BigL) + _solve(N, BigR)
        
def main():
    T, *_all = map(int, read().split())
    n = 0

    ans = []
    for _ in range(T):
        N = _all[n]
        KLR = _all[n+1:n+1+3*N]
        ans.append(solve(N, KLR))
        n += 1 + 3*N

    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 65840
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if X == 500*a + 100*b + 50*c:
        res += 1

print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long int
#define ld double
using namespace std;
int n,i,x,c[4];
ld dp[301][301][301];
ld rec(int a,int b,int c){
  int d=n-a-b-c;
	if(b<0||c<0||d<0||a==n)return 0;
	if(dp[a][b][c]!=0)return dp[a][b][c];
	return dp[a][b][c]=(rec(a+1,b-1,c)*b/n+rec(a,b+1,c-1)*c/n+rec(a,b,c+1)*(d)/n+1)*n/(n-a);
}
main(){
	cin>>n;
	for(i=0;i<n;i++)cin>>x,c[x]++;
	cout<<fixed<<setprecision(15)<<rec(c[0],c[1],c[2]);
}


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

int main(){
    int S;
    cin >> S;
    int head = S/100,tail = S%100;
    bool YYMM=(1<=tail&&tail<=12);
    bool MMYY=(1<=head&&head<=12);
    if (YYMM){
        if(MMYY){
            puts("AMBIGUOUS");
        }
        else{
            puts("YYMM");
        }
    }
    else{
        if(MMYY){
            puts("MMYY");
        }
        else{
            puts("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, k;
  cin >> n >> k;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < min(100, k); ++i) {
    vector <int> pref(n + 1);
    for (int i = 0; i < n; ++i) {
      int l = i - a[i];
      int r = i + a[i];
      l = max(l, 0);
      r = min(r, n - 1);
      ++pref[l];
      --pref[r + 1];
    }
    for (int i = 1; i <= n; ++i) {
      pref[i] += pref[i - 1];
    }
    for (int i = 0; i < n; ++i) a[i] = pref[i];
  }
  for (int i = 0; i < n; ++i) cout << a[i] << ' ';
}



Measured memory_bytes: 4996
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
const int N = 2500010;
ll fact[N], invf[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
    ll n, m;
    cin >> n >> m;
    fact[0] = invf[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
    }
    invf[N - 1] = divll(1, fact[N - 1]);
    FORR(i,N-1,1){
        invf[i - 1] = (invf[i] * i) % mod;
    }

    ll ans = 0;
    REP(x,m+1){
        if ((3 * m - x) % 2) continue;
        ll tmp = (nCr(n, x) * nCr(n + (3 * m - x) / 2 - 1, n - 1)) % mod;
        ans = (ans + tmp) % mod;
    }
    REP(i,m){
        ll tmp = (n * nCr(n + i - 2, n - 2)) % mod;
        ans = (ans - tmp + mod) % mod;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> flast(n + 1, -1);
    flast[0] = 0;
    bool poss = true;
    for (int i = 1; i <= n; ++i) {
        flast[i] = flast[i - 1];
        if (i - flast[i] > m) {
            ++flast[i];
            while (flast[i] < i && s[flast[i]] == '1') {
                ++flast[i];
            }
            if (flast[i] == i) {
                poss = false;
                break;
            }
        }
    }
    if (!poss) {
        cout << "-1\n";
        return 0;
    }
    stack<int> steps;
    int cind = n;
    while (cind > 0) {
        steps.push(cind - flast[cind]);
        cind = flast[cind];
    }
    while (!steps.empty()) {
        cout << steps.top() << " ";
        steps.pop();
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1356
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=200005;
int n,U,R,dep[N],fa[N],m;
vector<int>er[N],eb[N];

void dfs(int x){for(int v:eb[x])if(v!=fa[x])fa[v]=x,dep[v]=dep[x]+1,dfs(v);}
inline bool check(int u,int v){
	if(dep[u]<dep[v]) swap(u,v);
	int d=0;
	while(++d<=2&&u!=v)if(dep[u]<dep[v])v=fa[v];else u=fa[u];
	return u==v;
}
void dfs(int x,int fa,int k){
	m=max(m,dep[x]);
	if(dep[x]<=k)return;
	for(int v:er[x])if(v!=fa){
		if(!check(x,v))puts("-1"),exit(0);
		dfs(v,x,k+1);
	}
}

int main(){
	scanf("%d%d%d",&n,&U,&R);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),er[u].pb(v),er[v].pb(u);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),eb[u].pb(v),eb[v].pb(u);
	dfs(R),dfs(U,0,0);
	printf("%d\n",m<<1);
	return 0;
}

Measured memory_bytes: 32252
#include <stdio.h>

int main(){
	int a,b,ex,i;
	char op ;
	i=0;
	for (ex=0;i<1;){
	scanf("%d %c %d",&a,&op,&b);
		if (0<=a&&a<=20000&&0<=b&&b<=20000){
			if (op=='?'){
			break;
			}
			if (op=='+'){
			ex=a+b;
			}
			if (op=='-'){
			ex=a-b;
			}
			if (op=='*'){
			ex=a*b;
			}
			if (op=='/'){
			ex=a/b;
			}
			printf ("%d\n",ex);
		}
	}
	return 0;
}

Measured memory_bytes: 600
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
    A[i]-=1
ed=[]
d=set()
now=0
x=-1
while True:
    ed.append(now)
    d.add(now)
    ne=A[now]
    if ne in d:
        now=ne
        x=ne
        break
    else:
        now=ne
loop=[x]
now=x
while True:
    now=A[now]
    if now==x:
        break
    else:
        loop.append(now)
def ind(l,a):
    for i in range(len(l)):
        if a==l[i]:
            return i
dn=ind(ed,ne)
T=len(loop)
if K>=dn:
    ans=loop[(K-dn)%T]
    print(ans+1)
else:
    print(ed[K]+1)

Measured memory_bytes: 32512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    ll a, b;
    cin >> a >> b;
    n = a - b;
    m = a + b;
    k = a * b;
    cout << max(n,max(m,k)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<endl;
using namespace std;

int n;
ll a[100001],b[100001],c[100001];
ll sumcl[100001],sumb[100001],sumc[100001];
ll sumbb[100001];                   

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  int now=0;
  int sum=0;
  for(int i=0;i<n;){
    if(c[now]>b[i]){
      sumc[now]++;
      sum++;
      i++;
    }else{
      sumcl[now]=i-1;
      now++;
      if(now==n)break;
      sumc[now]=sum;
    }
  }
  for(int i=now;i<n;i++){
    sumc[i]=sum;
    sumcl[i]=n-1;
  }
  sum=0;
  now=0;
  for(int i=0;i<n;){
    if(b[now]>a[i]){
      sumb[now]++;
      sum++;
      i++;
    }else{
      now++;
      if(now==n)break;
      sumb[now]=sum;
    }
  }
  for(int i=now;i<n;i++){
    sumb[i]=sum;
  }
  sumbb[0]=sumb[0];
  for(int i=1;i<n;i++){
    sumbb[i]=sumb[i]+sumbb[i-1];
  }
  ll ans=0;
 /* for(int i=0;i<n;i++){
    cout<<sumc[i]<<" ";
  }
  cout<<endl;
  for(int i=0;i<n;i++){
    cout<<sumb[i]<<" ";
  }*/
//  cout<<endl;
 /* for(int i=0;i<n;i++){
    cout<<sumcl[i]<<" ";
  }*/
//  cout<<endl;
  for(int i=0;i<n;i++){
    if(sumcl[i]<0)continue;
  //  cout<<sumc[i]*sumb[sumcl[i]]<<" ";
    ans+=sumbb[sumcl[i]];
  }
//  cout<<endl;
  cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int main(){
    int count1, count2, j=0;
    count1 = 1;
    count2 = 0;
    char c[2];
    string S;
    cin >> S;

    for(size_t i = 1; i<S.size(); i++) {
        if(S[i] == S[0]) {
            count1++;
        } else if(count2 < 3) {
            c[j++] = S[i];
            count2++;
        } else count2++;
    }
    if(count1 == count2 && c[0] == c[1]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[105];
bool f(int n)
{
	if(n%3==0||n%5==0) return true;
	return false;
}
int main ( )
{
	int n;
	scanf("%d",&n);
	int m,k=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&m);
		if(m%2==0) a[k++]=m;
	}
	int flag=0;
	for(int i=0;i<k;i++)
		if(!f(a[i])) 
		{
			printf("DENIED\n");
			flag=1;
			break;
		}
	if(flag==0) printf("APPROVED\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a[1000];
    scanf("%s",a);
    int i,k=0,m=0;
    for(i=0;a[i]!='\0';i++)
    {
        if(a[i]=='+')
        {
            k++;
        }
        else
        {
            m++;
        }
    }
    if(k>m)
    {
        printf("%d",k-m);
    }
    else
    {
        printf("%d",-(m-k));
    }
}


Measured memory_bytes: 128