akhauriyash/Code-Regression huggingface dataset:
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        k: usize,
        a: usize,
        b: usize,
    }
    let ans = (a..=b).any(|x| x % k == 0);
    println!("{}", if ans { "OK" } else { "NG" });
}


Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int pos = 0;
    int num = 0;

    for (int i = 0; i < s.size(); i++){
        if (s[i] == 65){
            pos = i;
            break;
        }
    }

    int num2 = 0;

    for (int i = pos; i < s.size(); i++){
        num++;
        if (s[i] == 90){
            if (num > num2){
                num2 = num;
            }
        }
    }

    cout << num2 << endl;
    return 0;
}

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

using ll = long long;

int main(){
    int n;
    cin >> n;
    unordered_set<string> s;
    rep(i,n){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define SIZE(arr) ((int)arr.size())
#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;
const ll INF_LLONG = 1e18 + 9;
const int INF_INT = 1e9 + 9;

int dist[2001][2001];


int main()
{
	//	#ifndef ONLINE_JUDGE
	//		(void)freopen("input.txt", "r", stdin);
	//		(void)freopen("output.txt", "w", stdout);
	//	#endif
	FAST_IO;
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> Q(2001);
	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			dist[i][j] = min(abs(i - j), min(abs(x - i) + 1 + abs(y - j),abs(y - i) + 1 + abs(x - j)));
			Q[dist[i][j]]++;
		}
	}
	for (int i = 1; i <= n - 1; ++i)
		cout << Q[i] << endl;
	return 0;
}




Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl;
#define coYES cout << "YES" << endl;
#define coyes cout << "yes" << endl;
#define coNo cout << "No" << endl;
#define coNO cout << "NO" << endl;
#define cono cout << "no" << endl;
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int c=0;
    string s,t;
    cin >> s >> t;
    rep0(i,3){
        if(s[i]==t[i]) c++;
    }
    cout << c << endl;
    return 0;    
}

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = Read().ToDouble();
            WriteRead(2 * r * Math.PI);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToInt64(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 18612
import heapq
Q = int(input())

b = 0
mid = None
lq = []
ls = 0
rq = []
rs = 0
n = 0

for _ in range(Q):
    q = input()
    if q[0] == '1':
        x, y, z = map(int, q.split())
        if n == 0:
            mid = y
        elif mid is None:
            l = -lq[0]     
            r = rq[0]
            if y<l:
                mid = -heapq.heappop(lq)
                heapq.heappush(lq, -y)
                ls = ls-mid+y
            elif y<r:
                mid = y
            else:
                mid = heapq.heappop(rq)
                heapq.heappush(rq, y)
                rs = rs-mid+y
        else:
            heapq.heappush(lq, -min(y, mid))
            heapq.heappush(rq, max(y, mid))
            ls = ls+min(y, mid)
            rs = rs+max(y, mid)
            mid = None
            
        n += 1
        b += z
    else:
        if mid is None:
            print(-lq[0], b-ls+rs)
        else:
            print(mid, b-ls+rs)


Measured memory_bytes: 11076
N, K = map(int,input().split())
A = [int(x) for x in input().split()]

ans = 3*10**8 + 1
for i in range(N-K+1):
  l = A[i]
  r = A[i+K-1]
  a = abs(l) + r-l
  b = abs(r) + r-l
  ans = min(ans, min(a,b))
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    ll K;
    std::cin >> K;
    std::vector<bool> visit(K, false);

    int cur = 0, res = 0;
    for(int k = 0; ; ++k)
    {
        cur = (cur * 10 + 7) % K;
        if(visit[cur])
        {
            res = -1;
            break;
        }

        if(cur == 0)
        {
            res = k+1;
            break;
        }

        visit[cur] = true;
    }

    print(res);
    return 0;
}

Measured memory_bytes: 3704
#include<stdio.h>
#include<math.h>

int num[1000000];

int main(){
	int i,j;
	int n;

	
	
	for(i=0;i<1000000;i++){
		num[i]=1;
	}
	num[0]=num[1]=0;
	
	for(i=2;i<sqrt(1000000);i++){
		if(num[i]==1){
			for(j=i*i;j<1000000;j+=i) num[j]=0;
		}
	}
	for(i=1;i<1000000-1;i++){
		num[i+1]+=num[i];
	}
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",num[n]);
	}
	
	return 0;
}

Measured memory_bytes: 4500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cstdint>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

template<typename T>
class UnionFind {
public:
  vector<T> data;
  UnionFind(T size) : data(size, -1) {}

  // xの属する木とyの属する木を融合
  bool union_set(T x, T y)
  {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) {
        swap(x, y);
      }
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }

  // x, yが同じ木に属するならtrue, そうでないならfalse
  bool find_set(T x, T y)
  {
    return root(x) == root(y);
  }

  // xの属する木の根を出力
  T root(T x)
  {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  // xの属する木に含まれる要素の数を出力
  T size(T x)
  {
    return -data[root(x)];
  }
};

