akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;

#define MAX 100003
#define forl(i, start, stop, step) for (int i = start; i < stop; i += step)
#define rforl(i, start, stop, step) for (int i = start; i > stop; i += step)
#define pii pair<int, int>
#define F first
#define S second
#define vi vector<int>
#define vpii vector< pii >
#define vll vector<ll>
#define pb push_back

// define value of MAX as number of nodes in DSU
struct UFDS {
    int root[MAX], ranck[MAX];

    UFDS() {
        for (int i = 0; i < MAX; i++) {
            root[i] = i;
            ranck[i] = 1;
        }
    }

    int find(int x) {
        if (root[x] == x) return x;
        root[x] = find(root[x]);
        return root[x];
    }

    void unite(int x, int y) {
        int xroot = find(x), yroot = find(y);
        if (xroot == yroot) return;
        if (ranck[xroot] > ranck[yroot]) {
            root[yroot] = xroot;
            ranck[xroot] += ranck[yroot];
        }
        else {
            root[xroot] = yroot;
            ranck[yroot] += ranck[xroot];
        }
    }

    int same(int u, int v) {
        if (find(u) == find(v)) return 1;
        return 0;
    }
} dsu;

vi g[MAX];
int deg[MAX];

int main() {
    UFDS DS;

    int n, m, k; scanf("%d%d%d", &n, &m, &k);
    
    for (int i = 0; i < m; i++) {
        int u, v; scanf("%d%d", &u, &v);
        deg[u]++;
        deg[v]++;

        DS.unite(u, v);
    }

    for (int i = 0; i < k; i++) {
        int u, v; scanf("%d%d", &u, &v);
        g[u].pb(v);
        g[v].pb(u);
    }

    for (int i = 1; i <= n; i++) {
        int rut = DS.find(i);
        int sz = DS.ranck[rut] - deg[i] - 1;

        for (int v : g[i]) {
            if (DS.same(i, v)) --sz;
        }

        printf("%d ", sz);
    }

    return 0;
}

Measured memory_bytes: 7936
#include"bits/stdc++.h"
using namespace std;



