akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;
using P = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, x, y;
	cin >> n >> x >> y;
	
	vector< vector<P> > G(n);
	for(int i = 0; i < n - 1; ++i) {
		G[i].push_back( make_pair(i + 1, 1) );
		G[i + 1].push_back( make_pair(i, 1) );
	}
	
	x--;
	y--;
	G[x].push_back( make_pair(y, 1) );
	G[y].push_back( make_pair(x, 1) );
	
	vector<int> res(n - 1, 0);
	priority_queue<P, vector<P>, greater<P> > pq;
	
	for(int i = 0; i < n - 1; ++i) {
		vector<int> dist(n, 1e9 + 10);
		dist[i] = 0;
		pq.push( make_pair(0, i) );
		
		while( !pq.empty() ) {
			P p = pq.top();
			pq.pop();
			
			int v = p.second;
			
			if( dist[v] < p.first ) continue;
			
			for(auto &u : G[v]) {
				if( dist[u.first] > dist[v] + u.second ) {
					dist[u.first] = dist[v] + u.second;
					pq.push( make_pair(dist[u.first], u.first) );
				}
			}
		}
		
		for(int j = i + 1; j < n; ++j) {
			res[dist[j] - 1]++;
		}
	}

	for(auto& ans : res) {
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 384
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d",&n);
	if(n<30)printf("No");
	else printf("Yes");
	return 0;
}



Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n;
	vector<multiset<char>> ss;

	cin >> n;
	ss.resize(n);

	if (n == 1) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		cout << s << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++)
			ss[i].insert(s[j]);
	}

	multiset<char> ans;
	set_intersection(ss[0].begin(), ss[0].end(),
					 ss[1].begin(), ss[1].end(),
					 inserter(ans, ans.end()));
	for (int i = 2; i < n; i++) {
		multiset<char> tmp(ans.begin(), ans.end());

		ans.erase(ans.begin(), ans.end());
		set_intersection(ss[i].begin(), ss[i].end(),
						 tmp.begin(), tmp.end(),
						 inserter(ans, ans.end()));
	}

	for_each(ans.begin(), ans.end(), [](char x) {
		cout << x;
	});
	cout << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	ll diff = B - A;
	ll ans;
	if (diff % 2 == 0) {
		ans = diff / 2;
	}
	else {
		ll ans1 = (diff + 1) / 2 + N - B;
		ll ans2 = (diff + 1) / 2 + A - 1;
		ans = min(ans1, ans2);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        for(int i=1; i<s.Length; i++) {
            if (s[i] == s[i - 1]) return "Bad";
        }

        return "Good";
    }
}

Measured memory_bytes: 13140
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    vector<lint> sorted(n);
    REP(i, n){
        cin >> a[i];
        sorted[i] = a[i];
    }
    sort(ALL(sorted), greater<lint>());
    lint maxnum = sorted[0];
    lint secondnum = sorted[1];
    REP(i, n){
        if(a[i] == maxnum){
            cout << secondnum << endl;
        }
        else {
            cout << maxnum << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4736
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
    int s=0, c=0, f=0;
    cin >> s;
    if(s==1 ||
       s==2 ||
       s==4){
           cout << 4 << endl;
           return 0;
       }
    while(f!=2){
        if(s==4) ++f;
        if(s%2) s=3*s+1;
        else s/=2;
        ++c;
    }
    cout << c << endl;
}

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

A.sort()
sum = 0
for i in range(N):
    sum += A[i]

for i in range(N):
    if N - i > N - M:
        if sum / (4 * M) > A[N-1-i]:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 9188
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, sum = 0, j;
    cin>>n;
    vector<ll> v(n);
    for(i=0; i<n; i++) {
    	cin>>v[i];
    }
    for(i=0; i<n; i++) {
    	for(j = i + 1; j<n; j++) {
    		sum += v[i]*v[j];
    	}
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>

#define MAX 1000

using namespace std;

typedef unsigned long long ull;

int H,W,R,C;
char field[MAX][MAX]; //????´¢????±?
char pattern[MAX][MAX]; //????????????

ull hashh[MAX][MAX],temp[MAX][MAX];
ull target;

//a???R*C?????¨??????hash????¨????
void compute_hash(char a[MAX][MAX], int n, int m){
	const ull B1=9973;
	const ull B2=100000007;
	
	ull t1=1;//B1???C???
	for(int i=0;i<C;i++) t1*=B1;
	//????????????hash????¨????
	for(int i=0;i<n;i++){
		ull e=0;
		for(int j=0;j<C;j++) e=e*B1+a[i][j];
		for(int j=0;C+j<=m;j++){
			temp[i][j]=e;
			e=e*B1-t1*a[i][j]+a[i][j+C];
		}
	}
	ull t2=1;//B2???R???
	for(int i=0;i<R;i++) t2*=B2;
	for(int j=0;j+C<=m;j++){
		ull e=0;
		for(int i=0;i<R;i++) e=e*B2+temp[i][j];
		for(int i=0;i+R<=n;i++){
			hashh[i][j]=e;
			e=e*B2-t2*temp[i][j]+temp[i+R][j];
		}
	}
}

void solve(){
	compute_hash(pattern,R,C);//pattern???hash???????±???????
	target=hashh[0][0];
	compute_hash(field,H,W);//field???hash???????±???????
	//target??¨?????´??????hash??????search
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(target==hashh[i][j])
			printf("%d %d\n",i,j);
		}
	}
}