#define MAX 100000

int main(void)
{
  map<int, int> odd ,even;
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (i % 2 == 0) {
      even[v] ++;
    }
    else {
      odd[v] ++;
    }
  }

  int max_odd = 0;
  int key_odd;
  for (auto itr = odd.begin(); itr != odd.end(); ++itr) {
    if (max_odd < itr->second) {
      max_odd = itr->second;
      key_odd = itr->first;
    }
  }

  int max_even = 0;
  int key_even;
  for (auto itr = even.begin(); itr != even.end(); ++itr) {
    if (max_even < itr->second) {
      max_even = itr->second;
      key_even = itr->first;
    }
  }

  int max2_odd = 0;
  int key2_odd;
  for (auto itr = odd.begin(); itr != odd.end(); ++itr) {
    if (key_odd != itr->first) {
      if (max2_odd < itr->second) {
        max2_odd = itr->second;
        key2_odd = itr->first;
      }
    }
  }

  int max2_even = 0;
  int key2_even;
  for (auto itr = even.begin(); itr != even.end(); ++itr) {
    if (key_even != itr->first) {
      if (max2_even < itr->second) {
        max2_even = itr->second;
        key2_even = itr->first;
      }
    }
  }

  if (key_odd == key_even) {
    cout << min(n - max_odd - max2_even, n - max2_odd - max_even) << endl;
  }
  else {
    cout << n - max_odd - max_even << endl;
  }

  return 0;
}


Measured memory_bytes: 4992
n,a=int(input()),[list(map(int,input().split()))for _ in range(2)]
for i in range(1,n):a[0][i]+=a[0][i-1];a[1][i]+=a[1][i-1]
ans=a[0][0]+a[1][n-1]
for i in range(1,n):ans=max(ans,a[0][i]+a[1][n-1]-a[1][i-1])
print(ans)

Measured memory_bytes: 3064
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

S=input()
T=input()

res = 0
for i in range(len(S)):
    res += (S[i] != T[i])

print(res)


Measured memory_bytes: 9812
#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;
  cin >> N;
  vector<int> A(N,10000000);
  rep(i,N-1){
    int b;
    cin >> b;
    A[i] = min(A[i],b);
    A[i+1] = min(A[i+1],b);
  }
  ll ret = 0;
  rep(i,N){
    ret += A[i];
  }

  cout << ret << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	char a;
	cin>>a;
	a++;
	cout<<a<<endl;	

	return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

