akhauriyash/Code-Regression huggingface dataset:
class Node:
    def __init__(self, key):
        self.key = key
        self.prev = None
        self.next = None

class DoublyLinkedList:
    def __init__(self):
        self.nil = Node(None) # 番兵
        self.nil.prev = self.nil
        self.nil.next = self.nil # prevもnextも番兵に接続

    def insert(self, key):
        new = Node(key)
        new.next = self.nil.next   # 新しいNodeの後ろをもともと番兵の後ろにあったNodeに変更
        self.nil.next.prev = new   # もともと番兵の次にあったNodeの前を新しいNodeに変更
        self.nil.next = new        # 番兵の後ろを新しいNodeに変更
        new.prev = self.nil        # 新しいNodeの前をnilに指定

    def listSearch(self, key):
        cur = self.nil.next
        while cur != self.nil and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, t):
        if t == self.nil:
            return
        t.prev.next = t.next
        t.next.prev = t.prev

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

    def deleteLast(self):
        self.deleteNode(self.nil.prev)

    def deleteKey(self, key):
        self.deleteNode(self.listSearch(key))


if __name__ == '__main__':
    import sys
    input = sys.stdin.readline  # 入力の高速化

    n = int(input())

    dll = DoublyLinkedList()

    for _ in range(n):
        '''
        以下のようにcomとkeyに分けるとTimeLimitExceededになるので、comだけで処理しました
        (別のいい方法があれば教えて欲しいです)
        com, *key = input().split()
        この場合keyがリストになるので、com[7:]をkey[0]で置き換える必要があります。
        (xがない命令ではkey=[]となるだけ)
        '''
        com = input().rstrip()
        # 以下、本と順番など多少異なります
        if com[0] == 'i':
            dll.insert(com[7:])
        elif com[6] == 'F':
            dll.deleteFirst()
        elif com[6] == 'L':
            dll.deleteLast()
        else:
            dll.deleteKey(com[7:])

    cur = dll.nil.next
    ans = []
    while cur != dll.nil:
        ans.append(cur.key)
        cur = cur.next

    print(' '.join(ans))


Measured memory_bytes: 227600
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    Int sum = 0;
    Int i = 1;
    while (sum < n) {
        sum += i;
        i++;
    }
    for (Int j = 1; j < i; j++) {
        if (j == sum - n) continue;
        dump(j);
    }
    return 0;  
}

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int A,B;
  cin>>A>>B;
  char grid[100][100];
  for (int i=0; i<50; i++) {
    for (int j=0; j<100; j++) {
      grid[i][j]='.';
    }
  }
  for (int i=50; i<100; i++) {
    for (int j=0; j<100; j++) {
      grid[i][j]='#';
    }
  }
  A--,B--;
  for (int i=100-1; A; i-=2) {
    for (int j=0; j<100 && A; j+=2) {
      grid[i][j]='.';
      A--;
    }
  }
  for (int i=0; B; i+=2) {
    for (int j=0; j<100 && B; j+=2) {
      grid[i][j]='#';
      B--;
    }
  }
  cout<<100<<" "<<100<<endl;
  for (int i=0; i<100; i++) {
    for (int j=0; j<100; j++) {
      cout<<grid[i][j]<<flush;
    }
    cout<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
vector<int> v(n-1);
for(int i=0;i<n-1;i++){
    cin>>v[i];
    }
 int ans[n];
 for(int i=0;i<n;i++) ans[i]=0;
 for(int i=0;i<n-1;i++) ans[v[i]-1]++;
 for(int i=0;i<n;i++)   cout<<ans[i]<<endl;

}


Measured memory_bytes: 4768
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}
template<typename T>
void vvdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        vdeb(da[i]);
    }
}