int main(){
	scanf("%d %d",&H,&W);
	cin.ignore();
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			scanf("%c",&field[i][j]);
		}
		cin.ignore();
	}
	scanf("%d %d",&R,&C);
	cin.ignore();
	for(int i=0;i<R;i++){
		for(int j=0;j<C;j++){
			scanf("%c",&pattern[i][j]);
		}
		cin.ignore();
	}
	if(H>=R&&W>=C)
	solve();
}

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

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N,vector<int>(D));
    for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
        cin >> X[i][j];
    }
    }
    int ans = 0;
    for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
        int norm = 0;
        for (int k=0;k<D;k++){
        int diff = abs(X[i][k]-X[j][k]);
        norm += diff*diff;
        }
        bool flag = false;
        for(int k=0;k<=norm;k++){
            if(k*k==norm){
            flag = true;
            }
        }
        if(flag)ans++;
    }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>

using namespace std;
int main() {
	int h, a,ans;

	cin >> h >> a;
	ans = h / a;
	if (h % a != 0) {
		ans++;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stack>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

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

	while (cin >> a) {
		cin >> b;
		long long int m = a;
		long long int n = b;
		int r1, r2;
		int gcd, lcm;
		
		if (a < b) {
			c = a;
			a = b;
			b = c;
		}
		r1 = a % b;
		r2 = r1;

		while (r2 != 0) {
			r1 = r2;
			r2 = b % r1;
			b = r1;
		}
		gcd = b;
		lcm = (m * n) / gcd;

		cout << gcd << " " << lcm << endl;

	}

	return 0;
}


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

using namespace std;
const int kMod = 1e9 + 7;

map<long long, long long> mem;
long long Count(long long x) {
  if (x == 0) return 0;
  if (x == 1) return 1;

  if (mem.count(x)) return mem[x];
  if (x % 2 == 0) {
    return mem[x] = (2 * Count(x / 2) + Count(x / 2 - 1)) % kMod;
  } else {
    return mem[x] = (2 * Count(x / 2) + Count((x + 1) / 2)) % kMod;
  }
}

int main() {
  long long n; cin >> n;
  cout << Count(n + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]

queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(K):
    h,w = queue[i]
    U,D,L,R = 0,0,0,0
    while L < w:
        if cake[h][w-L-1]:
            break
        L += 1
    while R+w < W-1:
        if cake[h][w+R+1]:
            break
        R += 1
    while U < h:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h-U-1][k]:
                flag = True
        if flag:
            break
        U += 1
    while D+h < H-1:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h+D+1][k] != 0:
                flag = True
        if flag:
            break
        D += 1
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1

for i in cake:
    print(*i)