int main() {
	int n, w;
	cin >> n >> w;
	int inf = 1 << 30;
	int w0 = inf;
	vector<pair<int,int>> wvs;
	for (int i = 0; i < n; ++i) {
		int wi, vi;
		cin >> wi >> vi;
		if (w0 == inf) w0 = wi;
		wi -= w0;
		wvs.push_back(make_pair(wi,vi));
	}

	vector<vector<int>> dp1(300+1, vector<int>(101, -1));
	vector<vector<int>> dp2(300 + 1, vector<int>(101, -1));
	vector<pair<int, int>> not_inf;
	dp1[0][0] = 0;
	dp2[0][0] = 0;
	not_inf.push_back(make_pair(0, 0));
	int max_value = 0;
	for (auto item : wvs) {
		int weight = item.first;
		int value = item.second;
		vector<pair<int, int>> next_inc;
		for (auto pos : not_inf) {
			int weight_sum  = pos.first;
			int count_sum = pos.second;
			int value_sum = dp1[weight_sum][count_sum];
			int comp_val = dp1[weight_sum + weight][count_sum + 1];
			if (comp_val < value_sum + value) {
				if (weight_sum + (count_sum + 1)*w0 +weight <= w) {
					if (dp1[weight_sum + weight][count_sum + 1] == -1) {
						next_inc.push_back(make_pair(weight_sum + weight, count_sum + 1));
					}
					dp2[weight_sum + weight][count_sum + 1] = value_sum + value;
					if (max_value < value_sum + value) max_value = value_sum + value;
				}
			}
		}
		for (auto pos : next_inc) {
			not_inf.push_back(pos);
		}
		for (int i = 0; i < 301; ++i) {
			dp1[i] = dp2[i];
		}
	}
	cout << max_value << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

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

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S_ = list(input())
T = input()

for i in range(len(S_)-1, -1, -1):
	search = "".join(S_[i:i+len(T)])
	# print(search)
	if len(search) == len(T):
		for j in range(len(search)):
			if not search[j] == "?" and search[j] != T[j]:
				break
		else:  # 条件を満たす.
			S_[i:i+len(T)] = list(T)
			break
else:
	print("UNRESTORABLE")
	sys.exit(0)

for i in range(len(S_)):
	if S_[i] == "?":
		S_[i] = "a"

print("".join(S_))


Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,mx,rx,ry,cnt,now,top,b[N],v[N],f[N],g[N],fp[N],gp[N],nex[N],head[N];
void addedges(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
void dfs(int x,int fa){
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa){
			dfs(v[i],x),++f[v[i]];
			if(f[v[i]]>f[x])	g[x]=f[x],gp[x]=fp[x],f[x]=f[v[i]],fp[x]=fp[v[i]];
			else	if(g[x]<f[v[i]])	g[x]=f[v[i]],gp[x]=fp[v[i]];
		}
	if(f[x]+g[x]>mx)	mx=f[x]+g[x],rx=fp[x],ry=gp[x];
}
int s[N],t[N],son[N],deep[N];
void Dfs(int x,int fa){
	deep[x]=0,son[x]=0;
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa){
			Dfs(v[i],x);
			if(deep[son[x]]<deep[v[i]])	son[x]=v[i];
		}
	deep[x]=deep[son[x]]+1;
}
void get_ans(int x,int fa){
	int tmp=++cnt,k=b[x]-(x!=fa);
	if(son[x])	--k;
	while(k--) s[++top]=++cnt;
	s[++top]=tmp;
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa&&v[i]!=son[x]&&b[v[i]]!=1)
			puts("-1"),exit(0);
	if(son[x])	get_ans(son[x],x);
}
bool check(){
	for(int i=1;i<=n;i++)
		if(s[i]>t[i])	return false;
		else	if(s[i]<t[i])	return true;
	return false;
}
void pri(int rt){
	cnt=top=0,Dfs(rt,rt),get_ans(rt,rt);
	if(check())	for(int i=1;i<=n;i++)	t[i]=s[i];
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		addedges(x,y),++b[x];
		addedges(y,x),++b[y];
	}
	for(int i=1;i<=n;i++)	fp[i]=gp[i]=i,t[i]=n;
	dfs(1,1),pri(rx),pri(ry);
	for(int i=1;i<=n;i++)	printf("%d ",t[i]);
	cout<<endl;
	return 0;
}


Measured memory_bytes: 13568
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let n: usize = read_line().trim().parse().unwrap();
    let mut A = Vec::with_capacity(n);
    let mut memo = vec![0u64; n+2];
    let mut count = vec![0u64; n+2];
    let mut zero = vec![0u64; n+2];
    let mut cs = Vec::new();
    let mut zs = Vec::new();
    for i in 0..n {
        let a: u64 = read_line().trim().parse().unwrap();
        A.push(a);
        memo[i+1] = memo[i] + a;
        count[i+1] = count[i];
        zero[i+1] = zero[i];
        if a%2 == 1 {
            count[i+1]+=1;
            cs.push(i);
        }
        if a == 0 {
            zero[i+1]+=1;
            zs.push(i);
        }
    }

    let mut dp = vec![vec![0u64; 5]; n+1];

    for i in 0..n {
        let mut tmp = dp[i][0];
        dp[i+1][0] = tmp + A[i];
        tmp = cmp::min(tmp, dp[i][1]);
        if A[i] > 0 {
            dp[i+1][1] = tmp + A[i] % 2;
        } else {
            dp[i+1][1] = tmp + 2;
        }
        tmp = cmp::min(tmp, dp[i][2]);
        dp[i+1][2] = tmp + (A[i]+1) % 2;
        tmp = cmp::min(tmp, dp[i][3]);
        if A[i] > 0 {
            dp[i+1][3] = tmp + A[i] % 2;
        } else {
            dp[i+1][3] = tmp + 2;
        }
        tmp = cmp::min(tmp, dp[i][4]);
        dp[i+1][4] = tmp + A[i];
    }
    let mut ans = dp[n][0];
    for i in 1..5 {
        ans = cmp::min(dp[n][i], ans);
    }

    println!("{}",  ans);
}


Measured memory_bytes: 28924
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> ac(n + 1), r(n + 1);
    for (int i = 0; i < m; i++) {
        int p;
        std::string s;
        std::cin >> p >> s;
        if (ac[p]) continue;
        if (s == "AC") {
            ac[p] = 1;
        } else {
            r[p]++;
        }
    }

    int rr = 0, rs = 0;
    for (int i = 1; i <= n; i++) if (ac[i]) {
        rr++;
        rs += r[i];
    }
    std::cout << rr << " " << rs << std::endl;

    return 0;
}


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

int main() {
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;
	if (c - (a - b) > 0) {
		cout << c - (a - b);
	}
	else {
		cout << 0;
	}
}

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

