akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[101][101]={};
  int n,u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      a[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<n;j++)
      cout<<a[i][j]<<' ';
    cout<<a[i][n]<<endl;
  }
  return 0;
}



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

int main() {
  int N;
  cin >> N ;
  int n1 = N/1000;
  int n2 = (N - n1*1000)/100;
  int n3 = (N - n1*1000 - n2*100)/10;
  int n4 = N - n1*1000 - n2*100 - n3*10;

  if (n1 == n2 && n1 == n3 && n1 == n4) {
    cout << "Yes" << endl;
  }else if ((n1 == n2 && n1 == n3) || (n2 == n3 && n2 == n4)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){

   string n;
   cin >> n;
   
   if(n.at(0)=='7'){
      cout << "Yes" << endl;
   }
   else if(n.at(1)=='7'){
      cout << "Yes" << endl;
   }
   else if(n.at(2)=='7'){
      cout << "Yes" << endl;
   }
   else{
      cout << "No" << endl;
   }
}   

Measured memory_bytes: 3624
#include<stdio.h>
#include<map>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>

using namespace std;

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

const int MX = 100005;
const int MM = 998244353;

struct EV{
	int o, t, a, ad;
	EV(int o, int t, int a, int ad):o(o), t(t), a(a), ad(ad){}
	bool operator<(EV l)const{
		return t < l.t;
	}
};

int N;
int ans[MX], D[MX];

int main()
{
	vector<EV> L;
	int X, K, Q, t, a;
	scanf("%d%d", &X, &K);
	for(int i = 1; i <= K; i++){
		scanf("%d", D+i);
		L.emplace_back(0, D[i], 0, 0);
	}
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++){
		scanf("%d%d", &t, &a);
		L.emplace_back(1, t, a, i);
	}

	sort(L.begin(), L.end());

	int l = 0, r = X, u = 0, ch = 0, b = 0;
	for(EV c : L){
		if( c.o == 0 ){
			int d = c.t - b; b = c.t;
			if( ch ){
				int v = X-(u + (r-l));
				r = max(l, r - max(0, d-v));
				u = min(X, u+d);
			}
			else{
				l = min(r, l + max(0, d - u));
				u = max(0, u-d);
			}
			ch = !ch;
		}
		else{
			int d = c.t - b, a = c.a;
			int v = u + min(r-l, max(0, a-l));
			if( !ch ){
				ans[c.ad] = max(0, v - d);
			}
			else ans[c.ad] = min(X, v + d);
		}
	}

	for(int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 6768
n = gets.to_i
a = gets.chomp!.split().map(&:to_i)
txt = "APPROVED"
for i in a
  if i % 2 == 0
    if i % 3 == 0 || i % 5 == 0
      txt = "APPROVED"
    else
      txt = "DENIED"
      break
    end
  end
end

puts txt

Measured memory_bytes: 1788
D[13][3]={{1,0,0},{0,1,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,-1,0},{1,0,-1},{0,1,-1},{1,1,1},{-1,1,1},{1,-1,1},{1,1,-1}};
M[9][9][9],q[2];main(n,m,p,I,x,y,z,j,c,d){for(;scanf("%d%d%d",&n,&m,&p),n;){
	for(memset(M,I=0,sizeof(M)),c=1;I++<p;c*=-1){
		for(scanf("%d%d",&x,&y),z=1;;z++)if(!M[x][y][z]){M[x][y][z]=c;break;}
		for(d=0;d<13;d++){
			for(j=0;j<2;j++)for(q[j]=0;M[x+D[d][0]*q[j]][y+D[d][1]*q[j]][z+D[d][2]*q[j]]==c;q[j]+=2*j-1);
			if(q[1]-q[0]-1>=m){printf(c==1?"Black %d\n":"White %d\n",I);goto next;}
		}
	}
	puts("Draw");
next:
	for(;I++<p;)scanf("%d%d",&x,&y);
}exit(0);}

Measured memory_bytes: 612
#include <stdio.h>
#define N 6
#define MAX 102
  
int main(void){
  
    int i, face[N], temp;
    char str[MAX];
      
    for(i = 0; i < N; i++){
        scanf("%d", &face[i]);
    }
    while(fgets(str, MAX, stdin) != NULL){
        for(i = 0; str[i] != '\n'; i++){
            if(str[i] == 'E'){
                temp = face[3];
                face[3] = face[5];
                face[5] = face[2];
                face[2] = face[0];
                face[0] = temp;
            }
            else if(str[i] == 'W'){
                temp = face[3];
                face[3] = face[0];
                face[0] = face[2];
                face[2] = face[5];
                face[5] = temp;
            }
            else if(str[i] == 'S'){
                temp = face[4];
                face[4] = face[5];
                face[5] = face[1];
                face[1] = face[0];
                face[0] = temp;
            }
            else if(str[i] == 'N'){
                temp = face[4];
                face[4] = face[0];
                face[0] = face[1];
                face[1] = face[5];
                face[5] = temp;
            }
        }
    }
    printf("%d\n", face[0]);    
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
#define MAXN   10000001 
  
// stores smallest prime factor for every number 
lli spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (lli i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (lli i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (lli i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (lli j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
vector<lli> getFactorization(lli x) 
{ 
    vector<lli> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
int main() {
	fast;
	cin.tie(0);
	cout.tie(0);
	sieve();
	lli n;
	cin>>n;
	lli i;
	if(n==1)
	{
		cout<<1;
		return 0;
	}
	lli ans=1,j;
	for(i=2;i<=n;i++)
	{
		vector<lli>v=getFactorization(i);
		lli count=1,temp=1;
		fr(j,v.size()-1)
		{
			if(v[j]==v[j+1])
				count++;
			else
			{
				temp*=(count+1);
				count=1;
			}
		}
		temp*=(count+1);
		ans+=i*temp;
	}
	cout<<ans;
	
	
	return 0;
}

Measured memory_bytes: 81740
#!/usr/bin/env ruby

def all_even?(nums)
  new_nums = nums.select { |v| v.even? }
  nums.size == new_nums.size
end

count = 0
n, nums = readlines
nums = nums.split(" ").map(&:to_i)
while all_even?(nums) do
  nums = nums.map { |v| v / 2 }
  count += 1
end
puts count

Measured memory_bytes: 1916
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
W = [2]*N
list =(R,S,P)
list_2 = sorted(list)
count = 0
for i in range (0,3):
	if list_2[2-i] == P:
		for j in range (0,N):
			if T[j] == 'r':
				if W[j] == 2:
					W[j] = 1
					if j+K<N:
						if T[j+K] == 'r' :
							W[j+K] = 0
	if list_2[2-i]== R:
		for j in range (0,N):
			if T[j] == 's':
				if W[j] == 2:
					W[j] = 1
					if j+K<N:
						if T[j+K] == 's' :
							W[j+K] = 0
	if list_2[2-i]== S:
		for j in range (0,N):
			if T[j] == 'p':
				if W[j] == 2:
					W[j] = 1
					if j+K<N:
						if T[j+K] == 'p' :
							W[j+K] = 0

for i in range (N):
	if T[i] == 'r':
		count += P*W[i]
	elif  T[i] == 's':
		count += R*W[i]
	elif  T[i] == 'p':
		count += S*W[i]

print(count)



Measured memory_bytes: 4212
from collections import deque

players = {}
players["A"] = deque(input())
players["B"] = deque(input())
players["C"] = deque(input())

phase = "A"

while True:
    next = players[phase].popleft()
    phase = next.upper()
    if (len(players[phase]) == 0):
        print(phase)
        break


Measured memory_bytes: 3572
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))



n = readint()
x = readstr()

a = int(x,2)

bit = x.count('1')

z = [0]*(n+1)
for i in range(1,n+1):
    b = i
    while b>0:
        c = 0
        for j in range(b.bit_length()):
            if b&(1<<j):
                c += 1
        b%=c
        z[i]+=1

if bit!=1:
    p = a%(bit-1)
q = a%(bit+1)

ans = [1]*n
for i in range(n):
    if x[i]=='1':
        if bit==1:
            b = 0
            ans[i]-=1
        else:
            b = p-pow(2,n-i-1,bit-1)+bit-1
            b%=bit-1
    else:
        b = q+pow(2,n-i-1,bit+1)
        b%=bit+1
    ans[i]+=z[b]

printrows(ans)





Measured memory_bytes: 93256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


# da[i][j]:(0,0)~(i,j)の長方形の和
def da_generate(h, w, a):
    da = [[0] * w for j in range(h)]
    da[0][0] = a[0][0]
    for i in range(1, w):
        da[0][i] = da[0][i-1] + a[0][i]
    for i in range(1, h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i-1][j] + cnt_w
    return da


# da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和
def da_calc(p, q, x, y):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y] - da[x][q-1]
    if q == 0:
        return da[x][y] - da[p-1][y]
    return da[x][y] - da[p-1][y] - da[x][q-1] + da[p-1][q-1]


n, m, q = map(int, readline().split())
lr = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    l, r = map(int, readline().split())
    lr[l][r] += 1
da = da_generate(n + 1, n + 1, lr)
for _ in range(q):
    p, q = map(int, readline().split())
    print(da_calc(p, p, q, q))


Measured memory_bytes: 15640
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define ll long long

void exgcd(int a, int b, int& x, int& y) {
	if (!b) {
		x = 1, y = 0;
	} else {
		exgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
}

int inv(int a, int n) {
	int x, y;
	exgcd(a, n, x, y);
	return (x < 0) ? (x + n) : (x);
}

const int Mod = 1e9 + 7;

template <const int Mod = :: Mod>
class Z {
	public:
		int v;

		Z() : v(0) {	}
		Z(int x) : v(x){	}
		Z(ll x) : v(x % Mod) {	}

		friend Z operator + (const Z& a, const Z& b) {
			int x;
			return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));
		}
		friend Z operator - (const Z& a, const Z& b) {
			int x;
			return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));
		}
		friend Z operator * (const Z& a, const Z& b) {
			return Z(a.v * 1ll * b.v);
		}
		friend Z operator ~(const Z& a) {
			return inv(a.v, Mod);
		}
		friend Z operator - (const Z& a) {
			return Z(0) - a;
		}
		Z& operator += (Z b) {
			return *this = *this + b;
		}
		Z& operator -= (Z b) {
			return *this = *this - b;
		}
		Z& operator *= (Z b) {
			return *this = *this * b;
		}
		friend boolean operator == (const Z& a, const Z& b) {
			return a.v == b.v;
		} 
};

Z<> qpow(Z<> a, int p) {
	Z<> rt = Z<>(1), pa = a;
	for ( ; p; p >>= 1, pa = pa * pa) {
		if (p & 1) {
			rt = rt * pa;
		}
	}
	return rt;
}

typedef Z<> Zi;

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

Zi solve(int n, int m) {
	int d = gcd(n, m);
	Zi ret = 1;
	ret += qpow(2, m) - 2;
	ret += qpow(2, n) - 2;
	ret += qpow(2, d);
	return ret;
}

int n, m, T;

int main() {
	scanf("%d%d%d", &n, &m, &T);
	int n1 = gcd(n, T);
	int m1 = gcd(m, T);
	Zi ans = solve(n / n1, m / m1);
	ans = qpow(ans, 1ll * n1 * m1 % (Mod - 1));
	printf("%d\n", ans.v);
	return 0;
}


Measured memory_bytes: 256
def ans2():
    s = input()
    flag = True
    while flag:
        if (s[-7:])=='dreamer':
            s = s[:-7]
        elif (s[-5:])=='dream':
            s = s[:-5]
        elif (s[-6:])=='eraser':
            s = s[:-6]
        elif (s[-5:])=='erase':
            s = s[:-5]
        else:
            flag = False
    
    if not s:
        print("YES")
    else:
        print("NO")
ans2()

Measured memory_bytes: 3188
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;


int dp[405][405];
int pre[405];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
// #ifndef ONLINE_JUDGE
//    freopen ("INPUT.txt" , "r" , stdin);
//    freopen ("OUTPUT.txt" , "w" , stdout);
// #endif

    clock_t clk;
	clk = clock();

// --------------Code starts here---------------------------------------------------------------------

    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pre[i]=a[i]+pre[i-1];
    }

    fill_n(&dp[0][0],405*405,1e17);

    for (int i = 1; i <=n; i++)
    {
        dp[i][i]=0;
    }
    
    for(int i=n;i>=1;i--)
        for(int j=i-1;j<=n;j++)
            for(int k=i;k<j;k++)
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+pre[j]-pre[i-1]);

        cout<<dp[1][n];

