akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[2009][2009];
int b[2009][2009];
int dp[2009][2009][4];
int main()
{
    int n,m,ans;
    scanf("%d%d",&n,&m);
    memset(dp,0,sizeof(dp));
    for(int i=0; i<n; i++)
        scanf("%s",a[i]);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            b[i][j]=a[i-1][j-1]=='.'?0:1;
            //printf("%d",b[i][j]);
        }
        //printf("\n");
    }
    for(int i=1; i<=n; i++)
    {
        ans=0;
        for(int j=1; j<=m; j++)
        {
            dp[i][j][0]=ans;
            if(!b[i][j])
                ans++;
            else
                ans=0;
        }
    }
    for(int i=1; i<=n; i++)
    {
        ans=0;
        for(int j=m; j>=1; j--)
        {
            dp[i][j][1]=ans;
            if(!b[i][j])
                ans++;
            else
                ans=0;
        }
    }
    for(int j=1; j<=m; j++)
    {
        ans=0;
        for(int i=1; i<=n; i++)
        {
            dp[i][j][2]=ans;
            if(!b[i][j])
                ans++;
            else
                ans=0;
        }
    }
    for(int j=1; j<=m; j++)
    {
        ans=0;
        for(int i=n; i>=1; i--)
        {
            dp[i][j][3]=ans;
            if(!b[i][j])
                ans++;
            else
                ans=0;
        }
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            if(!b[i][j])
            {
                int num=1;
                for(int k=0; k<4; k++)
                {
                    num+=dp[i][j][k];
                    //printf("%d ",dp[i][j][k]);
                }
                //printf("\n");
                ans=max(ans,num);
            }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 82944
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

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

const int MAXN = 101, MAXK = 101;

int n,m,k,t,p,l;
bool joho[MAXN][MAXN];
bool still[MAXN];

int main()
{
    while(cin >> n && n)
    {
        memset(still, true, sizeof(still));
        memset(joho, false, sizeof(joho));
        int ans = -1;
        int num = 0;
        for(int i=1;i<=n;i++)
        {
            cin >> t;
            rep(j,t)
            {
                cin >> p;
                joho[i][p] = true;
            }
        }

        cin >> k;
        rep(j,k)
        {
            cin >> l;
            for(int i = 1;i<=n;i++) still[i] = still[i] & joho[i][l];
        }

        for(int i=1;i<=n;i++)if(still[i])
        {
            ans = i;
            num++;
        }
        if(num>=2 || num == 0) {cout << -1 << endl; continue;}
        else cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 876
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007
#define PI acos(-1)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>

using namespace std;

// clang-format on

int K;
int ia = 0, na = 0;
int result = 0;

int _f(string I, string N, int *_ia, int *_na) {
  if (I == "kougekida" && N == "kougekida") {
    if (*_ia > *_na) {
      return 1;
    }
    if (*_ia < *_na) {
      return -1;
    }
    *_ia = *_na = 0;
    return 0;
  }
  if (I == "kougekida" && N == "mamoru") {
    if (*_ia == 0) {
      return -1;
    }
    if (*_ia == 5) {
      return 1;
    }
    *_ia = 0;
    return 0;
  }
  if (I == "kougekida" && N == "tameru") {
    return *_ia == 0 ? -1 : 1;
  }
  if (I == "mamoru" && N == "mamoru") {
    return 0;
  }
  if (I == "mamoru" && N == "tameru") {
    *_na = min<int>(5, *_na + 1);
    return 0;
  }
  if (I == "tameru" && N == "tameru") {
    *_ia = min<int>(5, *_ia + 1);
    *_na = min<int>(5, *_na + 1);
    return 0;
  }
  return -_f(N, I, _na, _ia);
}

void f(string I, string N) {
  if (result == 0) {
    result = _f(I, N, &ia, &na);
  }
}

main {
  cin >> K;
  string I[K], N[K];
  rep(i, K) cin >> I[i];
  rep(i, K) cin >> N[i];
  rep(i, K) f(I[i], N[i]);
  cout << (result == 1 ? "Isono-kun"
                       : result == -1 ? "Nakajima-kun" : "Hikiwake-kun")
       << endl;
  bye;
}

Measured memory_bytes: 3208
/*input
0112
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

bool ismonth(string s){
	if(s[0]=='0'&&s!="00") return 1;
	if(s=="10"||s=="11"||s=="12") return 1;
	return 0;
}

bool MMYY(string s){
	return ismonth(string(s,0,2));
}
bool YYMM(string s){
	return ismonth(string(s,2,2));
}

int main(){
	IOS;
	string s;
	cin>>s;
	if(MMYY(s)&&YYMM(s)){
		cout<<"AMBIGUOUS\n";
	}
	else if(MMYY(s)){
		cout<<"MMYY\n";
	}
	else if(YYMM(s)){
		cout<<"YYMM\n";
	}
	else cout<<"NA\n";
	return 0;
}


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 MAX = 10;

string A[MAX];

void NO()
{
	cout<<"Impossible"<<endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

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

	int cnt = 0;

	FOR (i, 0, n)
	{
		cin>>A[i];
		FOR (j, 0, m)
		{
			if (A[i][j] == '#') cnt++;
		}
	}

	if (cnt != (n + m - 1))
	{
		NO();
	}

	int x = 0, y = 0;
	FOR (it, 1, cnt)
	{
		if (x == n-1)
		{
			if (A[x][y+1] != '#') NO();
			y++;
			continue;
		}
		if (y == m-1)
		{
			if (A[x+1][y] != '#') NO();
		}

		if (A[x+1][y] == '#' && A[x][y+1] == '#') NO();
		if (A[x+1][y] != '#' && A[x][y+1] != '#') NO();
		if (A[x+1][y] == '#') x++;
		else y++;
	}

	cout<<"Possible"<<endl;

}




Measured memory_bytes: 256
n, c, k = map(int, input().split())
t = sorted([int(input()) for i in range(n)])
count = 0
cur_t = -k
cur_c = 0
for v in t:
  if v - cur_t > k:
    count += 1
    cur_c = 1
    cur_t = v
  else:
    cur_c += 1
    if cur_c > c:
      count += 1
      cur_c = 1
      cur_t = v
print(count)    

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

typedef long long ll;

ll layers[51];
ll patties[51];

list<ll> burger;

int main()
{
    ll n, x;
    cin >> n >> x;
    layers[0] = 1;
    patties[0] = 1;
    for (int i = 1; i <= 50; i++)
    {
        layers[i] = 2 * layers[i - 1] + 3;
        patties[i] = 2 * patties[i - 1] + 1;
    }
    burger.push_back(n);
    ll result = 0;
    while (x > 0 && burger.size() > 0)
    {
        while (burger.size() > 0 && (burger.back() == -1 || layers[burger.back()] <= x))
        {
            if (burger.back() == -1) {x--; burger.pop_back(); continue;}
            x -= layers[burger.back()];
            result += patties[burger.back()];
            burger.pop_back();
        }
        if (burger.size() == 0 || x == 0) {break;}
        ll last1 = burger.back();
        burger.pop_back();
        burger.push_back(-1);
        burger.push_back(last1 - 1);
        burger.push_back(0);
        burger.push_back(last1 - 1);
        burger.push_back(-1);
    }
    cout << result << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;
		for(int i=0;i<n;i++) {
			double x1=sc.nextDouble();
			double y1=sc.nextDouble();
			double r1=sc.nextDouble();
			double x2=sc.nextDouble();
			double y2=sc.nextDouble();
			double r2=sc.nextDouble();

		double d=Math.sqrt(Math.pow(Math.abs(x1-x2),2)+Math.pow(Math.abs(y1-y2), 2));
		if(d>r1+r2)ans=0;
		if(Math.abs(r1-r2)<=d&&d<=r1+r2)ans=1;
		if(d<r1-r2)ans=2;
		if(d<r2-r1)ans=-2;
		System.out.println(ans);
		}
	}
}



Measured memory_bytes: 28260
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
static const ll mod = 1000000007;
# define INF (1 << 29)
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

// fは、binaryのkけた目を見て、0からxまでの間にいくつ1があるかを返す
ll f(ll x, int k){
    if(x==0){
        return 0;
    }

    ll two_pow_k = pow(2, k);
    ll blocks = x / two_pow_k;
    ll rest = x % two_pow_k;

    ll out = 0;
    out += (two_pow_k / 2 * blocks);
    if(rest+1 > two_pow_k / 2){
        out += (rest+1 - two_pow_k / 2);
    }
    return out;
}


int main(void){
    ll a,b; cin >> a >> b;
    ll ans = 0;
    for(int k=1; k<=48; k++){
        ll tmp_b = f(b,k);
        ll tmp_a = f(a-1, k);
        if((tmp_b - tmp_a)%2 ==1){
            ll one_ll = 1;
            ll tmp = one_ll << k-1;
            ans |= tmp;
        }
    }
    cout << ans;
    return 0;
}

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

def factorint(x):
  F={}
  i=2
  while i**2<=x:
    if x%i==0:
      c=0
      while x%i==0:
        x=x//i
        c+=1
      F[i]=c
    i+=1
  if x!=1:
    F[x]=1
  return F

def C(n,r):
  a=1
  b=1
  for i in range(r):
    a=a*(n-i)
    b=b*(r-i)
  return((a//b)%(10**9+7))

ans=1
for f in factorint(M):
  k=factorint(M)[f]
  ans*=C(N+k-1,k)        
print(ans%((10**9)+7))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
 	int n;
  	cin >> n;
  	vector<int> d(n);
  	for (int i = 0; i < n; ++i)
      cin >> d[i];
  	vector<int> result;
  	for(int i = 0; i < n - 1; ++i){
    	for (int j = i + 1; j < n; ++j){
        	result.push_back(d[i] * d[j]);
        }
    }
  	cout << accumulate(result.begin(), result.end(), 0) << endl;
  
  	return 0;
}

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

int main(void){
    
    int N;
    cin >> N;
    
    int val;
    long long sumV = 0;
    int minV = 1000001;
    int maxV = -1000001;
    for(int i = 0; i < N; i++){
        cin >> val;
        sumV += val;
        if (val > maxV)  maxV = val;
        if (val < minV) minV = val;
    }
    cout << minV << " " << maxV << " " << sumV << endl;
    return 0;
}


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

int main() {
  	int K, N;
  	cin >> K >> N;
  	int A[N];
  	for (int i = 0; i < N; i++){
      	cin >> A[i];
    }
  	int res = 0;
  	for (int i = 0; i < N - 1; i++){
      	if(A[i + 1] - A[i] > res) res = A[i + 1] - A[i];
    }
  	if(K - A[N - 1] + A[0] > res) res = K - A[N - 1] + A[0];
  	cout << K - res << endl;
}  

Measured memory_bytes: 1024
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())

p,q=(a1-b1)*t1,(a2-b2)*t2
if p>0:
  p*=-1
  q*=-1
if p+q<0:
  print(0)
if p+q==0:
  print('infinity')
if p+q>0:
  s,t=divmod((-p),(p+q))
  print(s*2+1) if t!=0 else print(s*2)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

#pragma warning(disable:4996)

int min(int a, int b) {
	if (a < b) return a;
	return b;
}

int main(void) {
	int n, k;
	char s[50 + 1];
	scanf("%d %d", &n, &k);
	scanf("%s", &s[0]);
	s[k-1] = s[k-1] - ('A' - 'a');
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/


/*long nCr(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/

int main(){
    int s, w;
    cin >> s >> w;
    if(s>w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
   
}


Measured memory_bytes: 3632
#include <stdio.h>
 
int main(void){
  unsigned int N;
  double sum=0;
  scanf("%d", &N);
  unsigned int i;
  for(i=1;i<=N;i++){
    if(i%3==0||i%5==0) continue;
    else sum+=i;
  }
  
  printf("%.0lf", sum);
  
  return 0;
}

Measured memory_bytes: 1744
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

D, N = MAP()

if D == 0 and N == 100:
    print(101)
elif D == 1 and N == 100:
    print(10100)
elif D == 2 and N == 100:
    print(1010000)
else:
    print((100**D)*N)


Measured memory_bytes: 5204
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String t = scn.next();
		for(int i=0; i<s.length(); i++){
		    if(s.equals(t)){
		        System.out.println("Yes");
		        return;
		    }else{
		        s = s.charAt(s.length()-1) + s.substring(0, s.length()-1);
		    }
		}
      	System.out.println("No");
	}
}


Measured memory_bytes: 38960
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;

vector<ll> x;
vector<ll> y;

int main()
{
  ll n, d, tempX, tempY, result = 0;
  cin >> n >> d;
  REP(i, n)
  {
    cin >> tempX >> tempY;
    x.push_back(tempX);
    y.push_back(tempY);
  }
  REP(i, n)
  {
    ll comp = x[i] * x[i] + y[i] * y[i];
    if (sqrt(comp) <= d)
    {
      result++;
    }
  }

  cout << result << endl;
}

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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LONG_LONG_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll ab = a*b;
    ll bc = b*c;
    ll ac = a*c;

    ll mine = min(ab,min(bc,ac));
    if(c % 2 == 0 || a % 2 == 0 || b % 2 == 0) {
        cout << 0 << endl;
    } else {
        cout << mine << endl;
    }
}

Measured memory_bytes: 256
S=input()
x=len(S)

if x%2==0:
    if S[x//2]!=S[x//2-1]:
        ANS=x//2

    else:
        base=S[x//2]

        for i in range(x//2):
            if S[x//2-1-i]!=base or S[x//2+i]!=base:
                ANS=x//2+i
                break

        else:
            ANS=x


else:
    base=S[x//2]

    for i in range(x//2+1):
        
        if S[x//2-i]!=base or S[x//2+i]!=base:
            ANS=x//2+i
            break

    else:
        ANS=x    


print(ANS)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <cstring>
#include <unordered_map>
#include <cstdlib>
using namespace std;


int main(){
    char s[100005];
    cin.getline(s, sizeof(s));
    int result[2];
    result[0] = 0;
    result[1] = 0;
    for (int i = 0; i < strlen(s); i++){
        char tmp = (int)'0' + i % 2;
        if (tmp == s[i]){
            result[0]++;
        }
        else{
            result[1]++;
        }
    }
    cout << min(result[0], result[1]) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 200005
#define mod 1000000007
using namespace std;
vector<int>adj[N];
bool vis[N];
int c=0;
void dfs(int x){
    vis[x]=1;
    c++;
    for(int i=0;i<adj[x].size();i++){
        int y=adj[x][i];
        if(vis[y]) continue;
        dfs(y);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        c=0;
        if(!vis[i]) dfs(i);
        ans=max(ans,c);
    }
    cout<<ans;
}
int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 20876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
//区間数え上げの問題
//https://www.hamayanhamayan.com/entry/2020/04/26/232032
// iを固定してjを回す
// S[i] = S[j+1]
int main(void){
    string S;
    cin >> S;
    int N = S.length();
    ll ans = 0;
    vector<ll> cnt(2020); // mod 2019 であるjの数
    cnt[0] = 1;
    int total = 0;
    int p = 1;
    RREP(i,N-1,0){
        total = (total + (S[i] - '0') * p) % 2019;
        ans += cnt[total];
        p = (p * 10) % 2019;
        cnt[total]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<cmath>
using namespace std;
const double EPS=1e-10;
struct Point{
	double x,y,z;
	Point(double x_=0,double y_=0,double z_=0):x(x_),y(y_),z(z_){}
	void input(){cin>>x>>y>>z;}
	Point operator+(Point a){return Point{x+a.x,y+a.y,z+a.z};}
	Point operator-(Point a){return Point{x-a.x,y-a.y,z-a.z};}
	Point operator*(double a){return Point{x*a,y*a,z*a};}
};
double dot(Point a,Point b){return a.x*b.x+a.y*b.y+a.z*b.z;}
Point cross(Point a,Point b){return Point{a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x};}
double abs(Point a){return sqrt(dot(a,a));}
double area(Point a,Point b,Point c){return abs(cross(b-a,c-a))/2;}
main()
{
	Point p1,p2,a,b,c;
	p1.input();
	p2.input();
	a.input();
	b.input();
	c.input();
	Point ph=cross(b-a,c-a);
	double base=dot(p2-p1,ph);
	if(abs(base)<EPS)
	{
		cout<<"HIT"<<endl;
		return 0;
	}
	double k=dot(a-p1,ph)/base;
	if(k<-EPS||k>1+EPS)
	{
		cout<<"HIT"<<endl;
		return 0;
	}
	Point L=(p2-p1)*k+p1;
	if(area(L,a,b)+area(L,b,c)+area(L,c,a)>area(a,b,c)+EPS)
	{
		cout<<"HIT"<<endl;
		return 0;
	}
	cout<<"MISS"<<endl;
}



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

using namespace std;
const int maxn = 1e5 + 10;
const int MOD = 1e9 + 7;
vector<int> graph[maxn];
int n;
long long dp[maxn][5];
/// 0 - white
/// 1 - black
void dfs(int node, int prev){
    dp[node][0] = 1;
    dp[node][1] = 1;
    for(int i = 0; i < (int) graph[node].size(); i ++){
        int sosed = graph[node][i];
        if(sosed == prev) continue;
        dfs(sosed, node);
    }
    for(int i = 0; i < (int) graph[node].size(); i ++){
        int sosed  =graph[node][i];
        if(sosed == prev) continue;
        dp[node][0] *= (dp[sosed][1] + dp[sosed][0]) % MOD;
        dp[node][0] %= MOD;
        dp[node][1] *= (dp[sosed][0]) % MOD;
        dp[node][1] %= MOD;
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i < n; i ++){
        int a, b;
        cin >> a >> b;
        a --; b --;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
  //  cout << "input end" << endl;
    dfs(0, -1);
    cout << (dp[0][0] + dp[0][1]) % MOD << endl;
    return 0;
}


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

int main() {
  while(1) {
    string n;
    cin >> n;
    int ans = 0;
    rep(i, n.size()) {
      ans += n[i] - '0';
    }
    if(ans == 0) break;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll a,b;
    cin>>a>>b;
    ll c=0;
    rep (i,0,b*2)
    {
        if (i*a-i+1>=b)
        {
            c=i;
            bb;
        }
    }
    cout<<c<<endl;
}


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

using namespace std;

int main() {

   int N;
   cin >> N;
   int a[N + 1];
   a[N] = -1;
   for (int i = 0; i < N; i++) {
      cin >> a[i];
   }
   int cnt = 0;
   int series = 1;
   for (int i = 1; i <= N; i++) {
      if (a[i] == a[i - 1]) series++;
      else {
         cnt += series / 2;
         series = 1;
      }
   }
   
   cout << cnt << endl;
   return 0;
}


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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  } else if (L < R) {
    cout << "Right" << endl;
  } else cout << "Balanced" << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  int ans = 0;
  for(int j=0; j<N; j++){
    int love = 0;
    love = vec.at(j);
    if(vec.at(love-1) == j+1){
      ans++;
    }
  }
  cout << ans / 2 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  ll x, y;
  cin >> x >> y;
  int cnt = 0;
  while(x <= y){
    x *= 2;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k;
    cin>>n;
    int a[n+1][4];
    for(i=1;i<=n;i++)
     cin>>a[i][1]>>a[i][2]>>a[i][3];
    int dp[n+1][4];
    dp[1][1]=a[1][1];
    dp[1][2]=a[1][2];
    dp[1][3]=a[1][3];
    for(i=2;i<=n;i++)
    {
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+a[i][2];
        dp[i][3]=max(dp[i-1][2],dp[i-1][1])+a[i][3];
    }
    cout<<max(max(dp[n][1],dp[n][2]),dp[n][3]);
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    int A[110], B[110];
    REP(i,N-1) cin >> B[i];

    REP(i,N-1){
        if(i == 0) A[i] = B[0];
        else{
            A[i] = min(B[i-1], B[i]);
        }
    }
    A[N-1] = B[N-2];

    int ans = 0;
    REP(i,N) ans += A[i];

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1000000000009
typedef long long ll;
typedef pair<int,int> P;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

signed main(){
    int N , K , a[17],b[17];
    cin >> N >> K;
    int Ans = INF;
    REP(i,N){cin >> a[i];b[i]=a[i];}
    REP(i,1<<(N-1)){
        REP(i,15){
            a[i]=b[i];
        }
        int sum=0;
        int c=1;
        int mx=a[0];
        REP(j,N-1){
            if((1 & i >> j) == 1){
                if(mx>=a[j+1]){
                    sum+=mx-a[j+1]+1;
                    a[j+1]=mx+1;
                }
            }
            mx = max(mx,a[j+1]); 
        }
        mx=a[0];
        REP(i,N){
            if(i==0)continue;
            if(mx<a[i]){
                c++;
                mx=a[i];
            }
        }
        if(c>=K){
            Ans = min(sum,Ans);
        }
    }
    cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))

p_t = [0]
for i in range(n):
    p_t.append(p_t[i] + p[i])

max_value = 0
max_index = 0
for i in range(n - k + 1):
    if max_value < p_t[i + k] - p_t[i]:
        max_value = p_t[i + k] - p_t[i]
        max_index = i

ans = 0
for i in range(max_index, max_index + k):
    ans += (p[i] * (p[i] + 1)) / (2 * p[i])

print(ans)

Measured memory_bytes: 25188
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    Color = [0] * 9
    for a in A:
        if a >= 3200:
            Color[-1] += 1
        else:
            Color[a // 400] = 1

    mi = sum(Color[:8]) + (1 if sum(Color[:8]) == 0 and Color[8] > 0 else 0)
    ma = sum(Color[:8]) + Color[8]

    print(mi, ma)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
unordered_map<int, int> cache;
int solve(vector<int>& heights, int index) {
	int n = heights.size();
	if (index >= n - 1) {
		return 0;
	}

	if (cache.find(index) != cache.end()) {
		return cache[index];
	}

	int ans = INT_MAX;
	if (index == n - 2) {
		ans = abs(heights[index + 1] - heights[index]) + solve(heights, index + 1);
	} else {
		ans = min(abs(heights[index + 1] - heights[index]) + solve(heights, index + 1), abs(heights[index + 2] - heights[index]) + solve(heights, index + 2));		
	}

	return cache[index] = ans;
}

int main() {
	int n, x;
	cin>> n;
	vector<int> heights;
	for (int i = 0; i < n; i++) {
		cin>>x;
		heights.push_back(x);
	}
	cout<<solve(heights, 0)<<endl;
}

Measured memory_bytes: 10904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  int ans = 1;  
  int n = A;
  
  if (B == 1) {
    ans = 0;
  }
  else {
    while (n < B) {
      ans++;
      n += (A-1);
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{
	public static void main (String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> list = new ArrayList<Integer>();
		String line;
		while((line = br.readLine()) != null){
			
			list.add(Integer.parseInt(line));
		}
		Collections.sort(list);
		Collections.reverse(list);
		
		System.out.println(list.get(0));
		System.out.println(list.get(1));
		System.out.println(list.get(2));
	}
}

Measured memory_bytes: 24232
n,m,c=map(int,input().split())
blist=list(map(int,input().split()))
ans=0
for i in range(n):
    tmpSum=c
    tmpList=list(map(int,input().split()))
    for j in range(m):
        tmpSum+=tmpList[j]*blist[j]
    if tmpSum>0:
        ans+=1
print (ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using vi = vector<int>;
template <class T>
using Grid = vector<vector<T>>;

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    int ans = 0, cnt = 0;
    rep(i, N - 1) {
        if (v[i] >= v[i + 1])
            cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 3764
#include<stdio.h>

int deep[50];

int fibonacci(int a){
  if(a==0||a==1){
  return deep[a]=1;
}
if(deep[a]!=-1) return deep[a];
  return deep[a]=fibonacci(a-2)+fibonacci(a-1);
}

int main(){
  int n,i;
for(i=0;i<50;i++){
    deep[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}



Measured memory_bytes: 2112
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int N;
	char W[100][100];
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	for (int i = 0; i < N - 1; i++) {
		size_t size = strlen(W[i]);
		if (W[i][size - 1] == W[i + 1][0]);
		else {
			puts("No");
			return 0;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (strcmp(W[i],W[j])==0) {
				puts("No");
				return 0;
			}
		}
	}
	
	puts("Yes");


	return(0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
vector<pii> G[MAXN];
LL dis[MAXN];

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int L, R, C;
        scanf("%d %d %d", &L, &R, &C);
        G[L].push_back(make_pair(R, C));
    }
    set<int> st;
    st.insert(1);
    for (int L = 1; L <= N; L++) {
        for (auto j : G[L]) {
            int R = j.first, C = j.second;
            auto it = st.lower_bound(L);
            if (it == st.end()) break;
            LL cur = dis[*it] + C;
            auto cur_it = prev(st.upper_bound(R));
            while (*cur_it >= L) {
                  if (dis[*cur_it] < cur) break;
                  if (cur <= dis[*cur_it]) {
                     cur_it = st.erase(cur_it);
                     cur_it = prev(cur_it);
                  }
            }

            //for (auto k = st.lower_bound(L); k != st.upper_bound(R);) {
            //    if (*k <= R && cur <= dis[*k]) k = st.erase(k);
            //    else k++;
            //}
            it = st.lower_bound(R);
            if (it == st.end() || dis[*it] > cur) {
               st.insert(R);
               dis[R] = cur;
            }
        }
    }
    if (st.find(N) == st.end()) return !printf("-1\n");
    else printf("%lld\n", dis[N]);
    return 0;
}


Measured memory_bytes: 11520
import scala.io.StdIn

object Main {
  //Console.setIn(new FileReader(new java.io.File("in")))
  //Console.setOut(new PrintStream(new java.io.File("output")))
  var caseNo = 1
  val magicMod = 1000000007

  def doCase(): Unit ={

    val Array(n, m, q) = readIntLine()

    val tally = Array.fill(n, n)(0)

    var read = 0
    while (read < m) {
      val Array(l, r) = readIntLine()
      tally(l - 1)(r - 1) += 1
      read += 1
    }

    val strictlyWithin = Array.fill(n, n)(-1)

    var query = 0
    while (query < q) {
      val Array(ql, qr) = readIntLine()
      println(dp(ql - 1, qr - 1, tally, strictlyWithin))
      query += 1
    }
  }

  def dp(l: Int, r: Int, tally: Array[Array[Int]], strictlyWithin: Array[Array[Int]]): Int = {
    if (l < 0 || r >= tally.length) {
      return 0
    }
    if (strictlyWithin(l)(r) == -1) {
      var answ = 0
      var i = l
      while (i <= r) {
        answ += tally(l)(i)
        i += 1
      }
      var j = l + 1
      while (j <= r) {
        answ += tally(j)(r)
        j += 1
      }
      if (r - l > 1) {
        answ += dp(l + 1, r - 1, tally, strictlyWithin)
      }
      strictlyWithin(l)(r) = answ
    }
    strictlyWithin(l)(r)
  }

  def main(args: Array[String]): Unit = {
    val noCases = 1
    for (i <- 0 until noCases) {
      doCase()
    }
  }

  def readIntLine(): Array[Int] = {
    StdIn.readLine().split(" ").map(_.toInt)
  }

  def readLongLine(): Array[Long] = {
    StdIn.readLine().split(" ").map(_.toLong)
  }

  def readBigIntLine(): Array[BigInt] = {
    StdIn.readLine().split(" ").map(BigInt.apply)
  }
}

Measured memory_bytes: 106164
#include<bits/stdc++.h>
using namespace std;
int n,m;
string s[501];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>s[i];
	}
	for(int i=1;i<=n;++i){
		for(int j=0;j<m;++j){
			if(j==0||(i%2==1&&j!=m-1)||s[i][j]=='#')printf("#");else printf(".");
		}
		printf("\n");
	}
	printf("\n");
	for(int i=1;i<=n;++i){
		for(int j=0;j<m;++j){
			if(j==m-1||(i%2==0&&j!=0)||s[i][j]=='#')printf("#");else printf(".");
		}
		printf("\n");
	}
}

Measured memory_bytes: 1024
#include <cstdio>
using namespace std;
#define NIL -1

struct Node { int parent, left, right; };
Node T[30];
int n, D[30], H[30];

void setDepth(int i, int d) {
    if (i == NIL) return;
    D[i] = d;
    setDepth(T[i].left, d + 1);
    setDepth(T[i].right, d + 1);
}

int setHeight(int i) {
    int h1 = 0, h2 = 0;
    if (T[i].left != NIL) h1 = setHeight(T[i].left) + 1;
    if (T[i].right != NIL) h2 = setHeight(T[i].right) + 1;
    return H[i] = (h1 > h2 ? h1 : h2);
}

int getSibling(int i) {
    int p = T[i].parent;
    if (p == NIL) return NIL;
    if (T[p].left != i && T[p].left != NIL) return T[p].left;
    if (T[p].right != i && T[p].right != NIL) return T[p].right;
    return NIL;
}

void print(int i) {
    printf("node %d: parent = %d, sibling = %d", i, T[i].parent, getSibling(i));
    int deg = 0;
    if (T[i].right != NIL) deg++;
    if (T[i].left != NIL) deg++;
    printf(", degree = %d, depth = %d, height = %d, ", deg, D[i], H[i]);
    if (T[i].parent == NIL) printf("root\n");
    else if (T[i].left == NIL && T[i].right == NIL) printf("leaf\n");
    else printf("internal node\n");
}


int main(void) {
    int i, v, l, r, rt;
    scanf("%d", &n);
    for (i = 0; i < n; i++) T[i].parent = NIL;

    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    for (i = 0; i < n; i++) {
        if (T[i].parent == NIL) rt = i;
    }

    setDepth(rt, 0);
    setHeight(rt);

    for (i = 0; i < n; i++) print(i);

    return 0;
}

Measured memory_bytes: 1040
n=int(input())
e=[0]*(n+1)

#素因数分解をしている
for i in range(2,n+1):
  cur=i
  for j in range(2,i+1):
    while cur % j == 0:
      e[j] += 1
      cur //=j

def num(m):
  return len(list(filter(lambda x: x>=m-1,e)))

print(num(75)+ num(25)*(num(3)-1)+ num(15)*(num(5)-1)+ num(5)*(num(5)-1)*(num(3)-2)//2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int a[2][n];
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<=i;j++){
      sum+=a[0][j];
    }
    for(int k=i;k<n;k++){
      sum+=a[1][k];
    }
    if(ans<sum){
      ans=sum;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin>>S;
    int N=S.size();
    char C='R';
    int countR=0;
    int countALL=0;
    vector<int>Rv;
    vector<int>ALLv;

    for(int i=0;i<N;i++){
        if(S[i]=='L'){
            if(C=='L'){
                countALL++;
            }
            else{//RからL
                countALL++;
                C='L';
            }
        }
        else{
            if(C=='L'){//LからR
                C='R';
                ALLv.pb(countALL);
                Rv.pb(countR);
                countR=1;
                countALL=1;
            }
            else{
                countR++;
                countALL++;
            }
        }
    }
    if(countR!=0){
        ALLv.pb(countALL);
        Rv.pb(countR);
    }
    for(int i=0;i<ALLv.size();i++){
        if(Rv[i]==0){
            REP(i,ALLv[i]){cout<<0<<" ";}
        }
        else if(ALLv[i]%2==0){
            REP(j,Rv[i]-1)cout<<0<<" ";
            cout<<ALLv[i]/2<<" ";
            cout<<ALLv[i]/2<<" ";
            REP(j,ALLv[i]-Rv[i]-1)cout<<0<<" ";
        }
        else{
            if(Rv[i]%2==0){
                REP(j,Rv[i]-1)cout<<0<<" ";
                cout<<ALLv[i]/2<<" ";
                cout<<ALLv[i]/2+1<<" ";
                REP(j,ALLv[i]-Rv[i]-1)cout<<0<<" ";
            }
            else{
                REP(j,Rv[i]-1)cout<<0<<" ";
                cout<<ALLv[i]/2+1<<" ";
                cout<<ALLv[i]/2<<" ";
                REP(j,ALLv[i]-Rv[i]-1)cout<<0<<" ";
            }
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1228
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    V<int> a(n),cnt(1e6+5,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    sort(all(a));
    a.erase(unique(all(a)),a.end());
    int ans=0;
    for(int v: a){
        if(cnt[v]==0)continue;
        if(cnt[v]==1)ans++;
         for(int i=2;i*v<=(1e6);i++){
             cnt[v*i]=0;
         }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 7928
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mina = []
zera = []
plua = []
for x in a:
  if x > 0: plua.append(x)
  elif x == 0: zera.append(x)
  else: mina.append(x)

mlim = len(mina) * len(plua)
zlim = len(zera) * (len(mina) + len(plua)) + len(zera) * (len(zera) - 1) // 2 + mlim

def minacheck(x):
  res = 0
  j = 0
  for i in range(len(plua)):
    while j < len(mina) and (plua[i] * mina[j]) <= x: j += 1
    res += j
  return res >= K

def pluacheck(x):
  res = 0
  j = 0
  for i in range(len(mina) - 1, -1, -1):
    while j < len(mina) and (mina[i] * mina[j] <= x): j += 1
    res += max(0, j - i - 1)
  j = 0
  for i in range(len(plua) - 1, -1, -1):
    while j < len(plua) and (plua[i] * plua[j] <= x): j += 1
    res += max(0, j - i - 1)
  return res >= K - zlim

if K <= mlim:
  ng = -pow(10, 18)
  ok = 0
  while ok - ng > 1:
    m = (ok + ng) // 2
    if minacheck(m): ok = m
    else: ng = m
  print(ok)
elif K <= zlim: print(0)
else:
  for i in range(len(mina)): mina[i] = -mina[i]
  mina.reverse()
  ng = 0
  ok = pow(10, 18)
  while ok - ng > 1:
    m = (ok + ng) // 2
    if pluacheck(m): ok = m
    else: ng = m
  print(ok)

Measured memory_bytes: 87764
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Rally
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int INF = 1 << 30;
const int MIN_X = 1;
const int MAX_X = 100;

/* typedef */

/* global variables */

int xs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", xs + i);
  sort(xs, xs + n);

  int mind = INF;
  for (int p = MIN_X; p <= MAX_X; p++) {
    int d = 0;
    for (int i = 0; i < n; i++) {
      int dx = xs[i] - p;
      d += dx * dx;
    }
    if (mind > d) mind = d;
  }

  printf("%d\n", mind);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    cout << (n - 2) * 180;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int c=0;
  for(int i=0;i<n-1;i++){
    if(x>=a[i]){
      c++;
      x-=a[i];
    }else{
      cout<<c;
      return 0;
    }
  }
  if(x==a[n-1])
    cout<<c+1;
  else
    cout<<c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int n = B - A - 1;
  
  if( n%2 == 1 ) cout << "Alice" << endl;
  else if ( n%2 == 0 ) cout << "Borys" << endl;

}

Measured memory_bytes: 256
N, K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,N):
    for j in range(1,K+1):
        dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))