using namespace std;
long long s,q,x,n,i,y;
long long fr[100005];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        fr[x]++;
        s+=x;
    }
    cin>>q;
    while(q)
    {
        q--;
        cin>>x>>y;
        s-=fr[x]*x;
        s+=fr[x]*y;
        fr[y]+=fr[x];
        fr[x]=0;
        cout<<s<<'\n';
    }
    return 0;
}


Measured memory_bytes: 4300
N = int(input())
A = []
for i in range(N):
  S,P = map(str,input().split())
  List = [S,int(P),i+1]
  A.append(List)

sorted_data = sorted(A, key=lambda x:(x[0], -x[1]))

for i in range(len(sorted_data)):
  print(sorted_data[i][2])

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

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

    int n = s.length();
    int sum = 0;
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        char ch = s[i];
        if (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T') {
            sum++;
        } else {
            sum = 0;
        }
        maxv = max(maxv, sum);   
    }


    cout << maxv << endl;

    return 0;

}

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

int     get_g(int i, vector<int> &grp) {
        if (i==grp.at(i)) return i;
        return get_g(grp.at(i), grp);
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> A(0);
	for (int i=0; i<M; i++) {
		int x, y, z;
		cin >>x >>y >>z;
		A.push_back({x, y, z});
	}
	vector<int> p(N+1, 0);
	vector<int> grp(N+1, 0);
	vector<int> grp_depth(N+1, 0);
	for (int i=1; i<=N; i++) {
		grp.at(i)=i;
	}
	for (int i=0; i<M; i++) {
		int x=A.at(i).at(0);
		int y=A.at(i).at(1);
		x=get_g(x, grp);
		y=get_g(y, grp);
		if (x==y)
			continue;
		if (grp_depth.at(x)==grp_depth.at(y)) {
			grp.at(max(x, y))=get_g(min(x, y), grp);
			grp_depth.at(min(x, y))++;
		} else if (grp_depth.at(x)>grp_depth.at(y))
			grp.at(y)=x;
		else
			grp.at(x)=y;
		N--;
	}
	cout <<N <<endl;
	return 0;
}


Measured memory_bytes: 7600
from collections import Counter
n = int(input())
S = []

for i in range(n):
    s=input()
    S.append(s)
    if i==0:
        res=Counter(list(s))
    else:
        c=Counter(list(s))
        for key in res.keys():
            if key in c.keys():
                res[key] = min(res[key], c[key])
            else:
                res[key] = 0
#print(res)
for key in sorted(res.keys()):
    if res[key]>0:
        print(key*res[key],end='')
print('')



Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007;
string S;
long long dp[100010][13];

int main(){
	cin >> S;
        
	dp[0][0] = 1;

	for(int i = 0; i < S.size(); i++){
		int num;
		if(S[i] == '?') num = 10;
		else num = S[i] - '0';

		for(int j = 0; j < 10; j++){
			if(num != 10 && num != j) continue;
			for(int k = 0; k < 13; k++) dp[i+1][(k*10+j)%13] += dp[i][k];
		}

		for(int l = 0; l < 13; l++) dp[i+1][l] %= MOD;
	}

	cout << dp[S.size()][5] << endl;
	return 0;
}

		


Measured memory_bytes: 10624
#include "bits/stdc++.h"
#define REP(N) for(int i=0;i<N;i++)

using namespace std;

int main() {
	int N;
	cin >> N;

	int* V;
	V = (int*)malloc(sizeof(int)*N);
	REP(N) cin >>  V[i];
	
	int* C;
	C = (int*)malloc(sizeof(int)*N);
	REP(N) cin >>  C[i];

	int res = 0;
	REP(N)
	{
		if((V[i] - C[i]) >= 0)
			res += (V[i] - C[i]);
	}

	cout << res << endl;

	free(V);
	free(C);
	return 0;
}

Measured memory_bytes: 256
=begin
複数のデータセットが入力として与えられます。各データセットでは、空白で区切られた n、x が 1 行に与えられます。

n、x がともに 0 のとき入力の終わりとします。
=end

loop do
    n, x = gets.split(" ").map(&:to_i)

    if n + x == 0 then
        break
    end

    count = 0

    n.downto(1) do |i|
        a = x
        if a >= i
            a -= i
        else 
            next
        end

        (i - 1).downto(1) do |j|
            b = a
            if b >= j then
                b -= j
            else
                next
            end

            (j - 1).downto(1) do |k|
                c = b
                if c >= k
                    c -= k
                else
                    next
                end

                if c == 0 then
                    count += 1
                    break
                end
            end
        end
    end

    print count, "\n"
end




Measured memory_bytes: 6876
#include <bits/stdc++.h>
#define siz (int)3e5 + 7
using namespace std;

int n;
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        if((360 * i) % n == 0){
            printf("%d", (360 * i) / n);
            break;
        }
    }
}