// -------------------------------------Code ends here------------------------------------------------------

    clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize(3 , "Ofast" , "inline")

#include <bits/stdc++.h>

#define rep(i , a , b) for(register int i=(a);i<=(b);i++)
#define per(i , a , b) for(register int i=(a);i>=(b);i--)


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int , int> pi;

template<class T>
inline void read (T &x) {
    x = 0;
    int sign = 1;
    char c = getchar ();
    while (c < '0' || c > '9') {
        if ( c == '-' ) sign = - 1;
        c = getchar ();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar ();
    }
    x = x * sign;
}

const int maxn = 2e5 + 10;
const int inf = int (1e9);
const ll INF = ll (1e18);
const double PI = acos (- 1);
const int mod = 998244353;
const double eps = 1e-8;

int n,ma;
ll k;
ll cnt[65];
ll num[65];
int main () {
    read (n);
    read (k);
    ma = 1;
    rep (i , 1 , n) {
        ll x;
        read (x);
        int j = 0;
        while (x) {
            cnt[ j ] += ( x & 1 );
            x /= 2;
            j ++;
        }
        ma = max (ma , j);
    }
    ll kk = k;
    int j = 0;
    while (kk) {
        kk /= 2;
        j ++;
    }
    ma = max (ma , j);
    bool f = 0;
    ll ans = 0;
    per (i , ma - 1 , 0) {
        num[i]=cnt[i];
        if ( f ) {
            if ( cnt[ i ] < n - cnt[ i ] ) {
                cnt[ i ] = n - cnt[ i ];
            }
            continue;
        }
        if ( cnt[ i ] < n - cnt[ i ] ) {
            if (( k >> i ) & 1 ) {
                cnt[ i ] = n - cnt[ i ];
            }
        } else {
            if (( k >> i ) & 1 ) {
                f = 1;
            }
        }
    }
    ll tmp = 0;
    rep (i,0,ma-1) {
        tmp=tmp+1ll*cnt[i]*(1ll<<i);
    }
    ans=max (ans,tmp);
    f=0;
    per (i , ma - 1 , 0) {
        cnt[i]=num[i];
        if ( f ) {
            if ( cnt[ i ] < n - cnt[ i ] ) {
                cnt[ i ] = n - cnt[ i ];
            }
            continue;
        }
        if ( cnt[ i ] < n - cnt[ i ] ) {
            if (( k >> i ) & 1 ) {
                f=1;
            }
        } else {
            if (( k >> i ) & 1 ) {
                f = 1;
            }
        }
    }
    tmp=0;
    rep (i,0,ma-1) {
        tmp=tmp+1ll*cnt[i]*(1ll<<i);
    }
    ans=max (ans,tmp);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    # Check only black cell
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # ok
      if s[nh][nw] == '#':
        break
    # failed
    else:
      print('No')
      break
  else:
    continue
  break
else:
  print('Yes')

      
  

Measured memory_bytes: 3064
#n=int(input())
a,b,c=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

mx=max(a,b,c)
dif=3*mx-(a+b+c)
if dif%2==0:
    ans=dif//2
else:
    ans=dif//2+2

print(ans)

Measured memory_bytes: 9176
from math import sqrt

def calc_stdev(l):
    res = 0
    mean = sum(l) / len(l)
    for i in l:
        res += (i - mean) ** 2
    
    return sqrt(res / n)

while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int, input().split()))

    print(calc_stdev(s))
    




Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    if(a==b && b==c){
    cout << 1 << endl;
    }
    else if(a==b || b==c || c==a){
    cout << 2 << endl;
    }
    else {
    cout << 3 << endl;
    }   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;