int main(void)
{
	int N, v, k, x;
	cin >> N;
	
	vector<vector<int>> G(N + 1, vector<int>(N + 1, 0));
	for (int i = 0; i < N; i++)
	{
		cin >> v >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x;
			G[v][x] = 1;
		}
	}

	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			if (j != 1) cout << " ";
			cout << G[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3172
import itertools
import copy

h, w, k = map(int, input().split())
C = [[False] * w for i in range(h)]
for i in range(h):
    C[i] = list(input())

result = 0
product = itertools.product(range(2), repeat=(h + w))
for p in product:
    operation_target = copy.deepcopy(C)
    rows = p[:w]
    cols = p[w:]
    for idx, i in enumerate(rows):
        if i == 1:
            for j in range(h):
                operation_target[j][idx] = '.'
    for idx, i in enumerate(cols):
        if i == 1:
            for j in range(w):
                operation_target[idx][j] = '.'
    counter = 0
    for i in range(h):
        for j in range(w):
            if operation_target[i][j] == '#':
                counter += 1
    if counter == k:
        result += 1
print(result)


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

int node[1 << 21] = {};
int SIZE;
void segtree(int size) {
  SIZE = 1;
  while(SIZE <= size) SIZE <<= 1;
}
inline int parent(int i) {return i ? (i - 1) >> 1 : 0;}
inline int lchild(int i) {return (i << 1) + 1;}
inline int rchild(int i) {return (i << 1) + 2;}
int add(int i, int v) {
  i += SIZE - 1;
  node[i] += v;
  while(i = parent(i)) node[i] = max(node[lchild(i)], node[rchild(i)]);
}
int find(int a, int b, int i = 0, int l = 0, int r = SIZE) {
  if(b <= l || r <= a) return 0;
  if(a <= l && r <= b) return node[i];
  return max(find(a, b, lchild(i), l, (l+r)/2), find(a, b, rchild(i), (l+r)/2, r));
}

int N, M;
int C[1000000];

int L[2000000];
int be[1000000];
int en[1000000];
void migrant(auto flag) {
  for(auto i = 0; i < 2 * N; ++i) L[i] = 0;
  for(auto i = 0; i < M; ++i) en[i] = be[i];
  if(flag) L[en[C[0]]++] = C[0];
  for(auto i = 1 + flag; i < N; i += 2) {
    L[en[C[i-1]]++] = C[i-1];
    L[en[C[i-1]]++] = C[i];
    if(C[i] == C[i-1]) continue;
    L[en[C[i]]++] = C[i-1];
    L[en[C[i]]++] = C[i];
  }
  if((N - flag) & 1) L[en[C[N-1]]++] = C[N-1];
}

vector<int> solve() {
  vector<int> res(M, 1e9);

  segtree(M);
  for(auto i = 0; i < N; ++i) add(C[i], 1);
  for(auto i = 1; i < M; ++i) be[i] = be[i-1] + 2 * find(i-1, i);

  for(auto i: {0, 1}) {
    migrant(i);
    for(auto c = 0; c < M; ++c) {
      int cost = (en[c] - be[c]) - find(c, c+1);
      for(auto i = be[c]; i < en[c]; ++i) add(L[i], -1);
      cost += N - (en[c] - be[c]) - find(0, M);
      for(auto i = be[c]; i < en[c]; ++i) add(L[i], 1);
      res[c] = min(res[c], cost);
    }
  }

  return res;
}

int main() {
  cin >> N >> M;
  for(auto i = 0; i < N; ++i) cin >> C[i];
  for(auto i = 0; i < N; ++i) --C[i];

  for(auto i: solve()) cout << i << "\n";
}

Measured memory_bytes: 34176
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <math.h>
#include <algorithm>

const long long MOD = 1000000007;

using namespace std;

void tyohuku(long long n, vector<vector<long long>>& tyo, vector<long long> temp) {
    if(temp.size() == n) {
        tyo.push_back(temp);
        return;
    }

    temp.push_back(0);
    tyohuku(n, tyo, temp);
    temp.pop_back();
    temp.push_back(1);
    tyohuku(n, tyo, temp);

    return;
}


int main(void) {

    long long i, j;
    long long n, m, x;
    long long min = -1;
    long long maisu = 0;
    long long temp, temp_b;
    long long max;
    string s1, s2;
    long long a, b, c, k;
    long long mod = 2019;
    vector<long long> t;
    vector<long long> dp;
    vector<long long> cost;
    vector<vector<long long>> understand, tyo;
    vector<long long> temp_a;
    long long temp_cost = 0;
    bool flag = true;

    cin >> n >> m >> x;

    for (i = 0; i < n; i++) {
        cin >> c;
        for (j = 0; j < m; j++) {
            cin >> a;
            t.push_back(a);
        }
        cost.push_back(c);
        understand.push_back(t);
        t.clear();
    }

    temp_a.resize(m);
    for (i = 0; i < m; i++) {
        temp_a[i] = 0;
    }
    
    tyohuku(n, tyo, dp);

    // for (i = 0; i < tyo.size(); i++) {
    //     for ( j = 0; j < tyo[i].size(); j++) {
    //         cout << tyo[i][j] << " ";
    //     }
    //     cout << endl;
    // }


    for (i = 0; i < tyo.size(); i++) {
        flag = true;
        temp_cost = 0;
        for (j = 0; j < tyo[i].size(); j++) {
            if (tyo[i][j] == 1) {
                temp_cost += cost[j];
                for (k = 0; k < m; k++) {
                    temp_a[k] += understand[j][k];
                }
            }
        }
        for (j = 0; j < m; j++) {
            if(temp_a[j] < x) {
                flag = false;
                break;
            }
        }

        if(flag) {
            if (min == -1 || min > temp_cost) {
                min = temp_cost;
            }
        }

        for (j = 0; j < m; j++) {
            temp_a[j] = 0;
        }
    }


    cout << min << endl;


    return 0;
}

Measured memory_bytes: 4188
#include <stdio.h>

int main(void)
{
	int a, b, c, temp;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a > c){
		temp = a;
		a = c;
		c = temp;
	}
	if (a > b){
		temp = a;
		a = b;
		b = temp;
	}
	
	if (b > c){
		temp = b;
		b = c;
		c = temp;
	}
	
	printf("%d %d %d\n", a, b, c);
	
	return (0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
ll fastexpo(ll x,ll y,ll m)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
void fff()
{
	string s;
	cin >> s;
	int co = 0;
	int ans = 0;
	FOR(i,0,3)
	{
		if(s[i] == 'R')co++;
		else 
		{
			ans = max(ans, co);
			co= 0;
		}
	}
	ans = max(ans, co);
	cout << ans << ln;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#define MAX 1000000000
int nmax=0;
int n,k,w[100000];
   
int check(int p){
    int i;
    int cnt=1,a=p;
    if(p<nmax) return 0;
    for(i=0;i<n;i++){
        if(a>=w[i]){
           a-=w[i];
        }else{
            cnt++;
            a=p-w[i];
        }
    }
    if(cnt>k) return 0;
    else return 1;
}
   
int main(void){
    int i;
    int left,right,mid;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        if(w[i]>nmax) nmax=w[i];
    }
   
    left=0,right=MAX;
    while(right-left>1){
        mid=(left+right)/2;
        if( check(mid) ) right=mid;
        else left=mid;
    }
    printf("%d\n",right);
    return 0;
}

/*実行結果
5 3
8
1
7
3
9
10*/


Measured memory_bytes: 2240
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int p,q,r;
  cin >> p >> q >> r;
  cout << (p+q+r-max({p,q,r})) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0;
  for(int i = 0; i < N; i++){
    int l;
    int r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

void swap(int *a, int *b){

	int temp = *a;
	*a = *b;
	*b = temp;
}

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
	
}

Measured memory_bytes: 256
N, K = map(int, input().split())
Requests = []
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)

    # 白ならKずらして黒についての要望と捉えることができる
    if c == 'W':
        x += K

    # 2Kずらすと必ず色が一致するので、2Kでmodを取ってよい
    x, y = x % (2 * K), y % (2 * K)
    Requests.append([x, y])


class Ruisekiwa2D:
    def __init__(self, h, w):
        self.H = h
        self.W = w
        self.G = [[0] * w for _ in range(h)]

    def load(self, points):
        # 問題によってイメージしやすいよう書き換えてください
        for x, y in points:
            self.G[x][y] += 1

    def load_imos(self, points):
        # pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
        for i1, j1, i2, j2 in points:
            self.G[i1][j1] += 1  # 左上
            if j2 + 1 < self.W:  # 右上
                self.G[i1][j2+1] -= 1
            if i2 + 1 < self.H:
                self.G[i2+1][j1] -= 1  # 左下
            if j2 + 1 < self.W and i2 + 1 < self.H:  # 右下
                self.G[i2+1][j2+1] += 1

    def calc(self):
        for y in range(self.W):
            for x in range(1, self.H):
                self.G[x][y] += self.G[x-1][y]

        for y in range(1, self.W):
            for x in range(self.H):
                self.G[x][y] += self.G[x][y-1]

    def get(self, i1, j1, i2, j2):
        if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
            return 0
        elif i1 > 0 and j1 > 0:
            return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]
        elif i1 <= 0 < j1:
            return self.G[i2][j2] - self.G[i2][j1-1]
        elif j1 <= 0 < i1:
            return self.G[i2][j2] - self.G[i1 - 1][j2]
        else:
            return self.G[i2][j2]