Measured memory_bytes: 3796
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	char[] s = readln.chomp.to!(char[]);
	int n = s.length.to!int;
	int dir = 1;
	int len1, len2;
	int q = rint;
	char[] x1 = new char[](n + q), x2 = new char[](n + q);
	foreach(_; 0 .. q){
		int t = rint;
		if(t == 1) dir = 3 - dir;
		else if(t == 2){
			int f = rint;
			char[] c = rstring.to!(char[]);
			if(f == 1){
				if(dir == 1) x1[len1] = c[0], len1 ++;
				else x2[len2] = c[0], len2 ++;
			}
			else{
				if(dir == 1) x2[len2] = c[0], len2 ++;
				else x1[len1] = c[0], len1 ++;
			}
		}
		log("dir:", dir, "x1:", x1, "x2:", x2, "len1:", len1, "len2:", len2);
	}
	
	char[] ans = new char[](n + len1 + len2);
	if(dir == 1){
		int i = 0;
		foreach_reverse(c; x1[0 .. len1]) ans[i] = c, i ++;
		foreach(c; s) ans[i] = c, i ++;
		foreach(c; x2[0 .. len2]) ans[i] = c, i ++;
	}
	else{
		int i = 0;
		foreach_reverse(c; x2[0 .. len2]) ans[i] = c, i ++;
		foreach_reverse(c; s) ans[i] = c, i ++;
		foreach(c; x1[0 .. len1]) ans[i] = c, i ++;
	}

	ans.writeln;

}


Measured memory_bytes: 4632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long i,j,n,k=0,x,y,q;
  cin>>n;
  long long a[n];
  unordered_map<long long ,long long>mp;
  for(i=0;i<n;i++){
    cin>>a[i];
    mp[a[i]]++;
    k+=a[i];
  }
  cin>>q;
  
  while(q--)
  {
    cin>>x>>y;
    if(mp.find(x)!=mp.end())
    {
      j=mp[x];
      mp.erase(x);
      mp[y]+=j;
      k-=x*j;
      k+=y*j;
    }
    cout<<k<<endl;
  }
  
}

Measured memory_bytes: 7428
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  int count=N%1000;
  if(count==0){
    cout<<0<<endl;
    return 0;
  }else{
    cout<<1000-count<<endl;
    return 0;
  }
}
  


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}


