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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
	int x, y; cin >> x >> y;
	if(y%2 == 1) cout << "No" << endl;
	else if(2*x > y) cout << "No" << endl;
	else if(4*x < y) cout << "No" << endl;
	else cout << "Yes" << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define INF 1e9
#define pb push_back
using namespace std;
typedef long long ll;
using pii = pair<ll, ll>;

int main() {
    int N;
    cin >> N;
    ll ans =0;
    for(int a =1; a<=N;a++){
        for(int b =1; b<=N;b++){
            int ab = __gcd(a,b);
            for(int c =1; c<=N;c++){
                int abc= __gcd(ab,c);
                ans += abc;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<long> Sum(vector<long> array)
{
	long N = array.size()+1;
	vector<long> result(N);
	result[0] = 0;
	for (int i = 1; i < N; i++)
	{
		result[i] = result[i - 1] + array[i-1];
	}
	return result;
}
int main()
{
	long  X, Y, A, B, C, value;
	
	cin >> X >> Y >> A >> B >> C;
	vector<long> Sa(A), Sb(B), Sc(C);
	vector<long> Avalue(A), Bvalue(B), Cvalue(C);
	for (long& a : Avalue) {
		cin >> a;
	}
	for (long& b : Bvalue) {
		cin >> b;
	}
	for (long& c : Cvalue) {
		cin >> c;
	}
	sort(Avalue.begin(), Avalue.end());
	sort(Bvalue.begin(), Bvalue.end());
	sort(Cvalue.begin(), Cvalue.end());
	reverse(Avalue.begin(), Avalue.end());
	reverse(Bvalue.begin(), Bvalue.end());
	reverse(Cvalue.begin(), Cvalue.end());

	Sa = Sum(Avalue);
	Sb = Sum(Bvalue);
	Sc = Sum(Cvalue);
	queue<long> Aq, Bq, Cq;
	for (int i = 0; i < X; i++)
	{
		Aq.push(Avalue[X - 1 - i]);
	}
	for (int i = 0; i < Y; i++)
	{
		Bq.push(Bvalue[Y - 1 - i]);
	}
	for (int i = 0; i < C; i++)
	{
		Cq.push(Cvalue[i]);
	}
	//しゃくとり累積和
	int s =0, t=0,u=0;
	for (int i = 0; i < C; i++)
	{
		if (Aq.empty() && Bq.empty()) {
			break;
		}
		if (!Aq.empty() && !Bq.empty()) {
			if (Cq.front() >= Aq.front() && Aq.front()<=Bq.front())
			{
				Aq.pop();
				Cq.pop();
				u++;
				continue;
			}
			else if (Cq.front() >= Bq.front() )
			{
				Bq.pop();
				Cq.pop();
				u++;
				continue;
			}
		}
		if (!Aq.empty()) {
			if (Cq.front() >= Aq.front())
			{
				Aq.pop();
				Cq.pop();
				u++;
				continue;
			}
		}
		if (! Bq.empty()) {
			if (Cq.front() >= Bq.front())
			{
				Bq.pop();
				Cq.pop();
				u++;
				continue;
			}
		}
	}
	cout << Sa[Aq.size()]+Sb[Bq.size()]+Sc[u];
	return 0;
}

Measured memory_bytes: 7232
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val inputs = readLine()!!.split(" ").map { it.toInt() }

    // 柱問題と一緒，その柱に至る最小の移動コストを左から順に記録しておく
    // 各足場について K パターンのコストを記録しておけば良い

    val costs = IntArray(n)

    for (i in 0 until n) {
        if (i == 0 ) {
            costs[i] = 0
            continue
        }

        if ( i <= k ) {
            costs[i] = Math.abs(inputs[i] - inputs[0])
            continue
        }

        var minCost = Int.MAX_VALUE
        for ( j in 1 until k + 1){
            val costTemp = costs[i-j] +  Math.abs(inputs[i] - inputs[i-j])
            if ( costTemp < minCost) {
                minCost = costTemp
            }
        }
        costs[i] = minCost
    }

    println(costs[n-1])
}

Measured memory_bytes: 51592
N=int(input())
A=list(map(int,input().split()))
def prime_factorization(n):
    r={}
    for i in range(2,int(n**.5)+1):
        num=0
        while(True):
            x,y=divmod(n,i)
            if y!=0:
                break
            n=x
            num+=1
        if num>0:
            r[i]=num
    if n>1:
        r[n]=1
    return r
mod=10**9+7
def mul(a,b):
    return ((a%mod)*(b%mod))%mod
def div(a,b):
    return mul(a,pow(b,mod-2,mod))
from collections import defaultdict
d=defaultdict(int)
for a in A:
    r=prime_factorization(a)
    for k,v in r.items():
        d[k]=max(d[k],v)
X=1
for k,v in d.items():
    X=X*pow(k,v,mod)%mod
r=0
for a in A:
    r=(r+div(X,a))%mod
print(r)

Measured memory_bytes: 48220
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
tree=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=MI()
    u-=1
    v-=1
    tree[u].append([v,w])
    tree[v].append([u,w])
q=deque([[0,0]])
al=[-1 for i in range(n)]
#al[0]=0
col=[0 for i in range(n)]
def dfs(a,b):
    al[a]=0
    col[a]=b
    for x,y in tree[a]:
        if al[x]<0:
            dfs(x,(y+b)%2)
dfs(0,0)
#print(col)
for i in range(n):
    print(str(col[i]))

    
    


Measured memory_bytes: 198476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    int counter = 0;

    while (input.ready())
    {
      String[] inputStr = input.readLine().split(" ");
      final int FROM_YEAR = Integer.parseInt(inputStr[0]);
      final int TO_YEAR = Integer.parseInt(inputStr[1]);

      if (TO_YEAR == 0)
      {
        break;
      }

      if (counter > 0)
      {
        System.out.println();
      }
      counter++;

      ArrayList<Integer> ansList = leapYearCount(FROM_YEAR, TO_YEAR);

      if (ansList.size() == 0)
      {
        System.out.println("NA");
        continue;
      }

      for (Integer each : ansList)
      {
        System.out.println(each);
      }
    }

  }

  private static ArrayList<Integer> leapYearCount(int fromYear, int toYear)
  {
    ArrayList<Integer> yearList = new ArrayList<>();
    for (int i = fromYear; i <= toYear; i++)
    {
      if (isLeapYear(i))
      {
        yearList.add(i);
      }
    }
    return yearList;
  }

  private static boolean isLeapYear(int year)
  {
    if (year % 4 != 0)
    {
      return false;
    }

    if (year % 100 == 0)
    {
      if (year % 400 == 0)
      {
        return true;
      }
      return false;
    }
    return true;
  }
}

Measured memory_bytes: 26164
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int S[N],n,u[N][N],l[2][N],r[2][N],flag[N][N];
char A[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;i++)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;i++)
		for (register int j=1;j<=n;j++)flag[i][j]=A[i][j]>='0'&&A[i][j]<='9';
	for (register int i=0;i<=n;i++)
		for (register int j=0;j<=n;j++)u[i][j]=flag[i][j]?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;x++){
		for (register int i=x;i;i--){
			int t=i&1;
			for (register int j=1;j<=n;j++)S[j]=S[j-1]+(u[x][j]<=i?A[x][j]-'0':0);
			for (register int j=n+1;j;j--){
				if (flag[i][j]){
					if (i<x){
						l[t][j]=min(l[t][j+1],l[t^1][j]);
						r[t][j]=max(r[t][j+1],r[t^1][j]);
					}
					else l[t][j]=j,r[t][j]=max(j,r[t][j+1]);
					if (l[t][j]<=r[t][j])ans+=(A[i][j]-'0')*(S[r[t][j]]-S[l[t][j]-1]-(i==x?A[i][j]-'0':0));
				}
				else l[t][j]=1e9,r[t][j]=-1;
			}
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 9216
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main (){

	for(int d=0; d<500; d++){

		int n;
		cin >> n;
		if(n == 0)break;

		int h[111];
		for(int i=0; i<n+1; i++){
			int high;
			cin >> high;
			h[i] = high;
		}

		//0  1  2  3  4

		int sa = h[1]-h[0];
		for(int i=0; i<n-1; i++){
			sa = h[i+1]-h[i];
			int a = h[i+2]-h[i+1];
			int b = h[i+3]-h[i+2];


			if(i == 0){////
				if(sa != a || sa != b){
					//０が雑草
					if(a == b){
						cout << h[0] << endl;
						break;
					}
					//１が雑草
					else if(b == h[4]-h[3] && h[3]-(2*b) == h[0]){
						cout << h[1] << endl;
						break;
					}
					//２が雑草
					else if(sa == h[4]-h[3]){
						cout << h[2] << endl;
						break;
					}
				
				}
			}////

			else if(sa != a){
					cout << h[i+2] << endl;
					break;
			}
		}

	}

	return 0;
}



Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N,M,X;
    cin >> N >> M >> X;
    int A[M];
    rep(i,M) cin >> A[i];
    int masu[N+1]={};
    rep(i,M) masu[A[i]]=1;
    int ans1=0,ans2=0;
    for(int i=X;i>=0;i--) if(masu[i]==1) ans1++;
    for(int i=X;i<=N;i++) if(masu[i]==1) ans2++;
    cout << min(ans1,ans2) << endl;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAGIC = 7474;

LL gcd(LL a, LL b)
{
	return a ? gcd(b % a, a) : b;
}

string solve(LL a, LL b, LL c, LL d)
{
	if(a < b || d < b)
		return "No";
	if(c >= b)
		return "Yes";
	a %= b;
	LL g = gcd(b, d);
	return a + ((b - a + g - 1) / g - 1) * g <= c ? "Yes" : "No";
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int t;
	cin >> t;
	while(t--)
	{
		LL a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << solve(a, b, c, d) << endl;
	}
	return 0;
}

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

#define int ll
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9;
const int MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

int A[N], PS[N];
map<int, vector<int> > MP;

int32_t main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, k, ans = 0; cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> A[i], PS[i] = (PS[i - 1] + A[i]) % k;
	for (int i = 1; i <= n; i++) PS[i] = ((PS[i] - i) % k + k) % k;
	MP[0].push_back(0);
	for (int i = 1; i <= n; i++) {
		vector<int> &v = MP[PS[i]];
		int x = upper_bound(all(v), i - k) - v.begin();
		ans += sz(v) - x;
		v.push_back(i);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 25216
#include <iostream>
using namespace std;
int main(void){
    while(1){
        int n,x;
        cin>>n>>x;
        if(n==0&&x==0) break;
        
        int count=0;
        for(int i=1;i<n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x) count++;
                }
            }
        }
        cout<<count<<endl;
    }
   
}



Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int N;
ll x, A[100005];
ll ans;

