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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int x[n][n];
  int y[n][n];
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    for(int j = 0; j < a.at(i); j++){
      cin >> x[i][j] >> y[i][j];
    }
  }
  
  int ans =0;
  for(int bit = 0; bit < (1 << n); bit++){
    int k = 0;
    bool ok = true;
    for(int i = 0; i < n; i++){
      if(bit & (1 << i)){
        k++;
        for(int j = 0; j < a.at(i); j++){
          int t = x[i][j] - 1;
          if(y[i][j]){
            if(1 & (bit >> t)) continue;
            ok = false;
          }
          else{
            if(1 & (bit >> t)) ok = false;
          }
        }
      }
    }
    if(ok) ans = max(ans, k);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};


int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    if((B-A)%2==0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 768
a,b,c,d = map(int,input().split())
m = c-a
n = d-b
t = [[1]]
for i in range(m):
    t[0].append((b*t[0][i])%998244353)
for i in range(n):
    t.append([(a*t[i][0])%998244353]+[0]*m)
for i in range(1,n+1):
    for j in range(1,m+1):
        t[i][j] = t[i][j-1]*(b+i) + t[i-1][j]*(a+j) - t[i-1][j-1]*((a+j-1)*(b+i-1))
        t[i][j] %= 998244353
print(t[n][m])

Measured memory_bytes: 147580
import java.util.*;
public class Main {
    public static void main(String[] args) {
        /* 入力 */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        //aひとつひとつは10**9以下だが、足し合わせるとintの最大値を超えてしまうので、a自体longで宣言しておく
        long a[] = new long[N];
        for (int i = 0; i<N; i++) {
            a[i] = sc.nextLong();
        }
        /* 
        DP配列宣言 dp[i][1] = dp[i][+], dp[i][0] = dp[i][-] と定義する。
        dp[i]は、a[i]までの部分列に対する答えを表し、dp[0]は定義しない（使わない）ことにする。
         */
        long dp[][] = new long[N][2];
        //dp[1]を初期化する。
        if (a[1] >= 0) {
            dp[1][1] = a[0] + a[1];
            dp[1][0] = -(a[0] + a[1]);
        } else {
            dp[1][1] = -(a[0] + a[1]);
            dp[1][0] = a[0] + a[1];
        }
        //dp[2]以降を漸化式で求める。
        for (int i = 2; i < N; i++) {
            if (a[i] >= 0) {
                dp[i][1] = Math.max(dp[i-1][1] + a[i], dp[i-1][0] + a[i]);
                dp[i][0] = Math.max(dp[i-1][1] - 2*Math.abs(a[i-1]) - a[i],
                dp[i-1][0] + 2*Math.abs(a[i-1]) - a[i]);
            } else {
                dp[i][1] = Math.max(dp[i-1][1] - 2*Math.abs(a[i-1]) + Math.abs(a[i]),
                dp[i-1][0] + 2*Math.abs(a[i-1]) + Math.abs(a[i]));
                dp[i][0] = Math.max(dp[i-1][1] + a[i], dp[i-1][0] + a[i]);
            }
        }
        //最終的な解は、元の数列a全体を使って、右端が+になる最適解と、右端が-になる最適解のうちの、より大きいほう。
        long answer = Math.max(dp[N-1][1],dp[N-1][0]);
        System.out.println(answer);
    }
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector< vector<int> > g(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      g[i][j] = (s[j] == '#');
      if ((i + j) & 1) {
        g[i][j] ^= 1;
      }
    }
  }

  int odd, even;
  function<void(int,int,int)> dfs = [&](int i, int j, int c) {
    if (i < 0 || i >= n || j < 0 || j >= m) {
      return;
    }
    if (g[i][j] != c) return;
    else {
      g[i][j] = -1;
      if ((i + j) & 1) odd++;
      else even++;
    }
    const int dx[] = {1, -1, 0, 0};
    const int dy[] = {0, 0, 1, -1};
    for (int k = 0; k < 4; k++) {
      dfs(i + dx[k], j + dy[k], c);
    }
  };

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] != -1) {
        odd = even = 0;
        dfs(i, j, g[i][j]);
        ans += (long long) odd * even;
        // cout << odd << ' ' << even << '\n';
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll a;
    cin>>a;
    string s;
    cin>>s;
    ll b=(s.at(0)-'0')*100+(s.at(2)-'0')*10+(s.at(3)-'0');
    a*=b;
    cout<<a/100<<endl;
}