print(dp[-1])

Measured memory_bytes: 55392
#include<bits/stdc++.h>
using namespace std;
inline void read(long long &x)
{
	x=0;
	long long p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
long long x,y;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(x);read(y);
	long long now=y/x;
	long long ans=0;
	while(now)now/=2,ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>

using namespace std;
typedef uint uint32_t;

#define GMAX 100
char grid[GMAX][GMAX];
uint A, B, w=0, b=0;

void print_grid(int i, int j) {
    for (int ii = 0; ii < i; ii++) {
        for (int jj = 0; jj < j; jj++) {
            char c;
            if (grid[ii][jj] == 0) c = '.';
            else if (grid[ii][jj] == 1) c = '#';
            else c = '_';
            cout << c;
        }
        cout << endl;
    }
}

int main() {
    for (int i = 0; i < GMAX; i++) {
        int fil = 0;
        if (i >= GMAX / 2) {
            fil = 1;
        }
        for (int j = 0; j < GMAX; j++) {
            grid[i][j] = fil;
        }
    }
    w++;b++;
    cin >> A >> B;
    // swap to black
    for (int i = 0; i < GMAX / 2 - 1; i+=2) {
        for (int j = 0; j < GMAX; j+=2) {
            if (b == B) goto ENDLOOP1;
            grid[i][j] = 1;
            b++;
        }
    }
ENDLOOP1:
    // swap to white
    for (int i = GMAX / 2 + 1; i < GMAX; i+=2) {
        for (int j = 0; j < GMAX; j+=2) {
            if (w == A) goto ENDLOOP2;
            grid[i][j] = 0;
            w++;
        }
    }
ENDLOOP2:
    cout << GMAX << ' ' << GMAX << endl;
    print_grid(GMAX, GMAX);
}


Measured memory_bytes: 256