int main(void) {
    
    scanf("%d %lld", &N, &x);
    rep(i, 0, N) scanf("%lld", &A[i]);
    
    rep(i, 1, N) {
      ll t = A[i-1]+A[i];
      if (t > x) {
        ll t2 = t - x;
        if (t2 > A[i]) {
          A[i-1] -= t2 - A[i];
          A[i] = 0;
        } else {
          A[i] -= t2;
        }
        ans += t2;
      }
    }
    
    
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int dif = 0; 
  if(s == "SAT") dif = 6;
  if(s == "FRI") dif = 5;
  if(s == "THU") dif = 4;
  if(s == "WED") dif = 3;
  if(s == "TUE") dif = 2;
  if(s == "MON") dif = 1;
  cout << 7-dif << endl;
  return 0;
}

Measured memory_bytes: 256
abcd = list(map(int, list(input())))

output = False

def calc_abcd(s):
    global output
    global abcd
    sum = abcd[0]
    for i in range(3):
        if s[i] == "+":
            sum += abcd[i+1]
        else:
            sum -= abcd[i+1]
    if sum == 7:
        result = str(abcd[0])+s[0]+str(abcd[1])+s[1]+str(abcd[2])+s[2]+str(abcd[3])+"=7"
        print(result)
        output = True


def dfs(s):
    global output
    if len(s) == 3:
        if not output:
            calc_abcd(s)
            return 0
        else:
            return 0
    dfs(s+"+")
    dfs(s+"-")
    return 0

