akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);

    ll n,k;
    cin >> n >> k;

    vector<ll> sun(n, 0);
    rep(i, k){
        ll d;
        cin >> d;
        rep(j, d){
            ll a;
            cin >> a;
            sun[a-1]++;
        }
    }
    ll count = 0;
    rep(i, n){
        debug(sun[i]);
        if(sun[i]==0){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn     cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;

int main()
{
    ll n,x,z=0;
    cin>>n>>x;
    ll a[n];
    rep(i,n)cin>>a[i];
    for(ll i=1;i<n;i++){
        if(a[i-1]+a[i]>x) {
            if(a[i-1]<x) z+=a[i]-x+a[i-1],a[i]=x-a[i-1];
            else z+=a[i]+a[i-1]-x,a[i]=0,a[i-1]=x;
        }
    }
    cout<<z<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define deb(x)   cout<<"> "<<#x<<" : "<<x<<endl;
#define deb2(x,y)cout<<"> "<<#x<<"->"<<x<<"  "<<#y<<"->"<<y<<endl;
#define LINE   cout << "--- LINE NO : " << __LINE__ <<"  ---"<< endl;
#define pnr(a)   for(auto x:a){cout<<x<<" ";}cout<<endl;
#define pnr2(a)  for(auto x:a){cout<<x.first<<" "<<x.second<<endl;}

#define  vt            vector
#define  ff            first
#define  ss            second
#define  int           long long
#define  db            long double
#define  umap          unordered_map
#define  pii           pair<int,int>
#define  Maxpq(x)      priority_queue<x>
#define  Minpq(x)      priority_queue<x,vt<x>,greater<x>>

#define  pb            push_back
#define  si(x)         (int)x.size()
#define  all(x)        x.begin(),x.end()
#define  mem(a,x)      memset(a,x,sizeof(a))
#define  FOR(a)        for(auto& x :  a )
#define  forr(i,n)     for(int i=0;i<n;i++)
#define  bits(n)       (int)log2(n)+1
#define  setbits(n)     __builtin_popcountll(n)

#define  pi            2*acos(0.0)
#define  inf           (int)1e18
#define  mxn           (int)2e5+5
#define  mod           (int)1e9+7

int mainx()
{
	int n;
	cin >> n;
	int a[n][4];
	forr(i , n)
	cin >> a[i][1] >> a[i][2] >> a[i][3];

	int dp[n][4];
	mem(dp , -1);

	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	dp[0][3] = a[0][3];
	for (int i = 1 ; i < n; i++)
	{
		dp[i][1] = max(dp[i - 1][2] , dp[i - 1][3]) + a[i][1];
		dp[i][2] = max(dp[i - 1][1] , dp[i - 1][3]) + a[i][2];
		dp[i][3] = max(dp[i - 1][1] , dp[i - 1][2]) + a[i][3];
	}
	cout << max(dp[n - 1][1] , max(dp[n - 1][2] , dp[n - 1][3])) << endl;
	// forr(i , n)
	// {
	// 	cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << endl;
	// }

	return 0;
}


inline void __INCLUDE() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	// `fr / eopen("out.txt", "w", stdout);
#endif
}

int32_t main() {

	//__INCLUDE();

	ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);

	//cout << fixed << setprecision(20);

	int tt = 1;
	//cin>>tt;
	for (int t = 1 ; t <= tt ; t++ )
	{
		// cout<<"Case #"<<t<<": ";
		mainx();
	}
	return 0 ;
}



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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		int dcnt= 0 ;
		if (i%2==0)
			continue;
		for (int j = 1; j <= i; ++j) {
			if (i%j==0)
				++dcnt;
		}
		if (dcnt == 8)
			++ans;
	}

	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
MOD = 998244353

N, K = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(K)]

# dp[i]: マスiに移動する方法
dp = [0] * 200010
dp[0] = 1

for i in range(N):
    for l, r in LR:
        if i+l < N:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < N:
            dp[i+r+1] -= dp[i]
            dp[i+r+1] %= MOD
    if i>=1:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD

print(dp[N-1])


Measured memory_bytes: 69796
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

map<int, int> mp;

void addMp(int tmp) {
  auto itr = mp.find(tmp);
  if (itr != mp.end()) mp[tmp]++;
  else mp[tmp] = 1;
}

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep (i, n) {
    int tmp;
    cin >> tmp;
    int dis = min(tmp, abs(tmp - k));
    ans += dis * 2;
  }
  P(ans);
  return 0;
}

Measured memory_bytes: 256
SIZE=100001; MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0


# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

a.sort()


ans = 0
for i in range(n):
    ans += a[i]*choose(i,k-1)
    ans -= a[i]*choose(n-i-1,k-1)
    ans %= MOD

print(ans)