R2D = Ruisekiwa2D(2 * K, 2 * K)
R2D.load(Requests)
R2D.calc()

ans = 0
for x in range(K):
    for y in range(K):
        tmp = 0
        tmp += R2D.get(0, 0, x - 1, y - 1)  # 左上
        tmp += R2D.get(x + K, 0, 2 * K - 1, y - 1)  # 右上
        tmp += R2D.get(x, y, x + K - 1, y + K - 1)  # 真ん中
        tmp += R2D.get(0, y + K, x - 1, 2 * K - 1)  # 左下
        tmp += R2D.get(x + K, y + K, 2 * K - 1, 2 * K - 1)  # 右下

        ans = max(ans, tmp, N - tmp)

print(ans)


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

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

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n, make_pair(0, 1));
	a[0] = make_pair(1, 1);
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		int r = a[x].first;
		if(!r) {
			a[x].second--;
			a[y].second++;
		} else {
			if(a[x].second == 1) {
				a[x].first = a[x].second = 0;
				a[y].first = 1;
				a[y].second++;
			} else {
				a[x].second--;
				a[y].first = 1;
				a[y].second++;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		cnt += a[i].first;
	}
	cout << cnt << endl;
	return 0;	
}


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

int main() {
  int N;
  cin >> N;
  set<int> s;
  int d;
  for (int i = 0; i < N; i++) {
  cin >> d;
  s.insert(d);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    long long k,a,b; cin>>k>>a>>b;
    if(k<(a-1)||(a+1)>=b) cout<<k+1<<endl;
    else{
        if((k-a-1)%2){
            long long n=(k-a)/2-1;
            long long ans=(n+1)*b-n*a+1;
            cout<<ans<<endl;
        }else{
            long long n=(k-a)/2;
            long long ans=(n+1)*b-n*a;
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,d,e=0,f,g,h,i,j,k;
	for(d=1;d<=100;d++)
	{
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a==-1&&b==-1&&c==-1)
	{
		break;
	}
	if(a==-1||b==-1)
	{
		printf("F\n");
		continue;
	}
	
	e=a+b;
	if(e>=80)
	{
		printf("A\n");
		continue;
	}
	else if(e>=65)
	{
		printf("B\n");
		continue;
	}
	else if(e>=50||c>=50)
	{
		printf("C\n");
		continue;
	}
	else if(e>=30)
	{
		printf("D\n");
		continue;
	}
	else if(e<30)
	{
		printf("F\n");
		continue;
	}	
	}
}




Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<int> av;
    for(int i = 1; i <= 9; ++i){
        for(int j = 1 ; j <= 9; ++j){
            av.insert(i*j);
        }
    }
    if(av.count(n) == 0){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    long int a[n];
    for(int i = 0; i < n; i++) scanf("%ld", &a[i]);
    sort(a, a + n);
    long int num = a[0];
    int count = 0;
    for(int i = 1; i < n; i++){
        if (num == 0) num = a[i];
        else if (a[i] == num) num = 0;
        else {
            count++;
            num = a[i];
        }
    }
    if (num != 0) count++;
    printf("%d\n", count);
    
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
while(true)
{
int w,h;
scanf("%d %d", &h, &w);
if(0==h&&0==w)
break;
for(int i = 0; i < h; ++i)
{
for(int j = 0; j  <w; ++j)
{
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int l[]=new int[8];
		for (int i = 0; i < n; i++) {
			l[i]=sc.nextInt();
		}
		int ans=1000000000;
		int temp;
		int x[]=new int[8];
		int la=0;
		int lb=0;
		int lc=0;
		int ld=0;
		int c0=0;
		int c1=0;
		int c2=0;
		for(x[0] = 0; x[0] < 4; x[0]++) {
			for (x[1] = 0; x[1] < 4; x[1]++) {
				for (x[2] = 0; x[2] < 4; x[2]++) {
					for (x[3] = 0; x[3] < 4; x[3]++) {
						for(x[4] = 0; x[4] < 4; x[4]++) {
							for (x[5] = 0; x[5]< 4; x[5]++) {
								for (x[6] = 0; x[6] < 4; x[6]++) {
									for (x[7] = 0; x[7] < 4; x[7]++) {
										
										for(int i=0;i<8;i++) {
											switch(x[i]) {
											case(0):
												la+=l[i];
												
												c0++;
												break;
											case(1):
												lb+=l[i];
											
												c1++;
												break;
											case(2):	
												lc+=l[i];
											
												c2++;
												break;
											case(3):
												ld+=l[i];
											}
										}
										if(la!=0&&lb!=0&&lc!=0) {
											temp=Math.abs(la-a)+Math.abs(lb-b)+Math.abs(lc-c);		
											
											temp+=10*(c0+c1+c2-3);
											ans=Math.min(temp,ans);
										}
										la=0;
										lb=0;
										lc=0;
										ld=0;
										c0=0;
										c1=0;
										c2=0;
										
										
										
								
									}
								}
							}
						}	
					}
				}
			}
		}
		System.out.println(ans);
		
	}
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}


Measured memory_bytes: 24164
def main():
    while True:
        N = int(input())
        if N == 0:
            exit()
        A = list(map(int,input().split()))
        can_drop = [[False] * N for _ in range(N)]
        # d[i]: i個のブロック列で最大何個落とせるか
        d = [0] * (N+1)

        # 隣接するのが落とせるかどうか
        for i in range(N-1):
            if abs(A[i] - A[i+1]) <= 1:
                can_drop[i][i+1] = True

        # 何個分をみるか。一個増えても落とせるやつ個数が増えたりしないので２刻み
        for i in range(3, N, 2):
            # どのブロックはじめで見るか。
            for j in range(N-i):
                # 間
                last = j + i
                for k in range(j+1, j+i):
                    # j~lastまでで落とせないが、j~k, k+1~lastに分けてみると、両方の部分で結果的にj~lastで落とせる場合
                    if not can_drop[j][last] and can_drop[j][k] and can_drop[k+1][last]:
                        can_drop[j][last] = True
                        break
                # j ~ lastで落ちないが、j+1~last-1で落とせて、jとlastの差が１以下の場合は、j~lastで落とせると言える
                if not can_drop[j][last] and can_drop[j+1][last-1] and abs(A[j] - A[last]) <= 1:
                    can_drop[j][last] = True

        # can_dropのTrueが続いている最長部分を探す
        for i in range(N):
            for j in range(N):
                if can_drop[j][i]:
                    d[i] = max(d[i], d[j-1] + i - j + 1)
        
            d[i] = max(d[i], d[i - 1])
        print(d[N-1])        

if __name__ == "__main__":
    main()


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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%d",&n)
#define PI              3.1415926535897932384626433832795
#define int             ll
#define loop0           for(int i=0;i<n;i++)
#define loop1           for(int i=1;i<=n;i++)
#define inpar0(ar)      for(int i=0;i<n;i++)cin>>ar[i]
#define inpar1(ar)      for(int i=1;i<=n;i++)cin>>ar[i]
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" "
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" "
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}

signed main(){
    vector<int> ar(1000,0);
    int x,n;cin>>x>>n;
    for(int i=0;i<n;i++){
        int in;cin>>in;
        ar[in]++;
    }
    if(ar[x]==0)cout<<x;
    else {
        int l;
        for(int i=x-1;i>=0;i--){
            if(ar[i]!=1){
                l=i;
                break;
            }
        }
        int r;
        for(int i=x+1;i<1000;i++){
            if(ar[i]!=1){
                r=i;
                break;
            }
        }
        if(x-l<=r-x)
            cout<<l;
        else cout<<r;
    }
}


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

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

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

int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i = sx; i < tx; i++) {
    printf("R");
  }
  for (int i = sy; i < ty+1; i++) {
    printf("U");
  }
  for (int i = tx; i > sx-1; i--) {
    printf("L");
  }
  for (int i = ty+1; i > sy; i--) {
    printf("D");
  }
  printf("R");
  for (int i = sy; i < ty; i++) {
    printf("U");
  }
  for (int i = sx; i < tx+1; i++) {
    printf("R");
  }
  for (int i = ty; i > sy-1; i--) {
    printf("D");
  }
  for (int i = tx+1; i > sx; i--) {
    printf("L");
  }
  printf("U");
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
s = input()
l = len(s)

ans = 0

for mask in range(2 ** (l-1)):
    f = s
    last_plus = 0
    for bit in range(l-1):
        if (mask >> bit) & 1:
            ans += int(s[last_plus: bit+1])
            last_plus = bit + 1

    ans += int(s[last_plus:])

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct UnionFind {
    int N;
    vector<int> parents;

    UnionFind(int _N) : N(_N){
        parents.assign(N,-1);
    }
    int find(int x) { //xの親を返す
        if (parents[x] < 0) return x;
        return parents[x] = find(parents[x]);
    }
    void unite(int x, int y) {  //xとyの含むグループを併合
        int px = find(x);
        int py = find(y);
        if (parents[px] > parents[py]) swap(px,py); 
        if (px != py) {
            parents[px] += parents[py];
            parents[py] = px;
        }     
    }
    bool same(int x, int y) { //x,yが同じグループにいるか判定
        return find(x) == find(y);
    }
    int size(int x) { //xと同じグループのメンバーの個数
        return -parents[find(x)];
    }
    vector<int> root() {//ufの根を列挙
        vector<int> res;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) res.push_back(i);
        }
        return res;
    }
    int group_count() { //ufのグループの数を数える
        int cnt = 0;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) cnt ++;
        }
        return cnt;
    }
};   