Measured memory_bytes: 3560
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() { 
    ll N, ans=0;
    vector<ll> a;
    cin >> N ;
    for(int i=0; i<N; i++){
        ll x;
        cin >>x;
        a.emplace_back(x); 
    }
    sort(a.begin(), a.end(), greater<ll>());
    for(int i=0; i<N; i++){
        ans += (i%2==0?1:-1) * a[i];
    }
    cout << ans << endl;
    
}

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

int main(){
  
  long long sum,a,N,M,m,b;
  cin>>N>>M;
  m=M;
  sum=0;
  vector<pair<long long,long long>>ans(N);
  for(int i=0;i<N;i++){
cin>>a>>b;
    ans[i]=make_pair(a,b);
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<M;i++){
    if(m>ans[i].second){
      m-=ans[i].second;
      sum+=ans[i].first*ans[i].second;
    }
    else{
      sum+=ans[i].first*m;
      break;
    }
  }
  
    cout<<sum<<endl;


}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int n;
  while(cin >> n) {
    string s; cin >> s;
    int ans = 0;
    REP(i,n) {
      string t;
      cin >> t;
      for (int i=0; s.size()+i*(s.size()-1)<=t.size(); ++i) {
        for (int j=0; j+s.size()+i*(s.size()-1)<=t.size(); ++j) {
          bool ok = 1;
          REP(k,s.size()) {
            int pos = j+i*k+k;
            if (s[k] != t[pos]) {
              ok = 0;
              break;
            }
          }
          if (ok) {
            ans++;
            goto out;
          }
        }
      }
    out:;
    }
    cout << ans << endl;
  }
}

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

int N,L;
string S[110];