Measured memory_bytes: 17868
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();
    for (int i = 0; i < s.length; i++) {
      if (i % 2 == 0 && s[i] == 'L') {
        System.out.println("No");
        return;
      } else if (i % 2 != 0 && s[i] == 'R') {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 22868
n, m = map(int,input().split())

l = list(map(int,input().split()))

l_sort = sorted(l , reverse=True)

l_sum = sum(l)

s = l_sum/(m*4)

ans = 0
for i in range(m):
    if l_sort[i] >= s:
        ans += 1



if ans == m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.nextInt();
		int b = sc.nextInt();
		sc.nextInt();
		System.out.println(a == b ? 0 : 1);
	}

}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void) {
	int i, j, k;
	int c;
	int n ,x;

	while(scanf("%d %d\n", &n , &x) && !( (n == 0) && (x == 0) )){
		c = 0;
		for(i = 1;  i <= n; i++){
			for(j = 1; j <= n; j++){
				if (i == j) continue;
				for(k = 1; k <= n; k++){
					if(i == k || j == k) continue;
					if( (i + j + k) == x ){
						c++;
					}
				}
			}
		}
		printf("%d\n", c/6);
	}

	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const double EPS = 1e-9;
const int N = 100000;

template <class T> T gcd(T a, T b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}

template <class T> bool isPrime(T x) {
	for (T d = 2; d * d <= x; d++) { if (x % d == 0) return false; }
	return true;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	string s;
	int pos;
	long long ans;
	pos = ans = 0;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'W') {
			ans += i - pos;
			++pos;
		}
	}

	cout << ans << '\n';
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) puts("Possible");
    else puts("Impossible");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

vector<int> g[100100];
vector<int> g2[100100];
bool used[100100];
vector<int> ans;
int N, M;
int index_list[100100];

void dfs(int u){
    if(used[u]) return;
    used[u] = true;
    for(auto& i: g[u]) dfs(i);
    ans.push_back(u);
}

void tsort(){
    for(int i = 0; i < N; i++){
        dfs(i);
    }
    reverse(ans.begin(), ans.end());
}

int dfs2(int u){
    int ma = -1, ma_index = -1;
    for(int i = 0; i < g2[u].size(); i++){
        int nex = g2[u][i];
        if(index_list[nex] > ma){
            ma_index = g2[u][i];
            ma = index_list[nex];
        }
    }
    return ma_index;
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < N-1+M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g2[b].push_back(a);
        used[i] = false;
    }

    tsort();

    for(int i = 0; i < N; i++){
        index_list[ans[i]] = i;
    }

    int root = ans[0];
    for(int i = 0; i < N; i++){
        if(i == root){
            cout << 0 << endl;
        }
        else{
            cout << dfs2(i) + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 15996
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    x=int(input())
    ans=x//11
    x-=ans*11
    ans*=2
    ans+=-(-x//6)
    print(ans)

if __name__ == '__main__':
    main()


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

signed main(void)
{
	int n, ans, cnt;
	cin  >> n;
	vector<int> a(n);
	bool color[8];

	cnt = ans = 0;
	rep(i, n)
	{
		cin >> a[i];
		if (a[i] >= 3200)
			cnt++;
	}
	rep(i, 8) color[i] = false;
	rep(i, n)
	{
		rep (j, 8)
		{
			if (400 * j <= a.at(i) && a.at(i) < 400 * (j + 1))
			{
				if (!color[j]) ans++;
				color[j] = true;
			}
		}
	}
	if (ans >= 1)
		cout << ans << endl;
	else
		cout << 1 << endl;
	cout << cnt + ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val s = sc.next
  val former = s.take(s.length / 2)
  val latter = s.takeRight(s.length / 2).reverse
  println(former.zip(latter).count(t => t._1 != t._2))
}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n + 1, 0);
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    b[a]++;
  }
  for (int i = 1; i <= n; ++i) { cout << b[i] << endl; }
}


