akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;

typedef struct{
  int v; //vocal
  int d; //dance
  int l; //looks
  int c; //cost

}status;

main(){

  int n,m,rank=0;                 //member:n, max_cost:m
  char str[33];                   //member_name

  
  while(scanf("%d %d",&n,&m) != EOF){
    
    status memo[333]={0},bydol[333];    //Dp_memo,  bydol_Status
    
    for(int i=0;i<n;i++){
      gets(str);
      gets(str);
      scanf("%d %d %d %d",&bydol[i].c,&bydol[i].v,&bydol[i].d,&bydol[i].l);
    }
    
    /*
      memo.v = {0};
      memo.d = {0};
      memo.l = {0};
    */
    
    for(int i=0;i<n;i++){
      
      for(int j=0;j<=m-bydol[i].c;j++){
	if(memo[j + bydol[i].c].v < memo[j].v + bydol[i].v){
	  memo[j + bydol[i].c].v = memo[j].v + bydol[i].v;
	  if(memo[j + bydol[i].c].v > rank){
	    rank=memo[j + bydol[i].c].v;
	  }
	}
	if(memo[j + bydol[i].c].d < memo[j].d + bydol[i].d){
	  memo[j + bydol[i].c].d = memo[j].d + bydol[i].d;
	  if(memo[j + bydol[i].c].d > rank){
	    rank=memo[j + bydol[i].c].d;
	  }
	}
	if(memo[j + bydol[i].c].l < memo[j].l + bydol[i].l){
	  memo[j + bydol[i].c].l = memo[j].l + bydol[i].l;
	  if(memo[j + bydol[i].c].l > rank){
	    rank=memo[j + bydol[i].c].l;
	  }
	}
	
      }
      
    }
    
    printf("%d\n",rank);
    rank=0;

  }
  return 0;

}

Measured memory_bytes: 1204
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    static boolean[][] a;
    static boolean[][] b;
    static int[][] nexts = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int w = scan.nextInt();
        a = new boolean[h][w];
        b = new boolean[h][w];
        int block = h * w;
        for (int i = 0; i < h; i++) {
            char[] line = scan.next().toCharArray();
            for (int j = 0; j < w; j++) {
                a[i][j] = line[j] == '.';
                block -= line[j] == '.' ? 1: 0;
            }
        }
        Deque<Tuple> q = new ArrayDeque<>();
        q.add(new Tuple(1, 0, 0));
        while (!q.isEmpty()) {
            Tuple c = q.removeFirst();
            if(c.x == w -1 && c.y == h - 1) {
                System.out.println(h *w - block - c.s);
                return;
            }
            for(int[] diff: nexts) {
                int nx = c.x + diff[0];
                int ny =  c.y + diff[1];
                if(nx< 0 || w <= nx || ny< 0 || h <=ny || !a[ny][nx] || b[ny][nx]) {
                    continue;
                }
                b[ny][nx] = true;
                q.addLast(new Tuple(c.s+1, nx, ny));
            }
        }
        System.out.println(-1);
    }

    static class Tuple{
        int s;
        int x;
        int y;
        Tuple(int s, int x, int y) {
            this.s = s;
            this.x = x;
            this.y = y;
        }
    }
}



Measured memory_bytes: 23764
#include<iostream>

using namespace std;

int main(){string s; cin >> s; int alphabet[26] = {0};
           for(int i = 0; i < s.size(); i++){
             alphabet[s[i] - 'a']++;}
           
           bool flag = true;
           
           for(int i = 0; i < 26; i++){
             if(alphabet[i] % 2 != 0){ flag = false;}}
           
           if(flag){cout << "Yes" << endl;}
           else{cout << "No" << endl;}
           
           return 0;}

            

Measured memory_bytes: 256
n = gets(chomp:true).to_i

array = []

n.times do
  order, key = gets.split
  case order
  when "insert"
    array.unshift(key.to_i)

  when "delete"
    if k = array.index(key.to_i)
      array.delete_at(k)
    end
    
  when "deleteFirst"
    array.shift

  when "deleteLast"
    array.pop
  end
end

puts array.join(" ")


Measured memory_bytes: 21392
#include <stdio.h>
#include <ctype.h>
 
int main(void){
    int i,j;
    char ch;
    while(1){
        scanf("%c",&ch);
        if(ch == '\n'){
            printf("\n");
            break;
        }
        else if(islower(ch)){
            printf("%c",toupper(ch));
        }
        else if(isupper(ch)){
            printf("%c",tolower(ch));
        }
        else{
            printf("%c",ch);
    }
}
    return(0);
}

Measured memory_bytes: 524
H,W=map(int,input().split())