dfs("")

Measured memory_bytes: 3064
s = input()
t = input()
l_s = len(s)
l_t = len(t)

s2 = s + s
l_s2 = len(s2)

next_idx = [[l_s2] * 26 for i in range(l_s2)]

for i in reversed(range(1, l_s2)):
    for j in range(26):
        next_idx[i-1][j] = next_idx[i][j]
    next_idx[i-1][ord(s2[i]) - ord("a")] = i

cur_idx = 0
for i in range(l_t):
    if i == 0:
        flg = False
        for j in range(l_s):
            if t[i] == s[j]:
                cur_idx += j
                flg = True
                break
        if flg:
            continue
        else:
            print("-1")
            exit()

    else:
        idx = next_idx[cur_idx%l_s][ord(t[i]) - ord("a")]

    if idx == l_s2:
        print("-1")
        exit()

    cur_idx += idx - (cur_idx % l_s)
    
print(cur_idx+1)

Measured memory_bytes: 71996
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int color[9]={};
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		if(a<=399) color[0]++;
		else if(a<=799) color[1]++;
		else if(a<=1199) color[2]++;
		else if(a<=1599) color[3]++;
		else if(a<=1999) color[4]++;
		else if(a<=2399) color[5]++;
		else if(a<=2799) color[6]++;
		else if(a<=3199) color[7]++;
		else color[8]++;
	}
	int minans=0;
	for(int i=0;i<8;i++){
		if(color[i]>0) minans++;
	}
	if(minans==0){
		minans=1;
		color[8]--;
	}
	cout << minans << ' ' << minans+color[8];
}


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