ll power(ll x,ll y,ll p){
   ll res = 1;x = x % p;
   while (y > 0){
      if (y & 1){
         res = (res*x) % p;
      }
      y = y>>1;
      x = (x*x) % p;
   }
   return res;
}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}

ll t, n;
bool esprimo(ll n){
   ll s=0;
   for(ll i=1;i*i<=n;i++){
       if(n%i==0){s++;}}
   if(s>=2){return false;}
   return true;
}
int main(){
   ll n;
   cin>>n;
   ll a[n+5][3];
   for(int i=1;i<=n;i++){
       cin>>a[i][0]>>a[i][1]>>a[i][2];
   }
   ll b[n+5][3];
   memset(b,0,sizeof b);
   for(int i=1;i<=n;i++){
       b[i][0]=max(a[i][1]+b[i-1][1],a[i][2]+b[i-1][2]);
       b[i][1]=max(a[i][0]+b[i-1][0],a[i][2]+b[i-1][2]);
       b[i][2]=max(a[i][1]+b[i-1][1],a[i][0]+b[i-1][0]);
   }
   cout<<max(b[n][0],max(b[n][1],b[n][2]));
}

Measured memory_bytes: 4992
import java.io.*;
import java.util.*;

public class Main {
    private void solve() {
        int N = sc.nextInt();
        int K = sc.nextInt();
        int C = sc.nextInt() + 1;

        String s = sc.next();

        int k = 0;
        int[] l = new int[K];
        for (int i = 0; i < N && k < K; ++i) {
            if (s.charAt(i) == 'o' && (k == 0 || l[k - 1] + C <= i)) {
                l[k++] = i;
            }
        }
        int[] r = new int[K];
        k = K - 1;
        for (int i = N - 1; i >= 0 && k >= 0; --i) {
            if (s.charAt(i) == 'o' && (k == K - 1 || i + C <= r[k + 1])) {
                r[k--] = i;
            }
        }
        
        for (int i = 0; i < K; i++) {
            if (l[i] == r[i]) {
                out.println(l[i] + 1);
            }
        }
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}

Measured memory_bytes: 47644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  int port = 1;
  int tap = 0;
  while(port < b) {
    port--;
    port += a;
    tap++;
  }
  cout << tap << endl;
  