int zui(int x){
	int ret=1,now=1;
	while(!(x&now)){
		ret++;
		now = now << 1;
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	vector<vector<int>> ans(n-1,vector<int>(0));
	rip(i,n-1,0){
		ans[i]=vector<int>(n-i-1);
		rip(j,n,i+1){
			ans[i][j-i-1]=zui((i+1)^(j+1));
		}
	}
	vvdeb(ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

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

int main() {
	int n;
	std::cin >> n;
	std::vector<std::string> s(n);
	rep(i, n) std::cin >> s[i];

	// 共通の文字をすべて保存
	std::vector<int> cnum(26, inf);

	rep(i, n) {
		std::vector<int> tmpNum(26, 0);
		rep(j, (int)s[i].size()) {
			tmpNum[s[i][j] - 'a']++;
		}
		rep(j, 26) {
			cnum[j] = std::min(cnum[j], tmpNum[j]);
		}
	}

	rep(i, 26) {
		rep(j, cnum[i]) {
			std::cout << (char)(i + 'a');
		}
	}

	std::cout << std::endl;

	return 0;
}

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

#define MOD 1000000007
// #define INF 100000000000

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


using P = pair<int, int>;
vector<int> dist;
vector<int> from;
vector<vector<int>> G;

void dijkstra() {
    priority_queue<P, vector<P>, greater<P>> que;
    dist[0] = 0;
    que.push(P(0, 0));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;

        for (int i=0; i < G[v].size(); ++i) {
            int to = G[v][i];
            if (dist[to] > dist[v] + 1) {
                dist[to] = dist[v] + 1;
                from[to] = v;
                que.push(P(dist[to], to));
            }
        }
    }
}


int main(int argc, char const *argv[]) {
    int N, M;
    cin >> N >> M;

    dist.resize(N, N+1);
    from.resize(N);
    G.resize(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a -= 1; b -= 1;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    // print(G);
    dijkstra();

    for (int i = 1; i < N; ++i) {
        if (dist[i] > N) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) {
        cout << from[i] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 11244
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
long long *bit;
long long *b;
long long *h;
long long nmax;
long long query(long long pos)
{
    long long ans=0;
    while(pos>0)
    {
        ans=max(bit[pos],ans);
        pos-=(pos&(-pos));
    }
    return ans;
}
void update(long long pos,long long bty)
{
    long long mx=query(pos-1);
    while(pos<=nmax)
    {
        bit[pos]=max(bit[pos],bty+mx);
        pos+=(pos&(-pos));
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j;
    cin>>n;
    b=new long long[n];
    h=new long long[n];
    nmax=0;
    for(i=0;i<n;i++) cin>>h[i],nmax=max(nmax,h[i]);
    for(i=0;i<n;i++) cin>>b[i];
    bit=new long long[nmax+1];
    for(i=0;i<=nmax;i++) bit[i]=0;
    for(i=0;i<n;i++)
    {
        update(h[i],b[i]);
    }
    cout<<query(nmax);
}


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

int main(){
	double n,m,l;
  cin>>n>>m>>l;
  
 	if(l==0){
    	cout << std::setprecision(20) <<(m-1)/n<<endl;
    }else{
    	cout << std::setprecision(20) <<(m-1)*(2*(n-l))/(n*n)<<endl;
    }

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import Counter

N = int(input())
s = []
for i in range(N):
    s1 = "".join(sorted(input()))
    s.append(s1)
    
c = list(Counter(s).values())
ans = 0
for i in c:
    if i >= 2:
        ans += (i * (i - 1)) // 2
print(ans)      

Measured memory_bytes: 19760
A, B, C, X, Y = map(int, input().split())
D = min(X, Y)
ans = D*min(A+B, 2*C)
X -= D; Y -= D
if X:
    ans += X*min(A, 2*C)
else:
    ans += Y*min(B, 2*C)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      ll x,pre=0,ans=0;
      for(int i=0;i<n;i++){
        cin>>x;
        ans=(ans + (x*pre)%M)%M;
        pre=(pre+x)%M;
      }
      cout<<ans;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <cassert>

using namespace std;


class Solution{

public:
    int min_cost(const vector<int>& A){

        int min_v = A[0], max_interval = 0, res = 0;
        for(int i = 1; i < A.size(); i ++){
            if(A[i] - min_v > max_interval) res = 1, max_interval = A[i] - min_v;
            else if(A[i] - min_v == max_interval) res ++;
            min_v = min(min_v, A[i]);
        }
        return res;
    }
};

int main() {

    int N, T;
    scanf("%d%d", &N, &T);

    vector<int> A(N);
    for(int i = 0 ; i < N; i ++) scanf("%d", &A[i]);
    printf("%d\n", Solution().min_cost(A));

    return 0;
}

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

int gcd(int x, int y)
{
  return x ? gcd(y % x, x) : y;
}

int main()
{

  int N, X;
  cin >> N >> X;
  int x[N];
  // vector<int> x;

  int code = 0;
  int diff[N];

  for (int i = 0; i < N; i++)
  {
    cin >> x[i];
    diff[i] = abs(X - x[i]);
  }

  if (N == 1)
  {
    cout << diff[0];
    return 0;
  }

  int step = 0;
  for (int i = 0; i < N - 1; i++)
  {
    if (step == 0)
    {
      step = gcd(diff[i], diff[i + 1]);
    }
    else
    {
      step = gcd(step, diff[i + 1]);
    }
  }

  cout << step;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(n+1,0) ;
	vll a(n) ;
	for(int i=0;i<n;i++){
		cin >> a.at(i) ;
		cnt.at(a.at(i))++ ;
	}
	ll sum = 0 ;
	for(int i=0;i<n;i++){
		ll sub = cnt.at(i+1) ;
		sum += sub*(sub-1)/2 ;
	}
	for(int i=0;i<n;i++){
		ll ans = sum-cnt.at(a.at(i))+1 ;
		cout << ans << endl ;
	}
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <queue>

#define MAX_V 100001
#define INF 1e18

using namespace std;

struct edge { int to; long long cost; };
typedef pair<long long, int> P;  // first は最短距離, second は頂点番号

vector<edge> tree[MAX_V];
long long d[MAX_V];
int N;

// s: 開始地点の頂点
void dijkstra(int s) {
    // greater<P> を指定することで first が小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + N, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) { continue; }
        for (int i = 0; i < tree[v].size(); i++) {
            edge e = tree[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int a, b, c;
    int Q, K, x, y;

    cin >> N;

    for (int i = 0; i < N-1; i++) {
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back(edge{b, c});
        tree[b].push_back(edge{a, c});
    }

    cin >> Q >> K; K--;

    dijkstra(K);

    for (int i = 0; i < Q; i++) {
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n,wt;
    cin>>n>>wt;
    pair<long long,long long> a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    long long dp[n+1][wt+1];
    for(int i=0;i<=n;i++)
        for(int j=0;j<=wt;j++)
            dp[i][j]=0;
    long long max_val=0;
    long long w,v;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=wt;j++)
        {
            w=a[i-1].first;
            v=a[i-1].second;
            if(j>=w)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
            }
            else
                dp[i][j]=dp[i-1][j];
            if(dp[i][j]>max_val)
                max_val=dp[i][j];
        }
    }
    cout<<max_val;
    return 0;
}

/*
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
*/


Measured memory_bytes: 79232
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	map<char, char> m;

	m['A'] = 'T';
	m['T'] = 'A';
	m['G'] = 'C';
	m['C'] = 'G';

	char tmp;
	cin >> tmp;
	cout << m[tmp] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int flag=0,a,b,c,d;
  string str;
  string n,ans;
  cin>>n;
  a=n[0]-'0';
  b=n[1]-'0';
  c=n[2]-'0';
  d=n[3]-'0';

  str="+-";

  ans[0]=n[0];
  ans[2]=n[1];
  ans[4]=n[2];
  ans[6]=n[3];
  ans[7]='=';
  ans[8]='7';
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      for(int k=0; k<2; k++){
	flag=0;
	if(i==0){
	  flag=a+b;
	}else{
	  flag=a-b;
	}
	if(j==0){
	  flag+=c;
	}else{
	  flag-=c;
	}
	if(k==0){
	  flag+=d;
	}else{
	  flag-=d;
	}
	if(flag==7){
	  ans[1]=str[i];
	  ans[3]=str[j];
	  ans[5]=str[k];
	}
      }
    }
  }
  for(int i=0; i<9; i++){
    cout<<ans[i];
  }
  cout<<'\n';
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
X = []
Y = []
max = 0
eo = [0, 0]
N.times do 
  a, b = gets.split.map(&:to_i)
  tot = a.abs + b.abs
  max = tot if tot > max
  eo[tot % 2] = 1
  X << a 
  Y << b 
end 

def calc(t_x, t_y, x, y, d, i)
  return "" if i == d.size
  xdiff = t_x - x
  ydiff = t_y - y
  if xdiff.abs >= ydiff.abs
    if xdiff >= 0
      'R' + calc(t_x, t_y, x + d[i], y, d, i + 1)
    else
      'L' + calc(t_x, t_y, x - d[i], y, d, i + 1)
    end
  else
    if ydiff >= 0
      'U' + calc(t_x, t_y, x, y + d[i], d, i + 1)
    else 
      'D' + calc(t_x, t_y, x, y - d[i], d, i + 1)
    end
  end 
end

if eo == [1, 1]
  puts -1
else
  if eo[0] == 1
    tot = 2
    d = [1, 1]
  else
    tot = 1
    d = [1]
  end
  while tot < max 
    d << d.last * 2
    tot += d.last 
  end
  d.reverse!
  puts d.size
  puts d.join(' ')
  (0...X.size).each do |i|
    puts calc(X[i], Y[i], 0, 0, d, 0)
  end
end


Measured memory_bytes: 1916
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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

n, m = MAP()
c = LIST()

dp = [INF]*(n+1)
dp[0] = 0

for i in range(n+1):
	for j in c:
		if i-j >= 0:
			dp[i] = min(dp[i], dp[i-j]+1)
# print(dp)
print(dp[n])



Measured memory_bytes: 8604
N = int(input())

memo = [{} for _ in range(N)]  # i 文字目に dict.key がきたとき, これ以降を何通りあるか を保存する


def judge(last):
    if last[1:] in ('AGC', 'ACG', 'GAC'):
        return False
    if last[0] == 'A':
        if last[1] == 'G' and last[-1] == 'C': return False
        if last[2] == 'G' and last[-1] == 'C': return False
    return True


MOD = 10 ** 9 + 7


def dfs(i, last):
    if i >= N:  # 末尾
        return 1

    if last in memo[i]:
        return memo[i][last]

    res = 0
    for c in 'AGCT':
        l = last[1:] + c
        if judge(l):
            res += dfs(i + 1, l) % MOD
    memo[i][last] = res % MOD
    return res


print(dfs(0, 'XXXX') % MOD)


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

int main()
{
    int N, ans[4] = {};
    string S[100010] = {};
    cin >> N;

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

        if (S[i] == "AC")
        {
            ans[0]++;
        }
        else if (S[i] == "WA")
        {
            ans[1]++;
        }
        else if (S[i] == "TLE")
        {
            ans[2]++;
        }
        else if (S[i] == "RE")
        {
            ans[3]++;
        }
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;

    return 0;
}

Measured memory_bytes: 6728
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr[] = mylist.get(0).split(" ");

        int h = Integer.valueOf(arr[0]);
        int a = Integer.valueOf(arr[1]);

        System.out.println(h % a == 0 ? h / a : (h / a) + 1);

    }

}


Measured memory_bytes: 21588
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

template <class T> struct SegmentTreeMin {
    
    int N;
    vector<T> node;
    const T INF = numeric_limits<T>::max() / 2;

    SegmentTreeMin (int n) { 
        N = 2 << (int)log2(n);
        node.resize(N*2, INF); 
    }
  
    void update(int idx, T val){
        idx += N;
        node[idx] = val;
        while (idx > 0) {
            node[idx>>1] = min(node[idx], node[idx^1]);
            idx >>= 1;
        }
    }

    T get_min(int l, int r) { 
        T ret = INF;
        l += N, r += N;
        while (l < r) {
            if (l & 1) ret = min(ret, node[l++]);
            if (r & 1) ret = min(ret, node[--r]);
            l >>= 1; r >>= 1;
        }
        return ret;
    }
    
};

template <class T> struct SegmentTreeMax {

    int N;
    vector<T> node;
    const T INF = numeric_limits<T>::min() / 2;
  
    SegmentTreeMax (int n) {
        N = 2 << (int)log2(n);
        node.resize(N*2, INF); 
    }
  
    void update(int idx, T val){
        idx += N;
        node[idx] = val;
        while (idx > 0) {
            node[idx>>1] = max(node[idx], node[idx^1]);
            idx >>= 1;
        }
    }
  
    T get_max(int l, int r) { 
        T ret = INF;
        l += N, r += N;
        while (l < r) {
            if (l & 1) ret = max(ret, node[l++]);
            if (r & 1) ret = max(ret, node[--r]);
            l >>= 1; r >>= 1;
        }
        return ret;
    }

};

int main ()
{
    int N; cin >> N;
    vector < ll > x(N),y(N);
    REP(i,N) cin >> x[i] >> y[i];

    vector < pair < ll,ll > > ord;
    REP(i,N) ord.push_back(make_pair(min(x[i],y[i]), i));
    sort(ord.begin(), ord.end());
    SegmentTreeMax < ll > Rmax(200010),Bmax(200010);
    SegmentTreeMin < ll > Rmin(200010),Bmin(200010);
    REP(i,N) {
        Rmax.update(i, max(x[i],y[i]));
        Rmin.update(i, max(x[i],y[i]));
        Bmax.update(i, min(x[i],y[i]));
        Bmin.update(i, min(x[i],y[i]));
    }
    ll ans = abs(Rmax.get_max(0,200005) - Rmin.get_min(0,200005)) * 
             abs(Bmax.get_max(0,200005) - Bmin.get_min(0,200005));
    REP(i,N) {
        int idx = ord[i].second;
        Rmax.update(idx, min(x[idx],y[idx]));
        Rmin.update(idx, min(x[idx],y[idx]));
        Bmax.update(idx, max(x[idx],y[idx]));
        Bmin.update(idx, max(x[idx],y[idx]));
        ll anst = abs(Rmax.get_max(0,200005) - Rmin.get_min(0,200005)) * 
                  abs(Bmax.get_max(0,200005) - Bmin.get_min(0,200005));
        ans = min(ans, anst);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 23916
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

int n, a, m = 0, M = 0, exceed = 0;
bool exist[8] = {};

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a;

		if (a < 3200){
			exist[a / 400] = true;
		}
		else{
			exceed++;
		}
	}

	for (int i = 0; i < 8; i++){
		if (exist[i]){
			m++;
		}
	}

	M = m + exceed;

	cout << max(m, 1) << " " << M << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,q,a[55],b[55],c[55],d[55],ans,A[15];
void solve(int cnt) {
	if(cnt==n+1) {
		int res=0;
		for(int i=1; i<=q; i++) {
			if(A[b[i]]-A[a[i]]==c[i]) {
				res+=d[i];
			}
		}
		ans=max(ans,res);
//		for(int i=1; i<=n; i++) {
//			cout<<A[i]<<" ";
//		}
//		cout<<"sum:"<<res<<endl;
		return;
	}
	A[0]=1;
	int mi=A[cnt-1];
	for(int i=mi; i<=m; i++) {
		A[cnt]=i;
		solve(cnt+1);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	for(int i=1; i<=q; i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	solve(1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
using System;
namespace ForAtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int r = int.Parse(str[1]);

            if (n >= 10)
            {
                Console.WriteLine(r);
            }
            else
            {
                Console.WriteLine(r + (100 * (10 - n)));
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <cctype>
#include <random>

using namespace std;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    if (abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 888
import math

n = int(input())

def koch(n,a,b): #a,b:tuple
    if n==0:
        return
    th = math.pi*60/180
    s = ((2*a[0]+b[0])/3,(2*a[1]+b[1])/3)
    t = ((a[0]+2*b[0])/3,(a[1]+2*b[1])/3)
    u = ((t[0]-s[0])*math.cos(th)-(t[1]-s[1])*math.sin(th)+s[0],(t[0]-s[0])*math.sin(th)+(t[1]-s[1])*math.cos(th)+s[1])

    koch(n-1,a,s)
    print(s[0],s[1])
    koch(n-1,s,u)
    print(u[0],u[1])
    koch(n-1,u,t)
    print(t[0],t[1])
    koch(n-1,t,b)

a = (0,0)
b = (100,0)
print(a[0],a[1])
koch(n,a,b)
print(b[0],b[1])


Measured memory_bytes: 5776
#include<bits/stdc++.h>
using namespace std;
//顺序确定 问题之只在于抽走哪一个
//先按原来顺序求出来总和再从总和里减去i-1到i和i到i+1的距离 加上i-1到i+1的距离
//12-2-6+4=8
#define MAXN 100005
long long n,a[MAXN],ans;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        ans+=abs(a[i]-a[i-1]);
    }
    ans+=abs(a[0]-a[n]);
    for(int i=1;i<=n;i++)
    {
        printf("%lld ",ans-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i+1]-a[i-1]));
    }
}


Measured memory_bytes: 2048
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H = lread();
    long W = lread();
    long N = lread();
    long m = max(H, W);
    writeln((N + m - 1) / m);
}


Measured memory_bytes: 256
from math import sqrt,floor
import sys
n = int(input())
bl = True
for i in range(n,100004):
  bl=True
  for j in range(2,floor(sqrt(n))+1):
    if i % j ==0:
      bl = False
      break
  if bl==True:
    print(i)
    sys.exit()
print(100003)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
using namespace std;
#define MAX 50
#define INF (1<<28)
#define EPS (1e-8)
struct edge{ int to,cost,l; };
struct state{
  int pos,prev,v;
  double cost;
  bool operator < (const state& p)const{return cost > p.cost;}
};

int n,m,si,ti;
vector<edge> G[MAX];
double d[MAX][MAX][MAX];

void init(){
  for(int i=0;i<MAX;i++){
    G[i].clear();
    for(int j=0;j<MAX;j++)
      for(int k=0;k<MAX;k++)
	d[i][j][k]=INF;
  }
}
void solve(){
  priority_queue<state> Q;
  Q.push((state){si,n,0,0});
  d[si][n][0]=0;
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.pos==ti&&s.v==1){printf("%.8f\n",s.cost);return;}
    if(s.cost>EPS+d[s.pos][s.prev][s.v])continue;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(e.to==s.prev)continue;
      for(int j=-1;j<=1;j++){
	int nv=s.v+j;
	if(nv<=0||e.l<nv)continue;
	double ncost=s.cost+(double)e.cost/nv;
	if(nv<=e.l&&nv>0&&ncost<d[e.to][s.pos][nv]-EPS){
	  d[e.to][s.pos][nv]=ncost;
	  Q.push((state){e.to,s.pos,nv,ncost});
	}
      }
    }
  }
  cout<<"unreachable"<<endl;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    init();
    cin>>si>>ti;
    si--,ti--;
    for(int i=0;i<m;i++){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      a--,b--;
      G[a].push_back((edge){b,c,d});
      G[b].push_back((edge){a,c,d});
    }
    solve();
 
  }
  return 0;
}

Measured memory_bytes: 2748
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

int sum(ll n)
{
	int ret = 0;
	while(n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

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


	int ans = sum(n);

	ll base = 1;
	for (ll d=0;;d++)
	{
		ll now = n * base;
		if (now == 0)
		{
			break;
		}
		amax(ans, sum(now));
		if (now >= 2)
		{
			amax(ans, sum(now - 1));
		}

		base *= 10;
		n /= 10;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;

int main()
{_
    ll n , a , b; cin >> n >> a >> b;
    n-=a;
    return cout << n % b , 0;
}
///SAliB


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

struct UnionFind {
    vector<int> data; int group;
    UnionFind(int N) : data(N, -1), group(N) {}
    void init(int N) {
        data.assign(N, -1);
        group = N;
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y){
            data[x] += data[y];
            data[y] = x;
            --group;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

struct Edge {
    int from, to, num;
    Edge(int f, int t, int n)
         : from(f), to(t), num(n) {}
};
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    int s_, t_, c_;
    map<int, vector<Edge>> edges;
    rep(i, M) {
        cin >> s_ >> t_ >> c_;
        --s_; --t_;
        edges[c_].push_back(Edge(s_, t_, i));
    }
    UnionFind uf(N);
    vector<pint> memo;
    for(const auto& pev: edges) { 
        rep(i, pev.second.size()) {
            Edge e = pev.second[i];
            if(uf.same(e.from, e.to)) continue;
            uf.unite(e.from, e.to);
            memo.push_back(pint(pev.first, i));
        }
    }
    int ans_num = 0, ans_cos = 0;
    for(const pint& p : memo) {
        Edge aim = edges[p.first][p.second];
        UnionFind temp(N);
        for(const pint& e : memo)
          if(p != e) temp.unite(edges[e.first][e.second].from, edges[e.first][e.second].to);
        int ra = temp.root(aim.from), rb = temp.root(aim.to);
        bool ok = true;
        REP(i, p.second + 1, edges[p.first].size()) {
            Edge e = edges[p.first][i];
            int rf = temp.root(e.from), rt = temp.root(e.to);
            if((ra == rf && rb == rt) || (ra == rt && rb == rf)) {
                ok = false;
                continue;
            }
        }
        if(ok) { ans_num++; ans_cos += p.first;}
    }
    cout << ans_num << ' ' << ans_cos << endl;
    return 0;
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
int n, k, q;

int main() {
    cin >> n >> k >> q;
    vector<int> ap(n, 0-q);
    for(int i = 0; i < q; ++i) {
        int a;
        cin >> a;
        ap.at(a-1)++;
    }

    for(int i = 0; i < n; ++i) {
        if(k+ap.at(i) <= 0) {
            cout << "No" << endl;
        }else {
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int l[10];
	int v1, v2;
	char d;
	int sum;
	double kyori;
	while (cin >> l[0]) {
		sum = l[0];
		cin >> d;
		for (int i = 1; i < 10; i++) {
			cin >> l[i] >> d;
			sum += l[i];
		}
		cin >> v1 >> d >> v2;
		kyori = (double)v1 * (double)sum / (double)(v1+v2);
		for (int i = 9; i >= 0; i--) {
			sum -= l[i];
			if (sum < kyori) {
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

template<typename T>
map<T, int> prime_factor(T n) {
    map<T, int> res;
    for(int i = 2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

const i64 MOD = 1e9 + 7;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<i64> count(n + 1, 0);
    for(int i : in(1, n + 1)) {
        auto mp = prime_factor(i);
        for(const auto& p : mp)
            count[p.first] += p.second;
    }
    i64 ans = 1LL;
    for(int i : in(2, n + 1)) {
        if(count[i] == 0) continue;
        (ans *= (count[i] + 1LL)) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int lam,gcd,a,b,c,d;
	while(cin>>a>>b)
	{
		c=a;
		d=b;
		if(a<b)
		{
			a=a+b;
			b=a-b;
			a=a-b;
		}
		while(a%b!=0)
		{
			int temp;
			temp=b;
			b=a%b;
			a=temp;
		}
		gcd=b;
		lam=d/gcd*c;
		printf("%d %d\n",gcd,lam);
	}
	return 0;
}

Measured memory_bytes: 3096
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  int a;
  cin>>a;
  string s,t,u;
  cin>>s>>t>>u;
  int count=0;
  rep(i,a){
    if(s.at(i)==t.at(i)&&t.at(i)==u.at(i)){
    }
    else{
      if(s.at(i)==t.at(i)||s.at(i)==u.at(i)||t.at(i)==u.at(i)){
        count+=1;
      }
      else{
        count+=2;
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n = int(input())
D = list(map(int,input().split()))
# from random import randint

# n = randint(1, 50)
# D = [randint(0, 12) for i in range(n)]

C = [0] * 13
C[0] = 1
for i in range(n):
    C[D[i]] += 1

if C[0] >= 2 or C[12] >=2:
    print(0)
    sys.exit()

for i in range(13):
    if C[i] >= 3:
        print(0)
        sys.exit()

# D = []
# for i in range(13):
#     for j in range(C[i]):
#         D.append(i)
# n = len(D)
# A = [0] * n

# print(C)
ans0 = 0
for i in range(2**13):
    zero = 0
    ib = format(i, "b").zfill(13)
    A = []
    for j in range(13):
        if C[j] == 1:
            A.append(j * (-1) ** int(ib[j]))
        if C[j] == 2:
            if int(ib[j]) == 0:
                A.append(j)
                A.append(-j)
            else:
                zero = 1
    if zero == 1:
        continue
    # print("not cont")
    ans = 30
    # if len(A)>1:
        # print(A)
    # print(ib, A)
    for j in range(len(A)):
        for k in range(j+1, len(A)):
            di = abs(A[k] - A[j])
            # print(ans)
            ans = min(ans, min(di, 24-di))
            if ans <= ans0:
                break
        if ans <= ans0:
            break
    # print(ib, ans0,ans)
    ans0 = max(ans0, ans)
print(ans0)

Measured memory_bytes: 46064
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int main(){
    int M, N;
    while(cin >> M >> N){
        vector<int> P(M);
        REP(i, M) cin >> P[i];
        int dp[10001] = {};
        const int INF = 1 << 29;
        REP(i, M + 1) dp[i] = INF;
        dp[0] = 0;
        REP(_, N) {
            int C, E;
            cin >> C >> E;
            for(int i = M; i >= 0; i--) if(dp[i] < INF) {
                int ni = min(i + C, M);
                dp[ni] = min(dp[ni], dp[i] + E);
            }
        }

        int ans = 0;
        int sum = 0;
        sort(P.begin(), P.end(), greater<int>());
        for(int i = 0; i < M; i++) {
            sum += P[i];
            //printf("%d - %d \n", sum, dp[i + 1]);
            if(dp[i + 1] < INF) {
                ans = max(ans, sum - dp[i + 1]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1292
using System;
using System.Linq;
using System.Text.RegularExpressions;

class C
{
	static void Main()
	{
		Console.ReadLine();
		var s = Console.ReadLine();

		foreach (var c in s.Distinct())
			s = Regex.Replace(s, $"{c}+", $"{c}");
		Console.WriteLine(s.Length);
	}
}


Measured memory_bytes: 29360
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

ll n,k;
map<int,int> A;

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

ll fac(int n){
    if(n==0||n==1) return 1;
    return n*fac(n-1);
}

int main(){
    cin>>n>>k;
    rep(i,0,n){
        int a,b;cin>>a>>b;
        A[a]+=b;
    }
    ll count=0;
    auto itr=A.begin();
    while(count<k){
        count+=itr->second;
        itr++;
    }
    itr--;
    cout<<itr->first<<endl;
}

Measured memory_bytes: 3200
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


void solve(long long N, long long M, std::vector<long long> A){

  priority_queue<ll> que;

  for(ll i=0; i<N; i++){
    que.push(A[i]);
  }

  // Greedy に割引券を適用していく。
  for(ll m=0; m<M; m++){
    ll val = que.top();
    que.pop();
    que.push(val / 2);
  }


  ll rst = 0;
  for(; !que.empty(); que.pop()){
    rst += que.top();
  }

  cout << rst << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
int main(){
    int n,m;
    cin >> n >> m;
    
    m--;
    vector<vector<ll> >a(n,vector<ll>(2));
    for(int i=0;i<n;i++){
        if(i==0){
            a[i][1] = 1;
        }else{
            a[i][0] = 1;
        }
    }
    rep(i,m){
        vector<vector<ll> >b(n,vector<ll>(2));
        rep(j,n){
            for(int k=-1;k<=1;k++){
                if(j+k>=n)continue;
                if(j+k<0)continue;
                if(j+k!=0){
                    if(k!=0){
                        b[j+k][0] += a[j][0];
                        b[j+k][1] += a[j][1];
                    }else{
                        b[j+k][0] += a[j][0]*2;
                        b[j+k][1] += a[j][1]*2;    
                    }
                }else{
                    if(j==0){
                        b[j+k][1] += 2*a[j][1];
                    }else if(j==1){
                        b[j+k][1] += a[j][0];
                        b[j+k][1] += a[j][1];
                    }
                }
                b[j+k][0] %= mod;
                b[j+k][1] %= mod;
            }
        }
        a = b;
        // rep(j,n){
        //     cerr << a[j][0] << " ";
        // }
        // cerr << endl;
        // rep(j,n){
        //     cerr << a[j][1] << " ";
        // }
        // cerr << endl;
    }
    ll sm = 0;
    rep(i,n){
        sm += a[i][1];
        sm %= mod;
    }
    cout << sm*4%mod << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 200005, MAXM = 3003, Mod = 1000000007 , MAXLog = 20;



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    int ans = 0;
    int neg = 0;
    queue<int> q;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '0') {
            int j = i;
            while (j < n && s[j] == '0')
                ++j;
            q.push(j);
            i = j - 1;
        }
        if (q.size() > k) {
            neg = q.front();
            q.pop();
        }
//        cout << i << ' ' << neg << '\n';
        ans = max(ans, i + 1 - neg);
    }

    cout << ans << '\n';



    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<climits>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

class UnionFind {
	public:

	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}
	
	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main(){

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

	vector< int > p(n+1);
	for(int i = 1; i <= n; i++)
	{
		cin >> p[i];
	}
	vector< int > x (m+1);
	vector< int > y (m+1);

	
	for(int i = 1; i <= m; i++)
	{
		cin >> x[i] >> y[i];
	}

	UnionFind u_f(n+1);
	
	for(int i = 1; i <= m; i++)
	{
		u_f.unite(x[i],y[i]);
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		if(u_f.same(i, p[i]) == true){
			ans ++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+11;
int n,a[N],b[N],c[N];
ll ans;
ll find1(int x){ 
	int l=1,r=n,mid,ret=0;
	while(l<=r){
		mid=(l+r)>>1;
		if(a[mid]<x) l=(ret=mid)+1;
		else r=mid-1;  
	}
	return (ll)ret;
}
ll find2(int x){
	int l=1,r=n,mid,ret=n+1;
	while(l<=r){
		mid=(l+r)>>1;
		if(c[mid]>x) r=(ret=mid)-1;
		else l=mid+1;
	}
	return (ll)ret;
}
void solve(int x){
//	printf("%d %d\n",find1(x),find2(x));
	ll l=find1(x),r=n-find2(x)+1;
	ans+=l*r;
}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);for(int i=1;i<=n;++i) scanf("%d",&b[i]);for(int i=1;i<=n;++i) scanf("%d",&c[i]);
	sort(a+1,a+1+n);sort(c+1,c+1+n);
	for(int i=1;i<=n;++i) solve(b[i]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    n = N
    k = K
    mi = n//k
    ma = mi+1
    res1 = abs(n - k*mi)
    res2 = abs(n-k*ma)
    print(res1 if res1 < res2 else res2)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	string s[101];
	int n,m,i;
	cin>>n>>m;
	for(i=1;i<=n;i++)cin>>s[i];
	sort(s+1,s+1+n);
	for(i=1;i<=n;i++)cout<<s[i];
	return 0;
}


Measured memory_bytes: 256