akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<63)-1
#define MAX 1000000000
bool f(vector<char> &A,vector<char> &B,string &S,int X){
    X--;
    if(X<0) return 1;
    rep(i,0,A.size()){
        if(S[X]==A[i]){
            if(B[i]=='R') X++;
            else X--;
            if(X>=(int)S.size()) return 0;
            if(X<0) return 1;
        }
    }
    return 0;
}
bool g(vector<char> &A,vector<char> &B,string &S,int X){
    X=(int)S.size()-X;
    if(X>=(int)S.size()) return 1;
    rep(i,0,A.size()){
        if(S[X]==A[i]){
            if(B[i]=='R') X++;
            else X--;
            if(X>=(int)S.size()) return 1;
            if(X<0) return 0;
        }
    }
    return 0;
}
signed main(){
    int N,Q; cin>>N>>Q;
    string S; cin>>S;
    vector<char> A(Q),B(Q);
    rep(i,0,Q) cin>>A[i]>>B[i];
    int left=0,right=N;
    while(left+1<right){
        int mid=(left+right)/2;
        if(f(A,B,S,mid)) left=mid;
        else right=mid;
    }
    int ans=left;
    if(f(A,B,S,right)) ans=right;
    left=0;
    right=N;
    while(left+1<right){
        int mid=(left+right)/2;
        if(g(A,B,S,mid)) left=mid;
        else right=mid;
    }
    if(g(A,B,S,right)) ans+=right;
    else ans+=left;
    cout<<N-ans<<endl;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl

using namespace std;

typedef long long ll;
typedef string str;

const ll MAXN = 2e5 + 10;
const ll MOD = 1e9 + 7;

vector<ll> G[MAXN];
ll c[MAXN], val[MAXN];
ll nw = 0;
void DFS(ll u, ll v){
	for(auto adj : G[u]){
		if(adj != v) DFS(adj, u);
	}
	val[u] = c[nw];
	nw ++;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >>n;
	ll u, v;
	for(int i = 1; i < n; i++){
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	for(int i = 0; i < n; i++) cin >> c[i];
	sort(c, c + n);
	DFS(1, -1);
	ll ans = 0;
	for(int i = 0; i < n-1; i++) ans += c[i];
	cout<<ans<<'\n';
	for(int i = 1; i <= n;i++) cout << val[i] << " ";
	return 0;
}


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

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

using ll = long long;
#define INF 1e9

string S;

int main(){
  cin >> S;
  vector<vector<ll>> sum(4, vector<ll>(S.size()+1, 0));
  int n = S.size();
  REP(i, n){
    if(S[i] == '?'){
      S[i] = 'D';
    }
  }
  REP(i, n){
    REP(j, 4){
      sum[j][i+1] = sum[j][i];
    }
    sum[S[i]-'A'][i+1]++;
  }
  const ll mod = 1e9+7;
  ll ans = 0;
  ll cmb = 1, cmb1, cmb2, cmb3;
   cmb = cmb1 = cmb2 = cmb3 = 1;
  REP(i, sum[3][n]){
    if(i < sum[3][n]-1){
      cmb1 *=3;
      cmb1 %= mod;
    }
    if(i < sum[3][n]-2){
      cmb2 *=3;
      cmb2 %= mod;
    }
    if(i < sum[3][n]-3){
      cmb3*=3;
      cmb3 %=mod;
    }
    cmb*=3;
    cmb %=mod;
  }
  FOR(i, 1, n-1){
    if(S[i] == 'B'){
      ans += cmb* sum[0][i] * (sum[2][n]-sum[2][i+1]);
      ans %=mod;
      ans += cmb1 * sum[3][i] * (sum[2][n]-sum[2][i+1]);
      ans %=mod;
      ans += cmb1 * sum[0][i] * (sum[3][n] - sum[3][i+1]);
      ans %=mod;
      ans += cmb2 * sum[3][i]*(sum[3][n] - sum[3][i+1]);
    }
    else if(S[i] == 'D'){
      ans += cmb1 *sum[0][i] * (sum[2][n]-sum[2][i+1]);
      ans %=mod;
      ans += cmb2 * sum[3][i] * (sum[2][n]-sum[2][i+1]);
      ans %=mod;
      ans += cmb2 * sum[0][i] * (sum[3][n] - sum[3][i+1]);
      ans %=mod;
      ans += cmb3 * sum[3][i]*(sum[3][n] - sum[3][i+1]);
    }
    ans %=mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4352
def cumulative_sum(l):
    cumu = [0]
    s = 0
    for num in l:
        s += num
        cumu.append(s)
    return cumu

N = int(input())
A = list(map(int,input().split()))
S = cumulative_sum(A)
S.sort()

now = S[0]
c = 1
ans = 0
for i in range(1,N+1):
    if S[i] == now:
        c += 1

    else:
        ans += c*(c-1)//2
        c = 1
        now = S[i]
print(ans+c*(c-1)//2)


Measured memory_bytes: 25976
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[i+1] == s[i]:
        l[chk] += 1
    else:
        chk += 1

if s[0] == s[n-1]:
        temp = 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
    ans += k*(l[i]//2)

if temp == 1 and edge != 0: 
    if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1
elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2
if n == 1:
    ans = k//2

print(ans)


Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long N, A, B;
    cin >> N >> A >> B;
    cout << N / (A + B) * A + min(A, N % (A + B)) << '\n';
}


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

unsigned long long conbination2(long n){
  return (unsigned long long)(n * (n - 1) / 2);
}

signed main() {
  map<int, int> numMap;
  int n;
  int a[200000];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(numMap.count(a[i]) == 0){
      numMap.insert(make_pair(a[i],1));
    }else{
      numMap[a[i]]++;
    }
  }
  unsigned long long summize = 0;
  for(auto i = numMap.begin(); i != numMap.end(); i++){
    summize += conbination2((long)i->second);
  }

  for(int i = 0; i < n; i++){
    cout << summize - conbination2((long)numMap.at(a[i])) +  conbination2((long)numMap.at(a[i]) - 1) << endl;
  }
}

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

int main() {
    long long N,M;
    string S,T;
    cin >> N >> M;
    cin >> S >> T;

    long long l;
    for(long long i=1; i<=M; ++i) {
        if((N * i) % M == 0) {
            l = N * i;
            break;
        }
    }

    long long p = l / N;
    long long q = l / M;
    for(long long i=0; i<N; ++i) {
        if((p * i) % q == 0) {
            long long j = (p * i) / q;
            if(S[i] != T[j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    cout << l << endl;
}

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

int main(){
  string s,t;
  string kekka = "";
  
  cin >> s >> t;
  
  for(int i = 0; i < t.size(); i++){
    kekka += s.substr(i,1) + t.substr(i,1);
  }

  if(s.size() > t.size()) kekka += s.substr(s.size()-1,1);
  
  cout << kekka;
}

Measured memory_bytes: 256
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const double pi=3.142857;

void solve()
{ 
    int n;
    cin >> n;
  vector<int> v[n+1];
  f(i,n-1)
  {
      int x;
      cin >> x;
      v[x].pb(1);
  }
  fp(i,1,n)
   cout << v[i].size() << '\n';
  return;
}

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int k, x; 
	cin >> k >> x;

	if (500 * k >= x) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
  long long N;
  int* x = (int*) calloc(100, sizeof(int));
  cin >> N;
  if (N == 0) {
    cout << '0';
    return 0;
  }
  for (int i = 0; N != 0; i++, N -= N & 1, N /= -2) {
    x[i] = N & 1;
  }
  int foo = 99;
  for (; x[foo] == 0; foo--);
  for (; foo >= 0; foo--) {
    cout << x[foo];
  }
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n, d, ans = 0;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i,n)rep(j,d) cin >> x[i][j];


    rep(i,n)for(int j = i+1; j < n; ++j){
        int sum = 0;
        rep(k,d){
            sum += abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]);
        }
        rep(k,sum+1){
            if(k*k == sum) ++ans;
        }
    }

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


Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [a, b] = input[0];

  const ab = Number(`${a}${b}`);

  return Math.round(Math.sqrt(ab)) ** 2 === ab ? "Yes" : "No";
};

console.log(main(read()));


Measured memory_bytes: 29576
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int a[3],n;
	while(cin>>a[0]>>a[1]>>a[2],a[0]||a[1]||a[2]){
		sort(a,a+3);
		int l=a[0]*a[0]+a[1]*a[1];
		cin>>n;
		for(int i=0,r;i<n;++i){
			cin>>r;
			cout<<(((2*r)*(2*r)>l)?"OK":"NA")<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
/*
Author: Srinjoy
Language: C++ 17
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define fileinput(s) freopen(s,"r",stdin)
#define MINUS(a) memset(a,0xff,sizeof(a))
typedef long long ll;
const ll mod = 1000000007;

template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }
 
template<class T>
istream& operator >> (istream& in, pair<T, T> & v){ in >> v.fi >> v.se;return in; }

void printArr(vector<int> arr){
	cout<<"\n------------------------------------\n";

	for(int i=0;i<arr.size();i++) cout<<arr[i]<<" ";
	
	cout<<"\n------------------------------------\n";
}

void printArr(vector<vector<int> > arr){
	cout<<"\n------------------------------------\n";

	for(vector<int> i:arr){
		for(int j:i){
			cout<<j<<" ";
		}
		cout<<endl;
	}
	
	cout<<"\n------------------------------------\n";

}

ll solve(ll n){
	if(n==1) return 1;

	return ( 1 + (2*solve(n/2)) ); 
}

int main(){
	optimiza_io
	ll h;
	cin>>h;

	cout<<solve(h)<<endl;

	
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
    int s, w;
    cin>>s>>w;
    if(w>=s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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


using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    string s; cin >> s;
    int ans = 0;
    int tmp = 0;
    int sum = 0;
    for(int i = 0;  i <s.length()-1; i ++){
        ans += 9;
    }
    for(int i = 0; i < s.length(); i ++){
        tmp += (int)(s[i]-'0');
    }
    ans = max(ans,tmp);
;
    for(int i = 0; i < s.length()-1; i ++){
        tmp = 0;
        if((int)(s[i]-'0')!=0){
            tmp += (int)(s[i]-'0')-1;
            tmp += 9*(s.length()-1-i);
            tmp += sum;
            ans = max(tmp,ans);
        }
        sum += (int)(s[i]-'0');
    }

    cout << ans;
    return 0;
}











Measured memory_bytes: 3616
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] h = new int[300], w = new int[300];
		int cnt = 0;
		
		while(true){
			h[cnt] = sc.nextInt();
			w[cnt] = sc.nextInt();
			
			if(h[cnt] == 0 && w[cnt] == 0)
				break;
			
			cnt ++;
		}
		
		for(int i = 0; i < cnt; i++){
			for(int j = 0; j < h[i]; j++){
				for(int k = 0; k < w[i]; k++){
					if((j + k) % 2 == 0)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

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

int main() {

int a;
rep(i,5){cin >> a ;if(a==0){cout <<i+1 <<endl;}}




}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010], m[100010];
int main(){
  int n;
  while(cin>>n){
    memset(m, 0, sizeof m);
    for(int i=0; i<n; ++i){
      scanf("%d",&a[i]);
      ++m[a[i]];
    }
    int ans=m[0]+m[1];
    for(int i=1; i<=100000; ++i){
      ans=max(ans, m[i]+m[i-1]+m[i+1]);
    }
    cout<<ans<<endl;
  }
  return 0;
}




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

using namespace std;

int main()
{

    string n,p;
    while(cin>>n)
    {
        int count=0;
        for(int i=0;i<6;i++)
            if(n[i]=='1')
            count++;

        cout<<count<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	int n, a, max = 0, min = 500, score = 0, i, j;
	while(scanf("%d", &n) != 0){
		if(n == 0) break;
		for(i = 0; i < n; i++){
			for(j = 0; j < 5; j++){
				scanf("%d", &a);
				score += a;
			}
			if(max < score) max = score;
			if(min > score) min = score;
			score = 0;
		}
		printf("%d %d\n", max, min);
		max = 0;
		min = 500;
	}
	return 0;
}

Measured memory_bytes: 600
# 素因数分解 ソート済みリスト (素因数,指数)
import math
def factoring(n,dict_count = {}):
    sup = math.floor(pow(n,1/2))
    n_new = n
    for i in range(2,sup + 1):
        if n % i == 0:
            n_new = n // i
            if i in dict_count:
                dict_count[i] += 1
            else:
                dict_count[i] = 1
            break
    if n == n_new:
        if n_new in dict_count:
            dict_count[n_new] += 1
        else:
            dict_count[n_new] = 1
        return sorted(list(dict_count.items()))
    return factoring(n_new,dict_count)

def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

N,M = map(int,input().split())
if M == 1:
    print(1)
    exit()
ans = 1
for a,b in factoring(M):
    ans *= comb(b+N-1,b)
    ans %= 10**9 + 7
print(ans)

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

namespace AOJ.Codes
{
    //問題の名称...  0117:   A reward for a Carpenter
    //問題文のURL... http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117&lang=jp
    //所要時間... AAA
    //学んだこと... AAA
    //教室内の大まかな着席位置... {左，中央，右} x {前，中央，奥}

    class _0117_aReward_foraCarpenter
    {
        static void Main(string[] args)
        {
            //読み込み
            var n = int.Parse(Console.ReadLine());
            var m = int.Parse(Console.ReadLine());

            //読み込み
            var M = new int[n, n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    M[i, j] = int.MaxValue;

            //読み込み＆マッピング
            //端が（１，１）なのに注意
            for (int i = 0; i < m; i++)
            {
                var abcd = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
                var a = abcd[0]; //街i
                var b = abcd[1]; //街j
                M[a - 1, b - 1] = abcd[2]; //i→j
                M[b - 1, a - 1] = abcd[3]; //j→i
            }

            //読み込み
            var sgVP = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
            var s = sgVP[0]; //自分の街
            var g = sgVP[1]; //柱のある町
            var V = sgVP[2]; //褒美
            var P = sgVP[3]; //柱の代金


            //計算 - 距離
            for (int k = 0; k < n; k++)
            {
                var newM = (int[,])M.Clone();
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        //どちらか∞ならスキップ。じゃなかったら大きかったら実行。
                        if ((M[i, k] != int.MaxValue && M[k, j] != int.MaxValue) && M[i, j] > M[i, k] + M[k, j])
                            newM[i, j] = M[i, k] + M[k, j];
                M = newM;
            }

            //計算 - おかね
            var ans = V - (M[s - 1, g - 1] + M[g - 1, s - 1] + P);


            //出力
            Console.WriteLine(ans);
            Console.ReadLine();

        }



    }
}



Measured memory_bytes: 14228
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	int n; cin >> n;
	string s; cin >> s;
	int x = 0, y = 0;
	rep(i, 0, n) {
		if (s[i] == '(') x++;
		else x--;
		y = min(y, x);
	}
	rep(i, 0, -y) {
		cout << '(';
	}
	cout << s;
	rep(i, 0, x - y) cout << ')';
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int N,sum = 0;
	cin >> N;
	std::vector<int> s(N);
	for (int i = 0; i < N; ++i){
		cin >> s.at(i);
		sum += s.at(i);
	}
	if(sum % 10 != 0){
		cout << sum << endl;
		return 0;
	}
	else{
		sort(s.begin(), s.end());
		for (int i = 0; i < N ; ++i)
		 {
		 	 if(s.at(i) % 10 != 0){
		 	 	sum -= s.at(i);
		 	 	break;
		 	 }
		 }
		sum = (sum % 10 == 0) ? 0 : sum;
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=100050;
void add(int &x, int y){ x+=y;if(x>=mod) x-=mod;}
char s[N];
int dp[N],nxa[N],nxb[N],lst[3],pre[N];
int main()
{
	int n,i;
	scanf("%s",s+1);
	n=strlen(s+1);
	int ok=0;
	for(i=1;i<n;i++) if(s[i]==s[i+1]) ok=1;
	if(!ok) return 0*printf("1\n");
	for(i=1;i<=n;i++) pre[i]=(pre[i-1]+s[i]-'a'+1)%3;
	for(i=n;i>=0;i--) nxa[i]=lst[(pre[i]+1)%3],nxb[i]=lst[(pre[i]+2)%3],lst[pre[i]]=i;
	dp[0]=1;
	for(i=0;i<n;i++) add(dp[nxa[i]],dp[i]),add(dp[nxb[i]],dp[i]);
	int sum=0;
	for(i=1;i<=n;i++) if(pre[i]==pre[n]) add(sum,dp[i]);
	printf("%i\n",sum);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

const int MAX=200010;

ll add(ll a, ll b) {
    return (a+b)%MOD;
}

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

    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<ll>> dp(h+1,vector<ll>(w));
    dp[0][0]=1;
    rep(i,h) {
        rep(j,w) {
            rep(bit,(1<<(w-1))) {
                bool flag=1;
                rep(l,w-2) {
                    if ((bit & (1<<l)) && (bit & (1<<l+1))) flag=0;
                }
                if (flag) {
                    int nj=j;
                    if (bit & (1<<j)) nj=j+1;
                    else if (j>0 && (bit & (1<<(j-1)))) nj=j-1;
                    dp[i+1][nj]=add(dp[i+1][nj],dp[i][j]);
                }
            }
        }
    }
    cout << dp[h][k-1] << endl;
    
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <stdio.h>
static const int Nmax = 100;

void swap(int* a, int* b)
{
  int p = *a;
  *a = *b;
  *b = p;
  return ;
}

void printarray(int* array,int length)
{
  for(int i = 0; i < length-1; i++)
  {
    printf("%d ",array[i]);
  }
  printf("%d\n",array[length-1]);
}

int selectionSort(int* A, int N){
  int i;
  int sc = 0;
  for (i = 0; i < N; i++){
    int min_index = i;
    int j;
    for(j = i; j < N; j++){
      if(A[j] < A[min_index]){
        min_index = j;
      }
    }
    if (min_index != i){
      swap(&A[i],&A[min_index]);
      sc++;
    }
    //printarray(A,N);
  }
  return sc;
}

int main(){
  int N;
  int A[Nmax];

  std::cin >> N;
  for(int i = 0; i < N; i ++){
    std::cin >> A[i];
  }
  int swap_count = selectionSort(A,N);
  printarray(A,N);
  printf("%d\n",swap_count);

  return 0;
}



Measured memory_bytes: 3216
#include <stdio.h>

int N;
int V[32], C[32];

int main(void) {
	int N;
	int i;
	int masudayuki = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &V[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%d", &C[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (V[i] > C[i]) masudayuki += V[i] - C[i];
	}
	printf("%d\n", masudayuki);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	int r;
	cin >> r;
	cout << 2*PI*r << endl;
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,i,a;
	string s;
	t = 1;
	while(t--) {
	 a = 0;
	 cin >> s;
	 for(i = 0; i < 4; i++) {
	  if(s[i] == '+')
	   a++;
	  else
	   a--;
	 }
	 cout << a << endl;
	}
	return 0;
}



Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    string n; cin >> n;
    ll ans = 0;
    int flg = 0;
    if(n.size() == 1) {
        ans = n[0] - '0';
    }
    else if(n[0] != '9') {
        for(int i = 1; i < n.size(); i++) {
            if(n[i] != '9') flg = 1;
        }
        if(flg){
            ans = ((n[0] - '0') - 1) + (n.size() - 1) * 9;
        } else {
            ans = n[0] - '0' + (n.size() - 1) * 9;
        }
    }
    else {
        for(int i = 1; i < n.size(); i++) {
            if(n[i] != '9'){
                ans = ((n[i - 1] - '0') - 1) + ((n.size() - 1) * 9);
                flg = 1;
                break;
            }
        }
        if(!flg) ans = 9 * n.size();
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define Yes(a) if(a)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define please return
constexpr auto AC = 0;
using namespace std;

int main(){
	ll a, b;
	cin >> a >> b;
	vector<ll> g(a), m(a);
	vector<vector<ll>> dp(a + 1,vector<ll>(b+1, 0));
	rep(i, a)cin >> g[i] >> m[i];
	rep(i, a) {
		rep(j, b + 1) {
			if (j >= g[i])dp[i+1][j] = max(dp[i][j-g[i]] + m[i], dp[i+1][j]);
			dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
		}
	}
	cout << dp[a][b] << endl;
	please AC;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define maxn 500005
#define maxm 205
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}

int n, m, sum;
bitset<4000005> f;
int main(){
	int i, j, x;
	n = read();
	f[0] = 1;
	for(i = 1;i <= n;i++) {
		x = read();
		f |= f << x;
		sum += x;
	}
	for(i = (sum + 1)  / 2;i <= sum;i++) if(f[i]) return printf("%d\n",i),0;
	return 0;
}


Measured memory_bytes: 5240
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int n;
  scanf("%d",&n);
  int l[n];
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  int ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(l[i]==l[j] || l[i]==l[k] || l[j]==l[k]){
          continue;
        }
        int max=l[i];
        chmax(&max,l[j]);
        chmax(&max,l[k]);
        int all=l[i]+l[j]+l[k];
        all-=max;
        if(max<all){
          ans++;
        }
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1736
#include<iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >>b;
    
   if(a < b){
       cout << "a < b\n";
   }
   else if(a > b){
       cout << "a > b\n";
   }
   else{
       cout << "a == b\n";
   }

    return 0;
}


Measured memory_bytes: 3012
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


class Tree:
    def __init__(self, crdinal, adjgrph, root):
        self.n = crdinal
        self.g = adjgrph
        self.root = root
        self.parent = [-1]*self.n
        self.depth = [-1]*self.n
        self.subsize = [1]*self.n
        self.result = [1]*self.n  # 0 : additive, 1 : multiplicative

        s = [self.root]
        while s:
            v = s.pop()
            if self.depth[v] == -1:
                if v == self.root:
                    self.depth[v] = 0
                else:
                    self.depth[v] = self.depth[self.parent[v]] + 1
                    s.append(v)
                for w in self.g[v]:
                    if self.depth[w] == -1:
                        self.parent[w] = v
                        s.append(w)
            else:
                self.subsize[self.parent[v]] += self.subsize[v]
                self.calc(v)

    def calc(self, v):
        # The following formula is calculated by bottom-up:
        self.result[self.parent[v]] *= self.result[v]+1
        self.result[self.parent[v]] %= m
        return None

    def wanted(self):
        # Edit the item you want by using self.depth, self.subsize, etc..
        # Default : self.parent
        return self.parent

    def rerooting(self) -> list:
        # Modify below if you want to use rerooting
        ans = [0]*n
        ans[self.root] = self.result[self.root]

        cum1 = [[1] for i in range(n)]  # 0 : additive, 1 : multiplicative
        cum2 = [[1] for i in range(n)]  # 0 : additive, 1 : multiplicative
        FromParent = [0]*n

        s = [self.root]
        while s:
            v = s.pop()

            # accumulate nbhd's result from the left side
            for w in self.g[v]:
                if w != self.parent[v]:
                    cum1[v].append(cum1[v][-1]*(self.result[w]+1) % m)
                    s.append(w)
                else:
                    cum1[v].append(cum1[v][-1]*(FromParent[v]+1) % m)

            # accumulate nbhd's result from the right side
            for w in self.g[v][::-1]:
                if w != self.parent[v]:
                    cum2[v].append(cum2[v][-1]*(self.result[w]+1) % m)
                else:
                    cum2[v].append(cum2[v][-1]*(FromParent[v]+1) % m)
            cum2[v] = cum2[v][::-1]

            # calculate the sub-result for parent's subtree when you see the child as root.
            # get the answer for each child.
            for i, w in enumerate(self.g[v]):
                if w != self.parent[v]:
                    FromParent[w] = cum1[v][i]*cum2[v][i+1] % m
                    ans[w] = (FromParent[w]+1) * self.result[w]
                    ans[w] %= m
        return ans


n, m = map(int, input().split())
g = [[] for _ in range(n)]

for _ in range(n-1):
    x, y = map(int, input().split())
    g[x-1].append(y-1)
    g[y-1].append(x-1)

T1 = Tree(n, g, 0)

for x in T1.rerooting():
    print(x)


Measured memory_bytes: 112492
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int N,b,c;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){cin >> a[i];}
  c=0; b=0;
  for(int i=0;i<N;i++){
    if(a[i]%4==0){b++;}
    if(a[i]%2==1){c++;}
  }
  string ans;
  if(c==0){ans="Yes";}
  else if(c==1){
    if(b==0){ans="No";}
    else{ans="Yes";}
  }
  else if(b+c==N){
    if(c-1<=b){ans="Yes";}
    else{ans="No";}
  }
  else{
    if(c<=b){ans="Yes";}
    else{ans="No";}
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
from itertools import product

H, W, N = map(int, input().split())
V = set([tuple(map(int, input().split())) for _ in range(N)])
D = tuple(product((-1, 0, 1), repeat=2))

A = set()
for a, b in V:
    for h, w in D:
        if 2 <= a + h <= H - 1 and 2 <= b + w <= W - 1:
            A.add((a + h, b + w))

ans = [0] * 10
for a, b in A:
    cnt = 0
    for h, w in D:
        if (a + h, b + w) in V:
            cnt += 1
    ans[cnt] += 1

ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep='\n')


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

int main(){
    string S,S_,S1,S1_,S2,S2_;
    cin>>S;
    int n = S.size();
    S_ = S.substr(0,n);
    reverse(S_.begin(),S_.end());
    if(S_ == S){
        S1 = S.substr(0,(n-1)/2);
        S1_ = S.substr(0,(n-1)/2);
        reverse(S1_.begin(),S1_.end());
        if(S1 == S1_){
            S2 = S.substr((n+3)/2-1,(n-1)/2);
            S2_ = S.substr((n+3)/2-1,(n-1)/2);
            reverse(S2_.begin(),S2_.end());
            if(S2 == S2_){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 1e6;

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(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >>a[i];
  bool even = true;
  rep(i,n) if(a[i]%2 == 1) even = false;
  cout << (even ? "second" : "first") << endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

const int N = 1e5+23;

int a[N], b[N];

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a+i, b+i);
  }
  long long ans = 0, cur = 0;
  for (int i = n-1; i >= 0; --i) {
    if (a[i]+cur == 0) continue;
    if (a[i]+cur < b[i]) {
      long long x = b[i]-a[i]-cur;
      cur += x;
      ans += x;
    } else {
      long long x = (a[i]+cur+b[i]-1)/b[i];
      debug(x*b[i]);
      debug(a[i]+cur);
      ans += x*b[i]-(a[i]+cur);
      cur += x*b[i]-(a[i]+cur);
    }
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
int N,M;
string s;
map<string, int> mp;
int ans = 0;
int main(){
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> s;
        mp[s]++;
    }
    cin >> M;
    for(int i = 0; i < M; ++i){
        cin >> s;
        mp[s]--;
    }
    
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans = max(ans,itr->second);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - Simple Calculator
https://atcoder.jp/contests/agc008/tasks/agc008_a

"""
import sys


def solve(x, y):
    if x == 0:
        if y < 0:
            return abs(y)+1
        else:
            return y
    elif x > 0:
        if y < 0:
            return abs(abs(y)-abs(x)) + 1
        elif y == 0:
            return x+1
        else:
            if x > y:
                return (x-y) + 2
            else:
                return y-x
    else:
        if y == 0:
            return -x
        if y < 0:
            if x > y:
                return abs(abs(y)-abs(x)) + 2
            else:
                return y-x
        else:
            return min(abs(abs(y)-abs(x))+1, abs(x)+y)


def main(args):
    x, y = map(int, input().split())
    ans = solve(x, y)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size() - 1) {
        if (s[i] == s[i+1]) {
            if (s[i+1] == '0') s[i+1] = '1';
            else s[i+1] = '0';
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;

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

	set<int> nums;
	for (int i = 0; i < n; i++) {
		cin >> a;

		if (nums.count(a) > 0) {
			nums.erase(a);
		} else {
			nums.insert(a);
		}
	}

	cout << nums.size() << endl;
	return 0;
}


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

# スペース区切りの整数の入力
sx, sy, tx, ty = map(int, input().split())

S = ""

xlen = tx - sx
ylen = ty - sy

#1
for i in range(xlen):
  S += "R"
for i in range(ylen):
  S += "U"
  
#2
for i in range(xlen):
  S += "L"
for i in range(ylen):
  S += "D"

#3
S += "D"
for i in range(xlen + 1):
  S += "R"
for i in range(ylen + 1):
  S += "U"
S += "L"

#4
S += "U"
for i in range(xlen + 1):
  S += "L"
for i in range(ylen + 1):
  S += "D"
S += "R"

print(S)

Measured memory_bytes: 3064
from copy import deepcopy
s = list(input())
t = list(input())
lens = len(s)
lent = len(t)
ans = deepcopy(s)
for i in range(len(s)):
  if s[i] == "?":
    ans[i] = "a"
def match(moji):
  for i in range(lent):
    if moji[i] != t[i] and moji[i] != "?":
      return False
  return True
for i in range(lent, lens+1):
  ns = s[lens-i:lens-i+lent]
  if match(ns):
    ans[lens-i:lens-i+lent] = t
    print("".join(ans))
    exit()
print("UNRESTORABLE")

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

#define int long long

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

	string s;
	cin >> s;

	if (s == "ABC") cout << "ARC";
	if (s == "ARC") cout << "ABC";
}


Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A & a, const B & b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A & a, const B & b) { a = max(a, (A)b); };


int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> V(N);
	REP(i, 0, N)cin >> V[i];
	ll ans = 0;
	REP(a, 0, 1+N) {
		REP(b, 0, 1+N) {
			if (a + b > K || a + b > N)continue;
			vector<ll> vec;
			ll sum = 0;
			REP(i, 0, a) {
				vec.push_back(V[i]);
				 sum+= V[i];
			}
			REP(i, 0, b) {
				vec.push_back(V[V.size() - 1 - i]);
				sum += V[V.size() - 1 - i];
			}
			sort(vec.begin(), vec.end());
			REP(i, 0, min(K - (a + b), a + b)) {
				if (vec[i] >= 0)break;
				sum -= vec[i];
			}
			maxs(ans, sum);
		}
	}
	PRI(ans);
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

// ax + by = c
// dx + ey = f
// det(A) = ae-bd
// A^(-1) = 1/det(A)* ((e,-b),(-d,a))
// x = 1/det(A) *(ce-bf)
// y =			*(-cd+af)

int main(int,char**){
	double a,b,c,d,e,f;
	double x,y;
	std::cout<< std::setprecision(3) << std::setiosflags(std::ios::fixed);
	while(std::cin >> a){
		std::cin >> b >> c >> d >> e >> f;
		double det(a*e-b*d);
		x= (c*e-b*f)/det + 0;
		y= (-c*d+a*f)/det + 0;
		std::cout<< x << ' ' << y<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int a,b;cin>>a>>b;
  if(a==b) {
    pr(0);
  } else if ((a+b)%2==0) {
    pr((a+b)/2);
  } else {
    pr("IMPOSSIBLE");
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(12);
  int a,b;
  double C;
  cin >> a >> b >> C;

  double PI = acos(-1.0);
  C = C/180.0*PI;
  cout << a*b*sin(C)/2.0 << endl;

  double cc = a*a+b*b - 2*a*b*cos(C);
  cout << a+b+sqrt(cc) << endl;
  cout << b*sin(C) <<endl;

  return 0;
}


Measured memory_bytes: 3480
import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())

root = [-1] * n

def r(x):
    if root[x] < 0:
        return x
    
    else:
        root[x] = r(root[x])
        return root[x]

def unite(x,y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    unite(x,y)


print(-min(root))

Measured memory_bytes: 13388
N,M=map(int,input().split())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
a.sort(key=lambda x: x[0])

i=0
cost=0
while(1):
    if M-a[i][1]>0:
        M-=a[i][1]
        cost+=a[i][0]*a[i][1]
        i+=1
    else:
        cost+=M*a[i][0]
        break
print(cost)

Measured memory_bytes: 29028
using System;

namespace ABC026A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            if (a == 2 || b ==2)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
N,K = map(int,input().split())
l = [0]*N
sum = 0

for i in range(K):
    d = int(input())
    l2 = list(map(int,input().split()))
    for j in range(d):
        l[l2[j]-1] += 1

for i in range(N):
    if l[i]==0:
        sum += 1

print(sum)

Measured memory_bytes: 9196