Measured memory_bytes: 4052
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h+2);
    REP(i,1,h){
        cin>>s[i];
        s[i]="#"+s[i]+"#";
    }
    rep(i,w+2){
        s[0]+="#";
        s[h+1]+="#";
    }
    vvi r(h+2),c(w+2);
    REP(i,1,h){
        rep(j,w+2){
            if(s[i][j]=='#')r[i].pb(j);
        }
    }
    REP(i,1,w){
        rep(j,h+2){
            if(s[j][i]=='#')c[i].pb(j);
        }
    }
    int ans=0;
    REP(i,1,h){
        REP(j,1,w){
            if(s[i][j]=='.'){
                auto rl=lower_bound(all(r[i]),j);
                rl--;
                auto rr=upper_bound(all(r[i]),j);
                auto cl=lower_bound(all(c[j]),i);
                cl--;
                auto cr=upper_bound(all(c[j]),i);
                ans=max(ans,((*rr-*rl-1)+(*cr-*cl-1)-1));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 72320
x, k, d = map(int, input().split())
if x < 0:
    a, b = divmod(-x, d)
    if a >= k:
        print(-x - k * d);exit()
    else:
        print(d - b if (k - a) % 2 else b)
elif x:
    a, b = divmod(x, d)
    if a >= k:
        print(x - k * d);exit()
    else:
        print(d - b if (k - a) % 2 else b)
else:
    print(k % 2 * d)

Measured memory_bytes: 61872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
int main(){
  int N,ans=0;
  cin >> N;
  int a[N];
  rep(i,N) cin >> a[i];
  for(int Q=0;Q<102;Q++){
    int b[N]={};
    int cnt=0;
  	rep(i,N){
    	if(a[i]>0) cnt++;
    	else cnt=0;
    	b[i] = cnt;
  	}
  	int c = 0;
  	rep(i,N){
    	if(b[i]==1)
      		c++;
  	}
  	ans += c;
    rep(i,N) a[i]--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
  
 
  
int main(){
  
    int n; 
	int r[1000],w[1000];
	int sum_r=0,sum_w=0,idx=0;
    while(scanf("%d",&n),n){
 		
		sum_r=sum_w=idx=0;
		for(int i=0;i<n;i++){
			scanf("%d %d",&r[i],&w[i]);
			sum_r+=r[i];
			sum_w+=w[i];
			if(r[idx]<r[i]) idx=i;
		}
 
		int r0=r[idx],r=sum_r-r0;
		w[idx]=0;

        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
 
            int res=2*r0;
            vector<vector<bool> > dp(1001,vector<bool>(1000,false));
 
            dp[0][0]=true;
            for(int i=0;i<n;i++){
                for(int j=0;j<=1000;j++){
                    if(dp[i][j]){
                        dp[i+1][j]=true; 
                        if(j+w[i]<=1000)
                            dp[i+1][j+w[i]]=true; 
                    }
                }
            }
 
            int opt=r0-r;
			while(!dp[n][opt]) opt--;
 
            res+=sum_w-opt;
            printf("%d\n",res);
 
 
 
        }
         
         
    }
}

Measured memory_bytes: 1420
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n = 0, a, b; string s; cin >> a >> b >> s;
	for (int h = 0; h < a; h++) {
		if (s[h] != '-') {
			n++;
		}
	}
	if (s[a] == '-') {
		n++;
	}
	for (int h = a + 1; h <= a + b; h++) {
		if (s[h] != '-') {
			n++;
		}
	}
	if (n == a + b + 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
x = NI()

a = x // 500
b = (x % 500) // 5
print (a*1000 + b * 5)

Measured memory_bytes: 65132
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);



        int a = scan.nextInt();
        int b = scan.nextInt();

        if(1 <= a && a<= 1000000000 && 1 <= b && b <= 1000000000){
            int d = a/b;
            int r = a%b;
            double f = (double)a/(double)b;

            System.out.println(d + " " + r + " " + BigDecimal.valueOf(f).toPlainString());



        }

    }
}



Measured memory_bytes: 26584
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[101],d,f,g,h,j,i;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&s[i]);
	}
	f=0;
	for(i=a;i>0;i--){
		d=0;
		for(j=0;j<a;j++){
			if(s[j]>=i){
				d++;
				if(i==d){
					f=1;
					break;
				}
			}
		}
		if(f==1) break;
	}
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 2740
import sys

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
cnt = 26 * [0]
Input = ""
loop = True

for I in sys.stdin:
    Input += I

for i1 in range(len(alphabet)):
    for i2 in range(len(Input)):
        if 'A' <= Input[i2] <= 'Z':
            w = Input[i2].lower()
        else:
            w = Input[i2]
        if alphabet[i1] == w:
            cnt[i1] += 1
    print(alphabet[i1] + " : " + str(cnt[i1]))

Measured memory_bytes: 7492
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<long long>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  long long count = A.at(0);
  if (N%2 == 0){
    for (int i = 0; i < N/2-1; i++) {
      count += A.at(i+1)*2;
    }
    cout << count << endl;
    return 0;
  }
  else {
    for (int i = 0; i < (N-1)/2; i++) {
      count += A.at(i+1);
    }
    for (int i = 0; i < (N-3)/2; i++) {
      count += A.at(i+1);
    }
    cout << count << endl;
  }
}

  
  
  