Measured memory_bytes: 25948
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define show(ans) cout << ans << endl
const long MOD = 1000000007;

long h[4];
long cnt[4];
long l[9];
long A, B, C;
long N;
long ans;


void dfs(long n, long k) {
	if(n == N+1){
		//show(n);
		for (long i = 1; i <= 3; i++) {
			if (cnt[i] == 0) return;
		}
		long tmp = (cnt[1] + cnt[2] + cnt[3] - 3) * 10 + abs(h[1] - A) + abs(h[2] - B) + abs(h[3] - C);
		//show(tmp);
		//cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << ' ' << cnt[3] << ' ' << tmp << endl;
		ans = min(ans, tmp);
		return;
	}
	h[k] += l[n];
	cnt[k]++;
	rep(j, 4) {
		dfs(n + 1, j);
	}
	h[k] -= l[n];
	cnt[k]--;
}

int main() {
	cin >> N;
	cin >> A >> B >> C;
	erep(i, N) cin >> l[i];
	ans = 1e9;
	rep(i, 4) dfs(1, i);
	show(ans);


	return 0;

}


Measured memory_bytes: 256
pub trait FromLn {
	fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
	let mut buf = String::new();
	let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
	T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
	let mut vs = vec![];
	for _ in 0..n { vs.push(readln()); }
	vs
}
macro_rules! fromln_primitives {
	($($t:ty),*) => { $(
		impl FromLn for $t {
			fn fromln(s: &str) -> $t {
				s.parse().unwrap()
			}
		}
	)* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
	fn fromln(s: &str) -> Vec<T> {
		s.split_whitespace().map(T::fromln).collect()
	}
}
impl FromLn for Vec<char> {
	fn fromln(s: &str) -> Vec<char> {
		s.chars().collect()
	}
}
macro_rules! fromln_tuple {
	($($t:ident),*) => {
		impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
			fn fromln(s: &str) -> ($($t),*) {
				let mut it = s.split_whitespace();
				let t = ($($t::fromln(it.next().unwrap())),*);
				assert_eq!(it.next(), None);
				t
			}
		}
	}
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);

struct Input {
    n: usize,
    k: i64,
    v: Vec<(i64, i64)>
}

fn read() -> Input {
    let (n, k) = readln();
    let v = readlns(n);
    Input{n: n, k: k, v: v}
}

fn solve(mut it: Input) -> String {
    it.v.sort();
    let mut answer = 0;
    for (a, b) in it.v {
        it.k -= b;
        if it.k <= 0 {
            answer = a;
            break;
        }
    }
    answer.to_string()
}

fn main() {
    let answer = solve(read());
    println!("{}", answer);
}


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

int h, w;
bool used[1010][1010] = {};
int dp[1010][1010] = {};
int rui[1010][1010] = {};

int dfs(int right, int bottom){
  if(right == w || bottom == h) return 0;
  if(used[right][bottom]) return dp[right][bottom];
  used[right][bottom] = true;
  if((right + bottom) % 2 == 0){
    return dp[right][bottom] = max(dfs(right+1,bottom),dfs(right,bottom+1)+rui[bottom][w]-rui[bottom][right]);
  }else{
    return dp[right][bottom] = min(dfs(right+1,bottom),dfs(right,bottom+1)+rui[bottom][w]-rui[bottom][right]);
  }
}

int main(){
  cin >> w >> h;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> rui[i][j+1];
      rui[i][j+1] += rui[i][j];
    }
  }
  int ans = dfs(0,0);
  int all = 0;
  for(int i = 0;i < h;i++){
    all += rui[i][w];
  }
  cout << abs(ans-(all-ans)) << endl;
  return 0;
}



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

const int N = 200010;
// vector<vector<int> > p;

