akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AFallingAsleep {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;

        vector<string> s(N);
        vector<int> t(N);
        REP(i, N) {
            cin >> s[i] >> t[i];
        }

        string target;
        cin >> target;

        bool ok = false;
        int res = 0;
        REP(i, N) {
            if (ok) res += t[i];
            if (s[i] == target) ok = true;
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AFallingAsleep solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char number[50000] = {0};
	int prime[5150];
	int i, j;
	int num;
	int counter;
	
	number[2] = 1;
	
	for (i = 3; i <= 50000; i += 2) number[i] = 1;
	
	for (i = 3; i * i<= 50000; i += 2){
		if (number[i] == 1){
			for (j = 2; i * j <= 50000; j++){
				number[i * j] = 0;
			}
		}
	}
	
	j = 0;
	for (i = 2; i <= 50000; i++){
		if (number[i] == 1){
			prime[j] = i;
			j++;
		}
	}
	
	while (1){
		
		scanf("%d", &num);
		
		if (num == 0){
			break;
		}
		
		counter = 0;
		for (i = 0; i < 5140; i++){
			if (prime[i] > num / 2){
				break;
			}
			if (num - prime[i] > 1 && number[num - prime[i]] == 1){
				counter++;
			}
			
		}
		
		printf("%d\n", counter);
	}
	
	return (0);
}

Measured memory_bytes: 480
#include<stdio.h>
int main(void)
{
	int q,c,a,n,m,i;
	scanf("%d",&q);
	for(i=0;i<q;i++){
		m=0;
		scanf("%d%d%d",&c,&a,&n);
		for(m=0;;m++){
			if(c>=1&&a>=1&&n>=1){
				c--;
				a--;
				n--;
			}
			else if(c>=2&&a>=1){
				c=c-2;
				a--;
			}
			else if(c>=3){
				c=c-3;
			}
			else{
				break;
			}
		}
		printf("%d\n",m);
	}
	return 0;
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

vector<string> v;
int n;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        sort(s.begin(), s.end());
        v.pb(s);
    }

    sort(v.begin(), v.end());
    v.pb("$");

    ll l = 0;
    ll r = 0;
    ll ans = 0;

    while(l < n) {
        while(v[l] == v[r]) r++;
        ll ok = r-l;
        ans += (ok*(ok-1))/2;
        l = r;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 7948
import math

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

MOD = 1000000007

dic1 = {}
a_zero = 0
b_zero = 0
both_zero = 0

for a, b in AB:
    if a == 0 and b != 0:
        a_zero += 1
    elif a != 0 and b == 0:
        b_zero += 1
    elif a == 0 and b == 0:
        both_zero += 1
    else:
        g = math.gcd(a, b)
        a //= g
        b //= g

        if b < 0:
            a, b = -a, -b

        if (a, b) in dic1:
            dic1[(a, b)] += 1
        else:
            dic1[(a, b)] = 1

pair = []
used = set()

for key, val in dic1.items():
    if key in used:
        continue

    a, b = key
    used.add((a, b))
    cnt = 0

    if a < 0:
        c, d = -b, -a
    else:
        c, d = b, a

    if (-c, d) in dic1:
        cnt += dic1.get((-c, d), 0)
        used.add((-c, d))

    pair.append((val, cnt))


all_cnt = 1
for cnt1, cnt2 in pair:
    all_cnt *= pow(2, cnt1, MOD) + pow(2, cnt2, MOD) - 1
    all_cnt %= MOD

all_cnt *= pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
all_cnt %= MOD

all_cnt += both_zero
all_cnt %= MOD

print((all_cnt - 1) % MOD)


Measured memory_bytes: 121848
#include<iostream>
using namespace std;
int main(){

	int x[10001],i,n,min=1000001,max=-1000001;
	long long wa=0;
	cin>>n;



	for(i=0;i<n;i++)
	{

		cin>>x[i];
		if(min>x[i]){
			min=x[i];
		}
		if(max<=x[i]){
			max=x[i];
		}

		wa+=x[i];

	}
	cout<<min<<" "<<max<<" "<<wa<<endl;



	return 0;
}


Measured memory_bytes: 3136
/*
        Author: Prokash
                CSE48, JU

*/

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

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int ara[2005];
int main()
{
    FAST;
    int n,in,ans=0;
    cin>>n;
    vector<int>v(n);
    map<int,int>mp;
    map<int,int>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        mp[v[i]]++;
    }
    for(it=mp.begin();it!=mp.end();it++)
    {
        if((it->second)<(it->first))
        {
            ans+=(it->second);
        }
        else
        {
            ans+=((it->second)-(it->first));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {

    int N, M; cin >> N >> M;
    vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i];
    map<long long, int, greater<long long>> D;
    for (int i = 0; i < M; ++i) {
        int b, c; cin >> b >> c;
        D[c] += b;
    }


    sort(A.begin(), A.end());

    long long res = 0;
    int change_sum = 0;

    for (auto x : D) {
        int j = lower_bound(A.begin(), A.end(), x.first) - A.begin();
        int change_count = min(x.second,  max(0, j - change_sum));
        res += x.first * change_count;
        change_sum += change_count;
    }

    for (int i = change_sum; i < N; ++i) res += A[i];
    cout << res << endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>S;
    N = S.size();
    ll blue_sum = 0;
    rep(i,N) blue_sum += S[i] - '0';
    mat dp(N*2 + 1, vec(blue_sum + 1, 0));
    //dp[i][b]:今まででb個の青ボールを使う
    dp[0][0] = 1;
    ll b = 0, r = 0; //各々使える最大値
    rep(i,N*2){
        if(i < N) {
            b += S[i] - '0';
            r += '2' - S[i];
        }
        reps(j, max(0LL, (i+1) - r), b + 1){
            dp[i+1][j] = dp[i][j];
            if(j > 0) (dp[i+1][j] += dp[i][j-1])%=MOD;
        }
    }
    cout<<dp[N*2][blue_sum]<<endl;
}

Measured memory_bytes: 125312
import sys

s=list(map(int,list(input())))
n=len(s)
if s[0]==0 or s[-1]==1:
    print(-1)
    sys.exit()
for i in range(n//2):
    if s[i]==s[n-2-i]:
        continue
    else:
        print(-1)
        sys.exit()
ans=[[1,2]]
last_edge=2
for i in range(3,n+1):
    ans.append([last_edge,i])
    if s[i-2]==1:
        last_edge=i
for u in ans:
    print(*u)

Measured memory_bytes: 62584
d_arr = []
d_arr.append(int(input()))
d_arr.append(int(input()))
d_arr.append(int(input()))
d_arr.append(int(input()))
d_arr.append(int(input()))

d_arr.sort(key=lambda x:(10-(x%10))%10)
print(sum([((x-1)//10+1)*10 for x in d_arr[:4]])+d_arr[4])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> v, w;
  v.push_back(X);
  w.push_back(Y);
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  rep(i,M){
    int a;
    cin >> a;
    w.push_back(a);
  }

  sort(ALLOF(v));
  sort(ALLOF(w));

  if(v[v.size()-1] < w[0]) cout << "No War" << endl;
  else cout << "War" << endl;

  return 0;
}



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

using namespace std;


bool fun(int m[][3],int num[],int n){
    
int a[3][3];
for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        a[i][j]=0;
    }
}

for(int k=0;k<n;k++){
    int temp=num[k];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(temp==m[i][j]){
                a[i][j]=1;
            }
        }
    }
    
}

if(a[0][0]==1 && a[1][1]==1 && a[2][2]==1){
     return true ;
}
else if(a[0][2]==1 && a[1][1]==1 && a[2][0]==1){
   // cout<<"Yes"; 
   return  true;
}

for(int i=0;i<3;i++){
    if(a[i][0]==1 && a[i][1]==1 && a[i][2]==1){
       // cout<<"Yes";
       return true ;
    }
}
for(int i=0;i<3;i++){
    if(a[0][i]==1 && a[1][i]==1 && a[2][i]==1){
        //cout<<"Yes";
        return true ;
    }
}

return false;
}

int main(){
    

int m[3][3];
for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        cin>>m[i][j];
        //a[i][j]=1;
    }
}

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

if(fun(m,num,n)){
    cout<<"Yes";
}
else{
    cout<<"No";
}

return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int N;
	while( cin >> N && N ){
		while( N-- > 0 ){
			int num1 = 0, num2 = 0;
			unsigned char mcxi1[9], mcxi2[9];
			cin >> mcxi1 >> mcxi2;
			for( size_t i = 0; mcxi1[i] != '\0'; i++ ){
				if( '2' <= mcxi1[i] && mcxi1[i] <= '9' ){
					if( mcxi1[i+1] == 'm' ){ num1 += 1000 * (int)( mcxi1[i] - '0' ); }
					else if( mcxi1[i+1] == 'c' ){ num1 += 100 * (int)( mcxi1[i] - '0' ); }
					else if( mcxi1[i+1] == 'x' ){ num1 += 10 * (int)( mcxi1[i] - '0' ); }
					else if( mcxi1[i+1] == 'i' ){ num1 += 1 * (int)( mcxi1[i] - '0' ); }
					i++;
				}else{
					if( mcxi1[i] == 'm' ){ num1 += 1000; }
					else if( mcxi1[i] == 'c' ){ num1 += 100; }
					else if( mcxi1[i] == 'x' ){ num1 += 10; }
					else if( mcxi1[i] == 'i' ){ num1 += 1; }
				}
			}
			for( size_t i = 0; mcxi2[i] != '\0'; i++ ){
				if( '2' <= mcxi2[i] && mcxi2[i] <= '9' ){
					if( mcxi2[i+1] == 'm' ){ num2 += 1000 * (int)( mcxi2[i] - '0' ); }
					else if( mcxi2[i+1] == 'c' ){ num2 += 100 * (int)( mcxi2[i] - '0' ); }
					else if( mcxi2[i+1] == 'x' ){ num2 += 10 * (int)( mcxi2[i] - '0' ); }
					else if( mcxi2[i+1] == 'i' ){ num2 += 1 * (int)( mcxi2[i] - '0' ); }
					i++;
				}else{
					if( mcxi2[i] == 'm' ){ num2 += 1000; }
					else if( mcxi2[i] == 'c' ){ num2 += 100; }
					else if( mcxi2[i] == 'x' ){ num2 += 10; }
					else if( mcxi2[i] == 'i' ){ num2 += 1; }
				}
			}
			int a = num1 + num2;
			char ans[8];
			int i = 0;
			if( a / 1000 > 1 ){
				ans[i++] = a/1000 + '0';
				ans[i++] = 'm';
			}
			if( a / 1000 == 1 ){ ans[i++] = 'm'; }
			a %= 1000;

			if( a / 100 > 1 ){
				ans[i++] = a/100 + '0';
				ans[i++] = 'c';
			}
			if( a / 100 == 1 ){ ans[i++] = 'c'; }
			a %= 100;

			if( a / 10 > 1 ){
				ans[i++] = a/10 + '0';
				ans[i++] = 'x';
			}
			if( a / 10 == 1 ){ ans[i++] = 'x'; }
			a %= 10;

			if( a > 1 ){
				ans[i++] = a + '0';
				ans[i++] = 'i';
			}
			if( a == 1 ){ ans[i++] = 'i'; }
			ans[i] = '\0';
			cout << ans << endl;
		}
	}
}

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

typedef long long ll;

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0);