  return 0;
}

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

#define DIVMAX(a, b) ((a)/(b) + (((a)%(b) != 0) ? 1 : 0))

void solve(int *list, int len, int range) {
    int ans = DIVMAX(len-1, range-1);
    printf("%d\n", ans);
}

int main()
{
    int n, k, i;
    scanf("%d %d", &n, &k);
    int *a = (int*)malloc((n+5)*sizeof(int));
    for(i = 0; i < n; ++i) { scanf("%d", &a[i]); }
    solve(a, n, k);
    return 0;
}

Measured memory_bytes: 512
n = int(input())
if 1 <= n < 105:
    print(0)
elif 105 <= n < 135:
    print(1)
elif 135 <= n < 165:
    print(2)
elif 165 <= n < 189:
    print(3)
elif 189 <= n < 195:
    print(4)
else:
    print(5)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>

using namespace std;

int n, t, mx, cnt;
int a[100005];
int m[100005];

int main()
{
    scanf("%d%d", &n, &t);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(int i = n-1; i >= 0; i--)
    {
        m[i] = max(a[i], m[i + 1]);
        if(m[i] - a[i] > mx)
        {
            mx = m[i] - a[i];
            cnt = 1;
        }
        else if(m[i] - a[i] == mx)
        {
            cnt++;
        }
    }
    printf("%d", cnt);
    return 0;
}


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  map<int, int> sum;
  vector<int> b;
  int s = 0;
  sum[0]++;
  b.pb(0);
  REP(i, n) {
    s += a[i];
    if(sum[s] == 0) b.pb(s);
    sum[s]++;
  }

  int ans = 0;
  
  REP(i, b.size()) {
    ans += (sum[b[i]] * (sum[b[i]]-1)) / 2;
  }

  cout << ans << endl;
  
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (ll)max((ll)a*c, max((ll)a*d, max((ll)b*c, (ll)b*d))) << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
using ll = long long;