int main() {
  int n,k;
  cin>>n>>k;
  int a[n];
  int g = 0,m = 0;
  for (int i = 0; i<n; i++) {
    cin>>a[i];
    g = __gcd(g,a[i]);
    m = max(m,a[i]);
  }
  if (k <= m && k%g == 0) {
    cout<<"POSSIBLE"<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}


Measured memory_bytes: 640
import numpy as np
from numba import njit

MOD = 10**9 + 7

@njit
def f(N):
  # 項数、0が出現したかどうか、9が出現したかどうか
  dp = np.zeros((N+1, 2, 2), np.int64)
  dp[0,0,0] = 1
  for n in range(N):
    # (0,0) からの遷移
    dp[n+1,0,0] += 8 * dp[n,0,0]  # 1 から 8
    dp[n+1,0,1] += dp[n,0,0]  # 0
    dp[n+1,1,0] += dp[n,0,0]  # 9
    
    # (0,1) からの遷移
    dp[n+1,0,1] += 9 * dp[n,0,1]  # 1 から 9
    dp[n+1,1,1] += dp[n,0,1]  # 0
    
    # (1,0) からの遷移
    dp[n+1,1,0] += 9 * dp[n,1,0]  # 0 から 8
    dp[n+1,1,1] += dp[n,1,0]  # 9
    
    # (1,1) からの遷移
    dp[n+1,1,1] += 10 * dp[n,1,1]
    
    dp[n+1] %= MOD
  return dp[N,1,1]
         
N = int(input())
print(f(N))

Measured memory_bytes: 145184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  for(int i = 0; i < W + 2; i++)
  cout << "#"; 
  cout<< endl;  
  for(int i = 0; i < H; i++){
      vector<string> moji(H);
      cin >> moji.at(i);
      cout << "#" + moji.at(i) + "#" <<endl;
  }
  for(int i = 0; i < W+2;i++)
    cout << "#"; 
  	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	char a[1001];
	int n,x=0;
	gets(a);
	n=strlen(a);
	for(int i=0;i<n;i++)
	{
		if(a[i]=='C')
		{
			for(int j=i+1;j<=n;j++)
			{
				if(a[j]=='F')
				{
					x++;
				}	
			}
		} 
	}
	if(x==0)
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r;
  int D;
  int X2000;
  
  cin >> r >> D >> X2000;
  
  vector<int> vec(100);
  
  for (int i = 1;i <= 10;i++){
      vec.at(0) = X2000;
      vec.at(i) = r*vec.at(i-1) - D;
      cout << vec.at(i) <<endl;;
  }
  
  }

Measured memory_bytes: 256
L = raw_input()
L = L.split()
for i, val in enumerate(L):
    L[i] = int(val)
N = L[0]
A = L[1]
B = L[2]
K = A + B - N
MAX = min(A, B)
MIN = max(0, K)
print(str(MAX)+" "+str(MIN))

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int n;
  cin>>n;
  vector<int> a(n);
  rep(i,0,n) cin>>a[i];
  sort(a.begin(),a.end());
  cout<<a[n/2]-a[n/2-1]<<'\n';
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if (B%C == 0 && A%C == 0) {
    cout << (B/C) - (A/C) + 1;
  }
  else {
    cout << (B/C) - (A/C);
  }
}
    

Measured memory_bytes: 3516
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    int ans = 1;
    vector<int>a(N);
    rep(i, N) {
        cin >> a[i];
        if (a[i] == ans)ans++;
    }
    cout << (ans == 1 ? -1 : N - ans + 1) << endl;
}

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

#define int long long

int solve(vector<int>& coins, int l, int r,vector<vector<int>> &dp){
	if (l>r) return 0;
	if (dp[l][r]!=-1) return dp[l][r];
	return dp[l][r]= max(coins[l]+min(solve(coins,l+2,r,dp),solve(coins,l+1,r-1,dp)),
		   	   coins[r]+min(solve(coins,l+1,r-1,dp),solve(coins,l,r-2,dp)));
}

signed main() {
	// freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
	int N;
	cin>>N;
	int sum=0;
	vector<int> coins(N);
	for (int i=0;i<N;i++){
		cin>>coins[i];
		sum+=coins[i];
	}
	vector<vector<int>> dp(N+1,vector<int>(N+1,-1));
	int X = solve(coins,0,N-1,dp);
	int Y = sum-X;
	cout<<X-Y<<endl;
    return 0; 
}


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

const string YES = "YES";
const string NO = "NO";