int main()
{
  ll a, b ;
  cin >> a >> b ;
  if(a * 500 >= b)  cout << "Yes" << endl ;
  else  cout << "No" << endl ;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define maxof(a,b,c) max(max(a,b),c)
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-maxof(a,b,c)+maxof(a,b,c)*10<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,A[200010]{};
  cin>>N>>K;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a-1]++;
  }
  sort(A,A+N);
  int ans=0;
  for(int i=0;i<N-K;i++)ans+=A[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 4420
function Main(inputs) {
	const inputlines = inputs.split("\n");
 	const testcase = inputlines[0];
  
  	let counts = ["AC", "WA", "TLE", "RE"];
  	counts["AC"] = counts["WA"] = counts["TLE"] = counts["RE"] = 0;
  
	for(let i=1;i <= testcase;i++){
  		let key = inputlines[i];
  		counts[key] = (counts[key])? counts[key] + 1 : 1 ;
	}
  
  	console.log("AC x "+counts['AC']);
	console.log("WA x "+counts['WA']);
  	console.log("TLE x "+counts['TLE']);
  	console.log("RE x "+counts['RE']);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37320
main = do
    [n,p] <- ((fmap read . words) <$> getLine) :: IO [Int]
    let mbi = ceiling $ nroot n (maxBound::Int)
    print $ solve mbi n p (ceiling $ nroot n p)


nroot :: Int -> Int -> Double
nroot n x = ((fromIntegral x) ** (1/(fromIntegral n)))

solve :: Int -> Int -> Int -> Int -> Int
solve _   1 p _  = p
solve mbi n p ac =
    case ac < mbi && ac^n <= p && p `mod` ac^n == 0 of
        True  -> ac
        False -> solve mbi n p (ac - 1)

Measured memory_bytes: 508
#include <iostream>
#include <string.h>

using namespace std;

#define size 50

int main(){
	char O[size], E[size];

	scanf("%s", O);
	scanf("%s", E);

	for(int i = 0; i < (int)(strlen(O)); i++){
		if(E[i] == '\0'){
			printf("%c", O[i]);
		}else{
			printf("%c%c", O[i], E[i]);
		}
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

struct Point {
    x: i16,
    y: i16,
}

impl Point {
    fn new(x: i16, y: i16) -> Point {
        Point { x: x, y: y }
    }
}

struct Vector2D {
    x: i16,
    y: i16,
}

impl Vector2D {
    fn new(x: i16, y: i16) -> Vector2D {
        Vector2D { x: x, y: y }
    }
}

fn main() {
    let line: Vec<i16> = read_vec();
    let a = Point::new(line[0], line[1]);
    let b = Point::new(line[2], line[3]);
    let v = calc_vector(&a, &b);
    let v2 = rotation_vector(&v);
    let c = add_vector(&b, &v2);
    let d = add_vector(&c, &rotation_vector(&v2));
    println!("{} {} {} {}", c.x, c.y, d.x, d.y);
}

fn calc_vector(a: &Point, b: &Point) -> Vector2D {
    Vector2D::new(b.x - a.x, b.y - a.y)
}

fn rotation_vector(v: &Vector2D) -> Vector2D {
    Vector2D::new(v.y * -1, v.x)
}

fn add_vector(p: &Point, v: &Vector2D) -> Point {
    Point::new(p.x + v.x, p.y + v.y)
}


Measured memory_bytes: 4352
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
namespace IO{
	const int BS=(1<<21)+3; LL Top=0; char Buffer[BS],*HD,*TL,SS[20];
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	int read(){
		int nm=0; char cw=Getchar(); for(;!isdigit(cw);cw=Getchar());
		for(;isdigit(cw);cw=Getchar()) nm=nm*10+(cw-'0'); return nm;
	}
} using namespace IO;
int n,m,dt[M]; LL tot,s[M],ans;
int main(){
	n=read(),m=read();
	for(register int last=read(),i=1,x;i<n;last=x,i++){
		x=read(),dt[last+2]++;
		if(last<x) dt[x+1]--,tot+=x-last,s[x+1]-=x-last-1;
		else tot+=x+m-last,dt[1]++,dt[x+1]--,s[1]+=m-last-1,s[x+1]-=m+x-last-1;
	} ans=tot;
	for(register int i=1;i<=m;i++) dt[i]+=dt[i-1],s[i]+=s[i-1]+dt[i],ans=min(ans,tot-s[i]);
	printf("%lld\n",ans); return 0;
}

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

int main() {
  int n;
  cin >> n;
  int sum = 0;
  vector<int> T(n);
  rep(i,n){
    cin >> T[i];
    sum += T[i];
  }
  int m;
  cin >> m;
  rep(i,m){
    int p, x;
    cin >> p >> x;
    p--;
    int ans = sum - T[p] + x;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
use std::io;

fn right_triangle() -> u32 {
    let mut abc = String::new();
    io::stdin().read_line(&mut abc).unwrap();
    let abc: Vec<u32> = abc.trim_right()
        .split_whitespace()
        .map(|e| e.parse::<u32>().unwrap())
        .collect();
    abc[0] * abc[1] / 2
}

fn main() {
    let ans = right_triangle();
    println!("{}", ans);
}

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

int main() {
  int N; cin >> N; // 支払う額
  int A; cin >> A; // 持ってる１円玉
  
  int x; // 必要な１円玉
    
  x = N % 500;
  
  if ( x > A ) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }


}



Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = stdIn.nextInt();


		if(n % 10 == 3) {

			System.out.println("bon");
		} else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
			System.out.println("pon");
		} else {
			System.out.println("hon");
		}

		stdIn.close();
	}
}


Measured memory_bytes: 35768
# 頂点の数（N）および辺の数（M）を入力する
N, M = map(int, input().split())

# 辺の長さを格納する辞書（dic_edge_dist）を設定する
dic_edge_dist = {(i, j) : float("inf") for i in range(1, N + 1) for j in range(1, N + 1)}
for i in range(1, N + 1):
    dic_edge_dist[(i, i)] = 0
# 辺を格納するリスト（list_edge）を設定する
list_edge = []

def warshall_floyd(dic_edge_dist):
    dic_shortest_dist = dic_edge_dist.copy()
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                dic_shortest_dist[(j, k)] = min(dic_shortest_dist[(j, k)], dic_shortest_dist[(j, i)] + dic_shortest_dist[(i, k)])
    return dic_shortest_dist

# 各辺について、、
for _ in range(M):
    # 頂点および辺の長さを入力する
    a, b, c = map(int, input().split())
    # dic_edge_distに辺の長さを格納する
    dic_edge_dist[(a, b)] = c
    dic_edge_dist[(b, a)] = c
    # list_edgeに辺を格納する
    list_edge.append((min(a, b), max(a, b)))

dic_shortest_dist = warshall_floyd(dic_edge_dist)
    
edge_count = 0
for i, j in list_edge:
    for k in range(1, N + 1):
        if dic_shortest_dist[(k, i)] + dic_edge_dist[(i, j)] == dic_shortest_dist[(k, j)]:
            edge_count += 1
            break
        if dic_shortest_dist[(k, j)] + dic_edge_dist[(j, i)] == dic_shortest_dist[(k, i)]:
            edge_count += 1
            break

print(len(list_edge) - edge_count)

Measured memory_bytes: 5496
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/bellman_ford_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <iomanip>      // std::setprecision

#define REP(i, N) for(int i=0; i<(N); i++)
using namespace std;
using namespace boost::math;

int main() {
	int N;

	cin >> N;
    multiset<double> v;
    double r = 0.0;
  
    REP(i, N) {
      int j;
      cin >> j;
      v.insert(j);
    }
  
    REP(i, N-1) {
      auto ms = 10000000.0;
      auto it = v.begin(), mit = ++v.begin();
      
      
      auto nv = (*mit + *(--mit)) / 2.0;
      v.erase(mit++);
      v.erase(mit);
      v.insert(nv);
    }

	cout << std::setprecision(9) << *v.begin() << endl;

	return 0;
}


Measured memory_bytes: 256
function Main(input) {
  var X = parseInt(input.split(/\n| /)[0]);
  var N = parseInt(input.split(/\n| /)[1]);
  var p = input.split("\n")[1].split(" ").map(n => parseInt(n));
 

  if (N === 0) {
    console.log(X);
  } else {
    for(i = X; i >= -100; i--){
      if(p.indexOf(i) === -1){
        console.log(i);
        break;
      } else if( p.indexOf(2 * X - i) === -1){
          console.log(2 * X - i);
          break;
        }
      }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29716
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,k;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	int ans=0;
	while(n)
	{
		ans++;
		n/=k;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    ab: [(usize, i64); n],
  }
  let mut ab = ab;
  ab.sort_by_key(|&(a, _)| - (a as i32));
  use std::collections::BinaryHeap;
  let mut que = BinaryHeap::new();
  let mut sum = 0;
  for day in 1 .. m + 1 {
    while let Some(&(a, b)) = ab.last() {
      if a > day {
        break;
      }
      que.push(b);
      ab.pop();
    }
    if let Some(b) = que.pop() {
      sum += b;
    }
  }

  puts!("{}\n", sum);
}


Measured memory_bytes: 10492
import math

A,B,H,M = map(int,input().split())

angle = (H*30 + 30*(M/60))-M*6
abs_angle = abs(angle)

if abs_angle >180:
  abs_angle = 360 - abs_angle

abs_angle = math.cos(math.radians(abs_angle))
ans_sqrt = A**2 + B**2 - 2*A*B*abs_angle

print(math.sqrt(ans_sqrt))

Measured memory_bytes: 9440
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

void solve(){
  int k, a, b; cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK\n";
      return;
    }
  }
  cout << "NG\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc;
	public void run(){
		sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			int n = sc.nextInt();
			if(n != 0){
				calc(n);
			}
			else{
				break;
			}
		}
	}
	public void calc(int n){
		int[] satis = new int[n];
		ArrayList<int[]> list = new ArrayList<int[]>();
		for(int i = 0; i < n; i++){
			int m = sc.nextInt();
			int s = sc.nextInt();
			satis[i] = s;
			int[] times = new int[22];
			for(int j = 0; j < m; j++){
				int start = sc.nextInt();
				int end = sc.nextInt();
				for(int k = start; k < end; k++){
					times[k] = 1;
				}
			}
			list.add(times);
		}
		
		ArrayList<Integer> person = new ArrayList<Integer>();
		ArrayList<Integer> satisfaction = new ArrayList<Integer>();
		ArrayList<int[]> schedule = new ArrayList<int[]>();
		
		person.add(-1);
		satisfaction.add(0);
		schedule.add(new int[22]);
		
		int maxSatis = 0;
		
		while(person.size() != 0){
			int nowPerson = person.get(0);
			person.remove(0);
			int nowSatisfaction = satisfaction.get(0);
			satisfaction.remove(0);
			int[] nowSchedule = schedule.get(0);
			schedule.remove(0);
			
			if(nowPerson == n-1){
				if(maxSatis < nowSatisfaction) maxSatis = nowSatisfaction;
			}
			else{
				for(int i = nowPerson + 1; i < n; i++){
					int[] newPersonSchedule = list.get(i);
					int[] newSchedule = new int[22];
					boolean ok = true;
					for(int t = 6; t < 22; t++){
						if(newPersonSchedule[t] == 1 && nowSchedule[t] == 1){
							if(maxSatis < nowSatisfaction) maxSatis = nowSatisfaction;
							ok = false;
							break;
						}
						else if(newPersonSchedule[t] == 1 || nowSchedule[t] == 1){
							newSchedule[t] = 1;
						}
					}
					if(ok){
						person.add(i);
						satisfaction.add(nowSatisfaction + satis[i]);
						schedule.add(newSchedule);
					}
				}
			}
		}
		System.out.println(maxSatis);
	}
	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 62528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("YES\n")
#define outn printf("NO\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
/*------------------------------------------------------------*/
int a[maxn],b[maxn],c[maxn];
//__int128 ans=0;
//void print(__int128 ans){
//	if(ans==0)return ;
//	print(ans/10);
//	putchar(ans%10+'0');
//}
ll ans=0;
int main(){
	int n;
	in(n);
	FOR(i,1,n)in(a[i]);
	sort(a+1,a+n+1);
	FOR(i,1,n)in(b[i]);
	sort(b+1,b+n+1);
	FOR(i,1,n)in(c[i]);
	sort(c+1,c+n+1);
	int c1=0,c2=1;
	FOR(i,1,n){
		while(c1<n&&b[i]>a[c1+1])c1++;
		while(c2<=n&&b[i]>=c[c2])c2++;
		ans+=(ll)c1*(ll)(n-c2+1);
	}
//	print(ans);
	outl(ans);
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();

        int answer = (new int[] { a, b, c }).Distinct().Count();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;



public class Main {
	
	InputUtil in = new InputUtil();

	public static void main(String[] args) throws IOException {
		new Main().exec();
	}

	public void exec() throws IOException {
		PrintWriter out = new PrintWriter(System.out);
		int H = in.nextInt();
		int[] heapData = in.nextInt(new int[H+1],1,H);
		MaximumHeap mh = new MaximumHeap(heapData);
		out.print(' ');
		OutputUtil.output(out, mh.getAll(), 1, H, " ");
		out.flush();
	}

	
}

class BinaryHeap {
	protected int[] data = null;
	
	public BinaryHeap(int[] data) {
		this.data = data;
	}
	
	public int[] getAll() {
		return data;
	}

	public int getParent(int i){
		if(i<=1 || data.length<=i) return -1;
		return i/2;
	}

	public int getLeft(int i){
		int leftId = i*2;
		return (i<=0 || data.length<=leftId) ? -1 : leftId;
	}

	public int getRight(int i){
		int rightId = i*2 + 1;
		return (i<=0 || data.length<=rightId) ? -1 :rightId;
	}
}

class MaximumHeap extends BinaryHeap {	
	
	public MaximumHeap(int[] data) {
		super(data);
		this.buildMaxHeap();
	}
	
	protected void maxHeapify(int i) {
		int leftId = getLeft(i);
		int rightId = getRight(i);
		int largest = i;
		if(leftId != -1 && data[largest] < data[leftId]) largest = leftId;
		if(rightId != -1 && data[largest] < data[rightId]) largest = rightId;
		if(largest != i){
			data[0] = data[i]; data[i] = data[largest]; data[largest] = data[0];
			maxHeapify(largest);
		}
	}
	
	public void buildMaxHeap() {
		for(int i=(data.length-1)/2; i>=1; i--)
			maxHeapify(i);
			
	}
	
}


class OutputUtil {
	public static final String EOF = System.lineSeparator();

	public static void output(PrintWriter out, int[] a, int off, int len, String delim) {
		out.print(a[off]);
		for(int i=off+1; i<off+len; i++){
			out.print(delim);
			out.print(a[i]);
		}
		out.println("");
		out.flush();
	}
}


class InputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int nextInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] nextInt(int[] a, int off, int num) throws NumberFormatException, IOException{
        int i=off;
        while(i<off+num) {
            for(String s: br.readLine().split(" ")){
            	if(i<off+num) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
}

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

using namespace std;

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


int main() {
    int n; cin >> n;
    vector<int> arr(n+1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    vector<int> dp(n+1, 0);
    dp[2] = abs(arr[2] - arr[1]);
    for (int i = 3; i <= n; i++) {
        dp[i] = min((dp[i-1] + abs(arr[i]-arr[i-1])),(dp[i-2]+abs(arr[i]-arr[i-2])));
    }
    cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
like = [0 for _ in range(m + 1)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in tmp[1:]:
        like[j] += 1
ans = 0
for i in like:
    if i == n:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void)
{

	int a, b, c;
	int yakusu_cnt = 0;

	cin >> a >> b >> c;

	for(int i = a; i <= b; i++)
	{
		if( c % i == 0)
		{
			yakusu_cnt++;
		}
	}
	cout << yakusu_cnt << endl;

	return 0;
}

Measured memory_bytes: 1164
import sys
from collections import Counter

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    w = input()
    cnt = Counter(w)

    for a in cnt.values():
        if a % 2:
            print('No')
            return 

    print('Yes')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();
		sc.close();

		int y = (n + x - 1) / x;
		System.out.println(y * t);
	}
}


Measured memory_bytes: 35608
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, q = map(int, input().split())
s=input().rstrip("\n")

cnt=[0]
c=0
for i in range(n-1):
    if s[i:i+2]=="AC":
        c+=1
    cnt.append(c)
#print(cnt)
for i in range(q):
    l, r = map(int, input().split())
    print(cnt[r-1]-cnt[l-1])

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  //ll n; cin>>n;
  ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  //cout<<<<endl;
  if(a<=5)cout<<0<<endl;
  else if(a>=13)cout<<b<<endl;
  else cout<<b/2<<endl;

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri(), h = ri(), w = ri();
	cout << (n-h+1)*(n-w+1) << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
t = [[0, 0, 0]]
n.times do |i|
  t << gets.chomp.split(' ').map(&:to_i) 
end
ans = true
1.upto(n) do |i|
  time = t[i][0] - t[i - 1][0]
  dist = (t[i][1] - t[i - 1][1]).abs + (t[i][2] - t[i - 1][2]).abs
  ans = false unless time >= dist && time % 2 == dist % 2
end
puts ans ? "Yes" : "No"


Measured memory_bytes: 9468
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

	int N; cin >> N;
    int tmp;
	map<int,int> m; 
    REP (i, N) {
        cin >> tmp; 
        m[tmp]++;
    }
    
    int Sum = 0;
    int k,v;
    for (const auto& kv : m) {
        k = kv.first;
        v = kv.second;
        if (v > k) Sum += v - k; 
        else if (v != k) Sum += v;
    }

    cout << Sum;

    return 0;
}

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

int main() {
        string s;
        cin >> s;
        int ans = 0;
        for (int i = 0; i < s.size(); i ++) {
                if (i % 2 == 1 && s[i] == 'g') ans ++;
                if (i % 2 == 0 && s[i] == 'p') ans --;
        }
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 512
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var N = Number.parseInt(inputStr[0]);
  var A = [];
  var fst = 0;
  var snd = 0;
  var now = 0;
  //パラメータを配列に確保しつつ最大値と２番目の値を変数に格納
  for( i=0 ; i<N ; i++ ){
    inputStr = input[i+1].split(" ");
    now = Number.parseInt(inputStr[0]);
    A.push(now);
    if( snd <= now ){
      snd = now;
    }
    if( fst <= now ){
      snd = fst;
      fst = now;
    }
  }
  //結果表示
  for( j = 0 ; j < N ; j++){
    if( A[j] === fst ){
      console.log(snd);
    } else {
      console.log(fst);
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

string s;
int main(){
	cin >> s;
	string temp = s;
	reverse(all(temp));
	int ans = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] != temp[i]){
			ans++;
			// cout << s[i] << " " << temp[i] << endl;
		}

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


Measured memory_bytes: 256
n,m = map(int,input().split())
c = list(range(n+1))
k = n
a = []
for i in range(n+1):
  a.append([i])
  
#print(a)
for i in range(m):
    x,y,z = map(int,input().split())
    t = c[x]
    s = c[y]
    if t == s:
        continue
    
    if len(a[s]) > len(a[t]):
        t,s = s,t
    a[t] += a[s]
    for z in a[s]:
        c[z] = t
    a[s] = []
    k -= 1
    
print(k)    
    
    
  
  


Measured memory_bytes: 21620
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif
int val(char c) {
    if (c >= '0' && c <= '9')
        return (int)c - '0';
    else
        return (int)c - 'A' + 10;
}
 
int toDeci(string str, int base) {
    int len = str.size();
    int power = 1; // Initialize power of base
    int num = 0;  // Initialize result
    int i;
    // Decimal equivalent is str[len-1]*1 +
    // str[len-1]*base + str[len-1]*(base^2) + ...
    for (i = len - 1; i >= 0; i--) {
        // A digit in input number must be
        // less than number's base
        if (val(str[i]) >= base) {
           throw invalid_argument("Invalid Number");
        }
        num += val(str[i]) * power;
        power = power * base;
    }
    return num;
}
 
char reVal(int num) {
    if (num >= 0 && num <= 9)
        return (char)(num + '0');
    else
        return (char)(num - 10 + 'A');
}
string fromDeci(int base, int inputNum) {
    string res;
    while (inputNum > 0) {
        res.push_back(reVal(inputNum % base));
        inputNum /= base;
    }
    reverse(res.begin(), res.end());
    return res;
}
// yeah this is very extra
int32_t main() {
	IAMSPEED
	ll n,k; cin >> n >> k;
	cout<<fromDeci(k,n).size();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L


int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < n-1; i++) {
        int x, y, k;
        cin >> x >> y >> k;
        x--;y--;
        g[x].push_back(make_pair(y, k));
        g[y].push_back(make_pair(x, k));
    }
    pair<int,int> start = g[0][0];
    for (int i = 0; i < n; i++) {
        if (g[i].size() == 1) {
            start = g[i][0];
            break;
        }
    }
    queue<pair<int, int>> q;
    q.push(start);
    vector<bool> visited(n);
    visited[start.first] = true;
    vector<int> color(n);
    while (!q.empty()) {
        pair<int,int> pp = q.front();
        q.pop();
        int u = pp.first, length = pp.second;
        for (auto v : g[u]) {
            int y = v.first;
            if (visited[y]) continue;
            int length1 = v.second;
            q.push(v);
            if (length1 % 2 == 0) color[y] = color[u];
            else color[y] = color[u] ^ 1;
            visited[y] = true;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << color[i] << "\n";
    }


    return 0;
}

Measured memory_bytes: 9556
#include<bits/stdc++.h>
 using namespace std;
 #define rep(i,n) for(int i=0;i<n;++i)
 #define all(v) v.begin(), v.end()
 typedef long long int ll;
 typedef unsigned long long ull;
 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;}
 typedef pair<ll,ll> P;
 const long long MOD = 1e9+7;
 const ll INF = 1LL << 60;

 int main(){
     string a;
     cin >> a;
     if(islower(a[0])){
         cout << "a" << endl;
     }else{
         cout << "A" << endl;
     }



 }


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    if (a[0] == 0 && a.front() == a.back()){
        cout << "Yes" << endl;
        return 0;
    }
    if (n % 3){
        cout << "No" << endl;
        return 0;
    }
    else {
        set<int> s;
        for (int i = 0; i < n; i++) s.insert(a[i]);
        if (s.size() == 2) {
            int cnt = 0;
            for (int i = 0; i < n; i++) if (a[i] == 0) cnt++;
            if (n / 3 == cnt) cout << "Yes" << endl;
            else cout << "No" << endl;
            return 0;
        }
        if (s.size() != 3){
            cout << "No" << endl;
            return 0;
        }
        vector<int> x(3);
        int now = 0;
        for (auto itr = s.begin(); itr != s.end(); itr++){
            x[now] = *itr;
            now++;   
        }
        vector<int> num(3, 0);
        for (int i = 0; i < n; i++){
            for (int j = 0; j < 3; j++){
                if (x[j] == a[i]) num[j]++;
            }
        }
        if (num[0] != num[1] || num[1] != num[2] || num[2] != num[0]){
            cout << "No" << endl;
            return 0;
        }
        bool flag = true;
        for (int i = 0; i < 3; i++){
            for (int j = i + 1; j < 3; j++){
                if ((x[i] ^ x[j]) != x[3 - i - j]) flag = false;
            }
        }
        if (flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int jd(vi D, int N){
  while(N > 0){
    for(int x : D){
      if (N%10 == x ){
        return 0;
      }
    }
    N /= 10;
  } 
  return 1;
}


int main() {
  int N, K; cin >> N >> K;
  vi D(K); rep(i,K) cin >> D[i];
  int ans=0;
  while(ans <= 0){
    ans = jd(D, N);
    if(ans==0) N++;
  }  
  cout << N << endl;
}


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

long long n,i,tmp,total;
string s[100002];

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

	cin>>n;
	for(i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}

	sort(s,s+n);

	total=0; tmp=1;
	for(i=1;i<n;i++){
		if(s[i]==s[i-1])tmp++;
		else{
			total+=(tmp*(tmp-1)/2);
			tmp=1;
		}

		if(i==n-1)total+=(tmp*(tmp-1)/2);
	}
	cout<<total<<"\n";

}

Measured memory_bytes: 5760