int main() {
    int N,M; cin >> N >> M;
    vector<int> P(N);
    rep(i,N) {
        int a; cin >> a;
        P[a - 1] = i;
    }
    UnionFind uf(N);
    rep(i,M) {
        int a,b; cin >> a >> b;
        --a; --b;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,N) {
        if (uf.same(i,P[i])) ++ans;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4048
#include <stdio.h>
#include <stdlib.h>
#define ll long long int

ll X[100];
ll Y[100];
int N;
int K;

int InRange(ll t, ll l, ll r){
	return l <= t && t <= r; // inclusive;
}

ll min (ll a, ll b){
	return a < b ? a : b;
}

ll minRange(ll a, ll b, ll c, ll d){
	ll ret = a;
	ret = min(ret, b);
	ret = min(ret, c);
	ret = min(ret, d);
	return ret;
}
ll max (ll a, ll b){
	return a > b ? a : b;
}

ll maxRange(ll a, ll b, ll c, ll d){
	ll ret = a;
	ret = max(ret, b);
	ret = max(ret, c);
	ret = max(ret, d);
	return ret;
}

int main(){
	
	int i,j,k,l,m;
	scanf("%d%d",&N, &K);
	for(i=0;i<N;i++) scanf("%lld%lld",&X[i], &Y[i]);
	
	ll w0,w1,h0,h1;
	ll ar;
	
	ll ans = (ll)4e18;
	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			for(k=0;k<N;k++){
				for(l=0;l<N;l++){
				
					w0 = minRange(X[i],X[j],X[k],X[l]);
					w1 = maxRange(X[i],X[j],X[k],X[l]);
					h0 = minRange(Y[i],Y[j],Y[k],Y[l]);
					h1 = maxRange(Y[i],Y[j],Y[k],Y[l]);
					
					ar = (w1 - w0) * (h1 - h0);
					if(ar == 0) continue; // 無いはず
					
					int cnt = 0;
					for(m=0;m<N;m++){
						if(InRange(X[m], w0, w1) && InRange(Y[m], h0, h1)) cnt++;
					}
					if(cnt >= K){
						ans = min(ans, ar);
					}
					
				}
			}
		}
	}
	
	printf("%lld\n",ans);
	
	
	
	
	return 0;
}