field=[list(input()) for _ in range(H)]
directions = [[-1, -1], [-1, 0], [-1, 1],
              [0, -1], [0, 1], [1, 0], [1, -1], [1, 1]]
for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            bombCnt = 0
            for k in directions:
                if (i + k[0] >= 0 and i + k[0] < H) and (j + k[1] >= 0 and j + k[1] < W):
                    if field[i + k[0]][j + k[1]] == '#':
                        bombCnt += 1
            field[i][j] = str(bombCnt)
for i in range(H):
    print("".join(field[i]))


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<deque>

using namespace std;

struct NodeData {
    vector<int> edge;
    int parent=-1;
    int point = 0;
};

int main() {
    int N, Q, a, b, p, x;
    cin >> N >> Q;
    vector<NodeData> tree(N);
    for(int i = 0; i < N - 1;  i++) {
        cin >> a >> b;
        tree[a-1].edge.push_back(b-1);
        tree[b-1].edge.push_back(a-1);
    }
    for(int q = 0; q < Q; q++) {
        cin >> p >> x;
        tree[p - 1].point += x;
    }

    deque<int> task;
    task.push_back(0);
    while(!task.empty()){
        int i = task.back();
        task.pop_back();
        for(int j : tree[i].edge) {
            if(tree[i].parent != j) {
                tree[j].parent = i;
                tree[j].point += tree[i].point;
                task.push_back(j);
            }
        }
    }
    for(const auto& node : tree) {
        cout << node.point << " ";
    }
}


Measured memory_bytes: 16244
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, K = map(int, input().split())
L = [int(v) for v in input().split()]

m = [None] * N

c = 0
for i in range(N):
    a = 0
    b = 0
    for j in range(N):
        if i != j:
            if i < j and L[i] > L[j]:
                a += 1

            if i > j and L[i] > L[j]:
                b += 1

    m[i] = (a, b)

aa = 0
bb = 0
for a, b in m:
    aa += a * K
    bb += b * (K - 1)

cc = 0
for a, _ in m:
    cc += a

