akhauriyash/Code-Regression huggingface dataset:
//ALDS1_3_C Elementary data structures - Doubly Linked List
#include <cstdio>
#include <cstring>
class DoublyLinkedList
{
    struct Node
    {
        int key;
        Node *prev, *next;
    };

    Node *nil;

public:
    DoublyLinkedList()
    {
        init();
    }

    ~DoublyLinkedList()
    {
        delete nil;
    }

    void init()
    {
        nil = new Node();
        nil->next = nil;
        nil->prev = nil;
    }

    void insert(int key)
    {
        Node *x = new Node();
        x->key = key;
        // 番兵の直後に要素を追加
        x->next = nil->next;
        nil->next->prev = x;
        nil->next = x;
        x->prev = nil;
    }

    void deleteNode(Node *t)
    {
        if (t == nil)
            return; // tが番兵の場合は処理しない
        t->prev->next = t->next;
        t->next->prev = t->prev;
        delete t;
    }

    Node *listSearch(int key)
    {
        Node *cur = nil->next; // 番兵のつぎの要素から辿る
        while (cur != nil && cur->key != key)
        {
            cur = cur->next;
        }
        return cur;
    }

    void deleteFirst()
    {
        deleteNode(nil->next);
    }

    void deleteLast()
    {
        deleteNode(nil->prev);
    }

    void deleteKey(int key)
    {
        // 検索したノードを削除
        deleteNode(listSearch(key));
    }

    void printList()
    {
        Node *cur = nil->next;
        int isf = 0;
        while (1)
        {
            if (cur == nil)
                break;
            if (isf++ > 0)
                printf(" ");
            printf("%d", cur->key);
            cur = cur->next;
        }
        printf("\n");
    }
};


int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    DoublyLinkedList dll;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);
        if (com[0] == 'i')
        {
            dll.insert(key);
            np++;
            size++;
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                    dll.deleteFirst();
                else if (com[6] == 'L')
                    dll.deleteLast();
            }
            else
            {
                dll.deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    dll.printList();
    return 0;
}


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

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

    int A[N];
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }

    if (H > sum) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
	
	public static void main(String[] args){
 Scanner scanner = new Scanner(System.in);
  int N = scanner.nextInt();
  int K = scanner.nextInt();
  scanner.nextLine();
  String[] d = scanner.nextLine().split(" ");
  Double[] exp = new Double[N];
  Double val;
  for(int x =0; x<N; x++){
    val = Double.parseDouble(d[x]);
    exp[x] = (val+1)/2;
  }
  Double res = 0.0;
  for(int y = 0; y<K; y++){
    res = res + exp[y];
  }
  Double sum = res;
  for(int y = K; y<N; y++){
    res = res + exp[y] - exp[y-K];
    sum = Math.max(sum, res);
  }
  System.out.println(sum);
  

}
}

Measured memory_bytes: 60688
#include <iostream>

using namespace std;