Measured memory_bytes: 128
# -*- coding: utf-8 -*-
from collections import defaultdict
string = input()
n = len(string)

# 文字列を反転する
string = string[::-1]

# 2019と10は互いに素
# 累積和に対してmod 2019をとったものの配列
S = [0]
d = 10
for i in range(n):
    t = int(string[i])*d+S[i]
    t = t % 2019
    S.append(t)
    d = (d * 10) % 2019

# Sの中で要素が一致する時の組み合わせの数を数える
count = 0
d = defaultdict(int)
for key in S:
    d[key] += 1

# print(S, d.values())

for j in d.values():
    if j >=2:
        count += j*(j-1)//2

# 愚直に探すと時間が足りない
# n=int(s)//2019
# for i in range(6, n+1):
#     count += s.count(str(2019 * i))
#     print(str(2019 * i))
print(count)

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
	i64 X, Y, Z;
	cin >> X >> Y >> Z;
	swap(X, Y);
	swap(X, Z);
		cout << X << " " << Y << " " << Z << endl;

  return 0;
}


Measured memory_bytes: 256
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n,@m,@q = gets.split.map(&:to_i)
    @g = Array.new(n+1){ Array.new(n+1,0) }
    m.times do
      l,r = gets.split.map(&:to_i)
      @g[l][r] += 1
    end
  end

  def init
    1.upto(n) do |x|
      1.upto(n) do |y|
        g[y][x] += g[y][x-1]
      end
    end
    1.upto(n) do |x|
      1.upto(n) do |y|
        g[y][x] += g[y-1][x]
      end
    end
  end

  def query(a,b)
    g[b][b] - g[b][a-1] - g[a-1][b] + g[a-1][a-1]
  end

  def solve
    init
    ans = []
    q.times do
      a,b = gets.split.map(&:to_i)
      ans << query(a,b)
    end
    ans
  end

  def show(ans)
    puts ans.join("\n")
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 17840
# ALDS1_5_A.py