print((aa + bb + cc) * K // 2 % (10 ** 9 + 7))

Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{	
	int a,b,t;
	scanf("%d%d%d",&a,&b,&t);
	printf("%d",b * ((int)t / a));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

using Graph = vector<vector<int>>;
int cou1 = 0;
int N, M;

//深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v){
  seen[v] = true; // v を訪問済みにする
  bool ok = true;
  for(int i=0;i<N;i++){
    if(!seen[i]) ok = false;
  }
  if(ok) cou1++;

  // vから行ける各頂点 next_v について
  for(auto nv : G[v]){
    if (seen[nv]) continue; // next_v が探索済みだったらスルー
    dfs(G, nv); // 再帰的に探索
  } 
  seen[v] = false;
}

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  cin >> N >> M;
  
  Graph G(N);
  for(int i=0;i<M;i++){
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  seen.assign(N, false); // 全頂点を「未訪問」にして初期化
  dfs(G, 0);

  cout << cou1 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N,M; cin >>N >>M;
  vector<vector<int>> v(100001);
  rep(i, N){
    int a,b; cin >>a >>b;
    v[a].push_back(b);
  }
  priority_queue<int> pq;
  ll res = 0;
  for (int i=1; i<=M; i++){
    for (auto x : v[i]) pq.push(x);
    if (pq.empty()) continue;
    res += pq.top(); pq.pop();
  }
  cout <<res <<endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

#ifndef INTERACTIVE
[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}
#endif // INTERACTIVE

int main() {
    int n; cin >> n;
    std::vector<long long> a(n);
    for (auto& x: a) cin >> x;
    for (int i = 0; i < n; ++i) {
        a[i] -= i + 1;
    }
    std::sort(a.begin(), a.end());
    long long cur = 0;
    long long d = 0;
    for (int i = 1; i < n; ++i) {
        d += a[i] - a[i - 1];
        cur += d;
    }
    long long ans = cur;
    for (int i = 1; i < n; ++i) {
        cur += (a[i] - a[i - 1]) * (i - (n - i));
        ans = std::min(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;


int main(){
    
    int a, b, c;
    int count=0;

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

    return 0;
}




Measured memory_bytes: 3092
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll X; cin >> X;

    if (X <= 6) {cout << 1 << endl; return 0;}
    if (X <= 11) {cout << 2 << endl; return 0;}

    ll Y = X / 11;
    if (X - Y * 11 == 0) cout << Y * 2;
    else if (X - Y * 11 < 7) cout << Y * 2 + 1;
    else cout << Y * 2 + 2;
    cout << endl; 
}


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

int main(){
    string n;
    cin >> n;
    for(int i=0;i<n.size();i++){
        if(n[i]=='1'){
            n[i]='9';
        }else if(n[i]=='9'){
            n[i]='1';
        }
    }
    int ans=atoi(n.c_str());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 

int c = 0;
 
#define INF INT_MAX/4
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  {
    for(int j=0;j<vertex;j++) {
      if(graph[start][j]<INF/2 && graph[j][j]<0) {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
      }
    }
  }
  
  for(int i=0;i<vertex;i++) {
    if(graph[start][i]>=INF/2) {
      cout << "INF" << endl;
    } else {
      cout << graph[start][i] << endl;
    }
  }

  while (c == 0) {}
  return 0;
}
 
inline int fastmin(int a, int b) {
  return (((a-b)>>31)&(a-b))+b;
}

int mymin_slow(int a, int b) {
  int t;
  if (a < b) {
    t = a;
    c+=2;
  } else {
    t = b;
    c+=1;
  }
  return t;
}
 
void check()
{
  for(int k=0;k<vertex;k++) {
    for(int i=0;i<vertex;i++) {
      int gik= graph[i][k];
      for(int j=0;j<vertex;j++) {
        graph[i][j]= mymin_slow(graph[i][j], gik+graph[k][j]);
      }
    }
  }
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
        {
          if(i==j)
            {
              graph[i][j]=0;
            }
          /*else
            {
            graph[i][j]=INF;
            }*/
        }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
    dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
      {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
      }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
      for(int i=0;i<vertex;i++)
      {
      for(int j=0;j<vertex;j++)
      {
      cout << graph[i][j] << " ";
      }  
      cout << endl;    
      }*/
   
}

Measured memory_bytes: 5300
N=int(input())
SP=[]
for i in range(N):
    SP.append(list(input().split()))
for i in range(N):
    SP[i].append(i+1)
A=[]
B=[]
C=[]
for i in range(N):
    A.append(SP[i][0])
A.sort()
B.append(A[0])
for i in range(0,N-1):
    if A[i]!=A[i+1]:
        B.append(A[i+1])
for i in range(len(B)):
    C.append([])
for i in range(len(B)):
    for j in range(len(SP)):
        if B[i]==SP[j][0]:
            C[i].append([int(SP[j][1]),SP[j][2]])
for i in range(len(C)):
    for j in range(1,len(C[i])):
        d=C[i][j]
        k=j-1
        while (k>=0 and C[i][k]<d):
            C[i][k+1]=C[i][k]
            k-=1
        C[i][k+1]=d
for i in range(len(C)):
    for j in range(len(C[i])):
        print(C[i][j][1])

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int count = 0;
    string S, T = "CODEFESTIVAL2016";
    cin >> S;
    for (int i = 0; i < S.size(); i++){
        if (S.at(i) != T.at(i)){
            count++;
        }
    }
    cout << count << endl;
    
}


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

int main() {
    stack<int> S1;
    stack<pair<int, int>> S2;
    int sum_area = 0;
    char ch;

    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') {
            S1.push(i);
        }
        else if (ch == '/' && S1.size() > 0) {
            int j = S1.top();
            S1.pop();
            sum_area += i - j;

            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    // Output all_area
    cout << sum_area << endl;

    // Output each_area
    vector<int> each_area;
    while (S2.size() > 0) {
        each_area.push_back(S2.top().second);
        S2.pop();
    }
    reverse(each_area.begin(), each_area.end());
    cout << each_area.size();
    for (int i = 0; i < each_area.size(); i++) {
        cout << " " << each_area[i];
    }
    cout << endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, N) for(i = 0; i < N; i++)
#define ll long long

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> H = {};

  vector<bool> rep = {};

  int i;
  rep(i, N) {
    ll input;
    cin >> input;
    H.push_back(input);
    rep.push_back(true);
  }

  vector<int> A = {}, B = {};
  rep(i, M) {
    int inputA, inputB;
    cin >> inputA >> inputB;
    inputA -= 1;
    inputB -= 1;
    A.push_back(inputA);
    B.push_back(inputB);
    if(H[inputA] < H[inputB]) {
      rep[inputA] = false;
    } else if(H[inputA] == H[inputB]) {
      rep[inputA] = false;
      rep[inputB] = false;
    } else {
      rep[inputB] = false;
    }
  }

  int ans = 0;
  rep(i, N) {
    if(rep[i]) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 5636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????


		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		int[] ary = new int[n];

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

			ary[i] = scan.nextInt();
		}

		scan.close();

		int intMax = ary[0];
		//?????§?????????
		for(int i = 0; i < ary.length; i++){

			if(intMax < ary[i]){

				intMax = ary[i];
			}
		}


		int intMin = ary[0];
		//????°??????????
		for(int i = 0; i < ary.length; i++){

			if(intMin > ary[i]){

				intMin = ary[i];
			}
		}

		long dbSum = 0;
		//????¨???????
		for(int i = 0; i < ary.length; i++){

			dbSum = dbSum + ary[i];

			//System.out.println("[" + i + "]" + "intSum: " + intSum + " ary:" + ary[i]);
		}


		System.out.println(intMin + " " + intMax + " " + dbSum);
	}
}

Measured memory_bytes: 31728
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	n := make([]bool, N)
	for i := 0; i < K; i++ {
		var d int
		fmt.Scanf("%d", &d)

		for j := 0; j < d; j++ {
			var a int
			fmt.Scan(&a)
			n[a-1] = true
		}
	}
	counter := 0
	for _, v := range n {
		if v == false {
			counter++
		}
	}

	fmt.Println(counter)
}