int main()
{
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++)
  {
    ll first = i * (i - 1) / 2;
    ll final = (n * 2 - i + 1) * i / 2;
    ll add = final - first + 1;
    ans = (ans + add) % 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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 (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

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

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int cnt[2][105];

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n), b(n);
	rep(i, n) {
		cin >> a[i];
		b[a[i]]++;
	}
	int ans = n;
	sort(b.begin(), b.end(), greater<int>());
	rep(i, k) {
		ans -= b[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

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

Measured memory_bytes: 256
import heapq
n, h = map(int, input().split())
q = []
for i in range(n):
    a, b = map(int, input().split())
    q.append([-a,True])
    q.append([-b,False])
heapq.heapify(q)
ans = 0
while h>0:
    damage, more = heapq.heappop(q)
    damage = -damage
    if more:
        cnt = -(-h//damage)
        ans += cnt
        h -= damage*cnt
    else:
        cnt = 1
        ans += cnt
        h -= damage
print(ans)

Measured memory_bytes: 29860
#include <bits/stdc++.h>
using Int = int64_t;

std::vector<std::string> f(std::string ss) {
   std::vector<std::string> res;
   std::string buf;
   for(char c : ss) {
      if( c == '\"' ) {
         res.push_back(buf);
         buf.clear();
      }
      else {
         buf.push_back(c);
      }
   }
   res.push_back(buf);
   return res;
}

int main() {
   for(;;) {
      std::string s;
      std::cin >> s;
      if( s == "." ) break;
      std::string t;
      std::cin >> t;
      std::vector<std::string> xs = f(s);
      std::vector<std::string> ys = f(t);
      if( xs.size() != ys.size() ) {
         std::cout << "DIFFERENT" << std::endl;
         continue;
      }
      Int count_0 = 0;
      Int count_1 = 0;
      Int n = xs.size();
      for(Int i = 0; i < n; i+=2) {
         if( xs[i] != ys[i] ) {
            count_0 += 1;
         }
      }
      for(Int i = 1; i < n; i+=2) {
         if( xs[i] != ys[i] ) {
            count_1 += 1;
         }
      }
      if( count_0 == 0 && count_1 == 0 ) {
         std::cout << "IDENTICAL" << std::endl;
      }
      else if( count_0 == 0 && count_1 == 1 ) {
         std::cout << "CLOSE" << std::endl;
      }
      else {
         std::cout << "DIFFERENT" << std::endl;
      }
   }
}



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

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

int main() {
	int N;
	cin >> N;
	vector<ll> A(N+1);
	for (int i = 0; i < N+1; ++i) {
		cin >> A[i];
	}
	vector<ll> B(N);
	for (int i = 0; i < N; ++i) {
		cin >> B[i];
	}

	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] <= 0) {
			if (A[i + 1] <= B[i]) {
				B[i] -= A[i + 1];
				ans += A[i + 1];
				A[i + 1] = 0;
			}
			else {
				A[i + 1] -= B[i];
				ans += B[i];
				B[i] = 0;
			}
		}
		else if (A[i] <= B[i]) {
			B[i] -= A[i];
			ans += A[i];
			A[i] = 0;
			if (A[i + 1] <= B[i]) {
				B[i] -= A[i + 1];
				ans += A[i + 1];
				A[i + 1] = 0;
			}
			else {
				A[i + 1] -= B[i];
				ans += B[i];
				B[i] = 0;
			}
		}
		else {
			A[i] -= B[i];
			ans += B[i];
			B[i] = 0;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4792
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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 (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long N, long long K) {
  ANS(min(N % K, min(abs(N % K - K), N)));
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  solve(N, K);
  return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve() {
    int n;
    cin >> n;

    vector<int> v(n);
    rep(i, 0, n) cin >> v[i];

    map<int, int> cnt1, cnt2;
    for (int i = 0; i < n; i += 2) {
        ++cnt1[v[i]];
    }
    for (int i = 1; i < n; i += 2) {
        ++cnt2[v[i]];
    }

    vector<pair<int, int>> ps1, ps2;
    for (auto &p:cnt1) {
        ps1.push_back({p.second,p.first});
    }

    for (auto &p:cnt2) {
        ps2.push_back({p.second,p.first});
    }

    sort(rbegin(ps1), rend(ps1));
    sort(rbegin(ps2), rend(ps2));

    int ans=n;
    rep(i,0,ps1.size()){
        if(ps1[i].second==ps2[0].second){
            if(ps2.size()==1) ans=min({ans,n-ps1[i].first,n-ps2[0].first});
            else ans=min(ans,n-ps1[i].first-ps2[1].first);
        }else{
            ans=min(ans,n-ps1[i].first-ps2[0].first);
        }
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main(){
  int n=100000;
  vector<bool> prime(100005,true);
  for(int i=2; i<=n; ++i){
    if(!prime[i]) continue;
    for(ll j=(ll)i*i; j<=n; j += i){
      prime[j] = false;
    }
  }
  vector<int> near2017(0);
  for(int i=3; i<=n; i+=2){
    if(prime[i] && prime[(i+1)/2]) near2017.push_back(i);
  }
  int q;
  cin >> q;
  for(int i=0; i<q; ++i){
    int l, r;
    cin >> l >> r;
    auto itl = lower_bound(near2017.begin(),near2017.end(),l);
    auto itr = upper_bound(near2017.begin(),near2017.end(),r);
    cout << itr - itl << endl;
  }
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(abs(a-b)<=d&&abs(b-c)<=d) printf("Yes");
    else if(abs(a-c)<=d) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 0) cout << "Positive";
	else if (a <= 0 && b >= 0) cout << "Zero";
	else if ((b - a) % 2 == 0) cout << "Negative";
	else cout << "Positive";
	return 0;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

ll gcd(ll a, ll b) {
    return (b % a == 0) ? a : gcd(b % a, a);
}

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

    ll g = gcd(360, X);
    cout << 360 / g << endl;

    return 0;
}

Measured memory_bytes: 3632
// 一見Nの分割で2^(N-1)だけ状態がありそうにみえる
// 操作を逆に考えて、スライムを解体するほうを考える
// これは状態が少なくて済む

// 状態: 区間[i,j), O(N^2)
// 結果: そのまま
// 遷移: 切る場所をすべて考える O(j-i)

#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

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

    int n;
    cin >> n;
    vector<i64> a_s(n);
    rep(i, n) { cin >> a_s[i]; }
    vector<i64> sas(n + 1, 0);
    copy(a_s.begin(), a_s.end(), sas.begin() + 1);
    rep(i, n)
    {
        sas[i + 1] += sas[i];
    }

    // [i,j)に限定したときの解
    vector dp(n + 1, vector<i64>(n + 1, 0));
    FOR(l, 2, n)
    {
        rep(i, n - l + 1)
        {
            auto j = i + l;
            i64 ans = 4'00'000'000'000 * 400 + 1;
            FOR(k, i + 1, j - 1)
            {
                chmin(ans, dp[i][k] + dp[k][j] + sas[j] - sas[i]);
            }
            dp[i][j] = ans;
        }
    }
    cout << dp[0][n] << '\n';

    return 0;
}


Measured memory_bytes: 4504
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 200005;
const LL MOD = 998244353;
const LL INF = (LL)1e9 + 5;

struct BIT {
	LL c[MAXN];
	void add(int p) {
		while (p < MAXN) {
			c[p]++;
			p += p & -p;
		}
	}
	LL get(int p) {
		LL res = 0;
		while (p > 0) {
			res += c[p];
			p -= p & -p;
		}
		return res;
	}
} tree;

LL N, K, a[MAXN], pref[MAXN];
pair<LL, LL> ord[MAXN];

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

	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		a[i] -= K;
		pref[i + 1] = pref[i] + a[i];
		ord[i + 1] = {pref[i + 1], i + 1};
	}
	ord[1] = {0, 1};
	
	int l = 1, r = 1;
	LL ans = 0;
	sort(ord + 1, ord + N + 2);
	while (l <= N + 1) {
		while (r <= N + 1 && ord[r].first == ord[l].first) {
			tree.add(ord[r].second);
			r++;
		}
		for (int i = l; i < r; i++) {
			ans += tree.get(ord[i].second - 1);
		}
		l = r;
	}
	
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 8064
n,m=map(int,input().split())
if n&1:
  for i in range(m):
    print(i+1,n-i)
else:
  a=0
  for i in range(m):
    if n&2:
      if i+1==(n//2+1)//2:a=1
    elif i+1==n//2//2+1:a=1
    print(i+1+a,n-i)

Measured memory_bytes: 9260
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main(){
int M,N,i;
long long int P,X,total;
cin>>N;
vector<int> T(N);
for(i=0;i<N;i++){
 cin>>T[i];
 }
total = accumulate(T.begin(),T.end(),0);
cin>>M;
vector<int> sum(M);
for(i=0;i<M;i++){
cin>>P>>X;
sum[i] = total -T[P-1] + X;
 }
for(i=0;i<M;i++){
cout<<sum[i]<<endl;
}
return 0;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (n, q) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut uf = UnionFind::new(n);

    for _ in 0..q {
        let (com, x, y) = {
            let i = read::<usize>();
            (i[0], i[1], i[2])
        };
        if com == 0 {
            uf.unite(x, y);
        } else {
            let res = uf.same(x, y);
            if res { println!("1"); }
            else { println!("0"); }
        }
    }
}

struct UnionFind {
    par: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind { par: (0..n).collect(), }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let px = self.find(x);
        let py = self.find(y);
        if px == py { return; }
        self.par[py] = px;
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn find(&mut self, x: usize) -> usize {
        if self.par[x] == x { x }
        else {
            let p = self.par[x];
            self.par[x] = self.find(p);
            self.par[x]
        }
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void PRINT(T container, bool withSize) { if(withSize) cout<<container.size()<<endl; for(auto it : container) cout<<it<<" "; cout<<endl; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


typedef tuple<int,int,int> block;
const int MAXS = 1e4+5;
ll dp[MAXS];

bool cmp(block lhs, block rhs) {
    return get<0>(lhs)+get<1>(lhs) < get<0>(rhs)+get<1>(rhs);
}

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

    int n; cin>>n;
    vector<block> vb;
    FOR(i,n) {
        int w,s,v; cin>>w>>s>>v;
        vb.emplace_back(w,s,v);
    }

    sort(ALL(vb), cmp);

    ll ans=0;
    FOR(i,n) {
        int w,s,v;
        tie(w,s,v) = vb[i];

        REV(j, s, 0) {
            ans |= MAX( dp[j] + v );
            if(j+w < MAXS) {
                dp[j+w] |= MAX( dp[j] + v );
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 384
import sys
input = sys.stdin.readline

K, N = map(int, input().split())
A = [int(x) for x in input().split()]

A.append(K+A[0])

B = []
for i in range(1,N+1) :
    B.append(A[i] - A[i-1])

print(sum(B)-max(B))


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

int N;
const int MAX_N = 1000000;
int W[MAX_N];

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

    ll left[MAX_N];
    ll right[MAX_N];

    for (int i = 0; i< N; i++) {
        for (int j = 0; j <= i; j++) {
            left[i] += W[j];
            
        }
        //cout << left[i] << endl;
    }

    for (int i = 0; i< N; i++) {
        for (int j = N-1; j > i; j--) {
            right[i] += W[j];
            
        }
        //cout << right[i] << endl;
    }

    ll ans[MAX_N];
    for (int i = 0; i < N; i++) {
        ans[i] = abs(left[i] - right[i]);
        //cout << left[i] << " " << right[i] << endl;
    }
    

    sort(ans, ans+N-1);

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


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,i,j,k,l,cnt,sum,mn,cntw[50],cntr[50],cntb[50];
	char s[51][51];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)	scanf("%s",s[i]);
	for(i=0;i<n;i++){
		cntw[i]=0;
		cntb[i]=0;
		cntr[i]=0;
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(s[i][j]=='W')	cntw[i]++;
			if(s[i][j]=='B')	cntb[i]++;
			if(s[i][j]=='R')	cntr[i]++;
		}
	}
	mn=9999999;
	for(i=0;i<n-2;i++){
		for(j=i+1;j<n-1;j++){
			sum=0;
			for(k=0;k<=i;k++)	sum+=m-cntw[k];
			for(k=i+1;k<=j;k++)	sum+=m-cntb[k];
			for(k=j+1;k<n;k++)	sum+=m-cntr[k];
			if(mn>sum)	mn=sum;
		}
	}
	printf("%d\n",mn);
	return 0;
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
  i64 r;
  cin >> r;
  cout << 3 * r * r << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

int n, m;

int f(string s, const string t) {
	int ret = 0;
	for (int i = 0; i < n; i++) {
		int j = i;
		while (t[i] != s[j]) j++;
		ret += abs(i - j);
		swap(s[i], s[j]);
	}
	return ret;
}


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

	while (cin >> n >> m) {
		string s;
		vector<int> p(m);
		for (int i = 0; i < n; i++) {
			char c;
			cin >> c;
			s += c;
		}
		for (int i = 0; i < m; i++) {
			cin >> p[i];
		}

		int ans = 1e9;
		for (int i = 0; i <= 1; i++) {
			string t;
			int x = i;
			for (int j = 0; j < m; j++) {
				string a = string(p[j], char('0' + x));
				t += a;
				x = !x;
			}
			assert(t.size() == n);
			if (count(s.begin(), s.end(), '0') != count(t.begin(), t.end(), '0')) continue;
			if (count(s.begin(), s.end(), '1') != count(t.begin(), t.end(), '1')) continue;
			ans = min(ans, f(s, t));
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3220
import math

a, b, x = map(int, input().split())
if x >= (((a ** 2) * b) / 2):
    print(math.degrees(math.atan(((2 * b - (2 * x / (a ** 2))) / a))))
else:
    print(math.degrees((math.atan((2 * x / (a * (b ** 2))) ** (-1)))))



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

int main()
{
   ll n, m;
   cin >> n >> m;
   vector<ll> A(n+1, 0), cnt(n+2, 0);
   for(ll i = 0; i <= n; i++)
        A[i] = i;
    for(ll i = 1; i <= n; i++)
        A[i] = (A[i-1] + A[i])%M;
    for(ll i = 1; i <= n+1; i++){
        ll sumL = A[i-1]%M;
        ll sumR = (A[n]%M- (n-i >= 0 ? A[n-i]%M : 0) + M)%M;
        cnt[i] = (sumR - sumL + 1%M + M)%M;
    }
    ll ans = 0;
    for(ll k = m; k <= n+1; k++)
        ans = (ans%M + cnt[k]%M)%M;
    cout << ans << "\n";
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int K = nextLong();

  const ll INF = 1LL << 61;
  vector<ll> dist(K+1, INF);

  deque<int> q;
  q.push_back(1);
  dist[1] = 1;

  while (!q.empty()) {
    int curr = q.front(); q.pop_front();

    if (curr % 10 != 9) {
      int nxt = (curr + 1) % K;
      if (dist[nxt] > dist[curr] + 1) {
        dist[nxt] = dist[curr] + 1;
        q.push_back(nxt);
      }
    }
    {
      int nxt = (curr * 10) % K;
      if (dist[nxt] > dist[curr]) {
        dist[nxt] = dist[curr];
        q.push_front(nxt);
      }
    }
  }

  ll ans = dist[0];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 4360
/*
	Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1000000000;

#define pii pair < ll, ll >
#define vi vector < ll >
#define vvi vector < vector < ll > >
#define vpii vector < pair < ll, ll > >
#define vvpii vector < vector < pair < ll, ll > > >
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

int main()
{
	vi vec, count(200005);
	ll n;
	cin >> n;
	for(ll i=0; i<n; i++){
		ll temp;
		cin >> temp;
		vec.pb(temp), count[temp]++;
	}

	ll sum = 0;
	for(ll u : count)
		sum += u*(u-1)/2;
	for(ll u : vec)
		cout << sum - (count[u]*(count[u]-1)/2) + ((count[u]-1)*(count[u]-2)/2) << endl;
	return 0;
}


Measured memory_bytes: 5872
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        StringBuilder ans = new StringBuilder();
        for(int i = 0; i < (ty-sy); i++) ans.append("U");
        for(int i = 0; i < (tx-sx); i++) ans.append("R");
        for(int i = 0; i < (ty-sy); i++) ans.append("D");
        for(int i = 0; i < (tx-sx); i++) ans.append("L");
        ans.append("D");
        for(int i = 0; i < (tx-sx+1); i++) ans.append("R");
        for(int i = 0; i < (ty-sy+1); i++) ans.append("U");
        ans.append("L");
        ans.append("U");
        for(int i = 0; i < (tx-sx+1); i++) ans.append("L");
        for(int i = 0; i < (ty-sy+1); i++) ans.append("D");
        ans.append("R");
        System.out.println(ans.toString());
    }
}



Measured memory_bytes: 23252