def rec(a, use):
    if use >= N:
        memo[a] = True
        return
    _next = A[use]
    rec(a+_next,use+1)
    rec(a,use+1)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
M = list(map(int, input().split()))

memo = [False]*2000
rec(0, 0)
# print(memo)
for i in M:
    if memo[i]:
        print('yes')
    else:
        print('no')



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


int n, A[5][5];
int f[105];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= 3; j++)
            cin >> A[i][j];

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

    bool bingo = 0;
    for (int i = 1; i <= 3; i++)
        if (f[A[i][1]] && f[A[i][2]] && f[A[i][3]])
            bingo = 1;
        else if (f[A[1][i]] && f[A[2][i]] && f[A[3][i]])
            bingo = 1;

    if (f[A[1][1]] && f[A[2][2]] && f[A[3][3]])
        bingo = 1;
    if (f[A[1][3]] && f[A[2][2]] && f[A[3][1]])
        bingo = 1;

    bingo ? cout << "Yes" : cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;

int n,k;
int h[100005];
int dp[100005] = {0};

int main(){
	memset(dp,0x3f,sizeof(dp)); dp[1] = 0;
	scanf("%d %d",&n,&k);
	for(int i = 1;i <= n;i ++) scanf("%d",&h[i]);
	for(int i = 2;i <= n;i ++){
		for(LL j = 1;j <= k;j ++){
			if(i - j >= 0) dp[i] = min(dp[i],dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}
//

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))

    task = 0
    for ai in a_list:
        task += ai

    if task > n:
        print("-1")
    else:
        print(n- task)


if __name__ == "__main__":
    resolve()



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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
#define ret dp[a.fi][a.se][b.fi][b.se]

using namespace std;

const LL MOD=1e9+7;

LL n,c[60],dp[60][30][60][30],ans=1e18;
string s[60];
bool vis[60][30][60][30];

bool isp(LL k,LL lb,LL ub)
{
	for(LL i=lb,j=ub;i<=j;i++,j--) if(s[k][i]!=s[k][j]) return false;
	return true;
}

string getstr(LL k,LL lb,LL ub)
{
	string res="";
	for(int i=lb;i<=ub;i++) res.pb(s[k][i]);
	return res;
}

string getstrr(LL k,LL lb,LL ub)
{
	string res="";
	for(int i=lb;i<=ub;i++) res.pb(s[k][i]);
	reverse(res.begin(),res.end());
	return res;
}

LL dfs(pii a,pii b)
{
	//cout<<a.fi<<' '<<a.se<<' '<<b.fi<<' '<<b.se<<endl;
	if(ret!=1e18) return ret;
	if(vis[a.fi][a.se][b.fi][b.se]) return 1e18;
	vis[a.fi][a.se][b.fi][b.se]=true;
	if(b.fi==0)
	{
		repn(i,n)
		{
			if(s[i].size()>=a.se)
			{
				if(getstr(a.fi,s[a.fi].size()-a.se,s[a.fi].size()-1)!=
				getstrr(i,s[i].size()-a.se,s[i].size()-1)) continue;
				if(isp(i,0,s[i].size()-a.se-1)) ret=min(ret,c[i]);
				else ret=min(ret,dfs(mpr(0,0),mpr(i,s[i].size()-a.se))+c[i]);
			}
			else
			{
				if(getstr(a.fi,s[a.fi].size()-a.se,s[a.fi].size()-a.se+s[i].size()-1)!=
				getstrr(i,0,s[i].size()-1)) continue;
				if(isp(a.fi,s[a.fi].size()-a.se+s[i].size(),s[a.fi].size()-1)) ret=min(ret,c[i]);
				else ret=min(ret,dfs(mpr(a.fi,a.se-s[i].size()),mpr(0,0))+c[i]);
			}
		}
	}
	else
	{
		repn(i,n)
		{
			if(s[i].size()>=b.se)
			{
				if(getstr(b.fi,0,b.se-1)!=getstrr(i,0,b.se-1)) continue;
				if(isp(i,b.se,s[i].size()-1)) ret=min(ret,c[i]);
				else ret=min(ret,dfs(mpr(i,s[i].size()-b.se),mpr(0,0))+c[i]);
			}
			else
			{
				if(getstr(b.fi,b.se-s[i].size(),b.se-1)!=
				getstrr(i,0,s[i].size()-1)) continue;
				if(isp(b.fi,0,b.se-s[i].size()-1)) ret=min(ret,c[i]);
				else ret=min(ret,dfs(mpr(0,0),mpr(b.fi,b.se-s[i].size()))+c[i]);
			}
		}
	}
	if(ret==1e18) ret=1e18-1;
	vis[a.fi][a.se][b.fi][b.se]=false;
	return ret;
}

int main()
{
	cin>>n;
	repn(i,n)
	{
		cin>>s[i]>>c[i];
		if(isp(i,0,s[i].size()-1)) ans=min(ans,c[i]);
	}
	rep(i,55) rep(j,25) rep(k,55) rep(p,25) dp[i][j][k][p]=1e18;
	repn(i,n) ans=min(ans,dfs(mpr(i,s[i].size()),mpr(0LL,0LL))+c[i]);
	if(ans>=1e17) puts("-1");
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 24576
nu = gets.to_i
plan = Array.new(nu + 1).map{Array.new(3, 0)}
for i in 1..nu
  plan[i] = gets.chomp.split.map(&:to_i)
end

for i in 1..nu
  if plan[i][0] - plan[i - 1][0] >= (plan[i][1] - plan[i - 1][1]).abs + (plan[i][2] - plan[i - 1][2]).abs
    if(plan[i][0] - plan[i - 1][0] - ((plan[i][1] - plan[i - 1][1]).abs + (plan[i][2] - plan[i - 1][2]).abs)) % 2 == 0
    else
      puts "No"
      exit
    end
  else
    puts "No"
    exit
  end
end

puts "Yes"


Measured memory_bytes: 17916
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
typedef pair<ll,ll> PL;
typedef pair<ll,pair<ll,ll>> PLL;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const double eps=1e-13;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

int N;
ll K;
ll A[200005],F[200005];

bool ok(ll m){
    ll cost=0;
    for(int i=0; i<N; i++){
        if(F[i]*A[i]<=m)continue;
        cost+=A[i]-m/F[i];
    }
    return (cost<=K);
}

int main(){
    cin>>N>>K;
    for(int i=0;i<N;++i)cin>>A[i];
    for(int i=0;i<N;++i)cin>>F[i];
    sort(A,A+N);
    sort(F,F+N,greater<int>());
    ll l=0,r=1e18;
    ll mid;
    int T=100;
    while(T--){
        mid=(l+r)/2;
        if(ok(mid))r=mid;
        else l=mid;
    }
    if(ok(l))cout<<l<<endl;
    else cout<<r<<endl;
}

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

string mark[4] = {"S", "H", "C", "D"};

int n;
string m;
int num;
int cards[4][13];

int main() {
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> m >> num;
    if(m == "S")      cards[0][num-1] = 1;
    else if(m == "H") cards[1][num-1] = 1;
    else if(m == "C") cards[2][num-1] = 1;
    else if(m == "D") cards[3][num-1] = 1;
  }

  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 13; j++){
      if(cards[i][j] != 1){
        cout << mark[i] << " " <<  j+1 << endl;
      }
    }
  }
}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
 