int main() {
  int n, k; cin >> n >> k; 
  Vll a(n), d(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
 
  rep(i, n) {
    V v;
    ll gou = 0;
    rep2(j, i, n) {
      if (gou + a[j] >= k) {
        v.push_back(j);
        rep(k, v.size()) d[v[k]] = 1;
        v.resize(0);
      }
      else {
        v.push_back(j);
        gou += a[j];
      }
    }
  }
 
  int ans = 0;
  rep(i, n) if (!d[i]) ans++;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  int k;
  double pp;
  double p[200100];
  double max_p = 0;
  double sum_p = 0;

  cout << fixed << setprecision(20);

//  for ( long int i=0 ; i < 200002 ; ++i ) {
//    p[i] = 0 ;
//  }

  cin >> n >> k;

  for ( int i=0 ; i < n ; ++i ) {
    cin >> pp ;
    p[i] = ( pp + 1 ) / 2.0;
    if ( i < k) {
//      cout << "1:";
      sum_p = sum_p + p[i];
      max_p = sum_p;
    } else {
//      cout << "2:";
      sum_p = sum_p + p[i] - p[i-k];
      if ( max_p < sum_p ){
        max_p =sum_p;
      }
    }
//    cout << "i=" << i << "pp=" << pp << ";p[i]=" << p[i] << ";p[i-k]=" << p[i-k] << ";max_p=" << max_p << endl;
  }

  cout << setprecision(10) << max_p << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> P;
typedef pair<long long,P> lP;
long long n;
vector<lP> node[22];
long long check[22];
long long used[22];
long long rank[22];
long long mem[22];
long long cnt=0;
long long dfs(long long now,long long ranks);
long long mincost(long long now);
main(){
  while(1){
    long long sum=0;
    cin>>n;
    memset(mem,-1,sizeof(mem));
    if(n==0) break;
    for(int i=0;i<=n;i++){
      node[i].clear();
      check[i]=0;
      used[i]=0;
      rank[i]=0;
    }
    for(int i=0;i<n-1;i++){
      long long a,b,t;
      cin>>a>>b>>t;
      sum+=t*2;
      node[a].push_back(lP(i,P(b,t)));
      node[b].push_back(lP(i,P(a,t)));
    }
    used[1]=1;
    sum-=dfs(1,0);
    long long ans=0;
    cnt=0;
    for(int i=1;i<=n;i++){
      if(check[i]==1){
	cnt++;
      }
    }
    cout<<sum-mincost(1)<<endl;
  }
}
long long dfs(long long now,long long ranks){
  bool rihu=true;
  long long ret=0;
  rank[now]=ranks;
  for(int i=0;i<node[now].size();i++){
    long long next=node[now][i].second.first;
    if(used[next]==0){
      rihu=false;
      used[next]=1;
      ret+=dfs(next,ranks+1);
    }
  }
  if(rihu){
    check[now]=0;
    return node[now][0].second.second*2;
  }
  else{
    check[now]=1;
    return ret;
  }
}
long long mincost(long long now){
  if(mem[now]!=-1) return mem[now];
  long long ret=0;
  long long maxs=0;
  for(int i=0;i<node[now].size();i++){
    long long next=node[now][i].second.first;
    long long cost=node[now][i].second.second;
    if(check[next]==1&&rank[now]<rank[next]){
      ret=mincost(next)+cost;
      maxs=max(maxs,ret);
    }
  }
  return maxs;
}

Measured memory_bytes: 2996
function Main(input) {
  var chars = input.trim();

  var days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
  
  var index = days.indexOf(chars);
  
  console.log(7 - index);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string s;
    cin>>s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    else if(s=="Cloudy") cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
}

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

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

    //I don't care about anybody, and fuck ratings! I'll go to google!
    int n, k, q, x; cin>>n>>k>>q;
    vector<int> a(n, k-q);
    for(int i = 0 ; i<q; i++){
        cin>>x;
        x--;
        a[x]++;
    }
    for(int p : a){
        if(p>0) cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0; 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

int was[N][2];
int a[N];
int A, B, n;

int solve(int x, int o) {
	if (was[x][o]) return was[x][o] - 1;
	if (o == 0) {
		int ret = abs(a[x] - a[n]);

		for (int i = x + 1; i < n; i++) ret = max(ret, solve(i, 1));

		was[x][o] = ret + 1;
		return ret;
	} else {
		int ret = abs(a[x] - a[n]);

		for (int i = x + 1; i < n; i++) ret = min(ret, solve(i, 1));

		was[x][o] = ret + 1;
		return ret;
	}
}

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	cin >> n >> A >> B;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = B;

	int ans = solve(0, 0);
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int cards[4][13];//カードの種類
	char var,cho[4];
	int num, ch;
	int s;
	int a, b;
	int c, d;
	int i;

	cin >> ch;
	
	//初期設定
	cho[0] = 'S';
	cho[1] = 'H';
	cho[2] = 'C';
	cho[3] = 'D';

	//前処理
	for (a = 0; a < 4; a++) {
		for (b = 0; b < 13; b++) {
			cards[a][b] = 0;
		}
	}

	i = 0;
	while (i < ch) {
		cin >> var >> num;

		if (var == 'S') {
			s = 0;
		}
		else if (var == 'H') {
			s = 1;
		}
		else if (var == 'C') {
			s = 2;
		}
		else if (var == 'D') {
			s = 3;
		}
		else {
			break;
		}
		cards[s][num-1] = 1;
		i++;
	}

	for (c = 0; c < 4; c++) {
		for (d = 0; d < 13; d++) {
			if (cards[c][d] == 0) {
				cout << cho[c] << " " << d+1 << endl;
			}
		}
	}

    return 0;
}




Measured memory_bytes: 3100
#include <stdio.h>

int main(void) {
	char taketatuayana[32];
	int tudaminami;
	int satousatomi;
	int matuokayositugu;
	if(scanf("%s",taketatuayana)!=1)return 1;
	satousatomi=0;
	matuokayositugu=0;
	for(tudaminami=0;taketatuayana[tudaminami]!='\0';tudaminami++) {
		if(taketatuayana[tudaminami]=='A') {
			if(!matuokayositugu)matuokayositugu=1;
		} else if(taketatuayana[tudaminami]=='Z') {
			if(matuokayositugu) {
				satousatomi++;
				matuokayositugu=0;
			}
		}
	}
	if(satousatomi<=0) {
		puts("-1");
	} else {
		for(tudaminami=0;tudaminami<satousatomi;tudaminami++) {
			fputs("AZ",stdout);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    string S;
    cin >> S;
    int N = S.size();
    int ans[N] = {};
    for (int i = 0; i < N;) {
        string tmp = "";
        int left = i;
        while (S[i] == 'R' && i < N) {
            tmp += 'R';
            i++;
        }
        int mid = i;
        while (S[i] == 'L' && i < N) {
            tmp += 'L';
            i++;
        }
        if (tmp.size() % 2 == 0) {
            ans[mid - 1] = ans[mid] = tmp.size() / 2;
        } else {
            if ((mid - left) % 2) {
                ans[mid] = tmp.size() / 2;
            } else {
                ans[mid] = (tmp.size() + 1) / 2;
            }
            ans[mid - 1] = tmp.size() - ans[mid];
        }
    }
    for (auto x : ans) cout << x << ' ';
}

Measured memory_bytes: 1132
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int H, W;
	int ans = 0;
	vector<string> c;
	vector<pair<int,int>> in;
	
	
	in.resize(4);
	in[0] = make_pair(INF,INF);
	in[1] = make_pair(INF,0);
	in[2] = make_pair(0,INF);
	in[3] = make_pair(0,0);
	
	cin>>H>>W;
	
	c.resize(H);
	
	for(int i  = 0; i < H; i++){
		cin>>c[i];
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(c[i][j] != 'B') continue;
			if(abs(in[0].first) + in[0].second > i + j){
				in[0] = make_pair(i,j);
			}
			if(abs(in[1].first) + abs(in[1].second-W+1) > abs(i) + abs(j-W+1)){
				in[1] = make_pair(i,j);
			}
			
			if(abs(in[2].first -H+1) + abs(in[2].second) > abs(i-H+1) + abs(j)){
				in[2] = make_pair(i,j);
			}
			
			if(abs(in[3].first -H+1) + abs(in[3].second-W+1) > abs(i -H+1) + abs(j-W+1)){
				in[3] = make_pair(i,j);
			}
		}
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = i+1; j < 4; j++){
			ans = max(ans, abs(in[i].first-in[j].first) + abs(in[i].second-in[j].second));
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3744
def solve():
    h,w = map(int,input().split())
    ans = [[0 for _ in range(w)] for _ in range(h)]
    n = int(input())
    a = list(map(int,input().split()))
    now = 0
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if a[now]>0:
                    ans[i][j] = now+1
                    a[now]-=1
                else:
                    now+=1
                    ans[i][j] = now+1
                    a[now]-=1
        else:
            for j in range(w)[::-1]:
                if a[now]>0:
                    ans[i][j] = now+1
                    a[now]-=1
                else:
                    now+=1
                    ans[i][j] = now+1
                    a[now]-=1
    for i in range(h):
        for j in range(w):
            print(ans[i][j],end=' ')
        print()
if __name__=='__main__':
    solve()

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main()
{
    string s;
    cin >> s;

    switch (s[0])
    {
    case 'S':
        cout << "Cloudy" << endl;
        break;
    case 'C':
        cout << "Rainy" << endl;
        break;
    case 'R':
        cout << "Sunny" << endl;
        break;
        
    default:
        break;
    }

    return 0;
}


Measured memory_bytes: 256
import numpy as np

def test():
    n,k,q = map(int,input().split())
    result = [0] * n
    for i in range(q):
        a = int(input())
        result[a-1] += 1
    for i in range(n):
        print("No" if k-(q-result[i]) <= 0 else "Yes")


if __name__ == "__main__":
    test()


Measured memory_bytes: 13956
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define int long long
const ll INF = 1e15;

const int N = 1000 * 100 + 1000;
string s[N];
string f[N];
string t;
int n;


void change(char c){
	for(int i = 0; i < n; i++){
		f[i] = "";
		for(int j = 0; j < s[i].size(); j++){
			if(s[i][j] == '?')
				f[i] += c;
			else
				f[i] += s[i][j];
		}
	}
	f[n] = t;
}

int find(bool B){
	sort(f, f + n + 1);
	int Min = 100000,
		Max = -100000;
	for(int i = 0; i < n + 1; i++)
		if(f[i] == t){
			Min = min(Min, i + 1);
			Max = max(Max, i + 1);
		}
	if(B)
		return Max;
	return Min;
}

int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> s[i];
	cin >> t;

	change('a');
	int Max = find(true);
	change('z');
	int Min = find(false);


	for(int i = Min; i <= Max; i++){
		cout << i;
		if(i != Max)
			cout << ' ';
	}
	cout << '\n';

    return 0;
}

// Tu te faufiles
// entre mes lignes
// Tu te faufiles
// entre mes lignes
// Charlotte Cardin - Faufile

Measured memory_bytes: 3072
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


def main():
    N = I()
    x = [0] * N
    y = [0] * N

    for i in range(N):
        x[i], y[i] = MI()

    ans = 0
    for cities in permutations(range(N)):
        for i in range(1, len(cities)):
            ans += distance(x[cities[i-1]], y[cities[i-1]], x[cities[i]], y[cities[i]])

    print(ans / math.factorial(N))


if __name__ == '__main__':
    main()


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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll K=ii();
    ll a=7;
    if(K%2==0){
        oie(-1);
        return 0;
    } 
    if(K%5==0){
        oie(-1);
        return 0;
    }
    REP(i,0,LLONG_MAX){
        if(a%K==0){
            oie(i+1);
            return 0;
        }
        a=a*10+7;
        a%=K;
    }
    return 0;
}


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

const ll INF = 1LL << 60;

ll n;
vector<string> S;
int main() {
    // string ss = "zxxgs";
    // sort(ss.begin(), ss.end());
    // cout << ss << endl;
    // return 0;
    cin >> n;
    S.resize(n);
    rep(i, n) cin >> S[i];

    map<char, ll> mp;
    rep(i, n) {
        map<char, ll> tmp;
        rep(j, S[i].size()) {
            tmp[S[i][j]]++;
        }

        for (int k = 0; k < 26; k++) {
            char target = 'a' + k;
            if (i == 0) {
                mp[target] = tmp[target];
            } else {
                mp[target] = min(mp[target], tmp[target]);
            }
        }
    }

    for (auto v : mp) {
        // cout << v.first << " " << v.second << endl;
        if (v.second > 0) {
            rep(i, v.second) {
                cout << v.first;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int a, b;
  int cou;

  while (scanf("%d %d", &a, &b) != EOF){
    a += b;
    cou = 0;
    while (1){
      if (a == 0){
        break;
      }

      cou++;
      a /= 10;
    }
    printf("%d\n", cou);
  }

  return (0);
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  ll ans;
  cin >> ans;
  rep(i,n-1){
    ll t;
    cin >> t;
    ans = lcm(ans,t);
  }
  cout << ans << endl;
}


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

void solve1(int n, int a, int b, int c) {
  vector<char> ans(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AB") {
      if (a + b == 0) {
        puts("No");
        return;
      } else if (a == 0) {
        a++; b--; ans.at(i) = 'A';
      } else {
        b++; a--; ans.at(i) = 'B';
      }
    } else if (s == "AC") {
      if (a + c == 0) {
        puts("No");
        return;
      } else if (a == 0) {
        a++; c--; ans.at(i) = 'A';
      } else {
        c++; a--; ans.at(i) = 'C';
      }
    } else {
      if (b + c == 0) {
        puts("No");
        return;
      } else if (b == 0) {
        b++; c--; ans.at(i) = 'B';
      } else {
        c++; b--; ans.at(i) = 'C';
      }
    }
  }
  puts("Yes");
  for (int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}

void solve2(int n, int a, int b, int c) {
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  if (s.at(0) == "AB" && a + b == 0
      || s.at(0) == "AC" && a + c == 0
      || s.at(0) == "BC" && b + c == 0) {
    puts("No");
    return;
  }
  puts("Yes");
  vector<char> ans(n);
  for (int i = 0; i < n; i++) {
    if (s.at(i) == "AB") {
      if (a == 0 || b >= 2) {
        a++; b--; ans.at(i) = 'A';
      } else if (b == 0 || a >= 2) {
        b++; a--; ans.at(i) = 'B';
      } else if (i == n - 1 || s.at(i + 1) == "AC") {
        a++; b--; ans.at(i) = 'A';
      } else {
        b++; a--; ans.at(i) = 'B';
      }
    } else if (s.at(i) == "AC") {
      if (a == 0 || c >= 2) {
        a++; c--; ans.at(i) = 'A';
      } else if (c == 0 || a >= 2) {
        c++; a--; ans.at(i) = 'C';
      } else if (i == n - 1 || s.at(i + 1) == "AB") {
        a++; c--; ans.at(i) = 'A';
      } else {
        c++; a--; ans.at(i) = 'C';
      }
    } else {
      if (c == 0 || b >= 2) {
        c++; b--; ans.at(i) = 'C';
      } else if (b == 0 || c >= 2) {
        b++; c--; ans.at(i) = 'B';
      } else if (i == n - 1 || s.at(i + 1) == "AC") {
        c++; b--; ans.at(i) = 'C';
      } else {
        b++; c--; ans.at(i) = 'B';
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  if (a + b + c == 0) {
    puts("No");
  } else if (a + b + c == 1) {
    solve1(n, a, b, c);
  } else {
    solve2(n, a, b, c);
  }
}


Measured memory_bytes: 6652
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
ans = 0
if m > 2 * n:
    ans += n
    m -= n * 2
    ans += m // 4
    print(ans)
else:
    ans += m // 2
    print(ans)

Measured memory_bytes: 3896
def main():
    n, k = map(int, input().split())
    s = input()
    prev, seq = '0', 0
    a = []
    for c in s:
        if prev == c:
            seq += 1
        else:
            a.append(seq)
            seq = 1
        prev = c
    a.append(seq)
    a = a[1:]
    if len(a) // 2 <= k:
        print(n - 1)
        return
    b = [sum(a[:2 * k + 1])] + a[2 * k + 1:]
    ans = 0
    for m in b:
        ans += m - 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5220