Measured memory_bytes: 4840
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=998244353;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

int main()
{
  int n,s; cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  vector<vector<vector<mint>>> dp(n+1, vector<vector<mint>>(s+1, vector<mint>(3)));
  dp[0][0][0].x = 1;
  rep(i,n) {
    rep(j,s+1) {
      rep(k,3) {
	for (int l = 2; l >= k; --l) {
	  dp[i+1][j][l] += dp[i][j][k]; // not add
	  if(k == 0 && l == 0) continue;
	  if(k == 2 && l == 2) continue;
	  if(j + a[i] <= s) dp[i+1][j + a[i]][l] += dp[i][j][k];
	}
      }
    }
  }

  cout << dp[n][s][2].x << "\n";
  
  return 0;
}


Measured memory_bytes: 493056
#E_Coprime
import math
import functools

# エラトステネスの篩
        
def primes(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    D_prime = [i for i in range(n+1)] 
    D_prime[0] = 0
    D_prime[1] = 1
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            D_prime[i] = i
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
            D_prime[j] = i
    return D_prime

    

Fnum_list2 = []
# 入力
N = int(input())
A = list(map(int,input().split()))

#Fnum_list = eratosthenes(N)

A.sort()
Amax = A[-1]
Fnum_list2 = primes(Amax)
j = A[0]
ans = 1
#Fnum_list = eratosthenes(N)
Ai_primes     = set()
Ai_primes_add = []
gcd_num = 0
for i in range(len(A) ):
    p = A[i]
    while p != 1:
        j = p
        p = int (p / Fnum_list2[j])
        if Fnum_list2[j] in Ai_primes:
            ans = 0
        else:
            Ai_primes_add.append(Fnum_list2[j])
    if Fnum_list2[j] in Ai_primes:
        break
    else:
        Ai_primes |= set(Ai_primes_add)
        Ai_primes_add.clear()

gcd_num = functools.reduce(math.gcd,A)

if ans == 0:
    if gcd_num == 1:
        ans = 2

# 出力
if ans == 1:
    print("pairwise coprime")
else:
    if ans == 2:
        print("setwise coprime")
    else:
        print("not coprime")
        

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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;

  int bill;

  if(N<=K){
    cout << (N*X) << endl;
  }
  else{
    cout << (K*X)+((N-K)*Y) << endl;
  }

return 0;  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array
const ll MOD=1e9+7;

ll pow(ll a, ll b) {
	ll res=1;
	while (b>0) {
		if (b&1) res*=a, res%=MOD;
		b/=2;
		a*=a;
		a%=MOD;
	}
	return res;	
}

int main() {
	int n;
	cin >> n;
	int a[n], b[n];
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	for (int i=0; i<n; i++) {
		cin >> b[i];
	}
	reverse(b, b+n);
	int start=-1, end=-1;
	for (int i=0; i<n; i++) {
		if (a[i]==b[i]) {
			if (start==-1) start=i;
			end=i;
		}
	}
	bool f=0;
	if (start!=-1) {
		int i=start, j=0;
		while (i<=end) {
			if (j==start) j=end+1;
			if (j==n) {
				f=1;
				break;
			}
			if (b[i]!=a[j]&&b[j]!=b[i]) swap(b[i], b[j]), i++;
			j++;
			if (j==n) {
				f=1;
				break;
			}
		}	
	}
	if (f) {
		cout << "No";
	} else {
		cout << "Yes" << endl;
		for (int i=0; i<n; i++) {
			cout << b[i] << " ";
		}
	}
	return 0;
}

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

int main() {
  ll n,m;
  ll zero=0;
  cin >> n >> m;
  ll mi=n;
  ll ma=1;
  for(ll i=0;i<m;i++) {
    ll l,r;
    cin >> l >> r;
    if(i==0) {
      mi=l;
      ma=r;
    }
    mi=max(mi,l);
    ma=min(ma,r);
  }
  cout << max(ma-mi+1,zero) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  // 入力
  int N, M;
  vector<int> s;
  vector<int> c;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int s_tmp;
    cin >> s_tmp;
    s.push_back(s_tmp);
    int c_tmp;
    cin >> c_tmp;
    c.push_back(c_tmp);
  }

  vector<bool> fixed;
  for (int i=0; i<M; i++) {
    fixed.push_back(false);
  }
  vector<int> value;
  if (N==1) {
    value.push_back(0);
  } else {
    value.push_back(1);
  } 
  for (int i=1; i<M; i++) {
    value.push_back(0);
  }

  int result = 0;
  for (int i=0; i<M; i++) {
    if (fixed[s[i]-1] == false) {
      if (s[i] == 1 && c[i] == 0 && N != 1) {  // 1桁以外で左から1桁目が0を指定された場合は存在しないため探索終了 
        result = -1;
        break;
      } else {
        value[s[i]-1] = c[i];
        fixed[s[i]-1] = true;
      }
    } else {
      if (c[i] != value[s[i]-1]) {  // 同じ桁で異なる値が指定された場合は存在しないため探索終了
        result = -1;
        break;
      }
    }
  }

  if (result != -1) {
    for (int i=0; i<N; i++) {
      result += value[i] * pow(10.0, double(N-i-1));
    }
  }

  // cout << s[0] << " " << s[1] << " " << s[2] << endl;
  // cout << c[0] << " " << c[1] << " " << c[2] << endl;
  // cout << fixed[0] << " " << fixed[1] << " " << fixed[2] << endl;
  // cout << value[0] << " " << value[1] << " " << value[2] << endl;

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);

		int x = scn.nextInt();
		int y = scn.nextInt();
		int cnt = 0;

		if(Math.abs(x) > Math.abs(y) && x > 0 && y >= 0) {
			x = -x;
			cnt++;
		} else  if(Math.abs(x) > Math.abs(y) && x > 0 && y <= 0) {
			x = -x;
			cnt++;
		} else if(Math.abs(x) < Math.abs(y) && x < 0 && y > 0) {
			x = -x;
			cnt++;
		} else if(Math.abs(x) < Math.abs(y) && x < 0 && y <= 0) {
			x = -x;
			cnt++;
		}
		
		while(Math.abs(x) != Math.abs(y)){
			x++;
			cnt++;
		}
		
		if(x == -y && x != 0) cnt++;



		System.out.println(cnt);
	}
}