using namespace std;
 
int main ( void )
{
    int ix, ih;
    while (cin >> ix >> ih, ix|ih) {
        double x = ix, h = ih;
        double th = sqrt((x*x*0.25) + (h*h));
        double s = x * x + 2.0 * x * th;
        printf("%.7f\n", s);
    }
    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define mll map<long long,long long>
#define vl vector<long long>
#define pb push_back
mll m;
vl v;

int main(void)
{
    long long i,n,j,a;
    cin>>n;
    v.resize(n);
    for(i=0;i<n;i++)
    {

        cin>>a;
        v[i]=i+a;
        m[i-a]++;

    }
    a=0;
    for(i=0;i<n;i++)
    {
        a+=m[v[i]];

    }
   cout<<a;
}


Measured memory_bytes: 27456
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      if (a == 0 && b == 0) break;
      else {
        for (int i = 0; i < a; i++) {
          for (int j = 0; j < b; j++) System.out.printf("#");
          System.out.printf("\n");
        }
      }
      System.out.printf("\n");
    }
  }
}



Measured memory_bytes: 64196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

bool is_anagram(std::string s1, std::string s2)
{
  std::sort(s1.begin(), s1.end());
  std::sort(s2.begin(), s2.end());
  return s1 == s2;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int n;
	cin >> n;
	for(int i=1; i<=n; i++){
		cout << "ACL";
	}
    return 0;
}


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