int main() {
	int m, f, r;
	while (cin >> m >> f >> r) {
		if ((m&f&r) == -1)break;
		int sum = m + f;
		if ((m | f) == -1) cout << "F" << endl;
		else if (sum >= 80) cout << "A" << endl;
		else if (sum >= 65 && sum < 80)cout << "B" << endl;
		else if (sum >= 50 && sum < 65) cout << "C" << endl;
		else if (sum >= 30 && sum < 50) {
			if (r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
}

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

int main() {
    int n,k;
    cin >> n >> k;
    vector<ll> h (n);
    for(int i=0; i<n; i++){
        cin >> h.at(i);
    }
    sort(h.begin(),h.end());
    ll ans = 1000000010;
    for(int i=0; i<n-k+1; i++){
        ans = min(ans,h.at(i+k-1) - h.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>


typedef long long ll;

using namespace std;

bool IsPalindrome(string s){
	string r = s;
	reverse(s.begin(), s.end());

	if (r == s){
		return true;
	} else {
		return false;
	}
}

int main() 
{ 
	string s;
	cin >> s;
	
	string f = s.substr(0, s.length()/2);
	string l = s.substr(s.length()/2+1, s.length());

	if (IsPalindrome(s) && IsPalindrome(f) && IsPalindrome(l)){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


	return 0; 
} 


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

int main(void) {
	int N, M;
	cin >> N >> M;
	vector <int> X;
	for (int i = 0; i < M; i++) {
		int x;
		cin >> x;
		X.push_back(x);
	}
	sort(X.begin(), X.end());

	vector <int> diff;
	for (int i = 0; i < M-1; i++) {
		diff.push_back(X.at(i+1)-X.at(i));
	}
	sort(diff.begin(), diff.end());

	int ans = 0;
	for (int i = 0; i < (M-N); i++) {
		ans += diff.at(i);
	}

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


Measured memory_bytes: 1400
//package code;
import java.io.*;
import java.util.*;
import java.math.*;
public class Main 
{
    public static int t,Dx ,Dy ,J,ans,n,len=0,answer,q ,k,x ,m, a[],tin[],tout[],discover[],time, b[],count,degree[],parent[] ,parent_count[], size[] ,mat[][] , depth[],pre[],blockSize;
    static long  mod=(long)(1e9) + 7 , dp[],sum ,mod1=(long)(998244353);
    static int[] dx={-1, 1,0,0} , dy={0 ,0 , -1 ,1};
    static boolean visited[],isPandatic[];
    public static TreeSet<Integer> ts[];
    public static LinkedList<Integer> lst ,adj[];
    public static PrintWriter pw;
    public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public static int max1=2000005;
    public static void main(String[] args){
        new Thread(null,null,"Prabhat Kumar Prajapati",1<<28)
        {
           public void run() 
           {
               try
               {
                   solve();
               }
               catch(Exception e)
               {   
                   e.printStackTrace();
                   System.exit(1);
               }
           }
        }.start();
    }
public static void solve()throws IOException
{
    pw = new PrintWriter(System.out);
    Scanner sc=new Scanner(System.in);
    n=sc.nextInt();
    m=sc.nextInt();
    x=sc.nextInt();
    mat=new int[n][m+1];
    ans=Integer.MAX_VALUE;
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++)
            mat[i][j]=sc.nextInt();
    }
    a=new int[m+1];

    func(0 , a , 0);
    if(ans==Integer.MAX_VALUE)pw.println(-1);
    else 
    pw.println(ans);
    pw.close();
}
static void func(int indx , int[] a , int cost){
    if(valid(a)){
        ans=Math.min(ans , cost);
        return;
    }
    if(indx>=n)return;
    
    func(indx+1 , a , cost);

    for(int j=1;j<=m;j++){
        a[j]+=mat[indx][j];
    }
    func(indx+1 , a , cost+mat[indx][0]);

    for(int j=1;j<=m;j++){
        a[j]-=mat[indx][j];
    }
}
static boolean valid(int[] a){
    for(int i=1;i<=m;i++){
        if(a[i]<x)return false;
    }
    return true;
}
// here ans will store number of nodes on longest path
static int dfs(int cur){
    int d1=0;
    int d2=0;
    visited[cur]=true;
    for(int ver:adj[cur]){
        if(visited[ver])continue;
        int x=dfs(ver);
        if(x>d1){
            d2=d1;
            d1=x;
        }
        else if(x>d2){
            d2=x;
        }
        ans=Math.max(ans , d1+d2+1);
    }
    //pw.println((cur+1)  +" "+d1+" "+d2);
    return d1+1;
}
public static long pow(long n,long p,long m)
{
    long  result = 1;
      if(p==0)
        return 1;
    
    while(p!=0)
    {
        if(p%2==1)
            result *= n;
        if(result>=m)
        result%=m;
        p >>=1;
        n*=n;
        if(n>=m)
        n%=m;
    }
    return result;
}

}

Measured memory_bytes: 36244
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
//#define mod 1000000007
#define mod 998244353
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
    	int n,k,i,j;
    	cin>>n>>k;
    	int a[n+1]={0};
    	for(i=0;i<k;i++)
    	{
    		int d;
    		cin>>d;
    		for(j=0;j<d;j++)
    		{
    			int x;
    			cin>>x;
    			a[x]++;
			}
		}
		int cnt=0;
		for(i=1;i<n+1;i++)
		{
			if(a[i]==0)
			cnt++;
		}
		cout<<cnt;
    	
	}

}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <bitset>
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;

int main() {
  int n,s; cin>>n>>s;
  int a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll dp[n+1][s+1]; fill(dp[0],dp[n+1],0);
  dp[0][0]=1;
  for(int i=0;i<n;i++) {
    for(int j=0;j<=s;j++) {
      // 含めない場合
      dp[i+1][j]+=dp[i][j];
      dp[i+1][j]%=M;
      // 含める場合
      if(j+a[i]<=s) {
        dp[i+1][j+a[i]]+=dp[i][j];
        dp[i+1][j+a[i]]%=M;
        dp[i+1][j]+=dp[i][j];
        dp[i+1][j]%=M;
      } else {
        dp[i+1][j]+=dp[i][j];
        dp[i+1][j]%=M;
      }
    }
    /*
    for(int j=0;j<=s;j++) {
      cout<<dp[i][j]<<" ";
    } cout<<endl;*/
  }
  cout<<dp[n][s]<<endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N); 
	vector<int> B(N);
	for (int n = 0; n < N; ++n) {
		cin >> A[n] >>B[n];
	}
	//so-to
	std::sort(A.begin(), A.end());
	std::sort(B.begin(), B.end());
	if (0 == N % 2) {//gu-su-
		int min = A[N/2] + A[N/2 -1];
		int max = B[N/2] + B[N/2-1]; 
		std::cout << max - min +1 << endl;
	}
	else {//kisuu	
		int min = A[(N-1)/2] ;
		int max = B[(N-1) / 2]; 
		std::cout << max - min + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 4776
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut dp: Vec<i64> = vec![1 << 30; n + 2];
    dp[0] = 0;
    for i in 0..n - 1 {
        for j in 1..k + 1 {
            if i + j < n {
                dp[i + j] = std::cmp::min(dp[i + j], dp[i] + (a[i + j] - a[i]).abs());
            }
        }
    }
    println!("{}", dp[n - 1]);
}


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

#define int long long
#define vi vector<int>
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)

void solve(){
	
	
	
	
	
}

int32_t  main(){

   int a,b;
   cin>>a>>b;
   cout<<a*b<<endl;
   
   
    return 0;	
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
#define INF 1000000000+10

const ll mod = 1000000000+7;
const int N = 300+5;

ld dp[N][N][N];


main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int c1 = 0, c2 = 0, c3  = 0;
	for(int i = 0 ; i<n ;i++)
	{
		int x;
		cin >> x;
		if(x==1)c1++;
		if(x==2)c2++;
		if(x==3)c3++;
	}
	for(int k = 0; k<=n; k++)
	{
		for(int j  = 0; j<=n; j++)
		{
			for(int i = 0; i<=n; i++)
			{
				if(i==0&&j==0&&k==0){
					dp[i][j][k] = 0;
					continue;
				}
				if(i>0)dp[i][j][k] += dp[i-1][j][k]*(ld)(i)/(ld)n;
				if(j>0)dp[i][j][k] += dp[i+1][j-1][k]*(ld)(j)/(ld)n;
				if(k>0)dp[i][j][k] += dp[i][j+1][k-1]*(ld)(k)/(ld)n;
				dp[i][j][k] += 1.0;
				dp[i][j][k] *= (ld)n/(ld)(i+j+k);
			}
		}
	}

	cout << fixed << setprecision(10) << dp[c1][c2][c3] <<endl;
}

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

int main() {
	string s;
	cin>>s;
	int e=s.size();
	int ans=0;
	for(int i=0;i<e;i++) {
		if(s[i]=='1') {
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import deque

Y,X=map(int,input().split())

cs=[list(input()) for i in range(Y)]

q=deque()
dist=[[-1 for i in range(X)] for j in range(Y)]
dist[0][0]=0
q.append([0,0])
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while(len(q)!=0):
    v=q.popleft()
    for i in range(4):
        nv =[v[0]+dy[i], v[1]+dx[i]]
        if nv[0] < 0 or nv[0] > Y-1 or nv[1] < 0 or nv[1] > X-1:
            continue
        if dist[nv[0]][nv[1]]!=-1 or cs[nv[0]][nv[1]] == "#":
            continue
        dist[nv[0]][nv[1]] = dist[v[0]][v[1]]+1
        q.append(nv)
        
black=0
res=dist[Y-1][X-1]
for i in range(Y):
    for j in range(X):
        if cs[i][j]=="#":
            black+=1
            

if res ==-1:
    print(-1)
else:
    print(Y*X-res-1-black)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    rep(i, 3){
        if(s[i] == 'a') a++;
        if(s[i] == 'b') b++;
        if(s[i] == 'c') c++;
    }
    if(a == 1 && b == 1 && c == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
ll N, M, K,H,W, ans[100000], mi1,mi2,sum;
string s;
int main() {
	cin >> N;
	sum = 0;
	vector<LL>A(N+2);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		sum += A[i];
		if (i % 2 == 0)ans[1] += A[i];
	}
	ans[1] = sum - 2*ans[1];
	for (int i = 1; i < N; i++) {
		ans[i+1] = 2 * A[i] - ans[i];
	}
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << endl;
	}
	return 0;

}



Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	int k, a, b;
	cin >> k >> a >> b;

	FOR(i, a, b + 1)
	{
		if (i % k == 0)
		{
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;
}

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

int main() {
  int64_t x;
  cin >> x;

  int64_t a=100;
  int year = 0;
  while(true){
    year++;
    a *= 1.01;

    if(a >= x){
      cout << year << endl;
      break;
    }
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define spn setprecision
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int main() {
	int n,m,ans=1;
	sd(n);sd(m);
	for(int i = 1; i*i <= m; i++){
		if(m%i==0){
			if(i<=m/n)ans=max(ans,i);
			if(i>=n)ans=max(ans,m/i);
		}
	}
	pd(ans);
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val d, g = sc.nextInt
    val p = new Array[Int](d)
    val c = new Array[Int](d)
    for (i <- 0 until d) {
      p(i) = sc.nextInt
      c(i) = sc.nextInt
    }

    // ボーナスを獲得できる/できないで全パターン探索
    var ans = Int.MaxValue
    for (mask <- 0 until (1 << d)) {
      // D問のビットパターン
      var s = 0
      var num = 0
      var restMax = -1

      for (i <- 0 until d) {
        if (((mask >> i) & 1) == 1) {
          // ボーナス獲得問題！
          // 通常問題の点数 + ボーナス点数
          s += 100 * (i + 1) * p(i) + c(i)
          // 解答した問題数
          num += p(i)
        } else {
          restMax = i
        }
      }

      var flg = true
      if (s < g) {
        // ボーナスを獲得していない問題のうち点数が最大の問題の点数
        val s1 = 100 * (restMax + 1)
        // 残り何問解答すればよいか
        val need = (g - s + s1 - 1) / s1
        if (need >= p(restMax)) {
          // 当該問題でまかなえない（=残りの点数に足りない）ことで、全問回答する場合は、
          // 別のビットパターンで対象となる！
          flg = false
        } else {
          num += need
        }

      }
      if (flg) {
        ans = math.min(ans, num)
      }
    }

    println(ans)
  }
}


Measured memory_bytes: 25776
#include <stdio.h>
#include <stdlib.h>

#include <string.h>

int acs(const void* a, const void* b){
	
	return *(int *)a - *(int *)b;	
}

int main(){
	
	int i,j,k,N;
	char S[110];
	int cnt=0;
	int max=0;
	int ex=0;
	int L[110];
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		scanf("%d",L+i);//printf("%d:::a\n",i);
	}
	qsort(L,N,sizeof(int),acs);	
	
	for(i=0;i<N-2;i++){
		//printf("%d:::\n",i);
		for(j=i+1;j<N-1;j++){
			if(L[i]!=L[j])
			for(k=j+1;k<N;k++){
				if(L[j]!=L[k]){
					//printf("%d\n",abs(L[j]-L[k]));
					if(abs(L[j]-L[k])<L[i] && L[i]<(L[j]+L[k])){
						cnt++;
						//printf("%d,%d,%d\n",L[i],L[j],L[k]);
					}
				}
			}
			
		}
	}
	printf("%d\n",cnt);
	return 0;
}


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

using namespace std;

int main(void)
{
    int64_t n, m;
    cin >> n >> m;
    multimap<int64_t, int64_t> sorted_map;
    for (size_t i = 0; i < n; i++)
    {
        int64_t a, b;
        cin >> a >> b;
        sorted_map.insert(pair<int64_t, int64_t>(a, b));
    }

    int64_t total = 0;
    int64_t left = m;
    for (auto j = sorted_map.begin(); j != sorted_map.end(); j++)
    {
        int64_t buy;
        if(j->second > left) buy = left; else buy = j->second;
        total += j->first * buy;
        if(left <= 0) break;
        left -= buy;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
  rep(i,n) cin >>h[i];
    int cnt=0;
    rep(i,n){
        if (h[i]>=k) cnt++;
    }
    cout << cnt<<endl;
}

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

string s;
ll ans=0;

void dfs(ll p,ll sum){
  if(p==s.size()){
    ans+=sum;
    return;
  }
  for(ll e=1;p+e<=s.size();e++){
    dfs(p+e,sum+stol(s.substr(p,e)));
  }
}

int main(){
  cin>>s;
  dfs(0,0);
  cout<<ans<<endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  ll diff = a-b; if(diff<0)diff*=-1;
  for(int pc=0; pc<=n-1; pc++){
    int mc = n-1-pc;
    ll m1 = pc*c-mc*d;
    ll m2 = pc*d-mc*c;
    if(m1<=diff && diff<=m2){ cout<<"YES"<<endl; return 0; }
  }

  cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []

for i in range(N):
    tmp = int(input())
    A.append(tmp)

As = ld = sorted(A, reverse=True)
# print(As)
m = As[0:2]
# print(m)
for i in range(N):
    if A[i] == m[0]:
        print(m[1])
    else:
        print(m[0])


Measured memory_bytes: 14196
#include<stdio.h>

typedef struct node{

  int p;
  int r;
  int l;
  int br;
}Node;

Node node[26];
int m;
void nodegene( Node*);
//void putdepth( Node*);

int depth(int);
int height(int);
void nodegene( Node* nod){

  nod -> l = -1;
  nod -> r = -1;
  nod -> p = -1;
  nod -> br = -1;
}


int depth(int k){
  int dep = 0;
  for(dep = 0 ; node[k].p != -1 ; dep++){
    k = node[k].p;
  }
  return dep;

}

int height(int k){
  int left=0,right=0; 
 
  if( node[k].l != -1 ) left = height(node[k].l) + 1;
 
  if( node[k].r != -1 ) right = height(node[k].r) + 1;

  if( right <= left ) return left;
 
  else if( right > left ) return right;
}


  
int main(){

  int i, j, n, l, r, nod, d, degree;

  Node c;
  scanf("%d",&m);

  for( i = 0; i < m; i++)nodegene(&node[i]);
  
  for( i = 0; i < m; i++){

    scanf("%d", &n);
    scanf("%d%d", &r, &l);
    node[l].p = n;
    node[r].p = n;
    node[l].br = r;
    node[r].br = l;
    node[n].r = r;
    node[n].l = l;
    
  }

  //  for(i = 0; i < m; i ++)putdepth(&node[i]);

  for( i = 0; i < m; i++){

    printf("node %d: parent = %d, sibling = %d, degree = ", i, node[i].p, node[i].br);

    if(node[i].r != -1 && node[i].l != -1)
      printf("2, ");
    else if(node[i].r != -1 || node[i].l != -1)
      printf("1, ");
    else
      printf("0, ");

    printf("depth = %d, height = %d, ",depth(i), height(i));

    if((node[i].r == -1 && node[i].l == -1) && node[i].p != -1)
      printf("leaf\n");
    else if(node[i].p == -1)
      printf("root\n");
    else if((node[i].l != -1 || node[i].r != -1) && node[i].p != -1)
      printf("internal node\n" );
    

  }
  return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  long long int n,x,a[100010];
  cin >> n >> x;
  for(long long int i=0;i<n;i++){
    cin >> a[i];
  }
  long long cnt=0;
  for(long long i=0;i<n-1;i++){
    if(a[i]+a[i+1]>x){
      cnt+=(a[i]+a[i+1])-x;
      a[i+1]-=(a[i]+a[i+1])-x;
      if(a[i+1]<0){
        a[i+1]=0;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#define N_MAX 10
#define M_MAX 100001
#define f first
#define s second
using namespace std;
typedef pair<bool,int> P;
int Binary_Search();
bool DP_Check(int);
int N,M,c[N_MAX];

int main(){
  while(1){
    cin>>N>>M;
    if(!N&&!M) break;
    for(int i=0;i<N;i++) cin>>c[i];
    cout<<Binary_Search()<<endl;
  }
  return 0;
}

int Binary_Search(){
  int l=0,r=M+1,m;
  while(l<r){
    m=(l+r)/2;
    DP_Check(m)?r=m:l=m+1;
  }
  return l;
}

bool DP_Check(int k){
  P dp[M+1];
  for(int i=0;i<=M;i++) dp[i].f=false,dp[i].s=0; 
  dp[0].f=true;
  for(int i=0;i<N;i++){
    for(int j=c[i];j<=M;j++){
      if(dp[j].f) continue;
      if(dp[j-c[i]].f&&dp[j-c[i]].s<k){
	dp[j].f=true;
	dp[j].s=dp[j-c[i]].s+1;
      }
    }
    for(int j=0;j<=M;j++) dp[j].s=0;
  }
  if(dp[M].f==true) return true;
  return false;
}

Measured memory_bytes: 1936
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

bool check(int x, int ng) {
    int appear = 0;
    while (x > 0) {
        int d = x % 10;
        appear |= 1<<d;
        x /= 10;
    }
    return (appear & ng) == 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int ng = 0;
    rep(i, n) {
        int d;
        cin >> d;
        ng |= 1<<d;
    }
    
    for (int i = n; ; i++) {
        if (check(i, ng)) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
s = input()
n = len(s)
if n % 2 == 1:
    pattern1 = '01' * (n // 2) + '0'
    pattern2 = '10' * (n // 2) + '1'
else:
    pattern1 = '01' * (n // 2)
    pattern2 = '10' * (n // 2)

diff1 = 0
diff2 = 0
for i in range(n):
    if pattern1[i] != s[i]:
        diff1 += 1
    if pattern2[i] != s[i]:
        diff2 += 1
print(min(diff1, diff2))

Measured memory_bytes: 3316
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    // [1, n], [1, k - 1] and a die
    // no tail up
    double prob = 0.0;
    for(int i = 1; i <= n; ++i) {
        double cur = 1.0 / n;
        int j = i;
        while(j < k) {
            cur *= 0.5;
            j <<= 1;
        }
        prob += cur;
    }
    cout << setprecision(10);
    cout << prob << endl;
    return 0;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
  int n, m;

  cin >> n;
  string blue_cards[n];

  for (int i = 0; i < n; i++) cin >> blue_cards[i];

  cin >> m;
  string red_cards[m];

  for (int i = 0; i < m; i++) cin >> red_cards[i];

  map<string,int> ans;

  for (string x : blue_cards) ans[x] += 1;
  for (string x : red_cards) ans[x] -= 1;

  int max = 0;
  for (auto &x : ans) if (x.second > max) max = x.second;

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


int flag[200020];
//vector<int>G[200020];
vector<int>G2[500050];
vector<P>edges;
bool possible;

bool vis[500050], act[500050];

void dfs(int n) {
	if (possible)return;
	if (vis[n])return;
	if (act[n]) { possible = true; return; }
	act[n] = true;
	for (auto nxt : G2[n]) {
		dfs(nxt);
	}
	vis[n] = true;
}

void solve() {
	int N, M; cin >> N >> M;
	string S; cin >> S;
	REP(i, N) {
		int f = S[i] - 'A';
		flag[i] = f;
	}
	REP(i, M) {
		int u, v; cin >> u >> v;
		u--, v--;
		if (!flag[u]) {
			if (!flag[v]) {
				G2[u].push_back(v+N);
				G2[v].push_back(u+N);
			}
			else {
				G2[u + N].push_back(v);
				G2[v + N].push_back(u);
			}
		}
		else {
			if (!flag[v]) {
				G2[u + N].push_back(v);
				G2[v + N].push_back(u);
			}
			else {
				G2[u].push_back(v + N);
				G2[v].push_back(u + N);
			}
		}
	}
	REP(i, N * 2) {
		dfs(i);
	}
	if (possible)print("Yes");
	else print("No");
}


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

	solve();
}

Measured memory_bytes: 27472
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

short H, W;
short A[80][80];

const short zure = 6400;
short dp[80][80][zure*2];
short solve(short y, short x, short d){
    if(d >= zure*2 || d < 0) return zure*2+1;
    if(y >= H || x >= W) return zure*2+1;
    if(y == H-1 && x == W-1) return min(abs(d+A[y][x]-zure), abs(d-A[y][x]-zure));
    if(dp[y][x][d] != -1) return dp[y][x][d];
    short ret = zure*2+1;
    ret = min(ret, solve(y+1, x, d+A[y][x]));
    ret = min(ret, solve(y, x+1, d+A[y][x]));
    ret = min(ret, solve(y+1, x, d-A[y][x]));
    ret = min(ret, solve(y, x+1, d-A[y][x]));
    return dp[y][x][d] = ret;
}

signed main(){
    cin >> H >> W;
    rep(i, H){
        rep(j, W){
            cin >> A[i][j];
        }
    }
    rep(i, H){
        rep(j, W){
            int B;
            cin >> B;
            A[i][j] -= B;
        }
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0, zure) << endl;
}

Measured memory_bytes: 160384
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a); i < (b); i += (s))
#define down(i, a, b, s) for (int i = (a); (b) < i; i -= (s))

ll n;

int main(int argc, char const *argv[]) {
  // freopen("A.txt", "r", stdin);

  while (cin >> n) {
    cout << (n - 2) * 180 << endl;
  }

  return 0;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
//#define int ll
#define pb push_back
#define __bp __builtin_popcount
using vint = vector<int>;
using pii = pair<int,int>;
using pdd = pair<ld,ld>;
using vpii = vector<pii>;
#define F first
#define S second
const int N = 3e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const int Mod = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(2) << fixed;
}

int n;

signed main()
{
	io();
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (a >= b)
	{
		b *= 2;
		--k;
	}
	while (b >= c)
	{
		c *= 2;
		--k;
	}
	cout << (k >= 0 ? "Yes": "No");
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
a.sort()

s = [0]*(a[-1]+1)
for i in range(n):
    s[a[i]] += 1
ans = 0
if a[-1] - 1 > 0:
    for i in range(1,a[-1]):
        ans = max(ans, s[i] + s[i-1] + s[i+1])
    print(ans)
else:
    print(max(s))

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

int main(){
    int n, m, a, b; cin >> n >> m;
    vector<int> cnt(n, 0);
    for (auto i = 0; i < m; i++) { cin >> a >> b; cnt[a - 1]++; cnt[b - 1]++; }
    for (auto i = 0; i < n; i++) if(cnt[i] % 2 != 0) { cout << "NO" << endl; return 0; }
    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 3724
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;

	vector<int> h(n);

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

	vector<int> dp(n);
	dp[0] = 0;

	for (int i = 1; i < n; i++) {
		int min = INT_MAX;
		for (int j = 1; j <= k && (i - j) >= 0; j++) {
			int tmp = abs(h[i] - h[i - j]) + dp[i - j];
			if (min > tmp) min = tmp;
		}
		dp[i] = min;
	}

	cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

#define MOD 2019

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long L, R;
	cin >> L >> R;

	long long ans = 0;
	long long d = (int) (R - L);
	if(d >= MOD - 1){
		ans = 0;
	}
	else{
		ans = L % MOD;
		ans *= ((R % MOD));
		ans = ans % MOD;
		if(ans < 0) ans += MOD;
		long long u = 0;
		for(long long i = 0; i <= d; i++){
			for(long long j = i + 1; j <= d; j++){
				u = (L + i) % MOD;
				u *= ((L + j) % MOD);
				u = u % MOD;
				if(u < 0) u += MOD;
				if(u < ans) ans = u;
			}
		}
	}
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 256