Measured memory_bytes: 10192
# coding: utf-8
def main():
    n, k = map(int, input().split())
    if n == k:
        return 0
    elif n < k:
        tmp = abs(n - k)
        if tmp < n:
            return tmp
        else:
            return n
    else:
        tmp = n // k
        n -= k * tmp
        tmp = abs(n - k)
        if tmp < n:
            return tmp
        else:
            return n
            
    
print(main())


Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N =1e5+100;

int main()
{
    ll n;
    while(~scanf("%lld",&n))
    {
         ll x,sum=0;
         for(int i=1;i<=n;i++)
         {
             scanf("%lld",&x);
             if(x!=i)
                sum++;
         }
         if(sum==0||sum==2)
            printf("YES\n");
         else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_075
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            var poses = new long[nk[0]][];
            var xs = new long[nk[0]];
            var ys = new long[nk[0]];
            for (int i = 0; i < nk[0]; i++)
            {
                poses[i] = ReadLongs();
                xs[i] = poses[i][0];
                ys[i] = poses[i][1];
            }

            long minRect = long.MaxValue;
            Array.Sort(xs);
            Array.Sort(ys);
            for (int i = 0; i < nk[0] - 1; i++)
            {
                for (int j = i + 1; j < nk[0]; j++)
                {
                    for (int k = 0; k < nk[0] - 1; k++)
                    {
                        for (int l = k + 1; l < nk[0]; l++)
                        {
                            int cnt = 0;
                            long x1 = xs[i];
                            long x2 = xs[j];
                            long y1 = ys[k];
                            long y2 = ys[l];
                            for (int m = 0; m < nk[0]; m++)
                            {
                                if (x1 <= poses[m][0] && poses[m][0] <= x2
                                    && y1 <= poses[m][1] && poses[m][1] <= y2)
                                {
                                    cnt++;
                                }
                            }
                            if (cnt >= nk[1])
                            {
                                minRect = Math.Min(minRect,
                                    (x2 - x1) * (y2 - y1));
                            }
                        }
                    }
                }
            }
            Console.WriteLine(minRect);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,m;
  cin >> n >> m;
  ll s = 0;
  vector<pair<ll,ll>> p(m + n);
  for(int i = 0;i< m + n;i++)
  {
      if(i < n)
      {
          ll a;
          cin >> a;
          p[i] = make_pair(a,1);
      }
      else
      {
          ll b,c;
          cin >> b >> c;
          p[i] = make_pair(c,b);
      }
  }
  sort(p.begin(),p.end());
  int j = 0;
  for(int i = m + n - 1;i > 0;i--)
  {
      ll t1 = p[i].first, t2 = p[i].second;
      if(j + t2 <= n) s += t1 * t2;
      else s += t1 * (n - j);
      j += t2;
      if(j >= n)break;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int Vmax = 50;

int n, m;
vector<int> a(Vmax), b(Vmax);

int graph[Vmax][Vmax];
bool visited[Vmax];

void dfs(int v) {

    visited[v] = true;
    rep(u, n) {
        if(!graph[v][u] || visited[u]) {
            continue;
        }
        dfs(u);
    }
}

int main() {
    cin >> n >> m;
 
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1;
    }

    int ans = 0;
    rep(i, m) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 0;
 
        rep(j, n) {
            visited[j] = false;
        }

        dfs(0);
 
        int bridge = 0;
        rep(j, n) {
            if(!visited[j]) {
                bridge = 1;
            }
        }

        if(bridge) {
            ans++;
        }

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);
    auto a = readln.split.to!(int[]);

    a.sort!"a > b"();

    auto c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];

    auto dp = new int[](n + 1);
    dp[] = -inf3;
    dp[0] = 0;

    foreach (i ; 1 .. n + 1) {
        foreach (ai ; a) {
            if (i - c[ai] < 0) continue;
            dp[i] = max(dp[i], dp[i - c[ai]] + 1);
        }
    }

    string ans;
    int mat = n;

    while (mat > 0) {
        foreach (ai ; a) {
            if (mat - c[ai] < 0) continue;
            if (dp[mat] == dp[mat - c[ai]] + 1) {
                ans ~= ('0' + ai);
                mat -= c[ai];
                break;
            }
        }
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

using namespace std;

int main(void){
	int n;
	//cout << "check 1" << endl;
	scanf("%d", &n);
	//cout << "check 2" << endl;
	int d[n]; 
	// input data
	for(int i = 0; i < n; i++){
		scanf("%d", &d[i]);
		//printf("%d ", d[i]);
	}

	int patterns = ( n*(n-1) ) / 2;
	int amount = 0;
	//printf("(patterns, amount) = (%d, %d) \n", patterns, amount);

	//printf("n = %d \n", n);
	for(int i = 0; i <= n-1; i++){
		int tmp = i;
		int j = tmp + 1;
		//printf("chack of i: %d\n", i);
		for(j = i+1; j < n; j++){
			//printf("(i, j) = (%d, %d) \n", i, j);
			//printf("d[%d] * d[%d] = %d \n", i, j, d[i] * d[j]);
			//cout << "chack" << endl;
			amount += d[i] * d[j];
			//printf("amount(%d, %d) = %d \n", i, j , amount);
			//j = j + 1;
			//printf("end for. j = %d \n", j);
		}
	}
	printf("%d\n", amount);

	return 0;
}


Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
A = [input() for _ in range(H)]

que = deque([(0, 0, 1)])
minDist = [[10**10] * W for _ in range(H)]

while que:
    h, w, d = que.popleft()

    if minDist[h][w] <= d:
        continue
    minDist[h][w] = d

    if (h, w) == (H - 1, W - 1):
        break

    for dh, dw in zip([0, 0, 1, -1], [1, -1, 0, 0]):
        toH, toW = h + dh, w + dw
        if 0 <= toH < H and 0 <= toW < W and A[toH][toW] == '.':
            que.append((toH, toW, d + 1))

if minDist[H - 1][W - 1] == 10**10:
    print(-1)
    exit()

white = sum([a.count('.') for a in A])
print(max(0, white - minDist[H - 1][W - 1]))


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
const int MAX = 40;
int us[MAX][MAX];
int sm[MAX][MAX];

// [u, d) * [l, r)
int query(int u,int d,int l,int r){
  return (sm[u][l]+sm[d][r])-(sm[u][r]+sm[d][l]);
}

int h,w,s;

using P = pair<int, int>;
int used[MAX][MAX][MAX][MAX];
P dp[MAX][MAX][MAX][MAX];

P dfs(int u,int d,int l,int r){
  if(sm[h][w]-query(u,d,l,r)>s) return P(-MAX*MAX,-MAX*MAX);
  if(used[u][d][l][r]) return dp[u][d][l][r];
  used[u][d][l][r]=1;
  P res(1,s-(sm[h][w]-query(u,d,l,r)));
  for(int m=u+1;m<d;m++){
    P x=dfs(u,m,l,r);
    P y=dfs(m,d,l,r);
    chmax(res,P(x.first+y.first,min(x.second,y.second)));
  }
  for(int m=l+1;m<r;m++){
    P x=dfs(u,d,l,m);
    P y=dfs(u,d,m,r);
    chmax(res,P(x.first+y.first,min(x.second,y.second)));
  }
  return dp[u][d][l][r]=res;
}

int solve(){
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin>>us[i][j];

  memset(sm,0,sizeof(sm));
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      sm[i+1][j+1]=us[i][j];

  for(int i=0;i<=h;i++)
    for(int j=1;j<=w;j++)
      sm[i][j]+=sm[i][j-1];

  for(int i=1;i<=h;i++)
    for(int j=0;j<=w;j++)
      sm[i][j]+=sm[i-1][j];

  memset(used,0,sizeof(used));
  P res=dfs(0,h,0,w);
  cout<<res.first<<' '<<res.second<<newl;
  return 0;
}

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

  while(cin>>h>>w>>s,h) solve();
  return 0;
}



Measured memory_bytes: 19780
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000000;

vector< pair<long,long> > drink;

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

  drink = vector< pair<long,long> >(n);
  REP(i,n){
    cin >> drink[i].first >> drink[i].second;
  }
  sort(drink.begin(),drink.end());
  long ans = 0;
  int left = m;
  int i = 0;
  while(left > 0){
    if (drink[i].second > left) {
      ans += (drink[i].first * left);
      left = 0;
      break;
    }
    ans += (drink[i].first * drink[i].second);
    left -= drink[i].second;
    i++;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
A_list = [int(num) for num in input().split()]

ans = 0
for i, num in enumerate(A_list):
  for j, n in enumerate(A_list):
    if i == j:
      continue
    s = abs(A_list[i] - A_list[j])
    if s > ans:
      ans = s
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

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

    int n; cin >> n;
    vector<ll> plus(n), minus(n);
    for (int i = 0; i < n; i++)
    {
        ll x, y; cin >> x >> y;
        plus[i] = x+y;
        minus[i] = x-y;
    }
    ll a = *max_element(plus.begin(), plus.end())-*min_element(plus.begin(), plus.end());
    ll b = *max_element(minus.begin(), minus.end())-*min_element(minus.begin(), minus.end());

    ll result = max(a, b);
    cout << result << endl;

    return 0;
}


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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> v(1000);
  vector<int> A(1000);
  for (int i = 1; i < 1000; i++) {
    v[i] = i + v[i - 1];
  }
  for (int i = 1; i < 999; i++) {
    if (v[i] - a == v[i + 1] - b) {
      cout << v[i] - a << endl;
      break;
    }
  }
}


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

int main(){
    int d,g;
    cin >> d >> g;
    vector<int> num(d), bonus(d);
    for(int i=0; i<d; i++){
        cin >> num.at(i) >> bonus.at(i);
    }
    int ans=100000;
    for(int i=0; i<(1<<d); i++){
        vector<int> full(d,0);
        for(int j=0; j<d; j++){
            if(i & (1<<j)){
                full.at(j) = 1;
            }
        }
        int point=0;
        int solve=0;
        for(int j=0; j<d; j++){
            point+=((j+1)*100*num.at(j)+bonus.at(j))*full.at(j);
            solve+=num.at(j)*full.at(j);
        }
        if(point>=g) ans=min(ans,solve);
        else{
            //全部とかない奴の中の一番高い問題
            int k=0;
            for(int j=0; j<d; j++){
                if(full.at(j)==0) k=j;
            }
            if(point+(k+1)*100*(num.at(k)-1) >= g){
                solve += ((g-point)+((k+1)*100)-1)/((k+1)*100);
                ans = min(ans,solve);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632