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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int n,m;
    cin >> n >> m;

    pii op[m]; // (C,B);
    priority_queue <int,vector<int>,greater<int>> pq;
    for (int i=0;i<n;i++){
        int tm;
        cin >> tm;
        pq.push(tm);
    }

    for (int i=0;i<m;i++){
        int b,c;
        cin >> b >> c;
        op[i]=mp(c,b);
    }

    sort(op,op+m,greater<pii>());

    for (int i=0;i<m;i++){
        int cnt=0;
        while (cnt<op[i].se && op[i].fi>pq.top()){
            pq.pop();
            pq.push(op[i].fi);
            cnt++;
        }
    }

    ll tot=0;
    while (!pq.empty()){
        tot+=(ll)pq.top();
        pq.pop();
    }

    cout << tot << el;

    return 0;
}

Measured memory_bytes: 1660
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
S = readline().decode()
prev = ''
total = 0
for c in S:
    if prev == c:
        total += 1
    prev = c

print(min(N - 1, total + K * 2))


Measured memory_bytes: 3564
#!/usr/bin/perl

use strict;
use warnings;

my $n = int(<STDIN>);
my @p = split(/\s+/, <STDIN>);
for (my $i = 0; $i < @p; $i++) {
	$p[$i] = int($p[$i]);
}

my $count = 0;

for (my $i = 1; $i < $n - 1; $i++) {
	my @d = ($p[$i-1], $p[$i], $p[$i+1]);
	my @dd = sort { $a <=> $b } @d;
	if ($dd[1] == $p[$i]) { $count++; }
}

print "$count\n";


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        if ((i % 3 != 0) && (i % 5 != 0))
            ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