Measured memory_bytes: 2492
#include<stdio.h>

int main()
{
	int A;
	int B;
	scanf("%d %d",&A,&B);
	if(A == 1 && B == 2)
	{
		printf("3");
	}
		if(A == 2 && B == 1)
	{
		printf("3");
	}
	if(A == 1 && B == 3)
	{
		printf("2");
	}
		if(A == 3 && B == 1)
	{
		printf("2");
	}
	if(A == 2 && B == 3)
	{
		printf("1");
	}
		if(A == 3 && B == 2)
	{
		printf("1");
	}
	return 0;	
}
	

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

int main(){
  string S;
  int K,Z=1,A,P;
  cin>>S>>K;
  P=K;
  int L=S.size();
  A=S[0]-'0';
  A--;
  for(int i=1;i<=K;i++){
    Z*=(L-i);
    Z/=i;
    Z*=9;
    if(i!=K){
      A*=(L-i);
      A/=i;
      A*=9;
    }
  }
  Z+=A;
  K-=1;
  int X=1;
  while(K>=0&&X<L){
    int B=S[X]-'0';
    if(B){
      A=B;
      A--;
      for(int i=1;i<K;i++){
        A*=(L-i-X);
        A/=i;
        A*=9;
      }
      A*=min(1,K);
      Z+=A;
      A=1;
      for(int i=1;i<=K;i++){
        A*=(L-i-X);
        A/=i;
        A*=9;
      }
      Z+=A;
      K--;
    }
    X++;
    if(X==L&&K==0){
      Z++;
    }
  }
  if(L==1&&P==1){
    Z=S[0]-'0';
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

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

    vector<int> cnt(5);
    for (int i = 0; i < 6; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    int e = 0, o = 0;
    for (int r : cnt) {
        r & 1 ? o++ : e++;
    }

    if (o == 0 || o == 2) {
        cout << "YES";
    } else {
        cout << "NO";
    }

    return 0;
}

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

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
int main(){
		ll n;cin>>n;
		ll a[n+1];for(int i=1;i<=n;i++)cin>>a[i];
		sort(a+1,a+1+n);
		double val=(a[1]*1.0);
		for(int i=2;i<=n;i++)
		{
		 val=(a[i]+val)/2;
		 }
		cout<<val<<endl;
		
		
		
	}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::*;

const need: [usize; 9] = [2,5,5,4,5,6,3,7,6];

fn func(dp: Vec<usize>, keta: usize, nokori: usize, vec: Vec<bool>) {
    if keta == 1 {
        for i in (0..9).rev() {
            if vec[i] && nokori == need[i] {
                print!("{}", i+1);
                return;
            }
        }
    }
    for i in (0..9).rev() {
        if vec[i] && nokori >= need[i] && keta-1 == dp[nokori - need[i]] {
            print!("{}", i+1);
            func(dp, keta-1, nokori - need[i], vec);
            return;
        }
    }
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut vec: Vec<bool> = vec![false; 9];
    for _ in 0..m {
        let a: usize = read();
        vec[a-1] = true;
    }
    let mut dp: Vec<usize> = vec![0; n+1];
    for i in 0..n {
        for j in 0..9 {
            if vec[j] && i+1 >= need[j] {
                let po = i+1 - need[j];
                if !(dp[po] == 0 && po != 0){
                    dp[i+1] = max(dp[i+1], dp[po] + 1);
                }
            }
        }
    }
    let maxk = dp[n];
    func(dp, maxk, n, vec);
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 5628
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef vector<P> vp;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}
bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
    
int main(){
    ll x, y; cin >> x >> y;
    
    ll ret = 0, e = x;
    while(e <= y){
        ret++;
        e *= 2;
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
import math

n, a, b = map(int, input().split())

sum_all = 0
for i in range(1, n + 1):
    sum_n = 0
    m = i
    while(m > 0):
        sum_n += m % 10
        m = int(m / 10)
    if a <= sum_n <= b:
        sum_all += i

print(sum_all)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

LL extgcd(LL a, LL b, LL &x, LL &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    LL g = extgcd(b, a % b, x, y);
    LL nextx = y, nexty = x-(a/b)*y;
    x = nextx; y = nexty;
    return g;
}

LL fact[200010];
LL invfact[200010];
const LL mod = 1e9 + 7;

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    fact[0] = 1;
    for(LL i=1; i<=200000; i++){
        fact[i] = (fact[i-1] * i) % mod;
    }
    for(LL i=0; i<=200000; i++){
        LL x, y;
        LL g = extgcd(fact[i], mod, x, y);
        while(x < 0) x += mod;
        x %= mod;
        invfact[i] = x;
    }

    LL ans = 0;
    for(int i=B; i<W; i++){
        LL tmp = fact[(H-A-1)+i];
        (tmp *= invfact[H-A-1]) %= mod;
        (tmp *= invfact[i]) %= mod;
        (tmp *= fact[(A-1)+(W-i-1)]) %= mod;
        (tmp *=  invfact[A-1]) %= mod;
        (tmp *=  invfact[W-i-1]) %= mod;
        (ans += tmp) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n), b(n), c(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    rep(i, n) {
        cin >> b[i];
    }
    sort(all(b));
    rep(i, n) {
        cin >> c[i];
    }
    sort(all(c));

    ll ans = 0;
    rep(i, n) {
        ll x = lower_bound(all(a), b[i]) - a.begin();
        ll y = c.end() - upper_bound(all(c), b[i]);
        ans += x*y;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k;
  cin>>n>>k;
  if(n==k){
    cout<<0<<endl;
  }
  else if(n>k){
    n%=k;
    cout<<min(n,llabs(n-k))<<endl;
  }
  else{
    cout<<min(n,llabs(n-k))<<endl;
  }
  return 0;
}

Measured memory_bytes: 3572
n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
dp = [0 for _ in range(n + 1)]
dp[1] = 1
s = 0
mod = 998244353

for i in range(1, n + 1):
    s += dp[i]
    for l, r in LR:
        if i + l <= n:
            dp[i + l] = (dp[i + l] + s) % mod
            if i + r + 1 <= n:
                dp[i + r + 1] = (dp[i + r + 1] - s) % mod

print(dp[n])


Measured memory_bytes: 16948
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000000000000
using namespace std;
int freq[30];
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	str A, B, C;
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> a >> b; SET(freq, 0);
	for (i = 1; i <= a; i++) {
		cin >> A;
		for (j = 0; j < A.length(); j++) {
			freq[A[j] - 'a']++;
		}
	}
	c = (a / 2) * (b / 2);
	d = (a % 2) * (b / 2) + (a / 2) * (b % 2);
	e = (a % 2) * (b % 2);
	for (i = 0; i < 26; i++) {
		f = min(c, freq[i] / 4);
		c -= f; freq[i] -= f * 4;
		g = min(d, freq[i] / 2);
		d -= g; freq[i] -= g * 2;
		h = min(e, freq[i] / 1);
		e -= h; freq[i] -= h;
		if (freq[i] > 0) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
#include <numeric>
#include <utility>
#include<math.h>
#include<functional>
#include<queue>
#include<sstream>
#include<stack>
#include<algorithm>

int solve(int a,int b){
    if(a==1&&b==1)std::cout<<1;
    else if(a==b||a<b)std::cout<<a;
    else if(a>b)std::cout<<a-1;
    return 0;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int a,b;
    std::cin>>a>>b;
    return solve(a,b);
}


Measured memory_bytes: 256
strs = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"

k = gets.to_i

ary = strs.split(', ')
puts ary[k-1]


Measured memory_bytes: 1916
N,M = map(int,input().split())


li = ["#"]*N
A = "#"
if N==1:
    for i in range(M):
        s,c = map(int,input().split())
        if not c==A and not A=="#":
            print(-1)
            exit()
        else:
            A=c
  
    if A == "#":
        print(0)
    else:
        print(int(A))
    exit()
    

for i in range(M):
    s,c = map(int,input().split())
    if s==1 and c==0:
        print(-1)
        break

    if not li[s-1]=="#" and not li[s-1]==c:
        print(-1)
        break
    if li[s-1]=="#":
        li[s-1]=c
    
else:
    if li[0]=="#":
        li[0]=1
        
    num="".join(map(str,li))
    num_new=num.replace("#","0")
    print(num_new)

Measured memory_bytes: 61816
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int L = read(), R = read();
    if (R-L >= 2018) {
        printf("0\n");
        return;
    }
    int_fast64_t ans = 2018;
    for (int_fast64_t i = L; i<R; i++) {
        for (int_fast64_t j = L+1; j<=R; j++) {
            ans = min(ans, i*j%2019);
        }
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#複素数でやってみる
from itertools import combinations
import math

while True:
    N=int(input())
    if N==0:
        break
    mp=[]
    for _ in range(N):
        a,b=map(float,input().split())
        mp.append(complex(a,b))
    center_lst=[]
    for p,q in combinations(mp,2):
        mid=(p+q)/2
        if abs(p-q)>2:
            continue
        d_vec=complex(-(p-q).imag,(p-q).real)/abs(p-q)
        t=1-abs(p-mid)**2
        center_vec1=mid+d_vec*math.sqrt(t)
        center_vec2=mid-d_vec*math.sqrt(t)
        center_lst.append(center_vec1)
        center_lst.append(center_vec2)
    
    ans=1
    for center in center_lst:
        tmp=0
        for x in mp:
            x_center=x-center
            if abs(x_center)<=1+1e-7:
                tmp+=1
        if tmp>ans:
            ans=tmp
    print(ans)


Measured memory_bytes: 6928
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    if A[N - M] >= sum(A) * (1 / (4 * M)):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
cnt=0
cnt_2=0
s = str(input())
for i in range(len(s)):
    if s[i]=='0' and i%2==0:
        cnt+=1
    if s[i]=='1' and i%2==0:
        cnt_2+=1
    if s[i]=='1' and i%2!=0:
        cnt+=1
    if s[i]=='0' and i%2!=0:
        cnt_2+=1
print(min(cnt,cnt_2))

Measured memory_bytes: 68820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

int main(){
  int k;
  string ans = "ACL";
  string res = "";
  cin >> k;
  rep(i,k){
    res += ans;
  }
  cout << res << endl;
  

  return 0;
}

Measured memory_bytes: 3552
program main;
var i, t : integer;
    n : array [1..5] of integer;


begin
   for i := 1 to 5 do read(n[i]);
   readln;
   t := 0;
   for i := 1 to 5 do
     if n[i] = 0 then 
       t := i;
   writeln(t);
end.

Measured memory_bytes: 1244
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		int result = 0;
		for(int i = 0; i < n; i++){
		    h[i] = sc.nextInt();
		    if(h[i] >= k) result++;
		}
		
		// 計算

		// 出力
        System.out.println(result);
	}
}

Measured memory_bytes: 50016
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll H;
cin>>H;
ll ans=1;
while(H>0){
    H/=2;
    ans*=2;
}
cout<<ans-1<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string s; cin >> s;
    char cur = 'h';
    if(s.length()%2!=0){
        cout << "No\n"; return 0;
    }
    for(auto c: s){
        if(c!=cur){
            cout << "No\n"; return 0;
        }
        cur = (cur=='h') ? 'i' : 'h';
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

template<typename T>
using RQ = std::priority_queue<T, std::vector<T>, std::greater<T>>;

int main() {
   for(;;) {
      Int n, m;
      std::cin >> n >> m;
      if( n == 0 and m == 0 ) break;
      Int s, g;
      std::cin >> s >> g;
      double inf = 1e16;
      std::vector<std::pair<Int,double>> edges[32*32];
      rep(ii,m) {
         Int x, y, d, c;
         std::cin >> x >> y >> d >> c;
         for(Int kk = 0; kk < 2; ++kk) {
            for(Int k = 1; k <= c; ++k) {
               edges[x*32+k].emplace_back(y*32+k+1, (double)d/k);
               if( k >= 2 ) {
                  edges[x*32+k].emplace_back(y*32+k-1, (double)d/k);
               }
               edges[x*32+k].emplace_back(y*32+k+0, (double)d/k);
            }
            std::swap(x,y);
         }
      }
      RQ<std::tuple<double,Int,Int>> q;
      q.emplace(0.0, s*32+1, -1);
      double dist[32*32][32];
      rep(i,32*32) rep(k,32) dist[i][k] = inf;
      while( not q.empty() ) {
         double d;
         Int v;
         Int prev;
         std::tie(d, v, prev) = q.top(); q.pop();
         // if( prev != -1 and d >= dist[v][prev/32] ) continue;
         for(auto next : edges[v]) {
            Int nv;
            double dd;
            std::tie(nv, dd) = next;
            if( prev != -1 and nv/32 == prev/32 ) continue;
            double nd = d + dd;
            if( nv == g*32+1 and v%32 != 1 ) continue;
            if( nd < dist[nv][v/32] ) {
               dist[nv][v/32] = nd;
               q.emplace(nd, nv, v);
            }
         }
      }
      double res = inf;
      rep(i,32) {
         res = std::min(res, dist[g*32+1][i]);
      }
      if( res >= inf ) {
         puts("unreachable");
      }
      else {
         printf("%lf\n", res);
      }
   }
}



Measured memory_bytes: 5364
#include<stdio.h>
#define int long long
int n;
int MAX(int a,int b){return a<b?b:a;}
int pr(int i){return (i+n-1)%n;}
int nx(int i){return (i  +1)%n;}
int i,j,d[2010][2010]={0};
signed main(){
  scanf("%lld",&n);
  for(i=0;i<2010*2010;i++)d[i/2010][i%2010]=-1000000000;
  for(i=0;i<n;i++)scanf("%lld",&d[1][i]);
  for(i=1;i<n;i++){
    for(j=0;j<n;j++){
      if(i%2){
	if(d[1][pr(j)]>d[1][nx(i+j-1)])d[i+1][pr(j)]=MAX(d[i+1][pr(j)],d[i][j]);
	else d[i+1][j]=MAX(d[i+1][j],d[i][j]);
      }
      else{
	//if(d[i][j]==0)continue;
	d[i+1][j]=MAX(d[i][j]+d[1][nx(i+j-1)],d[i][nx(j)]+d[1][j]);
      }
    }
  }
  for(i=j=0;i<n;i++)j=MAX(j,d[n][i]);
  printf("%lld\n",j);
  return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

int main() {

    int n, m;

    cin >> n >> m;
    vector<P> pharmacies(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        pharmacies[i] = P(a, b);
    }

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

    ll ans = 0;
    ll count = 0;

    for (auto p : pharmacies) {
        if (count + p.second >= m) {
            ll h = m - count;
            ans += h * p.first;
            break;
        } else {
            count += p.second;
            ans += p.second * p.first;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 100000)
var buf = make([]byte, 0, 100000)

func nextLine() []string {
	line := readLine()
	return strings.Split(line, " ")
}

func readLine() string {
	buf = buf[:0]
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	tmp := nextLine()
	Q, _ := strconv.Atoi(tmp[1])

	S := readLine()
	foundA := false
	sum := 0
	counter := make([]int, 0, len(S))
	for _, char := range S {
		switch char {
		case 'A':
			foundA = true
		case 'C':
			if foundA {
				sum++
			}
			foundA = false
		default:
			foundA = false
		}
		counter = append(counter, sum)
	}

	for i := 0; i < Q; i++ {
		tmp = nextLine()
		l, _ := strconv.Atoi(tmp[0])
		r, _ := strconv.Atoi(tmp[1])
		fmt.Println(counter[r-1] - counter[l-1])
	}
}

Measured memory_bytes: 6016
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=200000+10;
char s[maxn],h[maxn];
int i,j,k,l,t,n,m,cnt,num;
int main(){
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    fo(i,1,n)
        if (s[i]=='A') s[i]='1';else s[i]='0';
    i=1;
    fo(l,1,2*n+10){
        t=s[i]-'0';
        if (t^cnt) s[i]=(1-t)+'0';
        else{
            cnt^=1;
            num^=1;
            i++;
        }
        if (l==k){
            fo(j,i,n){
                t=s[j]-'0';
                if (t^cnt) printf("A");else printf("B");
            }
            fo(j,1,i-1){
                if (num) printf("A");else printf("B");
                num^=1;
            }
        }
        if (i>n) break;
    }
    if (l<k){
        if (!num){
            fo(i,1,n)
                if (i%2==1) printf("B");else printf("A");
            return 0;
        }
        fo(i,1,n){
            if (num) h[i]='A';else h[i]='B';
            num^=1;
        }
        if (l%2!=k%2){
            if (h[1]=='A') h[1]='B';else h[1]='A';
        }
        fo(i,1,n) printf("%c",h[i]);
        return 0;
    }
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
// #define F first
// #define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)
int A[100000+5];
int B[100000+5];
int C[100000+5];
int D[100000+5];
int ANS[100000+5];

class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N+5);
    FOR(i,1,M) {
        cin >> A[i] >> B[i];
        uf.merge(A[i],B[i]);
    }
    FOR(i,1,N) {
        ANS[i] = uf.size(i)-1;
    }
    FOR(i,1,K) {
        cin >> C[i] >> D[i];
        if (uf.issame(C[i],D[i])) {
            ANS[C[i]] -= 1;
            ANS[D[i]] -= 1;
        }
    }
    FOR(i,1,M) {
        if (uf.issame(A[i],B[i])) {
            ANS[A[i]] -= 1;
            ANS[B[i]] -= 1;
        }
    }

    FOR(i,1,N) {
        cout << ANS[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
using namespace std;
 
int main(void){
  string S;
  cin >> S;
  int ans = 0;
  int cnt = 0;
  for(int i = 0; i < S.size(); i++){
       if( S[i] == 'A' ||
           S[i] == 'C' ||
           S[i] == 'G' ||
           S[i] == 'T' ){
           cnt++;
       }else{
         if( ans < cnt ) ans = cnt;
         cnt=0;
       }
  }
  if( ans < cnt ) ans = cnt;
  cout << ans << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 1e16+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;
 
int main(){
    string s;
    cin>>s;
    int n =s.length();
    rep(i,n){
        if(i%2==0){
            if(s[i]=='L'){
                cout<<"No"<<endl;
                exit(0);
            }
        }
        else{
            if(s[i]=='R'){
                cout<<"No"<<endl;
                exit(0);
            }
        }
    }
    cout<<"Yes"<<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

ll N;

void dfs(string s, char max) {
    if(s.size() == N) {
        cout << s << endl;
        return;
    }
    repi2(i, 'a', max) {
        string temp = s;
        temp.push_back(i);
        dfs(temp, i == max ? max + 1 : max);
    }
}

int main(void) {
    cin >> N;
    dfs("a", 'b');
    return 0;
}


Measured memory_bytes: 1536
import collections
n = input()
a = list(input().split())

# 各数値の重複数辞書
counter = collections.Counter(a)

# 組み合わせ数
def combi(num):
    if num < 2:
        pair = 0
    else:
        pair = int(num * (num-1) / 2)
    return pair


total = sum([combi(v) for v in counter.values()])
for el in a:
    print(total - (counter[el] - 1))

Measured memory_bytes: 26784
mod = 10**9 + 7
S = input()

dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    if S[i] != '?':
        for m in range(13):
            dp[i+1][(10*m+int(S[i])) % 13] += dp[i][m]
            dp[i+1][(10*m+int(S[i])) % 13] %= mod
    else:
        for c in range(10):
            for m in range(13):
                dp[i+1][(10*m+c) % 13] += dp[i][m]
                dp[i+1][(10*m+c) % 13] %= mod

print(dp[len(S)][5])


Measured memory_bytes: 61916
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc171/tasks/abc171_f

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

template<int Mod>
struct MintBase {
  int64_t x; // typedef long long int64_t;
  MintBase(int64_t x=0):x((x%Mod+Mod)%Mod){}
  MintBase operator-() const { return MintBase(-x);}
  MintBase& operator+=(const MintBase a) {
    if ((x += a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator-=(const MintBase a) {
    if ((x += Mod-a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator*=(const MintBase a) { (x *= a.x) %= Mod; return *this;}
  MintBase operator+(const MintBase a) const { return MintBase(*this) += a;}
  MintBase operator-(const MintBase a) const { return MintBase(*this) -= a;}
  MintBase operator*(const MintBase a) const { return MintBase(*this) *= a;}
  MintBase pow(int64_t t) const {
    if (!t) return 1;
    MintBase a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime Mod
  MintBase inv() const { return pow(Mod-2);}
  MintBase& operator/=(const MintBase a) { return *this *= a.inv();}
  MintBase operator/(const MintBase a) const { return MintBase(*this) /= a;}
};

//const int Mod = 1000000007;
//const int Mod = 998244353;

using mint = MintBase<1000000007>;

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint factorial(const mint& x)
{
    mint ans = 1;
    for(mint i = x.x; i.x != 0; i -= 1)
    {
        ans *= i;
    }
    return ans;
}

mint factorial(const mint& x, const mint& n)
{
    mint ans = 1;
    mint m = x;
    for(int64_t i = 0; i < n.x; ++i)
    {
        ans *= m;
        m -= 1;
    }
    return ans;
}

mint Combination(int64_t x, int64_t y)
{
    return  factorial(x, y) / factorial(y);
}

const int MaxCount = 2 * 1000005;

mint fact[MaxCount];
mint ifact[MaxCount];

void setupFact()
{
    fact[0] = 1;
    ifact[0] = 1;
    rep(i, MaxCount - 1)
    {
        fact[i + 1] = fact[i] * (i + 1);
        ifact[i + 1] = fact[i + 1].inv();
    }
}

int main(int, const char**)
{
    setupFact();

    int64_t k;
    string s;
    cin >> k >> s;
    auto len = (int64_t)s.size() + k;
    mint ans = 0;
    rep(i, k + 1)
    {
        mint r = mint(26).pow(k - i);
        mint l = mint(25).pow(i);
        
        if(i == 0)
        {
            ans += (l * r);
        }
        else
        {
            auto a = i + len - k - 1;
            auto lc = fact[a] * ifact[a - i] * ifact[i];
            ans += (lc * l * r);
        }
    }
    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 36572