int main(){
    cin>>N>>L;

    for (int i = 0; i < N; i++)
    {
        cin>>S[i];
    }
    
    sort(S,S+N);

    string ans = "";
    for (int i = 0; i < N; i++)
    {  
        ans += S[i];
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def chk(n,S):
    if S[n]=="":
        print(n,flush=True)
        temp=input()
        if temp=="Vacant":
            exit()
        else:
            S[n]=temp
            return S[n]
    else:return S[n]

def chk2(S1,S2):
    T1=chk(S1,S)
    T2=chk(S2,S)
    if (S2-S1)%2!=0:
        if T1==T2:
            return True
        else:
            return False
    elif (S2-S1)%2==0:
        if T1!=T2:
            return True
        else:
            return False

def chk3(S1,S2):
    chk(S1,S)
    chk(S2,S)
    Sm=(S1+S2)//2
    if chk2(S1,Sm):
        chk3(S1,Sm)
    else:
        chk3(Sm,S2)

N=int(input())

S=[""]*N

chk3(0,N-1)



Measured memory_bytes: 4424
n=int(input())
h=list(map(int,input().split()))
now_an=0
max_an=0

for i in range(n-1):
    if h[i]>=h[i+1]:
        now_an+=1
    else:
        if now_an>=max_an:
            max_an=now_an
        now_an=0

if now_an>=max_an:
    max_an=now_an

print(max_an)

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	ll s1=0, s2=0;
	rep(i,n){
		int x;cin>>x;
		s1+=x*x;
		s2+=x;
	}
	cout<<(s2*s2-s1)/2<<endl;
	return 0;
}

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

long long N, A, B, C, D;
std::map<long long, long long> m;

long long cost(long long n) {
    if (n == 0) {
        return 0;
    } else if (n == 1) {
        return D;
    } else if (m.count(n)) {
        return m[n];
    }

    m[n] = std::min({
        n % 2 * D + A + cost(n / 2),
        (2 - n % 2) % 2 * D + A + cost((n + 1) / 2),
        n % 3 * D + B + cost(n / 3),
        (3 - n % 3) % 3 * D + B + cost((n + 2) / 3),
        n % 5 * D + C + cost(n / 5),
        (5 - n % 5) % 5 * D + C + cost((n + 4) / 5),
        n * D > 0 ? n * D : 1LL << 60,
    });

    return m[n];
}

int main() {
    int T;
    std::cin >> T;

    for (int i = 0; i < T; i++) {
        std::cin >> N >> A >> B >> C >> D;
        m.clear();
        std::cout << cost(N) << "\n";
    }
}

Measured memory_bytes: 4464
#include<stdio.h>

int main()

{

  int n;
  int box[100];
  int input;
  int i, j;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {

      scanf("%d", &input);
      box[i] = input;

    }

  for(j = i - 1; j >= 0; j--)
    {

      printf("%d", box[j]);

      if(j != 0) printf(" ");

    }

  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    if(n==1){
        cout<<"Hello World"<<endl;
        return 0;
    }else{
        int a,b; cin>>a>>b;
        cout<<a+b<<endl;
    }
}

Measured memory_bytes: 256
a, b = map(int, input().split())
ans = 0

def xor(x):
  if x % 4 == 0:
    return x
  elif x % 4 == 1:
    return 1
  elif x % 4 == 2:
    return x + 1
  else:
    return 0

xor_of_a = xor(a - 1)
xor_of_b = xor(b)

ans = xor_of_a ^ xor_of_b

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

int a[600000],p1=300000,p2=300001,n;
using namespace std; 
int main()
{
	scanf("%d",&n);
	int dir=2;
	for(int i=0;i<n;i++)
	{
		dir=3-dir;
		if (dir==1)
		{
			scanf("%d",a+p2);
			p2++;
		}
		else
		{
			scanf("%d",a+p1);
			p1--;
		}
	}
	if (dir==2)
	{
		for(int i=p1+1;i<p2-1;i++)
			printf("%d ",a[i]);
		printf("%d\n",a[p2-1]);
	}
		
	else
	{
		for(int i=p2-1;i>p1+1;i--)
			printf("%d ",a[i]);
		printf("%d\n",a[p1+1]);			
	}
		
	
	return 0;	
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	ll a, b, c;
	cin >> a >> b >> c;

    if(c < a+b){
        cout << "No" << endl;   
    }
    else{
        ll left = 4*a*b;
        ll right = (c-a-b)*(c-a-b);
        if(left < right) cout << "Yes" << endl;
        else cout << "No" << endl;   
    }

}


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

int main(){
    string S;
    cin >> S;
    int flag1=0,flag2=0,flag3=0;
    for(int i=0;i<(S.length() -1)/2;i++){
        if(S[i] != S[S.length() - i -1]) flag1 =1;
    }
    for(int i=0;i<(S.length() -1)/2;i++){
        if(S[i] != S[(S.length() -1)/2 - i -1]) flag2 =1;
    }
    for(int i=(S.length() + 3)/2;i<S.length();i++){
        if(S[i] != S[S.length() - i -1]) flag3 =1;
    }
    if(flag1==0 && flag2 ==0 &&flag3 == 0) cout << "Yes";
    else cout << "No";
    // cout << flag1 << " " <<flag2 <<" " <<flag3 ;
}

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

import math
from operator import mul
from functools import reduce


inf = 10**9+7


# nCr
def combination(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


# nまでの素数を列挙する
class PrimeUtil:
    def __init__(self, n):
        self.l_is_prime = [True for _ in range(n+1)]
        self.l_is_prime[0] = False
        self.l_is_prime[1] = False
        self.n = n
        self.primes = []
        for k in range(2, n+1):
            if self.l_is_prime[k]:
                self.primes.append(k)
                self._set_false(k)

    # pの倍数全てのl_is_primeのフラグをFalseにする
    def _set_false(self, p):
        k = p
        for _ in range(1, self.n//p):
            k += p
            self.l_is_prime[k] = False

    # 素因数分解した結果を返す
    def factor(self, k):
        ret = {}
        tmp = k
        for p in self.primes:
            if p > tmp:
                break
            while True:
                if tmp % p != 0:
                    break
                ret.setdefault(p, 0)
                ret[p] += 1
                tmp /= p
                if tmp == 1:
                    break
        if tmp > 1:
            ret[tmp] = 1
        return ret


def main():
    N, M = list(map(int, input().split()))
    pu = PrimeUtil(100000)
    ans = 1
    f = pu.factor(M)
    for v in f.values():
        ans *= combination(v+N-1, v)
        ans %= inf
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;


void trace(int A[], int N)
{
    int i;
    for (i = 0; i < N; i++) {
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

int bubbleSort(int A[], int N){
    bool flag = 1;
    int cnt = 0;
    while (flag){
        flag = 0;
        for (int i=N-1; i >= 1; i--) {
            if (A[i] < A[i-1]) {
                swap(A[i], A[i-1]);
                cnt += 1;
                flag =  1;
            }
        }
    }
    trace(A, N);
    return cnt;
}

int main() {
    int n, num_sec[101]={}, cnt=0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> num_sec[i];
    cnt=bubbleSort(num_sec, n);
    cout << cnt << endl;
}




Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N;
cin >> N;

int ans = 1;

for(int i =1; i*i <= N;i++) {
    ans = i*i;
}

cout << ans << endl;

return 0;
}

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

int32_t main(){

int n;cin>>n;
int f=0;
while(n>0){

    if(n%10==7){f=1;cout<<"Yes"<<"\n";break;}

    n=n/10;
}

if(f==0)cout<<"No"<<"\n";
return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>

int main(){
  int A[100][100];
  int n,i,j,num,n1,n2;

  scanf("%d",&n);

  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      A[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d",&num);
    scanf("%d",&n1);
    for(j=0;j<n1;j++){
      scanf("%d",&n2);
      A[num-1][n2-1] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",A[i][j]);
    }
    printf("%d\n",A[i][j]);
  }

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int N; cin>>N;
  
  int j=0;
  if(N>82){
    cout<<"No"<<endl;
    j=1;
  }
  else{
    for(int i=1; i<=9; i++){
      if(N%i==0 && N/i<10){
        cout<<"Yes"<<endl;
        j=1;
        break;
      }
    }
  }
  if(j==0){
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define mp make_pair
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define pq priority_queue
#define M map
#define UM unordered_map
#define graph unordered_map<int,vector<int>>
#define graphw unordered_map<int,vector<pair<int,int>>>
#define V vector
#define mod 1000000007
#define inf 3000000000000000007ll
#define P pair
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) signed(a.size())
#define FIXED cout << fixed << setprecision(12)
#define L list
#define D deque
#define ld long double
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define deb(x) cout<<#x<<" "<<x<<endl;
using namespace std;
// pair operation
template<class T, class U>istream& operator>>(istream& in, pair<T, U> &rhs) {in >> rhs.first; in >> rhs.second; return in;}
template<class T, class U>ostream& operator<<(ostream& out, const pair<T, U> &rhs) {out << rhs.first; out << " "; out << rhs.second; return out;}
template<class T, class U>pair<T, U> operator+(pair<T, U> &a, pair<T, U> &b) {return pair<T, U>(a.first + b.first, a.second + b.second);}
template<class T, class U>pair<T, U> operator-(pair<T, U> &a, pair<T, U> &b) {return pair<T, U>(a.first - b.first, a.second - b.second);}
// Linear STL
// VECTOR
template<class T>istream& operator>>(istream& in, vector<T> &a) {for (auto &i : a)cin >> i; return in;}
template<class T>ostream& operator<<(ostream& out, const vector<T> &a) {for (auto &i : a)cout << i << " "; return out;}
// SET
template<class T>ostream& operator<<(ostream& out, const set<T> &a) {for (auto &i : a)cout << i << " "; return out;}
template<class T>ostream& operator<<(ostream& out, const unordered_set<T> &a) {for (auto &i : a)cout << i << " "; return out;}
template<class T>ostream& operator<<(ostream& out, const multiset<T> &a) {for (auto &i : a)cout << i << " "; return out;}
// MAP
template<class T, class U>ostream& operator<<(ostream& out, const map<T, U> &a) {for (auto &i : a)cout << "(" << i.first << ", " << i.second << "(\n"; return out;}
template<class T, class U>ostream& operator<<(ostream& out, const unordered_map<T, U> &a) {for (auto &i : a)cout << "(" << i.first << ", " << i.second << "(\n"; return out;}


void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}



int main() {
	Fast;
	int t = 1;
	judge();
	// cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int fre[n + 1] = {};
		for (int i = 0; i < n - 1; i++) {
			int a;
			cin >> a;
			fre[a]++;
		}
		for (int i = 1; i <= n; i++) {
			cout << fre[i] << endl;
		}

	}
}


Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
int n, w, wi[105], vi[105];
long long dp[105][100005];

int main(){
	scanf("%d%d", &n, &w);
	int vsum = 0;
	for (int i=1;i<=n;i++){
		scanf("%d%d", &wi[i], &vi[i]);
		vsum += vi[i];
	}
	
	for (int i=1;i<=n;i++){
		for (int j=1;j<=vsum;j++){
			
			if (dp[i-1][j] > 0){
				if (dp[i-1][j+vi[i]] > 0){
					dp[i][j+vi[i]] = min(dp[i-1][j+vi[i]], dp[i-1][j]+wi[i]);
				} else{
					dp[i][j+vi[i]] = dp[i-1][j]+wi[i];
				}
				
				
				if (dp[i][j] > 0){
					dp[i][j] = min(dp[i][j], dp[i-1][j]);
				} else {
					dp[i][j] = dp[i-1][j];
				}
			}
			
			if (j == vi[i]){
				if (dp[i][j] > 0){
					dp[i][j] = min(dp[i][j], (long long) wi[i]);
				} else {
					dp[i][j] = wi[i];
				}
			}

		}
	}
	
	long long ans = 0;
	for (int i=vsum; i>=1; i--){
		if (dp[n][i] > 0 && dp[n][i] <= w){
			ans = i;
			break;
		}
	}
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 78080
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int, int> pii;
inline void chmax(int &a, const int &b) {a = max(a, b);}
inline void chmin(int &a, const int &b) {a = min(a, b);}
const int INF = 1 << 28;
string s;
int N;
pii dp[210][210], INIT;

pii solve(int l, int r) {
    pii &res = dp[l][r];
    if(dp[l][r] != INIT) return res;
    // 数字
    if(r - l == 1) {
        int val = s[l] - '0';
        return res = make_pair(val, val);
    }
    // 括弧をとっぱらって再帰的に
    // このとき、括弧含め幅が 3 以下 (つまり実質 2 以下) だと
    // 数式になりえないので飛ばす
    if(s[l] == '(' && r-l > 3) {
        pii tmp = solve(l+1, r);
        res.first = max(res.first, tmp.first);
        res.second = min(res.second, tmp.second);
    }
    if(s[r-1] == ')' && r-l > 3) {
        pii tmp = solve(l, r-1);
        res.first = max(res.first, tmp.first);
        res.second = min(res.second, tmp.second);
    }
    for(int k=l; k<r; k++) {
        if(s[k] != '+' && s[k] != '-') continue;
        pii v1 = solve(l, k), v2 = solve(k+1, r);
        if(s[k] == '+') {
            res.first = max(res.first, v1.first + v2.first);
            res.second = min(res.second, v1.second + v2.second);
        }
        else {
            res.first = max(res.first, v1.first - v2.second);
            res.second = min(res.second, v1.second - v2.first);
        }
    }
    return res;
}

int main() {
    cin >> s;
    N = s.length();
    INIT = make_pair(-INF, INF);
    for(int i=0; i<N; i++) {
        fill(dp[i], dp[i] + N + 1, INIT);
    }

    cout << solve(0, N).first << endl;
    /*
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<=N; j++) {
            if(dp_max[i][j] == -INF) continue;
            printf("%s\n", s.c_str());
            for(int k=0; k<N; k++) {
                if(i <= k && k < j) printf("=");
                else printf(" ");
            }
            printf(" -> %d\n", dp_max[i][j]);
        }
    }
    */
    return 0;
}


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


int main()
{
	long int memo[101][21] = {};
	int num[100];
	int n;

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

	memo[0][num[0]] = 1;

	for (int i = 1; i < n - 1; i++)
	{
		for (int j = 0; j <= 20; j++)
		{
			if (memo[i - 1][j] == 0) continue;
			if (j - num[i] >= 0) memo[i][j - num[i]] += memo[i - 1][j];
			if (j + num[i] <= 20) memo[i][j + num[i]] += memo[i - 1][j];
		}
	}

	cout << memo[n - 2][num[n - 1]] << endl;

	return 0;
}

Measured memory_bytes: 1184
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== BigInt begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== BigInt ends ======

// ====== PBDS begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== PBDS ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n){
        cin >> a[i];
    }
    ll coins = 1000, stocks = 0;
    rep(i,n){
        ll j = i + 1;
        while(j < n and a[j] <= a[j - 1]){
            j++;
        }
        stocks = (coins / a[j - 1]);
        coins %= a[j - 1];
        while(j < n and a[j] >= a[j - 1]){
            j++;
        }
        coins += (stocks * a[j - 1]);
        i = j - 1;
    }
    cout << coins;
}

int main(){
	// #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
typedef long long ll;

int ps[15];
int cs[15];


int main(void) {
  int D, G;
  scanf("%d%d", &D, &G);
  REP(i, D) {
    scanf("%d%d", &ps[i], &cs[i]);
  }
  int res = 1e9;
  REP(pat, 1 << D) {
    int restScore = G;
    int cur = 0;
    REP(i, D) {
      if(pat & (1 << i)) {
        restScore -= 100 * (i+1) * ps[i] + cs[i];
        cur += ps[i];
      }
    }
    for(int i = D-1; i >= 0 && restScore > 0; --i) {
      if(pat & (1 << i)) {
        // cannot use
      } else {
        int score = 100 * (i+1);
        int need = (restScore + score - 1) / score;
        int used = min(need, ps[i]);
        cur += used;
        restScore -= score * used;
      }
    }
    if(restScore <= 0) {
      res = min(res, cur);
    }
  }
  cout << res << endl;
  return 0;
}


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

int main(){
    long A,B,K; cin >> A >> B >> K;
    if(A>=K){
        cout << A-K << " " << B << endl;
    }
    else{ //A<K
        B-=(K-A); 
        long tmp = 0;
       cout << max(tmp,A-K) << " " << max(tmp,B) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll d, n;
  cin >> d >> n;
  if(n==100){
    n = 101;
  }
  ll ans = 0;
  if (d == 0){
    ans = n;
  }
  else{
    ans = n;
    rep(i, d){
      ans *= 100;
    }
  }
  print(ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
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=1000000007;
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; }
ll dp[100005][2][102];//j 0超えてない 1超えている
int main(){
    string s;
    cin>>s;
    int d;
    cin>>d;
    dp[0][0][0]=1;
    int n=s.size();
    for(int i=0;i<n;i++){
        int t=s[i]-'0';
        for(int j=0;j<2;j++){
            for(int k=0;k<(j?10:t+1);k++){
                for(int r=0;r<d;r++){
            (dp[i+1][j||(!j&&k!=t)][(k+r)%d]+=dp[i][j][r])%=mod;
                }
            }
        }
    }
    cout<<(dp[n][0][0]+dp[n][1][0]-1+mod)%mod<<endl;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
#define PI 3.1415926535897932386
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double ans=0;
    ans=a*a+b*b;
    ans-=(double)2*a*b*cos((h*60+m)/360.0*PI-m/30.0*PI);
    ans=sqrt(ans);
    printf("%.10lf",ans);
    return 0;
}

Measured memory_bytes: 4160
#include<iostream>
using namespace std;
#include<stdio.h>
int main()
{
	int h,w,i,j;
	while(1)
	{
		cin>>h>>w;
		if(h==0&&w==0)
			break;
		for(i=1;i<=h;i++)
		{
			for(j=1;j<=w;j++)
			{
				if(i%2==1)
				{
					if(j%2==1)
						cout<<'#';
					else
						cout<<'.';
				}
				else
				{	
					if(j%2==1)
						cout<<'.';
					else
						cout<<'#';
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}			
	return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

int n, a;
vector<int> x;
map<tuple<int, int, int>, long long> dp;

long long dfs(int now, int sum, int used)
{
  if (now == n) {
    return used && sum == a * used;
  }
  if (used * a < sum) return 0;
  auto status = make_tuple(now, sum, used);
  if (dp.count(status)) return dp[status];
  return dp[status] = dfs(now + 1, sum, used) + dfs(now + 1, sum + x[now], used + 1);
}

void hawawa()
{
  cin >> n >> a;
  x.resize(n);
  for (auto&& i : x) {
    cin >> i;
  }
  sort(x.begin(), x.end());
  cout << dfs(0, 0, 0) << "\n";
}

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

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

int main()
{
    int n, res = -1, sum;

    cin >> n;

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

    for( int i = 0; i < n; i++ )
    {
        for( int j = i + 1; j < n; j++ )
        {
            sum = a[i] * a[j];
            string s = "";
            while( sum != 0 )
            {
                s += sum % 10 + '0';
                sum /= 10;
            }
            bool judge = true;
            for( int k = 0; k < s.size() - 1; k++ )
                if( s[k] - s[k+1] != 1 )
                    judge = false;
            if( judge )
                res = max( res, a[i] * a[j] );
        }
    }

    cout << res << endl;

    return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  vector<int> a(5);rep(i,5) cin >> a[i];
  int k; cin >> k;

  bool flag = true;
  rep(i,5){
    for(int j = i+1;j<5;j++){
      if(abs(a[i]-a[j])>k) flag = false;
    }
  }  

  if(flag) cout << "Yay!" << endl;
  else cout << ":(" << endl;
    
  return 0;
}


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

int main() {
    int n, d[60];

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

    int sum = 0;
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
    
}

Measured memory_bytes: 3476
while True:
    n, x = (int(x) for x in input().split())
    if (n, x) == (0, 0): break
    cnt = sum(1 for i in range(1, n+1) for j in range(i+1, n+1) for k in range(j+1, n+1) if i + j + k == x)
    print(cnt)

Measured memory_bytes: 7716
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define foru(i,a,n) for(ll i=(a); i<=(n); ++i)
#define ford(i,n,a) for(ll i=(n); i>=(a); --i)
using namespace std;
typedef pair<int,int> ii;
const int inf = 1e9;
const int N = 222;
ll n, m, v[N], w[N], dp[N][101010];

ll sol(int x, int y){
	if(x < 0) return 0;
	if(dp[x][y] > -1) return dp[x][y];
	if(w[x] > y) 
		dp[x][y] = sol(x-1, y);
	else
		dp[x][y] = max(sol(x-1, y), sol(x-1, y - w[x]) + v[x]);
	return dp[x][y];
}

int main() {
	//freopen("zzz.inp","r",stdin);
	ios::sync_with_stdio(0);
	cin >>n >>m;
	foru(i,1,n) cin >>w[i] >>v[i];

	foru(i,0,N-1) foru(j,0,101000) dp[i][j] = -1;

	cout <<sol(n, m);
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 175616
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	int n,M;
	if(N%2==0){
		n=N/2;
		M=2*n*(n-1);
		cout<<M<<endl;
		for(int i=1;i<=N;i++){
			for(int j=i+1;j<=N;j++){
				if(i+j!=2*n+1){
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}else{
		n=(N-1)/2;
		M=2*n*n;
		cout<<M<<endl;
		for(int i=1;i<=N;i++){
			for(int j=i+1;j<=N;j++){
				if(i+j!=2*n+1){
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  int64 m;
  cin >> n >> m;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    xs[i] /= 2;
  }

  vector<int> ps(n);
  for (int i = 0; i < n; i++) {
    int x = xs[i];
    while (x % 2 == 0) {
      x /= 2;
      ps[i]++;
    }
  }
  for (int i = 1; i < n; i++) {
    if (ps[i] != ps[0]) {
      cout << 0 << endl;
      return 0;
    }
  }


  int64 lcm = xs[0];
  for (int i = 1; i < n; i++) {
    lcm = lcm * xs[i] / __gcd(lcm, xs[i]);
    if (lcm > m) {
      lcm = 0;
      break;
    }
  }

  if (lcm == 0) {
    cout << 0 << endl;
    return 0;
  }
  int64 c = m / lcm;
  cout << (c + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

int main() {
    rep(i,5){
        cin>>A;
        if(A == 0){
            cout<<i + 1<<endl;
            return 0;
        }
    }
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<int> ans(N + 5, 0);
  int a, b;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &a, &b);
    ++ans[a];
    ++ans[b];
  }

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


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		int total = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
			total += arr[i];
		}
		int max = 1;
		for (int i = 1; i * i <= total; i++) {
			if (total % i == 0) {
				int a = i;
				int b = total / i;
				int resultA = check(arr, a);
				if (resultA <= k && max < a) {
					max = a;
				}
				int resultB = check(arr, b);
				if (resultB <= k && max < b) {
					max = b;
				}
			}
		}
		System.out.println(max);
	}
	
	static int check(int[] arr, int x) {
		int n = arr.length;
		int[] mods = new int[n];
		for (int i = 0; i < n; i++) {
			mods[i] = arr[i] % x;
		}
		Arrays.sort(mods);
		int[] sumsA = new int[n];
		int[] sumsB = new int[n];
		int prevA = 0;
		int prevB = 0;
		for (int i = 0; i < n; i++) {
			sumsA[i] = mods[i] + prevA;
			prevA = sumsA[i];
			sumsB[n - 1 - i] = (x - mods[n - 1 - i]) % x + prevB;
			prevB = sumsB[n - 1 - i];
		}
		for (int i = 0; i < n - 1; i++) {
			if (sumsA[i] == sumsB[i + 1]) {
				return sumsA[i];
			}
		}
		return -1;
	}
}


Measured memory_bytes: 31168
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define ll long long
#define MAXN 105
using namespace std;
typedef pair<int,int> pii;
template <typename t>
inline void read(t& a)
{
    t ret(0),f(1);char ch(getchar());
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){ret = ret * 10 + (ch ^ 48);ch = getchar();}
    a = ret * f;
}
inline int Max(int x,int y){return x > y ? x : y;}
inline int Min(int x,int y){return x < y ? x : y;}
inline int cal(int x)
{
	int ret(0);
	while(x) ret += x % 10,x /= 10;
	return ret;
}
int main()
{
	int n,ans(0x3f3f3f3f);
	read(n);
	for(int i(1);i <= (n >> 1);i++)
		ans = Min(ans,cal(i) + cal(n - i));
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n,m;
    cin>>n>>m;
    unordered_map<int,vector<int>> D;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        D[a].push_back(b);
        D[b].push_back(a);
    }
    for(auto it :D[1]){
        for(auto iit :D[it]){
            if(iit==n){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 18632
n = int(input())
h = list(map(int, input().split()))

dp = [0]*(n)
if(n == 1):
    print(0)
else:
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

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

    print(dp[n - 1])


Measured memory_bytes: 13980
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextLine(r *bufio.Reader) string {
	var buf []byte
	for {
		line, isPrefix, err := r.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func nextStr(s *bufio.Scanner) string {
	s.Scan()
	ref := s.Bytes()
	cp := make([]byte, len(ref))
	copy(cp, ref)
	return string(cp)
}

func nextInt(s *bufio.Scanner) int {
	n, err := strconv.Atoi(nextStr(s))
	if err != nil {
		panic(err)
	}
	return n
}

func nextInt64(s *bufio.Scanner) int64 {
	n, err := strconv.ParseInt(nextStr(s), 0, 64)
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	K := nextInt(s)
	S := nextStr(s)

	if len(S) > K {
		fmt.Println(S[:K] + "...")
	} else {
		fmt.Println(S)
	}
}


Measured memory_bytes: 1776
from math import ceil
from collections import deque
N, D, A = map(int, input().split())
Monsters = sorted([list(map(int, input().split())) for i in range(N)])
Monsters = [[x, ceil(h / A)] for x, h in Monsters]


acc_damage = 0
que = deque([])

ans = 0
for x, h in Monsters:
    while que and x > que[0][0]:
        limit, damage = que.popleft()
        acc_damage -= damage

    need = max(0, h - acc_damage)
    ans += need
    acc_damage += need

    if need:
        que.append([x + 2 * D, need])

print(ans)

Measured memory_bytes: 137688
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> Int -> [(Int, Int)] -> Int
solve n w wvs = lastVec GV.! w where
    lastVec :: UV.Vector Int
    lastVec = foldl' go (GV.replicate (w + 1) 0) wvs
    go vec (wi, vi) = GV.generate (w + 1) $ \w' ->
        if wi > w' then vec GV.! w' else
            max (vec GV.! w') (vec GV.! (w' - wi) + vi)


main :: IO ()
main = do
    (n, w) <- readTuple2
    wvs <- replicateM n readTuple2
    print $ solve n w wvs


Measured memory_bytes: 4604
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    const double PI = 3.141592;
    
    int R;
    cin >> R;

    double ans = 2.0 * PI * R;

    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 3804