int main()
{
    int data[11];
    int temp;
    for(int a = 0;a<10;a++)
    {
        cin >> data[a];
        if(data[a]<0||data[a]>10000)return 0;
    }

    for(int x=0;x<10;x++)
    {
        for(int y=0;y<10;y++)
        {
            if(data[y]<data[y+1])
            {
                temp = data[y];
                data[y] = data[y+1];
                data[y+1] = temp;
            }
        }
    }
    cout << data[0] <<endl;
    cout << data[1] <<endl;
    cout << data[2] <<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>

namespace TokorotenLab
{
    class Logger
    {
    private:
        bool isEnable;

    public:
        Logger(bool isEnable = true) : isEnable(isEnable) {}

        template<class T>
        Logger& operator<<(const T& val)
        {
            if(isEnable)
            {
                std::cout << val;
            }
            return *this;
        }

        void set_enable()
        {
            isEnable = true;
        }

        void set_disable()
        {
            isEnable = false;
        }

        void endl()
        {
            if(isEnable)
            {
                std::cout << std::endl;
            }
        }
    };

    Logger logger;

    /*
    Arguments:
        Search range: [begin, end)
        Target function: f(x)
    Requirement:
        f(x) => { false, ..., false, true, ..., true }
    Judge:
        true_bound == begin => All f(x) are true
        true_bound == end => All f(x) are false
    */
    std::pair<long long, long long> binary_search(long long begin, long long end, std::function<bool(long long)> f)
    {
        long long false_bound = begin - 1LL; // ( ..., false_bound] => false
        long long true_bound = end; // [true_bound, ... ) => true
        long long x;

        while(true_bound - false_bound > 1LL)
        {
            x = false_bound + (true_bound - false_bound) / 2LL;
            if(f(x))
            {
                true_bound = x;
            }
            else
            {
                false_bound = x;
            }
        }

        return std::make_pair(false_bound, true_bound);
    }
}

using namespace std;

TokorotenLab::Logger logger = TokorotenLab::logger;

int main()
{
    string n, nr;

    cin >> n;

    nr = n;
    reverse(n.begin(), n.end());

    if(n == nr)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

int n,MAX,sum;
int a[105];

int main()
{
	cin >> n;
	for(int i = 1;i <= n; i++) {
		cin >> a[i];
		sum += a[i];
		MAX = max(a[i],MAX);
	}
	if(sum > 2 * MAX) cout <<"Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
  int N;// neg; 負のAiの個数 ,pos 正の．
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
      cin >> A[i];
  }
  sort(A.begin(), A.end());

  vector<int> x(N-1), y(N-1);
  int tmp_large = A[N-1];
  int tmp_small = A[0];
  for(int i=0; i<N-2; i++) {
    if(A[i+1]<0) {
      x[i] = tmp_large;
      y[i] = A[i+1];
      tmp_large = x[i] - y[i];
    } else  {
      x[i] = tmp_small;
      y[i] = A[i+1];
      tmp_small = x[i] - y[i];
    }
  }
  // 最後の一回 
  x[N-2] = tmp_large;
  y[N-2] = tmp_small;
  int M = x[N-2] - y[N-2];
  
  cout << M << endl; // tmp = M 
  rep(i, N-1) {
    cout << x[i] << ' ' << y[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
using namespace std;
long long a, b, k;
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    scanf("%d%d%d",&a,&b,&k);
    for(int i=a;i<=min(b,a+k-1);i++)printf("%d\n",i);
    for(int i=max(b-k+1,a+k);i<=b;i++)printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.Scanner;
import java.util.Stack;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FSugoroku solver = new FSugoroku();
        solver.solve(1, in, out);
        out.close();
    }

    static class FSugoroku {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int k = in.nextInt();
            char[] c = in.next().toCharArray();
            Stack<Integer> stk = new Stack<>();

            int index = n;
            while (index > 0) {
                boolean f = true;
                for (int i = k; i > 0; i--) {
                    int nxt = index - i;
                    if (nxt < 0) {
                        continue;
                    }
                    if (c[nxt] == '0') {
                        index -= i;
                        stk.push(i);
                        f = false;
                        break;
                    }
                }
                if (f) {
                    out.println(-1);
                    return;
                }
            }

            while (!stk.isEmpty()) {
                out.print(stk.pop());
                out.print(" ");
            }
            out.println();


        }

    }
}



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

int main(){
    int N;
    pair<string, pair<int, int>> C[1000];
    cin >> N;
    
    for(int i=0; i<N; i++){
	cin >> C[i].first >> C[i].second.first;
	C[i].second.first = 100-C[i].second.first;
	C[i].second.second = i+1;
    }
    sort(C, C+N);
    for(int i=0; i<N; i++){
	cout <<C[i].second.second<<endl;
    }    	    
}


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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int ans=s.size();
	for (int i = 0; i < s.size()-1; ++i)
	{
		if (s[i]!=s[i+1])
		{
			ans=min(ans,max(i+1,(int)s.size()-i-1));
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
def f(n, a):
    inf = float("inf")
    dp = [[0] * n for _ in range(n)]
    for i in range(n - 2, -1, -1):
        s = a[i]
        dpi = dp[i]
        for j in range(i + 1, n):
            mn = inf
            s += a[j]
            for d in range(i, j):
                k = dpi[d] + dp[d + 1][j]
                if k < mn:
                    mn = k
            dpi[j] = mn + s
    return dp[0][-1]


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


Measured memory_bytes: 7460
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    var (n, k) = listOfInt()
    val dd = listOfInt()

    while (true) {
        var sn = n.toString()
        if (sn.filter { it.toString().toInt() !in dd }.length == sn.length) {
            println(n)
            return
        }
        n++
    }
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 49492
#include <iostream>
#include <cstdio>
#define PI 3.141592653589
using namespace std;
 
int main(){
    double x;
    cin >> x;
     
    double z = x*PI;
    printf("%.6f %.6f\n",z*x,z*2.0);
     
    return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <cctype>

using namespace std;


int main()
{
    string str;
    getline(cin, str);

    for(size_t i = 0; i < str.size(); i++)
    {
        if(islower(str[i])){ str[i] = toupper(str[i]); }
        else if(isupper(str[i])){ str[i] = tolower(str[i]); }
    }
    cout << str << endl;

    return 0;
}

Measured memory_bytes: 3172
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <array>

using namespace std;
using ll = long long;

#define LIMIT 100000
using edge = struct { int to; ll cost; };
vector<edge> tree[LIMIT];
ll depth[LIMIT];

/*
	【 DFS(深さ優先探索) 】
	
	< 注意 >
	最初に
	tree[頂点番号].push_back({ 辺の先の頂点番号, 距離 });
	tree[辺の先の頂点番号].push_back({ 頂点番号, 距離 });
	を実行して初期化してください。
	
	< 実行内容 >
	depth[A]に指定した頂点(v)から頂点Aまでの距離を格納する
	
	< パラメータ >
	tree[A] : 点Aと接続する辺の可変長配列
	depth[A] : 点Aに達するまでの距離(コスト)
*/

void DFS(
	int v,      // int v : 現在探索中の頂点の番号
	int p = -1, // int p : 探索元の頂点、普通は-1を指定
	ll d = 0    // ll  d : 距離(コスト)の初期値、普通は0を指定
) {
	depth[v] = d;
	for (auto &e : tree[v]) {
		if (e.to == p) continue;
		DFS(e.to, v, d + e.cost);
	}
}


int main() {
	
	ll N, Q, K;
	vector<array<ll, 3>> T;
	vector<array<ll, 2>> X;
	int a, b, c;
	
	// 入力
	cin >> N;
	for(int i=0; i<N-1; i++){
		cin >> a >> b >> c;
		a--; b--;
		tree[a].push_back({b, c});
		tree[b].push_back({a, c});
	}
	
	cin >> Q >> K;
	DFS(K-1);
	for(int i=0; i<Q; i++){
		cin >> a >> b;
		a--; b--;
		cout << depth[a] + depth[b] << '\n';
	}
	
	return 0;
	
}


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

bool check( string &s){
  int st = 0, ed = s.size()-1;
  while( st<ed && s[st] == s[ed] ){ st++; ed--;}
  return  st >= ed;
}

int main(){
  while( getline(cin,buf) ){
    string s;
    for(int i=0;i<(int)buf.size();i++){
      if( 'a' <= buf[i] && buf[i] <= 'z' ) s += (buf[i]+'A'-'a');
      else if( 'A' <= buf[i] && buf[i] <= 'Z' ) s+= buf[i];
    }

    vector<string> ans;
    for(int i=1;i<(int)s.size();i++){
      int range = min( i, (int)s.size() - i - 1 );
      for(int j=range;j>0;j--){
	string r = s.substr(i-j,2*j+1);
	//	cout << r << endl;
	if( check(r) ) {
	  ans.push_back(r);
	  break;
	}
      }
    }

    for(int i=0;i<(int)s.size();i++){
      int range = s.size()-i;
      if( range & 1 ) range--;
      for(int j=0;range-j*2>2;j++){
	string r = s.substr(i+j,range-2*j);
	//	cout << r << endl;
	if( check(r) ) {
	  ans.push_back(r);
	  break;
	}
      }
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    

    set<string> M;
    for(int i=0;i<(int)ans.size();i++){
      //cout << ans[i] << endl;
      //cout << M.count( ans[i] ) << endl;
      if( M.count(ans[i]) != 0 ) continue;
      int range = ans[i].size();
      //     cout << range << endl;
      for(int j=1;range-2*j>2;j++){
	//	cout << ans[i].substr(j,range-2*j) << endl;
	M.insert(ans[i].substr(j,range-2*j));
      }
    }
    vector<string> res;
    for(int i=0;i<(int)ans.size();i++){
      //cout << M.count(ans[i]) << endl;
      //cout << ans[i] << endl;
      if( M.count(ans[i]) == 0 )
	res.push_back(ans[i]);
    }


    for(int i=0;i<(int)res.size();i++){
      if( i ) cout << " ";
      cout << res[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
 
int main() {

	int N;
	cin >> N;
	long long sum=0;
	long long A[N];
	cin >> A[0];
	long long max=A[0];
	for(int i=1; i<N; i++){
		cin >> A[i];
		if(max>=A[i]){
			sum += max-A[i];
		}
		else{
			max=A[i];
		}
	}
	cout << sum << endl;

  return 0;
}

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

int lcm(int a, int b)
{
	int r, a1=a, b1=b;
	while(b>0)
	{
		r=a%b;
		a=b;
		b=r;
	}
	return (a1*b1)/a;
}

int main()
{
	int x, l;
	
	cin>>x;
	
	if(360%x==0)
	cout<<360/x;
	
	else
	{
		l=lcm(360, x);
		cout<<l/x;
	}
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  vi dp(n + 1, 0);
  dp[0] = 1;
  dp[1] = 1;
  FOR(i, 2, n + 1) dp[i] = dp[i - 1] + dp[i - 2];
  cout << dp[n] << endl;
}


Measured memory_bytes: 3096
package main

import (
	"fmt"
)

func main() {

	var N ,M int

	fmt.Scan(&N,&M)

	A := SliceInt(M)

	for i:=0;i<M;i++{

		fmt.Scan(&A[i])
	}


	sum:=0

	for i:=0;i<M;i++{

		sum += A[i]

	}

	if N-sum >= 0{

		fmt.Println(N-sum)

	}else{

		fmt.Println(-1)
	}

}

//SliceInt 引数サイズのSliceを返す
func SliceInt(a int) []int {

	IntSample := make([]int, a)

	return IntSample

}

Measured memory_bytes: 2440
#!usr/bim/python
#! -*- coding: utf-8 -*-

import copy

n = raw_input()
n = int(n)

al = raw_input()
al = al.split()
al = map(int,al)

al.sort()

x = 0
y = 0
z = 0

mae = 0
saidai = 0

for i in range(n):
    a = al[i]
    if a == mae:
        x += 1
        y += 1
        z += 1
    elif a == mae + 1:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(y) + 1
        y = copy.copy(x) + 1
        x = 1
    elif a == mae + 2:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(x) + 1
        y = 1
        x = 1
    else:
        if z > saidai:
            saidai = copy.copy(z)
        z = 1
        y = 1
        x = 1
    mae = a

if z > saidai:
    saidai = z

print saidai


Measured memory_bytes: 11320
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}

int main() {
    ll p=1e9+7;
    ll n,m;cin>>n>>m;
    map<ll,ll>mp;
    ll tg=m;
    if(m==1){cout<<1<<endl;return 0;}
    //そいんすうぶんかい//
    for(ll i=2;i*i<=m;i++){
        ll cnt=0;
        while(tg%i==0){
            cnt++;
            tg/=i;
        }
        mp[i]=cnt;
    }
    if(tg!=1)mp[tg]=1;
    //////////////////////
    ll ans=1;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ans*=mod_cnb(n+itr->second-1,itr->second,p);
        ans%=p;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		System.out.println((a + b) / 2 + (a + b) % 2);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;

const ll N = 1e5;
ll mod_pow(ll x,ll n,ll mod){

  if(n==0)return 1;

  ll res=mod_pow( x*x%mod , n/2 , mod );

  if( n & 1 )res = res*x%mod;

  return res;

}



ll fact[N];

ll infact[N];



void make_factorial(void){

  fact[0] = 1;

  for( ll i = 1 ; i < N ; i++ ){

    fact[i] = fact[i-1] * i;

    fact[i] %= MOD;

  }

  for( ll i = 0 ; i < N ; i++ ){

    infact[i] = mod_pow( fact[i] , MOD-2 , MOD );

  }

}



ll comb(ll a,ll b){

  if(a == 0 && b == 0)return 1;

  if(a < b || a < 0)return 0;

  ll tmp = infact[a-b]* infact[b] % MOD;

  return tmp * fact[a] % MOD; 

}

int main(){
  ll n,k;
  cin>>n>>k;
  make_factorial();
  cout<<comb(n+k-1,n)<<endl;
  return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int res = 0;
    int n;
    cin >> n;
    vector<pair<int, int> > v[n];
    rep (i, n) {
        int a;
        cin >> a;
        rep (j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            v[i].emplace_back(x, y);
        }
    }
    
    FOR (bit, 0, 1 << n) {
        vector<bool> trust(n);
        int cnt = 0;
        rep (i, n) {
            if (bit & (1 << i)) {
                trust[i] = true;
                cnt++;
            }
        }
        bool ok = true;
        rep (i, n) {
            if (trust[i]) {
                rep (j, v[i].size()) {
                    int x = v[i][j].first, y = v[i][j].second;
                    if ((y && !trust[x]) || (!y && trust[x])) ok = false;
                }
            }
        }
        if (ok) res = max(res, cnt);
    }
    cout << res << endl;
    
    return 0;
}



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

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> cnt(N);
    for (int i = 1; i < N; i++) {
        if (S[i-1] == 'A' && S[i] == 'C') cnt[i] = 1;
    }
    vector<int> cum(N);
    for (int i = 1; i < N; i++) {
        cum[i] = cum[i-1] + cnt[i];
    }
    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << cum[r] - cum[l] << endl;
    }
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll eval(ll k){return (k*(k+1))/2;}
int main()
{
   ll ans = 0;
   ll n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
	   ll r = n/i;
	   ans+=i*eval(r);
   }
   cout<<ans;
}

Measured memory_bytes: 3628
x,n = map(int, input().split())
if n ==0:
    print(x)
else:
    l = list(map(int, input().split())) 
    for i in range(0,52):
        if x-i not in l:
            print(x-i)
            break
        elif x+i not in l:
            print(x+i)
            break

Measured memory_bytes: 9084
#include<stdio.h>

int gcd(int a, int b){
  if(a < b){
    a ^= b;
    b ^= a;
    a ^= b;
  }
  int r = a % b;
  if(r == 0) r = b;
  else r = gcd(b, r);
  return r;
}

int main(){
  int n;
  scanf("%d", &n);
  int g;
  scanf("%d", &g);
  for(int i = 1; i < n; i++){
    int a;
    scanf("%d", &a);
    g = gcd(a, g);
  }
  printf("%d", g);
  return 0;
}


Measured memory_bytes: 128
i,j,k;long s[444],p[444][444],S,P;main(a){for(gets(p);~scanf("%d",&a);i=j)for(s[++j]=S+=a;k=i--;p[i][j]=P)for(P=9e18;k<j;)P=fmin(P,p[i][k]+p[k++][j]+S-s[i]);printf("%ld",P);}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=200005;
int n;
int a[N];
int b[N];
int main(){
	n=read();
	For(i,1,n)
		a[i]=read();
	int ans=0;
	For(i,1,n){
		b[a[i]]=b[a[i]-1]+1;
		ans=max(ans,b[a[i]]);
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

int main() {
  long long n;
  cin >> n;
  long long h[1000001];

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

  int pre = -999;
  for (long long i = 0; i < n; i++) {
    if (pre <= h[i]-1) {
      pre = h[i]-1;
    } else if (pre <= h[i]) {
      pre = h[i];
    } else {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  ll X,Y;
  cin >> X >> Y;
  int ans = 0;
  while(Y>=X) {
    Y =  Y>>1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int linearSearch(int, int *, int, int);

int main(void)
{
	int n, S[10000], q, T[500], i, a = 0;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &S[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++)
		scanf("%d", &T[i]);
	for (i = 0; i < q; i++) {
		if (linearSearch(n, S, q, T[i]) != -1)
			a++;
	}
	printf("%d\n", a);
	return 0;
}

int linearSearch(int n, int *S, int q, int T)
{
	int i = 0;

	S[n] = T;
	while (S[i] != T)
		i++;
	if (i == n) {
		return -1;
	}
	return i;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
int main()
{
  // 入力
  int n, m;
  cin >> n >> m;
  
  int light[10] = {0};
  int p[10] = {0};
  
  for (int i = 1; i <= m; i++) {
    int k;
    cin >> k;
    int b = 0;
    for (int j = 1; j <= k; j++) {
      int s;
      cin >> s;
      b |= (1 << (s-1));
    }
    light[i-1] = b;
  }
  
  for (int i = 1; i <= m; i++) {
    int pi;
    cin >> pi;
    p[i-1] = pi;
  }
  
  int count = 0;
  for (int sw = 0; sw < (1 << n); sw++) {
    bool flag = true;
    for (int i = 1; i <= m; i++) {
      int a = light[i-1] & sw;
      if (numofbits(a) % 2 != p[i-1]) {
        flag = false;
        break;
      }
    }
    if (flag)
	    count++;
  }
  
  // 出力
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 無限大を表す値

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    int maxA = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
        maxA = max(maxA, A[i]);
    }
    int W = H + maxA;

    vector<vector<long long>> dp(N+1, vector<long long>(W+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if (j-A[i] >= 0) {
                dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-A[i]] + B[i]);
            }
        }
    }

    long long result = INF;
    for (int j = H; j <= W; ++j) result = min(result, dp[N][j]);
    cout << result << endl;
}

Measured memory_bytes: 90784
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
  ll a, b, x; cin >> a >> b >> x;
  ll aa = a / x;
  ll bb = b / x;
  ll c = a%x;
  ll d = b%x;
  if(c == 0 && d == 0) cout << bb-aa+1 << endl;
  if(c == 0 && d != 0) cout << bb-aa+1 << endl;
  if(c != 0 && d == 0) cout << bb - aa << endl;
  if(c != 0 && d != 0) cout << bb - aa << endl;
}


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

long long solve(long long a, long long b, long long c) {
    if (a % 2 || b % 2 || c % 2) return 0;
    if (a == b && b == c) return -1;
    long long d = solve(b/2+c/2, a/2+c/2, a/2+b/2);
    return d == -1 ? -1 : d + 1;
}

int main() {
    long long a, b, c; cin >> a >> b >> c;
    cout << solve(a, b, c) << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;


int main(){

    int n;
    cin >> n;
    n--;

    ll ans = 0;
    for(int a = 1; a <= n; a++) {
        ans += n / a;
    }

    cout << ans << endl;
}

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a+b > a-b && a+b > a*b){
	    cout<<a+b<<'\n';
	}
	else if(a-b > a*b){
	    cout<<a-b<<'\n';
	}
	else{
	    cout<<a*b<<'\n';
	}
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
int num_edge = 0, head[100000];
struct Edge { int nxt, to; }edge[100000];
LL n, m, sum = 0, f[1000000] = {}, W[1000][1000] = {}, now = 0;
string S,str;
void add_edge(int from, int to) {
	edge[++num_edge].nxt = from;
	edge[num_edge].to = to;
	head[from] = num_edge;
}

char c;
int main() {
	cin >>S;
	int flag = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != 'x')
			str.push_back(S[i]);
	}
	for (int i = 0; i < str.size() / 2; i++) {
		if (str[i] != str[str.size() - i - 1]) {
			flag = 1;
			break;
		}
	}
	if (flag == 1)
		cout << -1 << endl;
	else {
		int J = 0;
		for (int j = 0; j < str.size(); j++) {
			for (int i = J; i < S.size(); i++) {
				if (S[i] == str[j]) {
					f[j] = i - J;
					J = i + 1;
					break;
				}
			}
		}
		f[str.size()] = S.size() - J;
		for (int i = 0; i <= str.size() / 2; i++)
			sum += abs(f[i] - f[str.size() - i]);
		//if (str.size() % 2 == 0)
			//sum += f[str.size() / 2];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 6784
import java.util.Scanner;

public class Main
{
	public static void main(String[]args)
	{
		Scanner scn = new Scanner(System.in);
		int ques = scn.nextInt();
		for(int a= 1;a<10;a++)
		{
			if((ques/a)<=9)
			{
				if(ques/a*a==ques)
				{
					System.out.println("Yes");
					break;
				}
			}
			if(a==9)
				System.out.println("No");
		}
	}
}

Measured memory_bytes: 23764
def is_palindrome(n):
    n = str(n)
    return n[0:len(n)//2+1]==n[::-1][0:len(n)//2+1]

if __name__ == '__main__':
    a,b = list(map(lambda x: int(x), input().split(" ")))
    
    c = 0
    for i in range(a,b+1):
        if is_palindrome(i):
            c += 1
    
    print(c)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{

    public static void main(String args[]){

	Scanner scan = new Scanner(System.in); 

	int inning = scan.nextInt();

	int outcount = 0;
	int sum = 0;
	int[] base = new int[3];
	for(int i = 0; i < 3; i++){
	    base[i] = 0;
	}

	String s1 = "HIT";
	String s2 = "HOMERUN";
	String s3 = "OUT";


	int pass = 0;

	while(pass < inning){

	    String in = scan.next();

	    if(in.equals(s1)){
		if(base[2] == 1){
		    sum++;
		}
		base[2] = base[1];
		base[1] = base[0];
		base[0] = 1;
	    }

	    if(in.equals(s2)){
		for(int i = 0; i < 3; i++){
		    if(base[i] == 1){
			sum++;
			base[i] = 0;
		    }
		}
		sum++;
	    }

	    if(in.equals(s3)){
		outcount++;
	    }

	    if(outcount == 3){
		System.out.println(sum);
		sum = 0;
		outcount = 0;
		pass++;
		for(int i = 0; i < 3; i++){
		    base[i] = 0;
		}
	    }

	}
    }
}

Measured memory_bytes: 0
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        string a = Console.ReadLine();
        string[] b = a.Split(' ');
        int[] c = new int[2];
        c[0] = int.Parse(b[0]);
        c[1] = int.Parse(b[1]);
        int[,] cell = new int[c[0], c[1]];
        for (int i = 0; i < c[0]; i++){
            string oneLine = Console.ReadLine();
            for (int j = 0; j < c[1]; j++){
                if(oneLine[j] == '.'){
                    cell[i, j] = 0;
                }else{
                    cell[i, j] = -1;
                }
            }
        }

        for (int i = 0; i < c[0]; i++)
        {
            for (int j = 0; j < c[1]; j++)
            {
                if(cell[i, j] == -1){
                    //Do Nothing
                }else{
                    int sroundedBombCount = 0;
                    for (int y = -1; y < 2; y++){
                        if (i + y < 0 || i + y >= c[0])
                            continue;
                        for (int x = -1; x < 2; x++){
                            if (j + x < 0 || j + x >= c[1])
                                continue;
                            if(cell[i+y, j+x] == -1){
                                sroundedBombCount++;
                            }
                        }
                    }
                    cell[i, j] = sroundedBombCount;
                }

            }
        }

        for (int i = 0; i < c[0]; i++)
        {
            for (int j = 0; j < c[1]; j++)
            {
                if (cell[i, j] == -1)
                {
                    Console.Write("#");
                }
                else{
                    Console.Write(cell[i, j]);
                }

            }
            Console.WriteLine();
        }

    }
}

Measured memory_bytes: 11220
import Data.List  -- sortBy, group
import Data.Ord   -- comparing

mode ls = fst . head $ svls
  where vls = map valLen . group . sort $ ls     -- list of value-length pairs
        valLen ls = (head ls, length ls)
        svls = sortBy (flip $ comparing snd) vls -- sorted vls

maxLen ls = head . sortBy (flip $ comparing length) $ ls

main = do
  s <- getLine
  let ls = words s
      ml = [mode ls,  maxLen ls]
  putStrLn . unwords $ ml

Measured memory_bytes: 3572
s=list(map(int,input().split()))
a=int(s[0])
b=int(s[1])
list=[]
list.append(a%2019)
list.append(b%2019)
e=100000
if s[0]+2018<=s[1]:
  print(0)
else:
  if list[0]<list[1]:
    for i in range(list[0],list[1]+1):
      for j in range(list[0],list[1]+1):
        if i==j:
          continue
        else:
          d=(i*j)%2019
          e=min(d,e)
    print(e)
  else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
    int n;
    cin >> n;
    vl vec(n);
    rep(i, n) cin >> vec[i];
    int cnt = 0;
    rep(i, n){
        rep(j, i+1, n){
            rep(k, j+1, n){
                if((vec[i]+vec[j])>vec[k] && (vec[j]+vec[k])>vec[i] && (vec[k]+vec[i])>vec[j]){
                    if(vec[i] != vec[j] && vec[j] != vec[k] && vec[k] != vec[i]){
                        cnt++;
                    }
                } 
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main()
{
    int h, w;
    while (true)
    {
        cin >> h >> w;
        if ((h == 0) && (w == 0))
            break;

        for (int i = 0; i < h; i++)
        {
            if ((i == 0) || (i == h - 1))
            {
                for (int j = 0; j < w; j++)
                    cout << "#";
            }
            else
            {
                for (int j = 0; j < w; j++)
                {
                    if ((j == 0) || (j == w - 1))
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

using namespace std;

using ull = unsigned long long;


int main() {
    int N, A[20], B[20], C[20], sum = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for(int i = 0; i < N; ++i) {
        cin >> B[i];
        sum += B[i];
    }
    for(int i = 0; i < N - 1; ++i) {
        cin >> C[i];
    }
    for(int i = 1; i < N; ++i) {
        if(A[i - 1] + 1 == A[i]) {
            sum += C[A[i - 1] - 1];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int x, y, a, b, c;
vector<P> p;
int main(void){
    cin >> x >> y >> a >> b >> c;
    
    
    for(int i=0;i<a+b+c;i++){
        int v;
        cin >> v;
        p.push_back(P(v, i));
    }
    
    sort(p.begin(), p.end(), greater<P>());
    
    long long ans = 0;
    vector<int> cnt(3, 0);
    for(int i=0;cnt[2]<x+y;i++){
        int v = p[i].first;
        int d = p[i].second;
        if(d < a){
            if(cnt[0] < x){
                cnt[0]++;
                ans += v;
                cnt[2]++;
            }
        }else if(d < a+b){
            if(cnt[1] < y){
                cnt[1]++;
                ans += v;
                cnt[2]++;
            }
        }else{
            ans += v;
            cnt[2]++;
        }
        
    }
    cout << ans << endl;
    
    
}


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

    int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n,m;
  cin>>n>>m;
  int l[m],r[m],ma=-2,mi=INT_MAX;
  for(int i=0;i<m;i++){
  cin>>l[i]>>r[i];
  mi=min(mi,r[i]);
  ma=max(ma,l[i]);
  }
  cout<<max(mi-ma+1,0)<<endl;}


Measured memory_bytes: 1024
def update q, total, i, cost, remain
  q << [i, cost, remain]
  total[remain][i] = [total[remain][i], cost].min
end

def bfs dist, start, dest, ticket
  n = dist.size
  total = Array.new(ticket + 1).map{Array.new(n, 1000000)}
  q = Array.new
  q << [start, 0, ticket]
  
  while ! q.empty?
    pos, sum, remain = q.delete_at(0)
    return sum if pos == dest
    n.times do |i|
      next if dist[pos][i] == -1
      cost = sum + dist[pos][i]
      costWithTicket = sum + dist[pos][i] / 2
      if remain > 0 && (costWithTicket < total[remain - 1][i])
        update q,total,i,costWithTicket,remain - 1
      end
      if cost < total[remain][i]
        update q,total,i,cost,remain
      end
    end
    q.sort!{|e1, e2| e1[1] <=> e2[1]}
  end
end

loop do
  c,n,m,s,d = $stdin.gets.chomp.split(" ").map(&:to_i)
  break if (c|n|m|s|d == 0)
  dist = Array.new(n).map{Array.new(n, -1)}
  m.times do
    a,b,f = $stdin.gets.chomp.split(" ").map(&:to_i)
    dist[a - 1][b - 1] = f
    dist[b - 1][a - 1] = f
  end
  p bfs(dist, s - 1, d - 1, c)
end

Measured memory_bytes: 6356
#include <bits/stdc++.h> 
#define int long long
#define deb(x) cout<<#x <<" = "<<x<<"\n";
using namespace std; 
int k;
string s;
int n;
int dp[110][10][3];
int solve(int idx, int non_zero, int flag)
{
	if(non_zero > k)
		return 0;
	if(idx >=n )
		return non_zero == k;
	if(dp[idx][non_zero][flag] != -1)
		return dp[idx][non_zero][flag];
	
	int res = 0;
	int lim = 9;
	if(flag == 0) lim = s[idx] - '0';
	for(int i=0; i<=lim; i++)
	{
		int new_flag = flag;
		int new_non_zero = non_zero;
		if(flag == 0 && i<lim) new_flag = 1;
		if(i>0) new_non_zero++;
		res += solve(idx+1, new_non_zero, new_flag);
	}
	dp[idx][non_zero][flag] = res;
	return res;
}
signed main() 
{
	cin>>s;
	cin>>k;
	n = s.length();
	memset(dp, -1, sizeof(dp));
	cout<< solve(0, 0, 0) <<"\n";
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,p1[1000],p2[1000],p3[1000],i,k,x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&p1[i],&p2[i],&p3[i]);
//		printf("%d %d %d\n",p1[i],p2[i],p3[i]);
		if(p2[i]>p3[i]){
			x=p2[i]; p2[i]=p3[i]; p3[i]=x;
		}
		if(p1[i]>p2[i]){
			x=p1[i]; p1[i]=p2[i]; p2[i]=x;
		}
		if(p2[i]>p3[i]){
			x=p2[i]; p2[i]=p3[i]; p3[i]=x;
		}
	}
//	printf("\n");
//	for(i=0;i<n;i++) printf("%d %d %d\n",p1[i],p2[i],p3[i]);
	for(i=0;i<n-1;i++){
		for(k=i+1;k<n;k++){
			if(p1[i]!=0){
				if(p1[i]==p1[k] && p2[i]==p2[k] && p3[i]==p3[k]) p1[k]=0;
			}
		}
	}
//	printf("\n");
	x=0;
	for(i=0;i<n;i++){
//		printf("%d %d %d\n",p1[i],p2[i],p3[i]);
		if(p1[i]==0) x++;
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 2760
#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;

vector<vector<pair<int, int>>> graph;
vector<int> ans;

void dfs(int node, int par, int col) {
	ans[node] = col;
	for (auto e : graph[node]) {
		if (e.first != par)
			dfs(e.first, node, (e.second + col) % 2);
	}
}

int main () {
	int N; cin >> N;
	graph.resize(N);
	rep(i, N - 1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--, w %= 2;
		graph[u].emplace_back(make_pair(v,w));
		graph[v].emplace_back(make_pair(u,w));
	}

	ans.resize(N);
	dfs(0, -1, 0);
	rep(i, N) cout << ans[i] << endl;
}


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

int main()
{
	int w, n;
	cin >> w >> n;
	const int MAX_N = 30 + 1;
	int a[MAX_N];
	for (int i = 1; i <= w; i++) {
		a[i] = i;
	}
	int x, y;
	while (n--) {
		scanf("%d,%d", &x, &y);
		int tmp = a[y];
		a[y] = a[x];
		a[x] = tmp;
	}
	for (int i = 1; i <= w; i++) {
		cout << a[i] << endl;
	}
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << 180 * (N-2) << endl;


}

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

int main() {
  string S[110];
  int N,L,i;

  cin >> N >> L;
  for (i=0; i<N; i++) cin >> S[i];

  sort(S, S+N);

  for (i=0; i<N; i++) {
    cout << S[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int, input().split(' ')))
q = int(input())
b = []
c = []
for i in range(q):
    _b, _c = map(int, input().split(' '))
    b.append(_b)
    c.append(_c)

kosu = collections.Counter(a)
s = sum(a)
for i in range(q):

    x = kosu[b[i]]

    s += x * (c[i] - b[i])

    if c[i] in kosu.keys():
        kosu[c[i]] += x
    else:
        kosu.update(
            {c[i]: x}
        )
    kosu[b[i]] = 0

    print(s)


Measured memory_bytes: 30640
#include <iostream>
#include <cmath>

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

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll H, ll W, ll N) {
  auto m = max(H,W);
  auto ans = (N-1)/m+1;
  cout << ans << endl;
}

int main() {
  ll H;
  cin >> H;
  ll W;
  cin >> W;
  ll N;
  cin >> N;
  solve(H, W, N);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;
    
    std::vector<int> left(N, 0), right(N, 0);
    if (S[0] == 'E') left[0] = 1;
    for (int i = 1; i < N; ++i) {
        if (S[i] == 'E') left[i] = left[i - 1] + 1;
        else left[i] = left[i - 1];
    }
    if (S[N - 1] == 'W') right[N - 1] = 1;
    for (int i = N - 2; i >= 0; --i) {
        if (S[i] == 'W') right[i] = right[i + 1] + 1;
        else right[i] = right[i + 1];
    }
    
    int ans = N - 1 - right[1];
    for (int i = 1; i < N - 1; ++i) {
        ans = std::min((i - left[i - 1]) + (N - i - 1 - right[i + 1]), ans);
    }
    ans = std::min(N - 1 - left[N - 2], ans);
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3076