int main(){
    int k,n;
    cin>>k>>n;
    int ba[n],dis[n];
    for (int i = 0; i < n; ++i) {
        cin>>ba[i];
    }
    for (int j = 0; j < n-1; ++j) {
        dis[j]=ba[j+1]-ba[j];
    }
    dis[n-1]=ba[0]+k-ba[n-1];
    sort(dis,dis+n);
    cout<<k-dis[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// (?????????,??????,??????)
struct edge{ int to; ll cap; int rev; };

const int MAX_V = 110; // TODO:initialize
const ll F_INF = 12345678901234LL; // TODO:initialize
vector<edge> G[MAX_V];
int level[MAX_V]; // s??????????????¢
int iter[MAX_V]; // ???????????§??????????????£??????

void add_edge(int from, int to, ll cap){
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,0,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// ?¢?????????????dfs??§??¢???
ll dinic_dfs(int v, int t, ll f){
    if(v==t) return f;
    for(int &i=iter[v]; i<G[v].size(); ++i){
        edge &e=G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            ll d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// s??????t???????????§???
ll max_flow(int s, int t){
    ll flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        ll f;
        while((f=dinic_dfs(s,t,F_INF))>0) flow+=f;
    }
}

int main()
{
    vector<string> days({"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"});
    map<string,int> d;
    rep(i,days.size()) d[days[i]]=i;

    int n;
    ll w;
    while(cin >>n >>w,n)
    {
        rep(i,MAX_V) G[i].clear();

        int S = n+7, T = S+1;
        rep(i,7) add_edge(S,i,w);

        ll sumt = 0;
        rep(i,n)
        {
            ll t;
            int c;
            cin >>t >>c;

            sumt += t;
            add_edge(7+i,T,t);

            while(c--)
            {
                string s;
                cin >>s;
                add_edge(d[s],7+i,w);
            }
        }

        cout << (max_flow(S,T)==sumt?"Yes":"No") << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
   long long int n,x,i,j;
   cin >> n;
   for(i=sqrt(n);;i--)
   {
       if(n%i==0)
       {
           x=i-1+n/i-1;
           break;
       }
   }
   cout <<x<< endl;
   return 0;
 }

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, d, x;
  cin >> n >> d >> x;
  int sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    int day;
    rep(j,d) {
      day = j*a + 1;
      if (day <= d) sum++;
      else break;
    }
  }
  int ans = x + sum;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, c ] :: [Integer] <- map read . words <$> getLine
	print $ minimum $ [ f a b c, f b a c, f c a b ]

f a b c = abs $ x * bc - y * bc
	where
		x = a `div` 2
		y = a - x
		bc = b * c


Measured memory_bytes: 508
n,x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
if x<a[0]:
    ans = abs(x-a[0])
    a[0] -= abs(x-a[0])

for i in range(n-1):
    total = a[i]+a[i+1]
    if x < total:
        ans += total-x
        a[i+1]-= total-x

print(ans)

Measured memory_bytes: 63984
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
a = list(map(int,input().split()))
ans = [0]*(N)
for i in range(N//2+1,N+1):
    ans[i-1] = a[i-1]
for i in range(1,N//2+1):
    j = N//2 +1-i
    s = 0
    for k in range(2*j,N+1,j):
        s += ans[k-1]
    s = s % 2
    ans[j-1] = (s - a[j-1])%2
ans2 = []
for i in range(N):
    if ans[i] == 1:
        ans2.append(i+1)
print(len(ans2))
print(*ans2)

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

int run(int n, int a, int b, int c, int x, vector<int> &y, vector<int> &z) {
  int head = 0;
  rep (t, 10000+1) {
    if (y[head] == z[t]) head++;
    if (head == n) return t;
  }
  return -1;
}

int main() {
  int n, a, b, c, x;
  vector<int> z;
  vector<int> y;

  while(cin >> n >> a >> b >> c >> x, n) {
    y.resize(n);
    z.resize(10000+1);

    // vector<int> y(n);
    // vector<int> z(10000+1);
    z[0] = x;
    rep (i, n) cin >> y[i];

    for (int i=1; i<=10000+1; i++) z[i] = (a*z[i-1] + b) % c;

    // cout << "y: ";
    // rep (i, n) cout << y[i] << ' ';
    // cout << endl;
    // cout << "z: ";
    // rep (i, 300) cout << z[i] << ' ';
    // cout << endl;

    int ans = run(n, a, b, c, x, y, z);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3144
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int N;
int num[100002];

bool input() {
  int i, j, a, b;

  scanf("%d", &N);

  for (i = 0; i < N; i++) {
    scanf("%d %d", &a, &b);
    for (j = a; j <= b && j <= N + 1; j++) {
      num[j]++;
    }
  }

  return true;
}

int main() {
  int i, sum;

  input();
  for (i = N + 1; i > 0; i--) {
    if (num[i] >= i - 1) {
      break;
    }
  }
  printf("%d\n", i - 1);



  return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

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

	int n = s.length();

	int ans = INT32_MAX;
	int cnt = 0;

	char oddValue = s[0];
	string c = s;
	if (s[0] == '1')
	{
		c[0] == '0';
		cnt++;
	}
	else
	{
		c[0] = '1';
		cnt++;
	}

	for (int i = 1; i < n; i++)
	{	
		if (c[i] == '1' && c[i -1] == '1')
		{
			c[i]= '0';
			cnt++;
		}
		else if (c[i] == '0' && c[i -1] == '0')
		{
			c[i] = '1';
			cnt++;
		}
	}

	ans = min(ans,cnt);
	cnt = 0;

	for (int i = 1; i < n; i++)
	{
		if (s[i] == '1' && s[i -1] == '1')
		{
			s[i]= '0';
			cnt++;
		}
		else if (s[i] == '0' && s[i -1] == '0')
		{
			s[i] = '1';
			cnt++;
		}
	}

	ans = min(ans,cnt);
	cout<< ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int distance = 0;
    for (int i = 0; i < N; ++i)
    {
        int xi;
        cin >> xi;
        distance += min(xi, K - xi) * 2;
    }
    cout << distance << endl;

    return 0;
}

Measured memory_bytes: 256