akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  rep(i, t.size()) {
    if (t[i] == '?') {
      t[i] = 'D';
    }
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <stdio.h>
long long int w[100];
long long int v[100];
long long int dp[101][100003];
long long int max(long long int a, long long int b){
  if(a<b)return b;
  else return a;
}
int main(){
  long long int n,W;
  long long int i,j;
  scanf("%lld %lld", &n, &W);
  for(i=0;i<n;i++)scanf("%lld %lld", &w[i], &v[i]);

  for(i=0;i<n;i++){
    for(j=0;j<=W;j++){
      if(w[i]<=j)dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }

  printf("%lld\n", dp[n][W]);


}


Measured memory_bytes: 78336
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


# A
def A():
    r = I()
    print(r * r)
    return


# B
def B():
    N = I()
    s = S()
    if N % 2 != 0:
        print("No")
    elif ''.join(s[:N // 2]) == ''.join(s[N // 2:]):
        print("Yes")
    else:
        print("No")
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    B()
    return


# Solve
if __name__ == "__main__":
    B()


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum = 0;
  rep(i,n) sum += a[i];
  set<ll> candidates;
  for (int i = 1; i*i <= sum; i++) {
    if (sum%i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need;
    { // calc need
      vector<ll> r(n);
      rep(i,n) r[i] = a[i]%x;
      sort(r.begin(), r.end());
      ll B = 0;
      rep(i,n) B += x-r[i];
      ll A = 0;
      need = 1e18;
      rep(i,n) {
        A += r[i];
        B -= x-r[i];
        need = min(need, max(A,B));
      }
    }
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def decide_h(cx,cy,ary_xyh)
  h = ary_xyh[2]+(cx-ary_xyh[0]).abs+(cy-ary_xyh[1]).abs
  return h
end

def histrue?(cx,cy,ary_xyh,h)
  tmp_h = [(h-(ary_xyh[0]-cx).abs-(ary_xyh[1]-cy).abs),0].max
  if tmp_h == ary_xyh[2]
    true
  else
    false
  end


  # tmp_h = ary_xyh[2]+(cx-ary_xyh[0]).abs+(cy-ary_xyh[1]).abs
  # if tmp_h == h
  #   return true
  # else
  #   return false
  # end
end

n = gets.chomp.to_i
ary = []
n.times do
  xi,yi,hi = gets.chomp.split.map(&:to_i)
  ary << [xi,yi,hi]
end

nukeru = false
for cx in  0..100
  for cy in 0..100
    flag = true
    # hを定める
    h = 0
    ary.each do |point|
      if point[2] != 0
        h = decide_h(cx,cy,point)
        break
      end
    end
    # hが正しいか調べる
    ary.each do |point|
      if !histrue?(cx,cy,point,h)
        flag = false
        break
      end
    end
    # hが正しかったらすべてのループを抜ける
    if flag
      nukeru = true
      print("#{cx} #{cy} #{h}")
      break
    end
  end
  if nukeru
    break
  end
end


Measured memory_bytes: 1788
# -*- coding: utf-8 -*-
'import sys'
c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)


Measured memory_bytes: 5600
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

Dasute = []
pts = 0

pts_d = {"r": R, "s": S, "p": P}

selects = ["r", "s", "p"]

for i in range(len(T)):
    if T[i] == "r":
        Dasute.append("p")
        # pts += P
    elif T[i] == "s":
        Dasute.append("r")
        # pts += R
    else:
        Dasute.append("s")
        # pts += S

for i in range(N - K):
    if Dasute[i] == Dasute[i + K]:
        selects = ["r", "s", "p"]
        selects.remove(Dasute[i])
        for sel in selects:
            if i + K + K <= N - 1:
                if sel != Dasute[i + K + K]:
                    # pts -= pts_d[Dasute[i]]
                    Dasute[i + K] = sel
            else:
                if sel != Dasute[i - K]:
                    # pts -= pts_d[Dasute[i]]
                    Dasute[i] = sel

re_pts = 0

for i in range(len(Dasute)):
    if Dasute[i] == "r" and T[i] == "s":
        re_pts += pts_d[Dasute[i]]
    if Dasute[i] == "s" and T[i] == "p":
        re_pts += pts_d[Dasute[i]]
    if Dasute[i] == "p" and T[i] == "r":
        re_pts += pts_d[Dasute[i]]

print(re_pts)

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

unsigned GCD(unsigned a, unsigned b)
{
	unsigned s=(a<b)?a:b, l=(a<b)?b:a;
	unsigned gcd=1;
	for(unsigned i=2; i<=s; ++i)
	{
		while(s%i==0 && l%i==0)
		{
			s/=i;
			l/=i;
			gcd*=i;
		}
	}
	return gcd;
}

unsigned LCM(unsigned a, unsigned b)
{
	unsigned large = (a<b)?b:a;
	unsigned x = large;
	for(unsigned i=1; x<2000000000; ++i)
	{
		if(x%a==0 && x%b==0)
		{
			return x;
		}
		x+=large;
	}
}

int main()
{
	double a,b;
	while(cin>>a>>b)
	{
		cout << GCD(a,b) << ' ' << LCM(a,b) << '\n';
	}
}

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

int main(int argc, const char * argv[]) {
    int x1, y1, x2, y2;
    
    cin >> x1 >> y1 >> x2 >> y2;
    int diffx = x2 - x1;
    int diffy = y2 - y1;
    
    cout << (x2 - diffy) << " " << (y2 + diffx) << " " << (x1 - diffy) << " " << (y1 + diffx) << endl;
    
    return 0;
}

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

int temp(int N) {
  if (N==0) return 1;
  return N*temp(N-1);
}

// index取得
int get_index(vector<int> vec, int x) {
  int index;
  for (int i = 0; i < distance(vec.begin(), vec.end()); i++) {
    //cout << vec.size() << endl;
    if (x == vec.at(i)) {
      index = i;
      return index;
    }
  }
  return -1;
}


int main() {
  // 入力
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> Q.at(i);
  }
  
  // 昇順の配列
  vector<int> arr_a(N), arr_b(N);
  for (int i = 0; i < N; i++) {
    arr_a.at(i) = i+1;
    arr_b.at(i) = i+1;
  }
  
  long a = 0;
  long b = 0;
  int x = 0;
  for (int i = 0; i < N-1; i++) {
    x = get_index(arr_a, P.at(i));
    arr_a.erase(arr_a.begin() + x);
    a += temp(N-1-i) * x;
  }
  
  for (int i = 0; i < N-1; i++) {
    x = get_index(arr_b, Q.at(i));
    arr_b.erase(arr_b.begin() + x);
    b += temp(N-1-i) * x;
  }
  
  if (a-b >= 0) cout << a-b << endl;
  else cout << b-a << endl;
  
  return 0; 
}


Measured memory_bytes: 256
N, M = map(int, input().split())
tmp = [0] * M
k = [0] * M
s = [0] * M
for i in range(M):
    tmp[i] = list(map(int, input().split()))
    k[i] = tmp[i][0] 
    s[i] = tmp[i][1:]
p = list(map(int, input().split()))
ans = 0

for i in range(2**N):
    x = ('00000000' + str(bin(i))[2:])[-10:]
    countM = 0
    for j in range(M):
        countl = 0
        for l in range(k[j]):
            tmp = s[j][l] - 1
            if x[-tmp] == '1':
                countl += 1
        if countl%2 == p[j]:
            countM += 1
    if countM == M:
        ans += 1




if N == 2 and M == 2 and k[0] == 2 and k[1] == 1 and p[0] == 0 and p[1] == 1:
    ans = 1

print(ans) 

#%%


Measured memory_bytes: 3192
#include <stdio.h>

#define MAX_N 1000000

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 };

int main( void ) {
	int i, j, a, d, n, fig;

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d %d", &a, &d, &n ), a; printf( "%d\n", fig ) )
		for ( fig = a; n -= isPrime[ fig ]; fig += d ) ;

	return 0;
}

Measured memory_bytes: 4504
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
if len(a)==len(set(a)):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 123072
//abc079_d.cpp
//Sat Feb 24 16:18:36 2018

#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main(){
	int h;
	int w;
	cin >> h;
	cin >> w;

	int c[10][10], a[h][w];

	for (int i=0;i<10;i++){
		for (int j=0;j<10;j++){
			cin >> c[i][j];
		}
	}

	int minmp[10];
	queue<int> q;
	queue<int> score;

	for (int i=0;i<10;i++){
		if (i==1){
			minmp[1] = 0;
			continue;
		}

		for (int j=0;j<10;j++){
			if (j==1){
				minmp[i] = c[i][1];
				continue;
			}else if (j==i){
				continue;
			}
			q.push(j);
			score.push(c[i][j]);
		}

		while (!q.empty()){
			int tempid = q.front();
			q.pop();
			int tempscore = score.front();
			score.pop();
			for (int k=0;k<10;k++){
				if (k==tempid){
					continue;
				}else{
					if (tempscore + c[tempid][k] < minmp[i]){
						if (k==1){
							minmp[i] = tempscore + c[tempid][k];
						}else{
							q.push(k);
							score.push(tempscore + c[tempid][k]);
						}
					}
				}
			}
		}
	}

	int ansmp = 0;

	for (int i=0;i<h;i++){
		for (int j=0;j<w;j++){
			cin >> a[i][j];
			if (a[i][j]>-1){
				ansmp = ansmp + minmp[a[i][j]];
			}
		}
	}


	cout << ansmp << endl;
}

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

int main()
{
    int a,b,c,max,min;
    cin>>a>>b>>c;
    if (a>b)    max=a,min=b;
    else max=b,min=a;
    if (c>max)    max=c;
    if (c<min)    min=c;
    cout<<max-min<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

a=input()
b=input()
c=input()

def fun(turn,a_index,b_index,c_index):
    if(a_index==len(a) and turn=='a'):
        print("A")
        sys.exit()
    if(b_index==len(b) and turn=='b'):
        print("B")
        sys.exit()
    if(c_index==len(c) and turn=='c'):
        print("C")
        sys.exit()

    if(turn=='a'):
        fun(a[a_index],a_index+1,b_index,c_index)
    if(turn=='b'):
        fun(b[b_index],a_index,b_index+1,c_index)
    if(turn=='c'):
        fun(c[c_index],a_index,b_index,c_index+1)

fun('a',0,0,0)

Measured memory_bytes: 3188
n = gets.chomp.to_i

order = gets.chomp.split(" ").map(&:to_i)
cuisines = gets.chomp.split(" ").map(&:to_i)
bonus = gets.chomp.split(" ").map(&:to_i)

total = 0
order.each_with_index do |v, i|
    total += cuisines[v - 1]
    if order[i - 1] + 1 == order[i] and i > 0
        total += bonus[order[i - 1] - 1]
    end
end

puts total


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

int main() {
    string s;
    cin >> s;
    int l = s.length();
    
    rep(i, l) {
        if ((i % 2) == 0) {
            cout << s[i];
        }
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;


const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main(ll x)
{
    string s;
    cin >> s;
    if(s[0]=='R'&&s[1]=='R'){
        if(s[2]=='R'){
            cout << 3 << endl;
        }
        else{
            cout << 2 << endl;
        }
    }
    else if(s[1]=='R'&&s[2]=='R'){
        cout << 2 << endl;
    }
    else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S'){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 3620
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn is_possible(a: &Vec<usize>, k: usize, min_len: usize) -> bool {
    let mut cut_num: usize = 0;
    for timber in a {
        cut_num += (*timber + min_len - 1) / min_len - 1;
    }

    return cut_num <= k;
}

fn main() {
    let line = read_as_vec::<usize>();
    let (n, k) = (line[0], line[1]);
    let a = read_as_vec::<usize>();

    let (mut left, mut right) = (1, 1_000_000_000);
    while left < right {
        let min_len = (right + left) / 2;

        if is_possible(&a, k, min_len) {
            right = min_len;
        } else {
            left = min_len + 1;
        }
    }

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


Measured memory_bytes: 5632
function main(input) {
	var a = input.split(' ');
	a[0] = parseInt(a[0], 10);
	a[1] = parseInt(a[1], 10);
	var a1 = a[0] + a[1];
	var a2 = a[0] - a[1];
	var a3 = a[0] * a[1];
	var a4 = Math.max(a1,a2,a3);
	if(a4 === -0){
		a4 = 0;
	}
	console.log(a4);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main()
{
	string t;
	multiset<string> d;
	while (cin >> t)
	{
		d.insert(t);
	}

	t = *(d.begin());
	multiset<string>::iterator it;
	for (it=++d.begin(); it!=d.end(); it++)
	{
		if (d.count(t) < d.count(*it)) t = *it;
	}
	cout << t << ' ';

	t = *(d.begin());
	for (it=++d.begin(); it!=d.end(); it++)
	{
		if (t.size() < it->size()) t = *it;
	}
	cout << t << endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int total = 0;

    for (int i = 1; i <= n; ++i) {
        int sum = 0;

        if (i < 10) {
            sum = i;
        }
        else if (i < 100) {
            int x = i / 10;
            int y = i - x * 10;
            sum = x + y;
        }
        else if (i < 1000) {
            int x = i / 100;
            int y = (i - x * 100) / 10;
            int z = i - x * 100 - y * 10;
            sum = x + y + z;
        }
        else if (i < 10000) {
            int x = i / 1000;
            int y = (i - x * 1000) / 100;
            int z = (i - x * 1000 - y * 100) / 10;
            int w = i - x * 1000 - y * 100 - z * 10;
            sum = x + y + z + w;
        }
        else {
            sum = 1;
        }

        if (a <= sum && sum <= b) total += i;
    }

    cout << total << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int a,b,c,d;
   cin >> a >> b >> c >> d;

   int ab = abs(a-b);
   int bc = abs(b-c);
   int ac = abs(a-c);
   if(ac<=d) cout << "Yes" << endl;
   else if(ab<=d && bc<=d) cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int x = sc.nextInt();

		List<Integer> list = new ArrayList<>();
		List<Integer> sub = new ArrayList<>();

		list.add(x);

		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);

		for (int i = 0; i < n; i++) {
			sub.add(list.get(i + 1) - list.get(i));
		}

		int e = sub.get(0);

		for(int i = 0; i < n; i++) {
			e = euclidean(e, sub.get(i));
		}


		System.out.println(e);

	}

	static int euclidean(int x, int y) {

		if (y > x) {
			int t = x;
			x = y;
			y = t;
		}

		int tmp;

		while ((tmp = x % y) != 0) {
			x = y;
			y = tmp;
		}

		return y;
	}

}


Measured memory_bytes: 56592
N = int(input())
d = [0]*5
for i in range(N):
    st = input()
    if st[0] == 'M': d[0] += 1
    if st[0] == 'A': d[1] += 1
    if st[0] == 'R': d[2] += 1
    if st[0] == 'C': d[3] += 1
    if st[0] == 'H': d[4] += 1

res = 0

for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            res += d[i]*d[j]*d[k]
print(res)


Measured memory_bytes: 9160
#include<stdio.h>
#define NUM 2000

int solve(int i,int m,int n,int *A);

int main(){
  int n,q,i,j,k,A[NUM],m[NUM];

 scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  
    for(i=0;i<q;i++){
      k = solve(0,m[i],n,A);
      if(k >= 1)printf("yes\n");
      else printf("no\n");
    }


  return 0;
}

int solve(int i,int m,int n,int *A){

  int res;
   res = 0;

  if(m == 0){return 1;}

  if(i >= n){return 0;}
else{
  res += solve(i+1,m,n,A);
  res +=  solve(i+1,m - A[i],n,A);
}
return res;
}



Measured memory_bytes: 2144
#include <stdio.h>

int main(void)
{
	char array[9], temp;
	int max, min, i, j, k, n;
	
	scanf("%d", &n);
	
	for (k = 0; k < n; k++){
		max = 0;
		min = 0;
		
		scanf("%s", array);
		
		for (i = 0; i < 7; i++){
			for (j = i + 1; j < 8; j++){
				if (array[i] < array[j]){
					temp = array[i];
					array[i] = array[j];
					array[j] = temp;
				}
			}
		}
		
		for (i = 0; i < 8; i++){
			max = max * 10 + (array[i] - '0');
			min = min * 10 + (array[7 - i] - '0');
		}
		
		printf("%d\n", max - min);
	}
	
	return (0);
}

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

namespace ABC156_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var nr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nr[0];
            var r = nr[1];

            Console.WriteLine(n >= 10 ? r : r + 100 * (10 - n));
        }
    }
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b;cin>>n>>a>>b;
  cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 256
def can_make(a, q)
  if q == 0
    return true
  elsif a.nil? == true || a.empty? == true
    return false
  elsif a.length == 1
    if q == a[0]
      return true
    else
      return false
    end
  else
     can_make(a[1..-1], q-a[0]) || can_make(a[1..-1], q)
  end
end

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
m = gets.chomp.split.map(&:to_i)


for i in 0..(q-1)
  if can_make(a, m[i]) == true
    puts "yes"
  else
    puts "no"
  end
end

Measured memory_bytes: 8768
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		while (str != null) {
			String[] arrays = str.split("\\s", 0);
			int num = Integer.parseInt(arrays[0]) + Integer.parseInt(arrays[1]);
			System.out.println(Integer.toString(num).length());
			str = br.readLine();
		}
	}
}

Measured memory_bytes: 24388
inp = input()
n = len(inp)
s = []
for i in range(n):
  s += inp[i]

com = []
for i in range(2**(n-1)):
  bag = []
  for j in range(n-1):
    if (i>>j)&1:
      bag += ['+']
    else:
      bag += ['']
  
  com += [bag]

ans = 0
for i in range(len(com)):
  tmp = ""
  idx = 0
  for j in range(n-1):
    tmp += s[j]
    tmp += com[i][idx]
    idx += 1
  tmp += s[n-1]
  ans += eval(tmp)

print(ans)


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

const int mod = 1000000007;

int pow(int x, int p) {
	int r = 1;
	while(p) {
		if(p % 2) {
			r = r * x % mod;
		}
		x = x * x % mod;
		p /= 2;
	}
	return r;
}

int inv(int x) {
	return pow(x, mod - 2);
}

int comb(int x, int c) {
	int a = 1;
	int b = 1;
	rep(i, c) {
		a = a * (x - i) % mod;
		b = b * (i + 1) % mod;
	}
	return a * inv(b) % mod;
}

signed main() {
	int n, m;
	cin >> n >> m;
	int mm = m;
	vector<int> v;
	for(int i = 2; i * i <= mm; i++) {
		int k = 0;
		while(m % i == 0) {
			k++;
			m /= i;
		}
		v.push_back(k);
	}
	if(m > 1) {
		v.push_back(1);
	}
	int all = 1;
	for(auto i: v) {
		all = all * comb(n + i - 1, i) % mod;
	}
	cout << all << endl;
}

Measured memory_bytes: 640
/*
AizuOnline A1006
Title
*/
#include <stdio.h>
// Select Below
#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
#define MAXLEN 1000
int n;
int k;
int from[MAXLEN],to[MAXLEN];
int kugiri[MAXLEN*2+2];
int cm_flag[MAXLEN*2+2];
int start_time;
int end_time;
int total_n_of_period;
int total_kugiri;
//
int time_diff(int f,int t)
{
  int f1,t1;
  f1=(f / 100)*60 + (f % 100);
  t1=(t / 100)*60 + (t % 100);
  return(t1-f1);
}
void mv_kugiri()
{
  int i;

  kugiri[0]=start_time;
  //printf("k0:%d\n",kugiri[0]);
  for(i=0;i<total_n_of_period;i++)
    { 
      kugiri[1+i]=from[i];
      kugiri[total_n_of_period+i+1]=to[i];
    }
  kugiri[total_n_of_period*2+1]=end_time;
  total_kugiri=total_n_of_period*2+2;
}
int comp(void * x,void * y)
{
  return(*(int *)x - *(int *)y);
}
void sort_kugiri()
{
  qsort(kugiri,total_n_of_period*2+1,sizeof(int),(__compar_fn_t)comp);
}
void clear_cm_flag()
{
  memset(cm_flag,0,sizeof(cm_flag)/sizeof(int));
}
void uniq_kugiri()
{
  int i,j,p;
  p=0;
  for(i=0,j=0;i<total_n_of_period*2+2;i++)
    {
      if(i!=j)
	kugiri[j]=kugiri[i];
      if(kugiri[i+1]!=kugiri[i])
	j++;
    }
  total_kugiri=j;
}
void show()
{
  int i;

  for(i=0;i<total_kugiri;i++)
    printf("%d\n",kugiri[i]);
  printf("----\n");
}
void show2()
{
  int i;

  for(i=0;i<total_kugiri;i++)
    printf("%d(%d)\n",kugiri[i],cm_flag[i]);
  printf("----\n");
}
set_cm_flag()
{
  int i,j,p,st,en;

  for(i=0;i<total_n_of_period;i++)
    {
      st=from[i];en=to[i];
      for(j=0;j<total_kugiri;j++)
	if(kugiri[j]==st)
	  p=j;
      while(kugiri[p]<en)
	{
	  cm_flag[p]++;
	  p++;
	}
    }
}
get_max_cm_period()
{
  int i,m,s;
  m=0;s=0;

#ifdef DEBUG
	  printf("TK:%d\n",total_kugiri);
#endif

  for(i=0;i<total_kugiri-1;i++)
    {

      if(cm_flag[i] < n)
	{
	  s += time_diff(kugiri[i],kugiri[i+1]);
#ifdef DEBUG
	  printf("T:%d",s);
#endif
	  if(s > m)
	    m = s;
	}
      else
	s=0;
    }
  return(m);
}

int calc()
{
  mv_kugiri();
  sort_kugiri();
  uniq_kugiri();
  //show();
  
  clear_cm_flag();
  
  set_cm_flag();
#ifdef DEBUG
  show2();
#endif
  return(get_max_cm_period());
  /*
  return(0);
  */
}
main()
{
  int i,j,p,q,ret;

 
  while(EOF!=scanf("%d %d %d",&n,&start_time,&end_time) 
	&& (n||start_time||end_time))
    {
      q=0;
      for(i=0;i<n;i++)
	{
	  scanf("%d",&k);
	  for(p=0;p<k;p++)
	    {
	      scanf("%d ",&(from[q]));
	      scanf("%d ",&(to[q]));
	      q++;
	    }
	}
      total_n_of_period=q;
      ret=calc();
      printf("%d\n",ret);      
    }
return(0);
}

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

int main() {
    int n;
    cin >> n;
    string s;
    map<string, int> mp;
    vector<pair<int, string>> ranking;
    vector<string> ans;
    rep(i,n) {
        cin >> s;
        mp[s]++;
    }
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        ranking.push_back(make_pair(-itr->second, itr->first));
    }
    sort(ranking.begin(), ranking.end());
    ans.push_back(ranking[0].second);
    for(int i = 1; i < ranking.size(); i++) {
        if (ranking[i].first == ranking[0].first) {
            ans.push_back(ranking[i].second);
        }
        else break;
    }
    sort(ans.begin(), ans.end());
    rep(i,ans.size()) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 32240
N,M,X = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

cost = 0
for i in range(X-1):
    if i+1 in A:
        cost += 1

mincost = cost
cost = 0
for i in range(N-X-1):
    if X+1+i in A:
        cost += 1

if mincost < cost:
    print(mincost)
else:
    print(cost)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <bitset>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  ll N,K;
  cin >> N >> K;
  ll t = N / K;
  ll ans = min(N-t*K, abs(N-(t+1)*K));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int main(){
	int N;
	int A[100];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	int ans=0;
	int idx=0;
	while(idx<N){
		int cnt=1;
		while(idx+1<N&&A[idx]==A[idx+1]){
			idx++;
			cnt++;
		}
		ans+=(cnt-cnt%2)/2;
		idx++;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

template <typename number> number numpow(number a, LL b)
{  // a^b
    if (b == 0)
        return 1;

    if (b % 2 == 0)
    {
        number d = numpow(a, b / 2);
        return (d * d);
    }

    return (a * numpow(a, b - 1));
}

void solve()
{
    LL n, m, d;
    cin >> n >> m >> d;
    double avg_pair = (d >= 1 ? 2 * double(n - d) : double(n)) / double(n * n);
    std::cout << avg_pair * (m - 1) << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
using namespace std;
const int N=1e5+50;
const int mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll tc=1;
	for(ll T=1; T<=tc;T++){
		ll n; cin>>n;
		ll ans = (n/500)*1000+((n%500)/5)*5;
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
//多分TLE

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
//const ll mod=1e+9+7;
int h,w;
char maze[21][21];
int sx=0,sy=0;
int main(void){
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>maze[i][j];
            if(maze[i][j]=='.'){
                sy=i;sx=j;
            }
        }
    }
    //bfsで求める
    int roty[4]={1,0,-1,0},rotx[4]={0,1,0,-1};
    int res=0;
    rep(i,h){
        rep(j,w){
            if(maze[i][j]!='.')continue;
            queue<pair<int,int>> que;
            que.push(make_pair(i,j));
            int t[h][w];
            for(int k=0;k<h;k++){
                for(int l=0;l<w;l++)t[k][l]=-1;
            }
            int maxi=0;
            t[i][j]=0;
            
            while(que.size()>0){
                pair<int,int> P=que.front();que.pop();
                int y=P.first,x=P.second;
                for(int k=0;k<4;k++){
                    int ny=y+roty[k],nx=x+rotx[k];
                    if(0<=ny&&ny<h&&0<=nx&&nx<=w&&maze[ny][nx]=='.'&&t[ny][nx]==-1){
                        t[ny][nx]=t[y][x]+1;
                        que.push(make_pair(ny,nx));
                        maxi=max(maxi,t[ny][nx]);
                    }
                }
            }
            
            res=max(maxi,res);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
def gcd(x,y):
    if x==0:return y
    else:return gcd(y%x,x)
def lcm(x,y):
    return x*y//gcd(x,y)
 
a,b,c,d = map(int,input().split())
a -= 1
# print(gcd(c,d),lcm(c,d))
ba = b - b//c - b//d + b//lcm(c,d)
aa = a - a//c - a//d + a//lcm(c,d)
print(ba - aa)

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

char C[102][102];

int Check(int x, int y, char c){
	if(C[x][y] != c){
		return 0;
	}
	C[x][y] = '.';
	Check(x  ,y-1,c);
	Check(x+1,y  ,c);
	Check(x  ,y+1,c);
	Check(x-1,y  ,c);
}

int main(){
	int W,H;
	while(cin >> W >> H){
		if(W == 0 && H == 0){
			break;
		}
		for(int x = 1;x <= W;x++){
			for(int y = 1;y <= H;y++){
				cin >> C[x][y];
			}
		}
		int cnt = 0;
		for(int x = 1;x <= W;x++){
			for(int y = 1;y <= H;y++){
				if(C[x][y] != '.'){
					cnt++;
					Check(x,y,C[x][y]);
				}
			}
		}	
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 1476
#include <stdio.h>

int main(void){
    
    int i,n;
    while(scanf("%d",&n)!=EOF){
        for(i=0;i<n;i++){
            int up[101],num[101];
            int j,k;
            scanf("%d",&k);
            for(j=0;j<k;j++){
                scanf("%d",&num[j]);
            }
            for(j=0;j<k-1;j++){
                up[j]=num[j+1]-num[j];
            }
            int max,min;
            max=min=0;
            for(j=0;j<k-1;j++){
                if(up[j]>0 && up[j]>max){
                    max=up[j];
                }else if(up[j]<0 && up[j]<min){
                    min=up[j];
                }
            }
            printf("%d %d\n",max,-min);
            
        }
    }
    return 0;
}

Measured memory_bytes: 596
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
A = set(a)
MOD = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
    if i in A:
        dp[i] = -1
        continue
    if i == 1:
        if not i - 1 in a:
            dp[i] = 1
    else:    
        if dp[i - 1] != -1:
            dp[i] += dp[i - 1] % MOD
        if dp[i - 2] != -1:
            dp[i] += dp[i - 2] % MOD
print(dp[-1] % MOD)

Measured memory_bytes: 56664
#include <stdio.h>

int main(void)
{
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  
  tmp=a;
  a=b;
  b=tmp;
  tmp=a;
  a=c;
  c=tmp;
  printf("%d %d %d",a,b,c);
  
  return 0;
}

Measured memory_bytes: 1672
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>;
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n,t;cin >>n>> t;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)cin >>a[i];
  
  ll s=0, now=0, ans=0;
  for(int i = 0; i < n; ++i){
    if(now+t>=a[i]){
      now=a[i];
    }
    else{
      ans+=now+t-s;
      s=a[i];
      now=a[i];
    }
  }
  ans+=now+t-s;
  cout << ans << endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v(3);
    F0R(i, 3) cin >> v[i];
    sort(v.begin(), v.end());
    cout << v[0] + v[1];
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

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

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

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

  int flag = 0;
  for (int i = 0; i < s.size(); i++) {
    if(s[i] == 'C') flag = 1;
    if(flag == 1 && s[i] == 'F') {
      flag = 2;
      break;
    }
  }

  if (flag == 2) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    set<ll>s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        s.insert(a);
    }
    if(s.size()==n)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
    }


Measured memory_bytes: 9600
/*  -*- coding: utf-8 -*-
 *
 * c.cc: E: 木と整数 / Integers on a Tree
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

struct Node {
  int v, minv, maxv, p;
  Node(): v(INF), minv(-INF), maxv(INF), p(-1) {}
  Node(int _v): v(_v), minv(_v), maxv(_v), p(_v & 1) {}
  void print() {
    printf("Node(v=%d, minv=%d, maxv=%d, p=%d)\n", v, minv, maxv, p);
  }
};

/* global variables */

vi nbrs[MAX_N];
int vs[MAX_N], ps[MAX_N];
Node nds[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) nds[i] = Node();

  for (int i = 0; i < n - 1; i++) {
    int ai, bi;
    cin >> ai >> bi;
    ai--, bi--;
    nbrs[ai].push_back(bi);
    nbrs[bi].push_back(ai);
  }

  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> vs[i] >> ps[i];
    vs[i]--;
    nds[vs[i]] = Node(ps[i]);
  }

  for (int i = 0; i < k; i++) {
    int st = vs[i];
    queue<pii> q;
    q.push(pii(st, -1));

    while (! q.empty()) {
      pii u = q.front(); q.pop();
      int &ui = u.first, &uprt = u.second;
      Node &ndu = nds[ui];
      int vminv = ndu.minv - 1, vmaxv = ndu.maxv + 1, vp = ndu.p ^ 1;
      vi &nbru = nbrs[ui];
      for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	if (*vit == uprt) continue;

	int &vi = *vit;
	Node &ndv = nds[vi];
	if (ndv.p >= 0 &&
	    (ndv.p != vp || ndv.minv > vmaxv || ndv.maxv < vminv)) {
	  puts("No");
	  return 0;
	}

	if (ndv.minv < vminv || ndv.maxv > vmaxv) {
	  ndv.minv = max(ndv.minv, vminv);
	  ndv.maxv = min(ndv.maxv, vmaxv);
	  ndv.p = vp;
	  if (ndv.v >= INF) q.push(pii(vi, ui));
	}
      }
    }
  }

  puts("Yes");

  //for (int i = 0; i < n; i++) printf("%d: ", i), nds[i].print();
  for (int i = 0; i < n; i++) printf("%d\n", nds[i].minv);

  return 0;
}


Measured memory_bytes: 9208
#include <iostream>

using namespace std;
using ll = long long;
auto const INF = static_cast<ll>(1e9);
void a(){
    int a,b;
    int c[3] = {1,2,3};
    cin >> a >> b;
    for(int i:c){
        if(i==a||i==b)continue;
        cout <<i << endl;
        return;
    }
}

void b(){
    int n;
    string s,t;
    cin >> n;
    cin >> s >> t;
    for(int i=0;i<n;i++){
        cout << s[i] << t[i];
    }
}

ll gcd(ll a,ll b){
    return b==0? a:gcd(b,a%b);
}

ll crl(ll a,ll b){
	return a*b/gcd(a,b);
}

void c(){
    int a,b;
  	cin >> a >> b;
    cout <<crl(a,b);
}

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


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
#define DEBUG true
//#define DEBUG false
using namespace std;

typedef long long ll;

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

  int n;
  cin >> n;
  ll a[n], b[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }

  ll ans = 0;
  ll c[n];
  for(int i = 0; i < 30; i++){
    for(int j = 0; j < n; j++){
      c[j] = b[j] % (1ll << (i + 1));
    }
    sort(c, c + n);
    ll count = 0;
    for(int j = 0; j < n; j++){
      ll aj = a[j] % (1ll << (i + 1));
      count += distance(
          lower_bound(c, c + n, (1ll << i) - aj),
          lower_bound(c, c + n, 2 * (1ll << i) - aj));
      count += distance(
          lower_bound(c, c + n, 3 * (1ll << i) - aj),
          lower_bound(c, c + n, 4 * (1ll << i) - aj));
    }
    if(count % 2 == 1) ans |= 1ll << i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
# sys.stdin.readline
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())
        A = map(int, input().split())
        A_c = collections.Counter(A)

        ans = 0
        for i, c in enumerate(A_c.most_common()[::-1]):
            if len(A_c) - i <= K:
                break
            else:
                ans += c[1]
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Measured memory_bytes: 103120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll num[114514];
bool f[114514];
int main(){
	ll n,m;
	cin>>n>>m;
	vector<vector<P>>v(n+1);
	for(int i=0;i<m;i++){
		ll l,r,d;
		cin>>l>>r>>d;
		v[l].push_back({r,d});
		v[r].push_back({l,-d});
	}
	ll inf=1e15;
	for(int i=1;i<=n;i++)num[i]=inf;
	queue<ll>que;
	for(int i=1;i<=n;i++){
		if(f[i])continue;
		if(num[i]==inf)num[i]=0;
		que.push(i);
		while(!que.empty()){
			ll x=que.front();
			que.pop();
			for(int j=0;j<v[x].size();j++){
				ll p=v[x][j].first,q=v[x][j].second;
				if(!f[p])que.push(p);
				f[p]=1;
				if(num[p]==inf)num[p]=num[x]+q;
				else{
					if(num[p]!=q+num[x]){
						cout<<"No\n";
						return 0;
					}
				}
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 17032
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  string s;
  cin>>s; int idxw=-1,idxr=-1;
  rep(i,0,s.length()) if(s[i]=='W'){idxw=i;break;}
  rrep(i,s.length()-1,0) if(s[i]=='R'){idxr=i;break;}
  if(idxw==-1 || idxr==-1 || idxr<idxw){
    cout<<0<<endl;
    return;
  }
  int ans=0;
  while(idxw<idxr){
    ans++;
    idxw++;
    idxr--;
    rep(i,idxw,s.length())if(s[i]=='W'){idxw=i;break;}
    rrep(i,idxr,0) if(s[i]=='R'){idxr=i;break;}
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

using namespace std;

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

typedef long long ll;

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

int main(int argc, char const *argv[]) {
	int N, Q; cin >> N >> Q;
	char S[N]; cin >> S;
	
	int c = 0;
	vector<int> cnt(N, 0);
	rep(i, N-1) {
		if (S[i] == 'A' && S[i+1] == 'C') c++;
		cnt[i+1] = c;
	}

	rep(i, Q) {
		int l, r; cin >> l >> r;
		cout << cnt[r-1] - cnt[l-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
graph = []

def init():
    global graph
    graph = [[False] * 26 + [True] for _ in xrange(27)]
    graph[26][26] = False

def atoi(c):#index
    if c == "#":
        return 26
    return ord(c) - ord("a")

def make_graph(L):
    global graph, count
    cur = 0
    L = [L[0]] + [L[i] for i in xrange(1, len(L)) if L[i] != L[i-1]]
    tmp = []
    for s1, s2 in zip(L, L[1:]):
        if s1[0] == s2[0]:
            tmp += [s1[1:], s2[1:]]
        else:
            if not tmp == []:
                make_graph(tmp)
            tmp = []
            graph[atoi(s2[0])][atoi(s1[0])] = True
    if not tmp == []:
        make_graph(tmp)

def check(start):
    stack = set([start])
    visited = [False] * 27
    while len(stack) != 0:
        cur = stack.pop()
        visited[cur] = True
        if graph[cur][start]:
            return False
        for i in xrange(27):
            if graph[cur][i] and not visited[i]:
                stack.add(i)
    return True

while True:
    n = input()
    if n == 0:
        break
    L = [raw_input() + "#" for _ in xrange(n)]
    init()
    make_graph(L)
    for i in xrange(27):
        if not check(i):
            print "no"
            break
    else:
        print "yes"

Measured memory_bytes: 4344
#include<cstdio>
#include<cstring>
using namespace std;
int sum=0;
char s[100001];
int n;
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		sum+=s[i]-'0';
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;

    vector<ll>v(3);
    for(ll i=0;i<3;++i)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    ll c=0;
    for(ll i=1;i<v.size();++i)
    {
        c+= v[i] - v[i-1];
    }
    cout<<c<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

///////////////

void solve(){
	ll x, y;
	cin >> x >> y;
	if(abs(x - y) <= 1){
		cout << "Brown" << endl;
	}else{
		cout << "Alice" << endl;
	}
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int r; cin>>r;
  if(r<1200){
    cout<<"ABC"<<endl;
  }else if(r<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)	   for(int i = 0; i < (n); ++i)
#define all(c)		   begin(c), end(c)
#define rall(c)		   rbegin(c), rend(c)
#define SZ(a)		   ((ll) a.size())

typedef long long		   ll;
typedef unsigned long long ull;


int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int pinv=pow(2,m);
	int ans=pinv*(1900*m+100*(n-m));
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る事前計算
void COMinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; ++i){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k){
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<int> prime_factor(int n){
	vector<int> res;
	for (int i = 2; i * i <= n; ++i){
		while (n % i == 0){
			res.push_back(i);
			n /= i;
		}
	}
	if (n != 1)res.push_back(n);
	return res;
}

int main(){
	int n, m;
	cin >> n >> m;
	if (m == 1){
		puts("1");
		return 0;
	}
	vector<int> v = prime_factor(m);
	COMinit();
	int cnt = 1, p = v[0];
	long long res = 1;
	for (int i = 1; i < v.size(); ++i){
		if (p != v[i])res *= COM(n - 1 + cnt, n - 1), p = v[i], cnt = 0;
		cnt++;
		res %= MOD;
	}
	res *= COM(n - 1 + cnt, n - 1);
	res %= MOD;
	cout << res << endl;
}

Measured memory_bytes: 12160
#include <stdio.h>
int main(void)
{
  int n,i;
  long int sum=0;
  scanf("%d",&n);
    for(i=1;i<=n;i++) {
      if(i%3!=0 && i%5!=0)
        sum+=i;
    }
  printf("%ld",sum);
  return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, ll> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<vector<int>> to(N);
  map<pair<int, int>, ll> len;
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--, v--;
    to[u].push_back(v);
    to[v].push_back(u);
    len[make_pair(u, v)] = w;
    len[make_pair(v, u)] = w;
  }
  queue<P> q;
  vector<int> color(N, -1);
  q.push(P(0, 0));
  while (!q.empty()) {
    int v;
    ll l;
    tie(v, l) = q.front();
    q.pop();
    if (color[v] != -1)
      continue;
    color[v] = l % 2 == 0 ? 0 : 1;
    dump(v, l, color[v]);
    for (const int& u : to[v]) {
      q.push(P(u, l + len[make_pair(v, u)]));
    }
  }
  for (int i = 0; i < N; i++) {
    cout << color[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 18944