void solve(long long X){
    if (X == 7 || X == 5 || X == 3) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
s=input()
key=0
for i in range(1,len(s)+1):
    if i%2==1 and s[i-1]=="L":
        key=1
        break
    if i%2==0 and s[i-1]=="R":
        key=1
        break
print("Yes" if key==0 else "No")        

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;
 
#define MOD 1000000007

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll mod = pow(10, 9) + 7;

    ll n, k;
    cin >> n >> k;

    vector<ll> kai(n + 1LL, 1LL);

    ll base = 1LL;
    for(ll i = 1LL; i <= n; i++) {
        base *= i;
        base %= mod;
        kai[i] = base;
    }

    ll ans = 1LL;
    for(ll i = 1LL; i <= min(n - 1LL, k); i++) {
        base = kai[n];
        base %= mod;
        base *= modpow(kai[i], mod - 2LL, mod) % mod;
        base %= mod;
        base *= modpow(kai[n - i], mod - 2LL, mod) % mod;
        base %= mod;
        base *= kai[n - 1LL];
        base %= mod;
        base *= modpow(kai[i], mod - 2LL, mod) % mod;
        base %= mod;
        base *= modpow(kai[n - i - 1LL], mod - 2LL, mod) % mod;
        base %= mod;
        ans += base;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4744
#ワ―シャルフロイド法   d=[[0,1],[2,0]]を最短コストに変換する感じ
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,m=map(int,input().split())
abc=[]
d=[[10**9+7 for i in range(n)] for j in range(n)]
l=[[10**9+7 for i in range(n)] for j in range(n)]
for i in range(m):
    tmp=[int(j) for j in input().split()]
    abc.append(tmp)
    d[tmp[0]-1][tmp[1]-1]=tmp[2]
    d[tmp[1]-1][tmp[0]-1]=tmp[2]
    l[tmp[0]-1][tmp[1]-1]=tmp[2]
    l[tmp[1]-1][tmp[0]-1]=tmp[2]

for i in range(n):
    d[i][i]=0
    l[i][i]=0
d=warshall_floyd(d)

ans=0
for i in range(n):
    for j in range(n):
        if d[i][j]!=l[i][j] and l[i][j]!=10**9+7:
            ans+=1
print(ans//2)

    
    

Measured memory_bytes: 3568
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String N = scan.next();
		scan.close();
		String A = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String a = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
		if(A.contains(N)) {
			System.out.println("A");
		}else if(a.contains(N)){
			System.out.println("a");
		}
	}

}

Measured memory_bytes: 35764
from collections import deque

H, W, *S = open(0).read().split()
H, W, S = int(H), int(W), [list(s) for s in S]

white = sum(s.count(".") for s in S)

S[0][0] = ""
Q = deque([(0, 0, 1)])
while Q:
    h, w, count = Q.popleft()
    if (h, w) == (H - 1, W - 1):
        print(white - count)
        quit()

    for nh, nw in [(h, w + 1), (h, w - 1), (h + 1, w), (h - 1, w)]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == ".":
            S[nh][nw] = ""
            Q.append((nh, nw, count + 1))
print(-1)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int N;
    cin >> N;
    string S;
    map<string, ll> mp;
    for(int i = 0; i < N; i++){
        cin >> S;
        sort(all(S));
        mp[S]++;
    }
    ll ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        ans += itr->second * (itr->second - 1) / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 2e5+5;
const ll MOD = 1e9+7;

int num[MAXN], tmp[MAXN];
ll ans = 0;

void mergesort(int left, int right)
{
    if (right - left <= 1)
        return;
    int mid = (left + right) >> 1;
    int i = left, j = mid, k = left;
    mergesort(left, mid);
    mergesort(mid, right);
    while (i < mid && j < right)
    {
        if (num[i] <= num[j])
            tmp[k++] = num[i++];
        else
        {
            tmp[k++] = num[j++];
            ans += mid-i;
        }
    }
    while (i < mid)
        tmp[k++] = num[i++];
    while (j < right)
        tmp[k++] = num[j++];
    rep(i, left, right-1){
        num[i] = tmp[i];
    }
}

int main()
{
    IOS;
    int n;
    cin >> n;
    rep(i, 0, n-1){
        cin >> num[i];
    }
    mergesort(0, n);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4704
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll n;
    cin>>n;
    ll h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    ll ans=0;
    ll maxH=0;
    for(int i=0;i<n;i++){
        if(h[i]>=maxH){
            ans+=1;
        }
        maxH=max(maxH,h[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 40000
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,a,b;
	cin>>n>>a>>b;

	ll an=0;
	k=(n/(a+b));
	an=(k*a);
	an+=(min(n%(a+b),a));
	cout<<an;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

#define max 1000000
int main(){
    bool prime[max] = {1,1,0};
    range(i,2,max){
            if(!prime[i]){
                for(int j = i + i; j <= max; j += i){
                    prime[j] = 1;
                }
            }
    }
    int a, b, n;
    while(cin >> a >> b >> n, a||b||n){
        rep(i,max){
            if(prime[a + b * i] == 0){
                n--;
            }
            if(!n){
                cout << a + b * i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 2140
#include <cstdio>
#include <vector>
#include <algorithm>
#define abs std::abs
#define minf std::min
#define maxf std::max
typedef long long ll;
typedef long double ld;

ll a, b, r;

int main() {
    scanf("%lld%lld", &a, &b);
    r = a * b;
    if(r % 2 == 1)
        printf("Odd\n");
    else
        printf("Even\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
const static int LEN=200000;
int main()
{
    int x[LEN],n;
    cin>>n;

    for(int i=0; i<n; i++) cin>>x[i];

    int minp=x[0];
    int maxp=-2000000000;

    for(int i=1; i<n; i++){
        maxp=max(maxp,x[i]-minp);
        minp=min(x[i],minp);
    }
    cout<<maxp<<endl;
    return 0;
}



Measured memory_bytes: 3880
#include <stdio.h>
int main(void){
	
	while(1){
		int a,i;
		char num[1010];
		scanf("%s",&num);
		if(num[0]=='0') break;
		else{
			int sum=0;
			for(i=0;i<strlen(num);i++){
				sum+=num[i]-'0';
			}
			printf("%d\n",sum);
		}
		
	}
	return 0;
}



Measured memory_bytes: 2044
/* 部分文字列の場所以外の'?'は'a'に置き換えてしまうのが辞書順最小。
今回の場合、部分文字列を入れる位置は必ずしも後ろの方が良いとは限らないので、
候補を全て挙げて、最小のモノを探す必要がある。*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string s, t;
    cin >> s >> t;
    
    int n = s.size();
    int m = t.size();

    vector<string> v;

    if (n < m){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }else{
        for (int i = n - m; i >= 0; i--){
            bool flag = true;
            for (int j = 0; j < m; j++){
                if (!(s[i + j] == t[j] || s[i + j] == '?')){
                    flag = false;
                    break;
                }
            }

            if (flag){
                string temp = s;
                for (int j = 0; j < m; j++){
                    temp[i + j] = t[j];
                }
                v.push_back(temp);
            }
        }

        if (!v.size()){
            cout << "UNRESTORABLE" << endl;
            return 0;
        }else{
            sort(v.begin(), v.end());
            string ans = v[0];
            for (int i = 0; i < ans.size(); i++){
                if (ans[i] == '?') ans[i] = 'a';
            }
            cout << ans << endl;
            
            return 0;
        }
    }
}

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

int main() {
  ll x,n;
  cin >> x >> n;
  ll q;
  vector<ll> p;
  ll y=101;
  ll ans=101;
  
  if(n==0) {
    y=x;
  } else {
    for (ll i=0;i<n;i++) {
      cin >> q;
      p.push_back(q);
    }
    for (ll i=-1;i<102;i++) {
      auto itr = std::find(p.begin(), p.end(), i);
      if( itr == p.end() ) {
        if( llabs(x-i)<ans ) {
          ans = llabs(x-i);
          y=i;
        }
      }
    }
  }
  cout << y;
  
  return 0;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int a, b, c;

int main(){
	cin >> a >> b >> c;
	cout << max(c, max(a, b))*10 + a + b + c -max(c, max(a, b)) << endl;
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a,b,t;
  cin>>a>>b>>t;
  cout<<floor(t/a)*b;
}


Measured memory_bytes: 764
n, m = map(int, input().split())
den = []
for _ in range(m):
    i = list(map(int, input().split()))
    i.pop(0)
    tden = [0] * n
    for j in i:
        tden[j - 1] = 1
    den.append(tden)

p = list(map(int, input().split()))

import itertools as it

stat = [i for i in it.product([0, 1], repeat=n)]
ans = 0
for st in stat:
    f = 1
    for no, td in enumerate(den):
        l = [min(i, j) for i, j in zip(st, td)]
        tento = sum(l) % 2
        if p[no] != tento:
            f = 0
            break
    if f: ans += 1
print(ans)


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

int main() {
  string N, M, O;
  cin >> N >> M >> O;

  char a = N.at(0);
  char b = M.at(0);
  char c = O.at(0);

  int d = (int)a - 32;
  int e = (int)b - 32;
  int f = (int)c - 32;
  cout << (char)d << (char)e << (char)f << endl;
}

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

int main (){
   int a,b;
   int ans;
   cin>> a>> b;
   ans=max(a+b,a-b);
   ans=max(ans,a*b);
   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  long long int count = 0;
  int len = S.size();
  long long int num_A = 0;
  for(int ii=0; ii<len-2; ii++){
    if(S[ii]=='A'){
      num_A++;
      if(S[ii+1]=='B' && S[ii+2]=='C'){
        count += num_A;
        S[ii]='B';
        S[ii+1]='C';
        S[ii+2]='A';
        ii++;
        num_A--;
      }
    }else{
      num_A = 0;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_V 100
#define INF INT_MAX / 2 - 1

int cost[MAX_V][MAX_V];
int mindis[MAX_V];
bool used[MAX_V];
int V;

void printv(string name, int v[], int len) {
	cout << name << " :";
	for (int i = 0; i < len; i++)
		cout << " " << v[i];
	cout << endl;
}

int prim() {
	fill_n(mindis, V, INF);
	fill_n(used, V, false);

	mindis[0] = 0;
	int res = 0;

	while (1) {
		int v = -1;
		for (int u = 0; u < V; u++)
			if (!used[u] && (v == -1 || mindis[u] < mindis[v]))
				v = u;
		if (v == -1)
			break;
		used[v] = true;
		if (mindis[v])
			res += mindis[v] / 100 - 1;

		for (int u = 0; u < V; u++)
			mindis[u] = min(mindis[u], cost[v][u]);
//		printv("mindis", mindis, V);
	}

	return res;
}

int main() {
	while (1) {
		for (int i = 0; i < MAX_V; i++)
			fill_n(cost[i], MAX_V, INF);
		cin >> V;
		if (V == 0) break;

		int E;
		cin >> E;
		for (int i = 0; i < E; i++) {
			int u, v, dis;
			scanf("%d,%d,%d\n", &u, &v, &dis);
			cost[u][v] = cost[v][u] = dis;
		}
		cout << prim() << endl;
	}
	return 0;
}

Measured memory_bytes: 1288
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
total=0
cnt=0
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(m):
        total+=a[j]*b[j]
    if 0<total+c:
        cnt+=1
    total=0
print(cnt)


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

int main(){
	int x, y;
	
	while(1){
		cin >> x >> y;
		if ( x == 0 && y == 0 ) break;
	
     	if ( x < y ){
		  cout << x << " " << y << endl;
     	} else {
		  cout << y << " " << x << endl;
	    }
   }
	
   return 0;
}


Measured memory_bytes: 3124
#-*- coding:utf-8 -*-
#approach:
#????????????????????±??????N???S??????????????¨W???E??????????????¨????????????
rolls = raw_input().split()
n = input()
#?????????????£????
nsrolls = [rolls[0],rolls[1],rolls[5],rolls[4]]
werolls = [rolls[0],rolls[2],rolls[5],rolls[3]]
#?????????????£????
nsrolls2 = [rolls[1],rolls[2],rolls[4],rolls[3]]
werolls2 = [rolls[1],rolls[5],rolls[4],rolls[0]]
# print nsrolls
# print werolls
# print nsrolls2
# print werolls2
for x in xrange(n):
    top,front = raw_input().split()
    #??????????????????????????¨??????????????????????????????
    if top in nsrolls and front in nsrolls:
        topps = nsrolls.index(top)
        frontps = nsrolls.index(front)
        tmprolls = werolls
        listmode = 0
        # print "?????°????????????ns"
    elif top in werolls and front in werolls:
        topps = werolls.index(top)
        frontps = werolls.index(front)
        tmprolls = nsrolls
        listmode = 1
        # print "?????°????????????we"
    elif top in nsrolls2 and front in nsrolls2:
        topps = nsrolls2.index(top)
        frontps = nsrolls2.index(front)
        tmprolls = werolls2
        # print "?????°????????????ns2"
        listmode = 1
    elif top in werolls2 and front in werolls2:
        topps = werolls2.index(top)
        frontps = werolls2.index(front)
        tmprolls = nsrolls2
        listmode = 0
        # print "?????°????????????we2"

    #????????????????????????????????¨???????????£??????????????§??\????????¢?????´???????????§OK
    revflag = topps-frontps
    if listmode == 0:
        pass
        if revflag==3 or revflag==-1:
            print tmprolls[1]
        elif revflag==-3 or revflag==1:
            print tmprolls[3]
    else:
        if revflag==3 or revflag==-1:
            print tmprolls[3]
        elif revflag==-3 or revflag==1:
            print tmprolls[1]

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
struct edge
{
	int to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
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); }
//bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
//int index(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

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

bool fld[200][200];
int cnt[200][200];
int main()
{
	int t, n;
	while (cin >> t >> n, t)
	{ 
		MS(fld, false);
		REP(i, 200)REP(j, 200)
		{
			cnt[i][j] = INF;
		}
		REP(i, n)
		{
			int x, y;
			cin >> x >> y;
			x += 100; y += 100;
			fld[x][y] = true;
		}
		int sx, sy;
		cin >> sx >> sy;
		sx += 100, sy += 100;
		cnt[sx][sy] = 0;
		queue<P> que;
		que.push(P(sx, sy));
		while (que.size())
		{
			P now = que.front();
			int tx = now.first;
			int ty = now.second;
			que.pop();
			if (cnt[tx][ty] == t) break;
			REP(i, 6)
			{
				int nx = tx + dx[i];
				int ny = ty + dy[i];
				if (fld[nx][ny]||cnt[nx][ny]!=INF) continue;
				que.push(P(nx, ny));
				cnt[nx][ny] = cnt[tx][ty] + 1;
			}
		}
		int ans = 0;
		REP(i, 200)REP(j, 200)
		{
			if (cnt[i][j] < INF) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1416
#include<stdio.h>

int main()
{
  int i;
  int n;

  int H[300]={};

  scanf("%d", &n);

  for(i = 1;i <= n;i++) scanf("%d", &H[i]);

  for(i = 1;i <= n;i++){
    printf("node %d: ", i);
    printf("key = %d, ", H[i]);
    if( i/2 >= 1 ) printf("parent key = %d, ", H[i/2]);
    if( i*2 <= n ) printf("left key = %d, ", H[i*2]);
    if( i*2+1 <= n ) printf("right key = %d, ", H[i*2+1]);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2104
import java.util.*;

public class Main {    
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
       
        int N = sc.nextInt();
       
        int a[] = new int[N];       
        
        for(int i = 0;i < N;i++){
            a[i] = sc.nextInt();
        }
        
        for(int i = 0;i < N;i++){
           if(a[i] == 2){
               break;
           }            
           if(a[i] != 2){
               continue;
           }else if(a[N-1] != 2){
               System.out.println(-1);
               return;
           }
       }

        int count = 1;

        int index = a[0];
        
        while(true){
           if(count > N){
               System.out.println(-1);
               return;
           }            
           if(index == 2){
               System.out.println(count);
               return;
           }else{           
              index = a[index-1];
              count++;
           }           
        }                
       
    }        
}        

Measured memory_bytes: 58704
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

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

    vector<int> v;

    int c = 0;
    if(a >= b){
        c = a;
    }
    else {
        c = b;
    }
    for(int i = 1; i <= c; i++){
        if(a % i == 0 && b % i == 0){
            //cout << i << endl;
            v.push_back(i);
        }
    }

    sort(v.begin(), v.end(), greater<int>());
    cout << v[k-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//ll mod = 1000000007;
ll mod = 998244353;

signed main()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>> vp(n);
    rep(i, n)
    {
        ll x, l;
        cin >> x >> l;
        vp[i] = {x + l, x - l};
    }
    sort(all(vp));
    ll l = -INT_MAX;
    ll ans = 0;
    rep(i, n)
    {
        if (vp[i].second >= l)
        {
            l = vp[i].first;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4816
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

struct q {
	int a, b;
};

bool cmp(q a, q b) {
	return a.b < b.b;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<q> a(n);
	for (q& i : a) cin >> i.a >> i.b;
	sort(all(a), cmp);
	ll t = 0;
	for (int i = 0; i < n; i++) {
		if (t + a[i].a <= a[i].b) {
			t += a[i].a;
		}
		else {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 1792
import sys


# ???????????????????§???¢?????§???
# https://ja.wikipedia.org/wiki/????§???¢
def is_rectangle(a, b, c):
    """ ????????¢?????§???
        4??????????§??????¨???90???
    """
    return a**2 + b**2 == c**2


def is_rhombus(a, b, c):
    """ ????????¢?????§???
        ??¨???????????????????????????????????????
    """
    return a==b


if __name__ == '__main__':
    rectangle_count = 0  # ???????????§???????????¢?????°
    rhombus_count = 0  # ???????????§???????????¢?????°

    # ??????????????\???
    for line in sys.stdin:
        a, b, c = [int(x) for x in line.strip().split(',')]

        # ????????¢???????????¢???????????????
        if is_rectangle(a, b, c):
            rectangle_count += 1
        if is_rhombus(a, b, c):
            rhombus_count += 1
    
    # ????????????????????????
    print('{0}\n{1}'.format(rectangle_count, rhombus_count))

Measured memory_bytes: 7708
#include <iostream>
using namespace std;
int main()
{
	int N, Y;
	cin >> N >> Y;
	int res10000 = -1, res5000 = -1, res1000 = -1;
	for (int a = 0; a <= N; a++)
	{
		for (int b = 0; b + a <= N; b++)
		{
			int c = N - a - b;
			int total = 10000 * a + 5000 * b + 1000 * c;
			if (total == Y)
			{
				res10000 = a;
				res5000 = b;
				res1000 = c;
			}
		}
	}
	cout << res10000 << " " << res5000 << " " << res1000 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
#include <set>
using namespace std;

const int maxn = 100010;

int n,m;
int x[maxn], y[maxn];
set<int> s[maxn];

void calc(int u)
{
	s[u].insert(u);
	for (int i=m;i>=1;i--)
	{
		if (s[u].count(x[i]) && s[u].count(y[i]))
		{
			s[u].clear();
			return;
		}
		if (s[u].count(x[i])) s[u].insert(y[i]);
		if (s[u].count(y[i])) s[u].insert(x[i]);
	}
}

bool check(int u, int v)
{
	if (s[u].size() == 0||s[v].size()==0) return false;
	for (set<int>::iterator it = s[v].begin(); it != s[v].end(); it++)
	{
		if (s[u].count((*it))) return false;
	}
	return true;
}

int main()
{
	//freopen("E.in","r",stdin);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d%d",&x[i],&y[i]);
		
	for (int i=1;i<=n;i++) calc(i);
	int ans = 0;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<i;j++)
		{
			if (check(i,j)) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5760
n,k = map(int,input().split()) 
A=list(map(int,input().split()) )

kyori = [-1] *len(A)

junban =[]

x=0
d=0
while kyori[x] == -1:
    
    junban.append(x)
    kyori[x]=d
    d+=1
    x=A[x]-1
    
    
roop_x = x
roop_d = d - kyori[x]

# for k in range(100):

if k<d:
    print(junban[k]+1)
    
else:
    
    k0 = kyori[x]
    k1 = (k-k0)%roop_d
    
    print(junban[k0+k1]+1)


Measured memory_bytes: 102848
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

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

const double PI = acos(-1.0);
int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double alpha = (H * 60 + M) / 720 * (PI * 2);
  double beta = M / 60 * (PI * 2);
  double theta = alpha - beta;
  double res = sqrt(A*A + B*B - 2.0*A*B*cos(theta));
  cout << fixed << setprecision(10) << res << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void solve() {

}

int main() {
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  rep(i,n) {
    if( i + 2 < n ) {
      if( s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' ) ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int fa[100010],sz[100010];
std::unordered_set<int>stA[100010],stB[100010];
std::queue<std::pair<int,int>>que;
int hd(int x){return fa[x]==x?x:fa[x]=hd(fa[x]);}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),a,b;
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<n;++i){
		a=gi(),b=gi();
		++sz[a],++sz[b];
		stA[a].insert(b);
		stA[b].insert(a);
	}
	for(int i=1;i<n;++i){
		a=gi(),b=gi();
		++sz[a],++sz[b];
		if(stA[a].count(b))que.push({a,b});
		else stB[a].insert(b),stB[b].insert(a);
	}
	for(int i=1;i<n;++i){
		if(que.empty())return puts("NO"),0;
		int a=que.front().first,b=que.front().second,A=hd(a),B=hd(b);que.pop();
		if(A==B){--i;continue;}
		if(sz[A]>sz[B])std::swap(A,B),std::swap(a,b);
		fa[A]=B;sz[B]+=sz[A];
		stA[A].erase(b);stB[A].erase(b);
		stA[B].erase(a);stB[B].erase(a);
		for(int j:stA[A]){
			j=hd(j);
			if(j==A||j==B)continue;
			if(stB[B].count(j))que.push({j,B});
			else{
				stA[j].erase(A);stA[j].insert(B);
				stA[B].insert(j);
			}
		}
		stA[A].clear();
		for(int j:stB[A]){
			j=hd(j);
			if(j==A||j==B)continue;
			if(stA[B].count(j))que.push({j,B});
			else{
				stB[j].erase(A);stB[j].insert(B);
				stB[B].insert(j);
			}
		}
		stB[A].clear();
	}
	return puts("YES"),0;
}


Measured memory_bytes: 34200
#include <bits/stdc++.h>
using namespace std;
int MAXNUM = 1e5 + 5;
int a[(int)(1e5 + 5)];
int main () {
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	int result = 0;
	for (int i = 0; i < MAXNUM-2; ++i)
	{
		int tmp = 0;
		tmp += a[i];
		tmp += a[i + 1];
		tmp += a[i + 2];
		result = max(result,tmp);
	}
	cout << result << endl;

}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,m;
    
    cin>>n>>m;

    li a[m];

    li sum=0;

    f(i,0,m-1)
    {
        cin>>a[i];
        sum+=a[i];
    }

    if(n>=sum)
        cout<<n-sum;
    else
        cout<<-1;

    return 0;
}

Measured memory_bytes: 3676
from math import gcd
n = int(input())
a = list(map(int,input().split()))
l = 0
r = 0
x = [0] * (n+1)
y = [0] * (n+1)
for i in range(n):
    x[i+1] = gcd(x[i],a[i])
for i in range(n)[::-1]:
    y[i] = gcd(y[i+1],a[i])
m = []
for i in range(n):
    m.append(gcd(x[i],y[i+1]))
print(max(m))

Measured memory_bytes: 24828
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> p(N), q(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> q.at(i);
  }
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    a.at(i) = i+1;
  }
  int num = 1;
  map<vector<int>, int> mp;
  do {
    mp[a] = num;
    num++;
  } while (next_permutation(a.begin(), a.end()));
  int ans = abs(mp[p] - mp[q]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3=y1-y2+x2;
  int y3=x2-x1+y2;
  int x4=x3-(x2-x1);
  int y4=y3-(y2-y1);
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<" "<<endl;
}

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


int main()
{
	int p, q, r;
	int max = 0;
	int time = 0;
	cin >> p >> q >> r;

	if (p > q)
	{
		max = p;
	}
	else
	{
		max = q;
	}

	if (max < r)
	{
		max = r;
	}

	time = p + q + r - max;
	cout << time;
}

Measured memory_bytes: 256