int main(){
	int n;
	int x;
	vector<int> L;

	cin >> n;
	cin >> x;

	for (size_t i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		L.push_back(tmp);
	}

	int cnt = 1;
	int sum = 0;

	for (size_t i = 0; i < n; ++i) {
		sum += L.at(i);
		if (sum < x + 1) {
			cnt++;
		}
	}

	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
#include <string>
using namespace std;

inline namespace atcoder {
    using i32 = int32_t; using u32 = uint32_t;
    using i64 = int64_t; using u64 = uint64_t;
    using f32 = float; using f64 = double;

    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    for (int i = 0; i < n; ++i, ++ans) {
        while (i < n - 1 && s[i] == s[i + 1]) ++i;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3736
from collections import deque
H,W = map(int,input().split())
s = [input() for _ in range(H)]

dist = [[0]*W for _ in range(H)]
count = 0

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':  # 黒マスだった場合
            dist[i][j] = -1
        else:
            count += 1
dist[0][0] = 1  # スタートを１に更新

move = deque()
move.append((0,0))

def bfs(move, dist):
    while move:
        y,x = move.popleft()
        d = dist[y][x]
        for dy,dx in ((0,1), (0,-1), (1,0), (-1,0)):
            new_y = y + dy
            new_x = x + dx
            if new_y < 0 or new_y >= H or new_x < 0 or new_x >= W:
                continue
            if dist[new_y][new_x] == 0:  # セルが未到達のとき
                dist[new_y][new_x] = d+1
                move.append((new_y,new_x))
    return dist[H-1][W-1]
move_score = bfs(move,dist)
if move_score == 0:
    print(-1)
else:
    print(count - move_score)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <stdio.h>
#include <unordered_map>
using namespace std;

template<class InputIterator, class T>
InputIterator find(InputIterator begin, InputIterator end, const T& value) {
	for (; begin != end; ++begin) {
		if (*begin == value) return begin;
	}
	return end;
}

int main(void)
{
	int n;
	bool flag = true;
	vector<string> vec;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		string str;
		cin >> str;
		if (i != 0) {
			if (vec[i - 1].at(vec[i - 1].size() - 1) != str.at(0) || find(vec.begin(), vec.end(), str) != vec.end()) {
				flag = false;
			}
		}
		vec.emplace_back(str);
	} 
	if (flag) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


	return 0;
}

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

using namespace std;


int main()
{


	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/

	int k;
	int a, b;
	int cnt = 0;

	cin >> k >> a >> b;

	for (int i = a; i <= b; i++)
	{
		if (i % k == 0 )
		{
			cnt++;
		}
	}
	if (cnt > 0)
	{
		cout << "OK";
	}

	else
	{
		cout << "NG";
	}




}

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

struct Participant {
	int point;
	int answer;
};

int main() {
	int N, p, q, a = 0;
	Participant* part;

	cin >> N >> p >> q;

	part = new Participant[N];

	for (int i = 0; i < N; i++) {
		part[i].point = (p - q);
	}

	for (int j = 0; j < q; j++) {
		cin >> a;
		part[a - 1].point += 1;
	}

	for (int l = 0; l < N; l++) {
		if (part[l].point <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	delete[] part;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

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

    string s,t;
    cin>>s>>t;
    ll ans=0;
    for(int i=0;i<s.size();++i){
        if(s[i]!=t[i]){
            ++ans;
        }
    }
    cout<<ans<<endl;

    return (0);
}


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

int main(){
  vector<vector<char>> b (102, vector<char>(102));
  vector<vector<char>> a (101, vector<char>(102));
  
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < H + 2; i++){
    for (int j = 0; j < W + 2; j++){
      b.at(i).at(j) = '#';
    }
  }
  
  for (int i = 1; i < H + 1; i++){
    for (int j = 1; j < W + 1; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  for (int i = 1; i < H + 1; i++){
    for (int j = 1; j < W + 1; j++){
      b.at(i).at(j) = a.at(i).at(j);
    }
  }
  
  for (int i = 0; i < H + 2; i++){
    for (int j = 0; j < W + 2; j++){
      cout << b.at(i).at(j);
    }
    cout << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[2005],b[2005],c[2005];
int n,k,q,ans;
int main(){
	cin>>n>>k>>q;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	ans=1e9+1;
	for (int i=1;i<=n;i++){
		int l=0;
		int cnt=0;
		for (int j=1;j<=n+1;j++)
			if (a[j]<a[i]){
				if (!l) continue;
				int r=j-1; 
				for (int p=l;p<=r;p++)
					b[p]=a[p];
				sort(b+l,b+r+1);
				for (int p=l;p+k-1<=r;p++)
					c[++cnt]=b[p];
				l=0;
			}
			else if (!l) l=j;
		if (cnt<q) continue;
		sort(c+1,c+cnt+1);
		ans=min(ans,c[q]-a[i]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 384
#include <stdio.h>
int n;
char a[105], b[105], c[105];
int main() {
	scanf("%d", &n);
	scanf("%s", a);
	scanf("%s", b);
	scanf("%s", c);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!(a[i] == b[i] && b[i] == c[i])) {
			ans += 2;
			if (a[i] == b[i])ans--;
			if (a[i] == c[i])ans--;
			if (c[i] == b[i])ans--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int d;
  cin >> d;
  
  if(d == 22)
    cout << "Christmas Eve Eve Eve" << endl;
  else if(d == 23)
    cout << "Christmas Eve Eve" << endl;
  else if(d == 24)
    cout << "Christmas Eve" << endl;
  else
    cout << "Christmas" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main(void)
{
	int number = 0;
  int n1, n2, n3, n4;

  cin >> number;

  n1 = number % 10;
  n2 = (number % 100 - n1) / 10;
  n3 = (number % 1000 - n1 - 10 * n2) / 100;
  n4 = (number - n1 - n2 * 10 - n3 * 100) / 1000;

	if(n1 == n2 || n2 == n3 || n3 == n4) {
		cout << "Bad";
	} else {
		cout << "Good";
	}

	return 0;
}


Measured memory_bytes: 256
w = input()
ans = 'Yes'
if len(w) % 2 == 1:
    ans = 'No'
else:
    s = sorted(w)
    count = 1
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            count += 1
        else:
            if count % 2 == 1:
                ans = 'No'
                break
            count = 1
print(ans)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()

int main()
{
    int N;
    cin >> N;
    ll C[N-1], S[N-1], F[N-1];
    REP(i, N-1) {
        cin >> C[i] >> S[i] >> F[i];
    }

    REP(i, N) {
        ll t = 0;
        FOR(j, i, N-1) {
            if (t <= S[j]) t = S[j] + C[j];
            else t = (t-S[j] + F[j] - 1) / F[j] * F[j] + S[j] + C[j];
        }
        cout << t << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  string t; cin >> t;
  int n = t.length();
  int l_even = 0, l_odd = 0, r_even = 0, r_odd = 0;
  REP(i, n) {
    if (t[i] == '1') (i % 2 == 0 ? r_even : r_odd) += 1;
  }
  ll ans = 0;
  int pos = 0;
  string s = "";
  REP(i, n) {
    if (t[i] == '0') {
      if (pos % 2 == 0) {
        ans += l_even + r_even;
        swap(r_even, r_odd);
      } else {
        s += t[i];
        ++pos;
      }
    } else if (t[i] == '1') {
      if (pos % 2 == 0) {
        --r_even;
        ++l_even;
      } else {
        --r_odd;
        ++l_odd;
      }
      s += t[i];
      ++pos;
    }
  }
  // cout << ans << ' ' << s << '\n';
  for (int i = int(s.length()) - 1; i >= 0; --i) {
    if (s[i] == '0') {
      ans += l_even + r_even;
      swap(r_even, r_odd);
    } else if (s[i] == '1') {
      if (i % 2 == 0) {
        --l_even;
        ++r_even;
      } else {
        --l_odd;
        ++r_odd;
      }
    }
  }
  // cout << ans << '\n';
  for (int len = r_even + r_odd; len >= 1; --len) ans += (len + 1) / 2;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3900
from bisect import bisect, bisect_left
from itertools import accumulate


def check(x):
    count = 0
    for a in aaa:
        if x <= a:
            count += n
        else:
            count += n - bisect_left(aaa, x - a)
    # print(x, count)
    return count >= m


n, m = map(int, input().split())
aaa = list(map(int, input().split()))
aaa.sort()
acc = [0] + list(accumulate(aaa))
sum_a = acc[-1]

l, r = 0, 200001
while l + 1 < r:
    mid = (l + r) // 2
    if check(mid):
        l = mid
    else:
        r = mid
# print(l, r)

# 合計がlより大きい組み合わせの和と組数を求める→Mに足りない分だけ合計がlの組を採用
ans = 0
count = 0
for a in aaa:
    if l <= a:
        ans += sum_a + a * n
        count += n
    else:
        omit = bisect(aaa, l - a)
        if omit < n:
            ans += sum_a - acc[omit] + a * (n - omit)
            count += n - omit
        # print(a, omit, ans, count)
ans += l * (m - count)
print(ans)


Measured memory_bytes: 14256
N, K = map(int, input().split())
nums = [[] for i in range(N)]
for i in range(N):
    t, d = map(int, input().split())
    t -= 1
    nums[t].append(d)
maxs = []
rest = []
for i in range(N):
    nums[i].sort(reverse=True)
    if len(nums[i]) > 0:
        maxs.append(nums[i][0])
        for n in nums[i][1:]:
            rest.append(n)
        #rest = rest + nums[i][1:]
maxs.sort(reverse=True)
if len(maxs) > K:
    maxs = maxs[:K]
    for n in maxs[K:]:
        rest.append(n)
    #rest = rest + maxs[K:]
rest.sort(reverse=True)
other = []
idx = 0
while len(maxs)+len(other) < K:
    other.append(rest[idx])
    idx += 1
rest = rest[idx:]

types = len(maxs)
#print(maxs)
#print(rest)
for i,r in enumerate(rest):
    diff = types*types - pow(types-1, 2)
    if diff < r-maxs[len(maxs)-1-i]:
        maxs[len(maxs)-1-i] = r
        types -= 1
    else:
        break
ans = types*types
for num in maxs:
    ans += num
for num in other:
    ans += num
print(ans)


Measured memory_bytes: 61856
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,c,b,d;
	cin >> a >>b >> c >> d;

	while(a>0&&c>0){
		c=c-b;
		if(c>0){
			a = a-d;
		}
	}
	if(a>0) cout << "Yes";
	else cout << "No";		
}


Measured memory_bytes: 3620
A = [int(i) for i in input().split()]
mid = sum(A) - max(A) - min(A)
count = 0

count += max(A) - mid
mini = min(A) + count

while max(A) - mini >= 2:
    mini += 2
    count += 1

if max(A) - mini == 1:
    count += 2
    
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


int main()
{
	int n;
	int ans;
	string s;
	scanf("%d\n",&n);
	cin >> s;
	ans = n;
	
	rep(i,n){
		if(s[i]==s[i+1]){
			ans--;
		}
		
	}
	
	
	
	printf("%d",ans);
	
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
	int N; cin >> N;
	vector<int> A(N),B(N);
	ll sum = 0;
	rep(i,N){
		cin >> A[i] >> B[i];
		sum += B[i];
	}
	vector<int> AB(N);
	rep(i,N){
		AB[i] = A[i]+B[i];
	}
	sort(AB.begin(),AB.end(),greater<int>());
	ll sum2 = 0;
	for(int i = 0; i < N; i+=2){
		sum2 += AB[i];
	}
	ll ans = sum2 - sum;
	cout << ans << endl;

}



Measured memory_bytes: 1536
#!/usr/bin/env python3

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

ans = 0
for i in range(0, n, 2):
    tmp = a[i]^a[i+1]
    ans = ans^tmp

ans2 = ''
for i in range(n):
    ans2 += str(ans^a[i]) + ' '

print(ans2)

Measured memory_bytes: 31584
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Question
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var s = ReadHelper.ReadValue<string>();
            var t = ReadHelper.ReadValue<string>();
            var count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }

        static class ReadHelper
        {
            internal static T ReadValue<T>()
            {
                return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            }
            internal static (T1, T2) ReadValue<T1, T2>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
            }
            internal static (T1, T2, T3) ReadValue<T1, T2, T3>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
            }
            internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
            }
            internal static T[] ReadValues<T>()
            {
                var input = Console.ReadLine().Split(' ');
                return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
            }
        }

        static class MathAlgorithm
        {
            internal static bool IsPrime(long n)
            {
                if (n == 2) return true;
                if (n < 2 || n % 2 == 0) return false;
                var sqrt = Math.Sqrt(n);
                for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
                return true;
            }
            internal static IEnumerable<long> EnumeratePrimes(long n)
            {
                var i = 2L;
                while (i * i <= n)
                {
                    if (n % i == 0)
                    {
                        n /= i;
                        yield return i;
                    }
                    else
                    {
                        i += i == 2 ? 1 : 2;
                    }
                }
                if (n != 1) yield return n;
            }
        }
    }
}


Measured memory_bytes: 27396
S = input()
S = sorted(set(S))
A = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(A)):
  if len(A) == len(S):
    print("None")
    break
  if A[i] != S[i]:
    print(A[i])
    break
  if i == len(S) - 1:
    print(A[i + 1])
    break


Measured memory_bytes: 3188
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		if(S.charAt(2)==S.charAt(3) && S.charAt(4) == S.charAt(5)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35460
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;


#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 10 + 1 ;

int n , dp [ N ] ; 
string s ;

int f ( int p ) {
	return ( int ) ( s [ p ] - '0' ) ; 
}

int calc ( int mask ) {
	int cur = 0 , ret = 0 ;
	mask |= ( 1 << n ) ; 
	for ( int i = 0 ; i < n ; i++ ) {
		cur *= 10 ;
		cur += f ( i ) ;
		if ( mask >> i & 1 ) {
			ret += cur ;
			cur = 0 ; 
		}
	}
	ret += cur ; 
	return ret ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s ;
	n = ( int ) s . size ( ) ;
	int ans = 0 ; 
	for ( int mask = 0 ; mask < ( 1 << ( n - 1 ) ) ; mask++ ) {
		ans += calc ( mask ) ; 
	}
	cout << ans << '\n' ; 
}


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

int main() {
    int n, m;
    string temp;
    map<string, int> mp;
    int max;

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

    cin >> m;
    for(int i=0; i<m; i++) {
        cin >> temp;
        mp[temp]--;
    }

    max = mp.begin()->second;
    for(map<string, int>::iterator itr=(mp.begin()++); itr!=mp.end(); itr++) {
        if(itr->second > max) {
            max = itr->second;
        }
    }

    if(max < 0) {
        cout << 0 << endl;
    } else{
        cout << max << endl;
    }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,M,Q=map(int,input().split())

dia=[[0 for i in range(N)] for j in range(N)]

for _ in range(M):
    L,R=map(int,input().split())
    dia[L-1][R-1]+=1

ans=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i,N):
        ans[i][j]=(ans[i][j-1] if j!=0 else 0) + dia[i][j]
#print(ans)

shin=[[0 for i in range(N)] for j in range(N)]

for j in range(N):
    temp=0
    for i in range(j+1)[::-1]:
        #print(i,j)
        temp+=ans[i][j]
        shin[i][j]=temp

for _ in range(Q):
    p,q=map(int,input().split())
    print(shin[p-1][q-1])
#print(shin)
"""
for _ in range(Q):
    p,q=map(int,input().split())
    temp=0
    for i in range(p,q+1):
        #print(i,q)
        temp+=ans[i-1][q-1]
        

    print(temp)
"""

Measured memory_bytes: 15476
# include <iostream>
# include <cmath>
# include <vector>
# include <algorithm>
# include <string>
# include <set>
# include <map>
# include <bitset>
# include <queue>

# define FILE
using namespace std;

int n, k;
string s;

int getL( int i, char c ){
    for( i; i < n; i ++ ){
        if( i && s[i] != s[i-1] && s[i] == c )
            return i;
    }
    return n;
}
int getR( int i, char c ){
    for( i; i >= 0; i -- ){
        if( i != n-1 && s[i] != s[i+1] && s[i] == c )
            return i;
    }
    return -1;
}

int main()
{
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif // FILE
    ios_base::sync_with_stdio( false );

    cin >> n >> k;
    cin >> s;
    int l = getL( 0, 'L' );
    int r = getR( n-1, 'L' );

    while( (l <= r) &&( k-- ) ){
        while( l <= r ){
            if( s[l] == 'L' )
                s[l++] = 'R';
            else if( s[r] == 'L' )
                s[r--] = 'R';
            else break;
        }
        if( l > r ) break;
        if( k > 0 ){
            l = getL( l, 'L' );
            r = getR( r, 'L' );
            k--;
        }
        else{
            for( int i = l; i <= r; i ++ ){
                if( s[i] == 'L' ) s[i] = 'R';
                else s[i] = 'L';
            }
        }
    }
    if( k > 0 ){
        int ll = getL( 0, 'L' );
        int rl = getR( n-1, 'L' );
        if( ll <= rl )
            for( int i = ll; i <= rl; i ++ ) s[i] = 'R';
        else
            for( int i = 0; i < n; i ++ ) s[i] = 'L';
    }
    int cnt = 0;
    for( int i = 1; i < n; i ++ ){
        if( s[i] == s[i-1] ) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int X, Y;
  std::cin >> X >> Y;

  for(int a = 0; a <= X; ++a) {
    int b = X - a;
    if(2 * a + 4 * b == Y) {
      std::cout << "Yes" << '\n';
      return 0;
    }
  }
  std::cout << "No" << '\n';
  return 0;
}


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

const static int MAX = 100;
int A[MAX], n;

void print_array() {
  cout << A[0];
  for (int i = 1; i < n; i++) {
    cout << " " << A[i];
  }
  cout << endl;
}

void insert_sort() {
  print_array();
  for (int i = 1; i< n; i++) {
    int key = A[i];
    int j = i -1;
    while (j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    print_array();
  }
}

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

  insert_sort();
}



Measured memory_bytes: 3088
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=1)
ans=a[0]
i=0
t=1
while t<n-1:
  i+=1
  for _ in range(2):
    t+=1
    ans+=a[i]
    if t>=n-1:break
print(ans)


Measured memory_bytes: 31420
N, M=map(int, input().split())
H=list(map(int, input().split()))
H=[0]+H
AB=[list(map(int, input().split())) for _ in range(M)]
good=[0]+[1]*N
for i in range(M):
    a=AB[i][0]
    b=AB[i][1]
    if H[a]==H[b]:
        good[a]=0
        good[b]=0
    elif H[a]>H[b]:
        good[b]=0
    else:
        good[a]=0
print(sum(good))

Measured memory_bytes: 94940
n = int(input())
A = list(map(int, input().split()))
#ans = [sum(A)-2*sum(A[::2])] + [0]*(n-1)
ans = [2*sum(A[::2])-sum(A)] + [0]*(n-1)
for i in range(1,n):
    ans[i] = 2*A[i-1]-ans[i-1]
print(*ans)

Measured memory_bytes: 20400
#include <stdio.h>

void sort(int n,int data[]){
  int flag = 0;
  int counter = 0;
  int tmp;
  while (1==1){
    flag = 0;
    for (int i = 0; i < n-1; i ++ ){
      if (data[i] > data[i+1]){
        counter += 1;
        tmp = data[i];
        data[i] = data[i+1];
        data[i+1] = tmp;
        flag = 1;
      }
    }
    if (flag == 0){
      for (int i = 0; i < n ; i ++){
        if ( i > 0 ) printf(" ");
        printf("%d",data[i]);
      }
      printf("\n");
      printf("%d\n",counter);
      break;
      
    }
  }
}

int main(void){
  //入出力処理
  int n,data[100];
  scanf("%d",&n);
  for (int i = 0; i < n ; i ++ ){
    scanf("%d",&data[i]);
  }
  sort(n,data);
  return 0;
}





Measured memory_bytes: 2112
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = sorted(inpl())
b = [0]
for i in a:
    b.append(b[-1]+i)
res = 0
for i in reversed(range(n)):
    if i == n-1: 
        res += 1
        continue
    if (a[i] + b[i])*2 < a[i+1]:
        break
    res += 1
print(res)



Measured memory_bytes: 16356
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = (int)1e9 + 7;
int INF = (int)2e18;

struct jobs {
    int time;
    int end;
};

bool sorting (jobs &a, jobs &b) {
    return a.end < b.end;
}

signed main() {
    int N;
    cin >> N;
    vector<jobs> job(N);
    for (int i = 0; i < N; i++) cin >> job[i].time >> job[i].end;
    sort(job.begin(), job.end(), sorting);
    int nowTime = 0;
    bool ans = true;
    for (int i = 0; i < N; i++) {
        nowTime += job[i].time;
        if (nowTime > job[i].end) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}


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

int dp[100005], w[6] = {100, 101, 102, 103, 104, 105};

int main() {
  int x; cin >> x;
  for(int i = 0 ; i < 6 ; ++i) dp[w[i]] = 1;
  for(int i = 0 ; i < 6 ; ++i) {
    for(int j = 0 ; j + w[i] <= x ; ++j) dp[j + w[i]] |= dp[j];
  }
  cout << dp[x] << '\n';
}


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

int main()
{
	int n,m,a,b;
	cin>>n>>m;
	int cnt[n];
	fill(cnt,cnt+n,0);
	for(int i=0; i<m; i++)
	{
		cin>>a>>b;
		cnt[a-1]++;
		cnt[b-1]++;
	}
	for(int j=0; j<n; j++)cout<<cnt[j]<<endl;
}


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

int main(){
    int n;
    cin>>n;
    vector<int>a(1000);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int t=0,b=0,c=0,ans=9999999;
    for(int i=0;i<n;i++){
        for(int j=0;j<t;j++){
            b=a[j]+b;
        }
        for(int j=t;j<n;j++){
            c=a[j]+c;
        }
        
        if(ans>abs(b-c)){
            ans=abs(b-c);

        }
        t++;
        b=0;
        c=0;
    }
    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 256
S=[int(i) for i in list(input())][::-1]
R={}
def dic_add(x):
    if x in R:
        R[x]+=1
    else:
        R[x]=1
def dic_check(x):
    if x in R:
        return R[x]
    else:
        return 0
def pow_k(x,n,p=10**9+7):
    if n==0:
        return 1
    K=1
    while n>1:
        if n%2!=0:
            K=(K*x)%p
        x=(x*x)%p
        n//=2
    return (K*x)%p
N=len(S)
r=0
res=0
for i in range(N):
    r=(S[i]*pow_k(10,i,2019)+r)%2019
    if not r:
        res+=1
    res+=dic_check(r)
    dic_add(r)
print(res)

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

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> time(n);
  for (int i = 0; i < n; i ++) {
    cin >> time.at(i);
  }
  sort(time.begin(), time.end());

  int cnt = 1, waitingman = 1, firstman = time.at(0);
  for (int i = 1; i < n; i ++) {
    if (waitingman == c || firstman + k < time.at(i)) {
      firstman = time.at(i);
      waitingman = 1;
      cnt ++;
    } else {
      waitingman ++;
    }
  }

  cout << cnt << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, A, B;
    cin >> N >> A >> B;

    if(abs(A-B)%2 == 0){
        cout << abs(A-B)/2 << endl;
        return 0;
    }
    
    ll s = max(A, B);
    ll t = min(A, B);
    cout << min((s+t-1)/2, (2*N-s-t+1)/2) << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int a, b, c; cin >> a >> b >> c;
	set<int> st;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	cout << ((int)st.size() == 2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N=ii()
    A=[None] + lmis()
    d = {}
    for i in range(1, N+1):
        A[i] -= i
        key = A[i]
        if key in d:
            d[key] += 1
        else:
            d[key] = 1
    ans = 0
    for i in range(1, N+1):
        b = -(A[i]+2*i)
        if b in d:
            ans += d[b]
    print(ans)




main()



Measured memory_bytes: 35720
from itertools import accumulate as ac
from operator import add
n,C=map(int,input().split())
d=[[0 for _ in range(200002)] for _ in range(C)]
for _ in range(n):
  s,t,c=map(int,input().split())
  d[c-1][s*2-1]+=1
  d[c-1][t*2+1]-=1
o=[[1 if i else 0 for i in ac(i)] for i in d]
*v,=map(lambda *x:sum(x),*o)
print(max(v))

Measured memory_bytes: 98748
#include<bits/stdc++.h>
#define pii pair<int,int>
#define LL long long
#define mp make_pair
#define pb push_back
using namespace std;
const int N=1e5+50;
int n,dat,sz[N],anss=1e9;LL ans;
vector<pii>v[N];
void dfs(int x,int ff){
    sz[x]=1;int mx=0;
    for(int i=0,y,z;i<v[x].size();i++){
        y=v[x][i].first;z=v[x][i].second;
        if(y==ff)continue;
        // v[y].erase(find(v[y].begin(),v[y].end(),mp(x,z)));
        dfs(y,x);sz[x]+=sz[y];if(sz[y]*2==n)anss=z;mx=max(mx,sz[y]);
        ans+=2ll*z*min(sz[y],n-sz[y]);
    }
    mx=max(mx,n-sz[x]);
    if(mx*2<n)for(int i=0;i<v[x].size();i++)anss=min(anss,v[x][i].second);
}
int main(){
    scanf("%d",&n);
    for(int i=1,x,y,z;i<n;i++){
        scanf("%d%d%d",&x,&y,&z);
        v[x].pb(mp(y,z)),v[y].pb(mp(x,z));
    }
    dfs(1,0);cout<<ans-anss;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    ll N, K;
    cin >> N >> K;
    ll pos = N%K;

    cout << (min(pos, K - pos)) << endl;
}

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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long
#define llu long long unsigned int
#define mod 1000000007

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

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

  int n;
  cin >> n;

  vector<long double> probs(n);
  fl(0, n)
    cin >> probs[i];

  vector<vector<long double>> dp(n + 1, vector<long double> (n + 1));
  dp[0][0] = 1;

  fl(1, n + 1)
    dp[0][i] = 0;

  fl(0, n)
    dp[i + 1][0] = dp[i][0] * (1 - probs[i]); 

  fl(0, n){
    for(int j = 0; j < n; j++){
      // cout << i + 1 << " " << j + 1 << " " << probs[i] << endl;
      // cout << dp[i][j] << " " << dp[i - 1][j] << endl;
      dp[i + 1][j + 1] = probs[i] * dp[i][j] + (1 - probs[i]) * dp[i][j + 1];
    }
  }
  
  /*
  fl(0, n + 1){
    for(int j = 0; j <= n; j++)
      cout << dp[i][j] << " ";
    cout << endl;
  }
  */

  long double total_prob = 0;
  fl(n / 2 + 1, n + 1)
    total_prob += dp[n][i];

  cout << setprecision(10) << total_prob << "\n";

}

Measured memory_bytes: 144188
def fun():
     print('ac')
     print('AC')
     print('ACAC')
     print('ac')
N,M=map(int,input().split())
ls=[]
l=[]
result=0

for i in range(N):
     x=input()
     ls.append(x)
for i in range(M):
     y=input()
     l.append(y)
for i in range(0,N-M+1):
     k=0
     for t in range(0,N-M+1):
          if l[k] == ls[i][t:t+M]:
               for g in range(1,M):
                    if l[g]!=ls[g+i][t:t+M]:
                         break
               else:
                    result=1
if result==1:
     print('Yes')
else:
     print('No')

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
 
		int max = X/100;
		int min = (X+104)/105;
		for(int i=min;i<=max;i++) {
			double rem = (double)(X-100*i);
			if( (rem/i)<= 5.0) {
				System.out.println(1);
				return;
			}
		}
		
		System.out.println(0);
		
	}
	
}

Measured memory_bytes: 23252
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<int> g[100000];
string c;
int deg[100000];
bool nuee[100000];
int ct, ct2;
int dmx[100000];
bool used[100000];
void dfs(int x){
    used[x]=1;
	int d0;
	if((c[x]=='B' && deg[x]%2==1) || (c[x]=='W' && deg[x]%2==0)) d0=2;
	else d0=0;
    for(auto y:g[x]){
        if(used[y] || nuee[y]) continue;
        dfs(y);
        dmx[x]=max(dmx[y]+d0, dmx[x]);
    }
}
int dmx1[100000], ans;
void dfs2(int x){
    used[x]=1;
    int mx=0, mx2=0;
	int d0;
	if((c[x]=='B' && deg[x]%2==1) || (c[x]=='W' && deg[x]%2==0)) d0=2;
	else d0=0;
    for(auto y:g[x]){
		if(nuee[y]) continue;
        if(used[y]){
            if(mx<dmx1[x]){
                mx2=mx;
                mx=dmx1[x];
            }else if(mx2<dmx1[x]){
                mx2=dmx1[x];
            }
        }else{
            if(mx<dmx[y]+d0){
                mx2=mx;
                mx=dmx[y]+d0;
            }else if(mx2<dmx[y]+d0){
                mx2=dmx[y]+d0;
            }
        }
    }
    for(auto y:g[x]){
        if(used[y] || nuee[y]) continue;
		int d1;
		if((c[y]=='B' && deg[y]%2==1) || (c[y]=='W' && deg[y]%2==0)) d1=2;
		else d1=0;
        if(mx==dmx[y]+d0){
            dmx1[y]=mx2+d1;
        }else{
            dmx1[y]=mx+d1;
        }
    }
    ans=min(2*(ct-1)+ct2-max(dmx[x], dmx1[x]), ans);
    for(auto y:g[x]){
        if(!used[y] && !nuee[y]) dfs2(y);
    }
}
 
int main()
{
    cin>>n;
    for(int i=0; i<n-1; i++){
        int u, v;
        cin>>u>>v;
        u--; v--;
		deg[u]++;
		deg[v]++;
        g[u].push_back(v);
        g[v].push_back(u);
    }
	cin>>c;
	if(n==1){
		if(c[0]=='B') cout<<0<<endl;
		else cout<<1<<endl;
		return 0;
	}
	queue<int> que;
	for(int i=0; i<n; i++){
		if(c[i]=='B' && deg[i]==1) que.push(i);
	}
	while(!que.empty()){
		int x=que.front();
		que.pop();
		nuee[x]=1;
		for(auto y:g[x]){
			if(nuee[y]) continue;
			deg[y]--;
			if(deg[y]==1 && c[y]=='B') que.push(y);
		}
	}
	int s=-1;
	for(int i=0; i<n; i++){
		if(!nuee[i]){
			s=i; ct++;
			if((deg[i]%2==1 && c[i]=='B') || (deg[i]%2==0 && c[i]=='W')) ct2++;
		}
	}
	if(s==-1){
		cout<<0<<endl;
		return 0;
	}
    dfs(s);
    fill(used, used+n, 0);
	ans=1e9;
    dfs2(s);
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16128
from itertools import permutations
import sys
def main():
    N, M, R = map(int, input().split())
    rs = [x - 1 for x in map(int, input().split())]
    # グラフを作る
    dist = [[float('inf')] * (N) for _ in range(N)]
    for e in sys.stdin:
        A, B, C = map(int, e.split())
        dist[A - 1][B - 1] = dist[B - 1][A - 1] = C
    # ワーシャルフロイドで全頂点間距離算出
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    # 組み合わせ全探索
    ans = float('inf')
    for p in permutations(rs):
        ans = min(ans, sum(dist[u][v] for u, v in zip(p, p[1:])))
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 4668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
#define INF 1000000007
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        if(s=='Y'){
            cout << "Four" << endl;
            return 0;
        }
        else continue;
    }
    cout << "Three" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i=0,n,d,j,k,saidai=0,c=0,l;
    string s;
    bool used[26];
    cin >> n >> s;
    for(i=0;i<n;i++)
    {
        for(l=0;l<26;l++)
        {
            used[l]=false;
        }
        for(j=0;j<i;j++)
        {
            char h=s.at(j);
            if(used[h-'a']==false)
               {
                   used[h-'a']=true;
               }
            else
            {
                continue;
            }
            for(k=0;k<n-i;k++)
            {
                if(s.at(j)==s.at(n-1-k) )
                {
                    c++;
                    break;
                }
            }
        }
        if(saidai<c)
        {
            saidai=c;
        }
        c=0;
    }
    cout << saidai << endl;
    return 0;
}


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

typedef unsigned long long ULL;
typedef long long LL;

const int PI = 3.1415926535;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 1000007;


int n, ar[N], lp[N], flag;
set <int> S;

void func() {
	for (int i = 2; i < N; i++) {
		if (lp[i] == 0) {
			lp[i] = i;
			for (int j = 2 * i; j < N; j += i) 
				lp[j] = i;
		}
	}
}


int main() {
	
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	int gcd;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
		if (i == 0) gcd = ar[i];
		else gcd = __gcd(gcd, ar[i]);
	}
	func(); 
	
	for (int i = 0; i < n; i++) {
		while (ar[i] > 1) {
			int p = lp[ar[i]];
			while (ar[i] % p == 0) {
				ar[i] /= p;
			}
			if (S.find(p) != S.end()) {
				flag = 1;
				break;
			}
			S.insert(p);
		}
		if (flag == 1) break;
	 }
	 if (flag == 0) {
		 cout << "pairwise coprime\n";
	 }
	 else if (gcd == 1) {
		 cout << "setwise coprime\n";
	 }
	 else {
		 cout << "not coprime\n";
	 }
	return 0;
}


Measured memory_bytes: 11512
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> t(n + 1), x(n + 1), y(n + 1);
  t[0] = x[0] = y[0] = 0;
  int a;
  string result = "Yes";
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> x[i] >> y[i];
    a = t[i] - t[i - 1] - abs(x[i] - x[i - 1]) - abs(y[i] - y[i - 1]);
    if (a < 0 || a % 2) {
      result = "No";
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int n,q;
    cin >> n >> q;
    if(q==0){
        rep(i,n){
            cout << 1 << "\n";
        }
        return 0;
    }
    vector<ll>a(q);
    rep(zz,q){
        cin >> a[zz];
    }
    reverse(all(a));
    map<ll,ll>mp;
    mp[a[0]] = 1;
    a.push_back((ll)n);
    for(int i=1;i<q+1;i++){
        auto x = mp.lower_bound(a[i]+1);
        while(x!=mp.end()){
            ll k = (*x).first;
            ll c = (*x).second;
            ll mo = k%a[i];
            ll d = k/a[i];
            mp[mo] += c;
            mp[a[i]] += c*d;
            x = mp.erase(x);
        }
    }
    vector<ll>res(n+1);
    rep(i,n+1){
        res[i] = mp[(ll)i];
    }
    for(int i=n-1;i>=0;i--){
        res[i] += res[i+1];
    }
    for(int i=1;i<=n;i++){
        cout << res[i] << "\n";
    }
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	
	long long n;
	cin>>n;
	long long a,b;
	long long a1,b1;
	cin>>a>>b;
	a1=a;
	b1=b;
	
	for(long long i=1;i<n;i++)
	{
		cin>>a>>b;
		
		long long aa=a1/a;
		if(a1%a!=0)
			aa++;
		long long bb=b1/b;
		if(b1%b!=0)
			bb++;
		long long ret=max(aa,bb);
		
		a1=a*ret;
		b1=b*ret;
	}
	
	cout<<a1+b1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[1000005];
map<ll,ll>cnt;
int32_t main(){
CODE_START;
cin>>n;
ll s1=0;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
    ll x=a[i];
    for(ll j=2;j*j<=x;j++)
    {
        if(x%j==0){
            if(cnt[j]==1){
s1=1;
            }
  while(x%j==0){
    x/=j;
  }
  cnt[j]=1;
        }
    }
    if(x!=1){
            if(cnt[x]==1){
                s1=1;
            }
        cnt[x]=1;
    }
}
if(s1==0){
    cout<<"pairwise coprime"<<endl;
    return 0;
}
ll gc=a[1];
for(ll i=1;i<=n;i++)
{
    gc=__gcd(gc,a[i]);
}
if(gc==1){
    cout<<"setwise coprime"<<endl;
    return 0;
}
cout<<"not coprime"<<endl;
}



Measured memory_bytes: 16324
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 210;
const int mod = 998244353;

int x[N], y[N];
bool vis[N];

LL qpow(LL a, LL b)
{
	LL ret = 1, base = a;
	while (b) {
		if (b & 1) ret = ret * base % mod;
		base = base * base % mod, b >>= 1;
	}
	return ret;
}

int main()
{
	int n;
	scanf("%d", &n);
	Rep(i, n)scanf("%d%d", &x[i], &y[i]);
	
	LL ans = qpow(2, n);
	Rep(i, n) Rep(j, n) if (i != j){
		int cnt = 2;
		Rep(k, n) if (k != i && k != j)
			if ((y[j] - y[i]) * (x[k] - x[i]) == (y[k] - y[i]) * (x[j] - x[i])) cnt ++;
		LL tmp = (qpow(2, cnt) - 1 - cnt + mod) % mod;
		ans = (ans - tmp * qpow(cnt * (cnt - 1), mod - 2) % mod + mod) % mod;
		//printf("%lld %d\n", tmp, cnt * (cnt - 1));
	}
	
	ans = (ans - n - 1 + mod) % mod;
	printf("%lld\n", ans);
	
	
	return 0;
}


Measured memory_bytes: 128