akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
  
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
  
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
  
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
 
typedef long long int64;
const int INF = 1 << 30;
 
int main(){
  int C, D, W, X;
  vector< vector< int > > E, F;
  vector< vector< vector< int > > > dp;
 
  while(cin >> C >> D >> W >> X, C){
    E  = vector< vector< int > >( C, vector< int >(D));
    F  = vector< vector< int > >( C, vector< int >(D));
    dp = vector< vector< vector< int > > >
      ( D + 1, vector< vector< int > >(W + 1, vector< int >( X + 1, -1)));
 
    cin >> E;
    cin >> F;
 
    dp[0][W][X] = 0;
    for(int i = 0; i < D; i++) {
      for(int j = 0; j <= X; j++) {
        for(int k = 0; k < C; k++) {
          if(E[k][i] == 0) continue;
          for(int l = W; l >= F[k][i]; l--) {
            if(dp[i][l][j] == -1) continue;
            // 複数回ライブをやる
            if(j > 0) {
              int value = 0, futan = 0;
              for(int m = k; m >= 0; m--) { // あれこれ右行ってないけど意外と反例ないかもね
                if(E[m][i] == 0) break;
                value += E[m][i]; futan += F[m][i];
                if(l - futan < 0) break;
                dp[i + 1][l - futan][j - 1] = max( dp[i + 1][l - futan][j - 1], dp[i][l][j] + value);
              }
            }
            // 一回だけ
            dp[i + 1][l - F[k][i]][j] = max( dp[i + 1][l - F[k][i]][j], dp[i][l][j] + E[k][i]);
          }
        }
      }
      for(int j = 0; j <= W; j++) {
        for(int k = 0; k <= X; k++){
          dp[i + 1][j][k] = max( dp[i + 1][j][k], dp[i][j][k]);
        }
      }
    }
 
    int ret = 0;
    for(int j = 0; j <= W; j++){
      for(int k = 0; k <= X; k++){
        ret = max( ret, dp[D][j][k]);
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1420
#include <iostream>
#include <vector>
#include <math.h>

class Point
{
    private:
        void CalcDist();

    public:
        long double dist;
        long x;
        long y;
        Point(long long val1, long long val2);
};

Point::Point(long long val1, long long val2)
{
    x = val1;
    y = val2;
    CalcDist();
}

void Point::CalcDist()
{
    dist = sqrt((x*x) + (y*y));
}


using Pos = std::vector<Point>;

int main(void)
{
    long long  N,D;
    Pos points;

    std::cin >> N >> D; 
    
    for(long long i=0;i<N;i++)
    {
        long long x, y;
        std::cin >> x >> y;
        points.push_back(Point(x,y));
    }

    long long num = 0;
    for(auto p : points)
    {
        if(p.dist <= D)
            num++;
    }

    std::cout << num << std::endl;

    return 0;
}

Measured memory_bytes: 11688
N, K = map(int, input().split())
d = [int(x) for x in input().split()]

avail = [x for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] if x not in d]

i = 0
while 1 :
    okflg = True
    for c in (str(N + i)) :
        if int(c) not in avail :
            okflg = False
            
    if okflg == True :
        print(N + i)
        break
    i += 1

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC075_b
int main() {
	int H, W;
	cin >> H >> W;

	string A[100];
	rep(i, H) {
		cin >> A[i];
	}

	rep(i, H) {
		rep(j, W) {
			if (A[i].at(j) == '.') {
				int cnt = 0;
				for (int a=-1; a<=1; a++) {
					for (int b=-1; b<=1; b++) {
						int neighbor_x = j+b;
						int neighbor_y = i+a;
						if ((neighbor_x >= 0 && neighbor_x < W) && (neighbor_y >= 0 && neighbor_y < H)) {
							if (A[neighbor_y].at(neighbor_x) == '#') {
								cnt += 1;
							}
						}
					}
				}
				A[i].at(j) = cnt + '0';
			}
		}
	}
	rep(i, H) {
		cout << A[i] << endl;
	}
}

Measured memory_bytes: 256
import fractions
A,B,C,D=map(int,input().split())
listA=range(A)
listB=range(B+1)
listC=range(0,B+1,C)
listAC=range(0,A,C)
listD=range(0,B+1,D)
listAD=range(0,A,D)
listCD=range(0,B+1,C*D//fractions.gcd(C,D))
listACD=range(0,A,C*D//fractions.gcd(C,D))
lenA=len(listA)
lenB=len(listB)
lenC=len(listC)
lenAC=len(listAC)
lenD=len(listD)
lenAD=len(listAD)
lenCD=len(listCD)
lenACD=len(listACD)
ans=lenB-lenA-lenC+lenAC-lenD+lenAD+lenCD-lenACD
print(ans)

Measured memory_bytes: 5076
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()

ans = 0

tu = sr - 1
td = h - sr
tl = sc - 1
tr = w - sc

tkh_count_u = 0
tkh_count_d = 0
tkh_count_l = 0
tkh_count_r = 0

aok_count_u = 0
aok_count_d = 0
aok_count_l = 0
aok_count_r = 0

for i in range(n):
    if s[i] == "U":
        tkh_count_u += 1
    if s[i] == "D":
        tkh_count_d += 1
    if s[i] == "L":
        tkh_count_l += 1
    if s[i] == "R":
        tkh_count_r += 1

    if tu < tkh_count_u - aok_count_d:
        ans = 1
        break
    if td < tkh_count_d - aok_count_u:
        ans = 1
        break
    if tl < tkh_count_l - aok_count_r:
        ans = 1
        break
    if tr < tkh_count_r - aok_count_l:
        ans = 1
        break

    if t[i] == "U":
        if aok_count_u - tkh_count_d < tu:
          aok_count_u += 1
    if t[i] == "D":
        if aok_count_d - tkh_count_u < td:
          aok_count_d += 1
    if t[i] == "L":
        if aok_count_l - tkh_count_r < tl:
          aok_count_l += 1
    if t[i] == "R":
        if aok_count_r - tkh_count_l < tr:
          aok_count_r += 1

if ans == 1:
    print("NO")
else:
    print("YES")


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int solve() {
    int n;
    vector<int> A, B;
    cin >> n;
    A.resize(n);
    for (int i = 0; i < n; i++)
        cin >> A[i];
    B.clear();
    for (auto a: A) {
        auto itr = lower_bound(B.begin(), B.end(), a);
        if (itr == B.end()) {
            if (B.empty() && a == 1)
                B.push_back(a);
            else if (!B.empty() && B.back() == a - 1)
                B.push_back(a);
        }
    }
    if (B.empty())
        return -1;
    return n - B.size();
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int ans = solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9 + 7
A.sort(reverse=True)
kaijou = [1 for _ in range(N+1)]
for k in range(1, N):
  kaijou[k+1] = kaijou[k]*(k+1)%mod



b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

def combination(n, k):
  foo = kaijou[n]*modinv(kaijou[k]*kaijou[n-k]%mod)%mod
  return foo

ans = 0

for k in range(N-K+1):
  ans += A[k]*combination(N-k-1, K-1)
  ans %= mod

for k in range(N-K+1):
  ans -= A[-k-1]*combination(N-k-1, K-1)
  ans %= mod

print(ans)



Measured memory_bytes: 20032
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val s = read()
    if(s.length % 2 == 1){
        println("No")
        return
    }
    for(i in 0 until s.length step 2){
        if(s[i] != 'h' || s[i + 1] != 'i'){
            println("No")
            return
        }
    }
    println("Yes")
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

Measured memory_bytes: 33808
#include<stdio.h>
int main()
{
	char a[100][100];
	int n=0,m=0,i=0;
	scanf("%d%d",&n,&m);
	
	for(int j=0;j<n;j++)
	{
		scanf("%s",a[j]);
	 } 
	 for(i=0;i<m+2;i++)
	 printf("#");
	 printf("\n");
	 for(i=0;i<n;i++)
	 {
	 	printf("#");
	 	for(int j=0;j<m;j++)
	     {
	     	printf("%c",a[i][j]);
	     } 
	    printf("#\n");
	 }
	 for(i=0;i<m+2;i++)
	 printf("#");
	 printf("\n");
	 return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int a,b,c=0,m=0,n=0;
    string s[100],t[]={"....",".###",".#.#","####","#...","#.#."};
    cin>>a>>b;
    if(a>b)c=3;
    m=max(a,b);
    n=min(a,b);
    for(int i=0;i<100;i++){
        s[i]="";
        for(int j=0;j<25;j++){
            if(i%4==0||(i/4)*25+j>=m){
                s[i]+=t[0+c];
            }else if(i%4==2&&(i/4)*25+j<n-1){
                s[i]+=t[2+c];
            }else{
                s[i]+=t[1+c];
            }
        }
    }
    cout<<"100 100"<<endl;
    for(int i=0;i<100;i++){
        cout<<s[i]<<endl;
    }
}


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;

int n;
int pos[maxN];

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

	cin >> n;

	for(int i = 1; i <= n; i++){
		int x;	cin >> x;
		pos[x] = i;
	}
	
	int i = 1;
	int mx = 0;
	while(i <= n){
		int j = i + 1;
		while(j <= n && pos[j - 1] < pos[j]){
			j++;
		}
		
		mx = max(mx, j - 1 - i + 1);
		i = j;
	}
	
	cout << n - mx << '\n';

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	int i ,j ,n=0 ,data[10],data2[3], databox=0;
	for(i=0;i<10;i++) {
		scanf("%d",&data[i]);
	}
	for(i=0;i<3;i++) {
		databox=0;
		n=0;
		for(j=0;j<10;j++) {
			if (databox<data[j]) {
				n = j;
				databox = data[j];
			}
		}
		data2[i] = data[n];
		data[n]=0;
		printf("%d\n",data2[i]);
	}
	
	return 0;
}

Measured memory_bytes: 0
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	string s;
	cin >> s;
	REP(i,s.size()) cout << 'x';
	cout << endl;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

string s,t;

int main(){
  cin >> s >> t;
  REP(i,s.size()){
    REP(j,s.size()){
      if(t[j] != s[(i+j)%s.size()]) break;
      if(j==s.size()-1){
        cout << "Yes" <<endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define vi vector<int>
#define pb push_back
using namespace std;
int main()
{
	int n;
	cin>>n;
	cout<<3*n*n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define INF 100000000
#define NIL -1
#define WHITE 0
#define BLACK 1

typedef struct nodes{
	int number;
	int d;
	struct nodes *next;
}Node;

void addNode(Node*, int, int);

main(){
	int n, i, j, k, m, l, u, *d, *flag, mincost;
	Node *G, *p;

	scanf("%d", &n);
	d = (int *)malloc(sizeof(int) * n);
	flag = (int *)malloc(sizeof(int) * n);
	G = (Node *)malloc(sizeof(Node) * n);
	for (i = 0; i < n; i++){
		G[i].next = &(G[i]);  //??£??\?????°0
		d[i] = INF;
		flag[i] = WHITE;
		scanf("%*d%d", &k);
		for (j = 0; j < k; j++){
			scanf("%d%d", &m, &l);
			addNode(&(G[i]), m, l);
		}
	}

#ifdef DEBUG
	printf("*********************\n");
	for (i = 0; i < n; i++){
		printf("[%d] ", i);
		for (p = G[i].next; p != &(G[i]); p = p->next){
			printf("%d-%d , ", p->number, p->d);
		}
		printf("\n");
	}
	printf("*********************\n");
#endif

	d[0] = 0;  // ?§?????????????

	while (1){
		mincost = INF;
		for (i = 0; i < n; i++){
			if (flag[i] != BLACK && d[i] < mincost){
				mincost = d[i];
				u = i;
			}
		}
		if (mincost == INF)break; // ??¢?´¢??????(??¨???BLACK)
		flag[u] = BLACK;

		for (p = G[u].next; p != &(G[u]); p = p->next){
			if (d[p->number] > d[u] + p->d){
				d[p->number] = d[u] + p->d;
			}
		}
	}

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

	return 0;
}

void addNode(Node*graph, int k, int d){
	Node* p;

	for (p = graph->next; p->next != graph; p = p->next);
	p->next = malloc(sizeof(Node));
	p->next->next = graph;
	p->next->number = k;
	p->next->d = d;

#ifdef DEBUG
	printf("**add** %d %d \n", p->number, p->d);
#endif
}

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

using namespace std;
using ll=long long;

int main()
{
   int n;cin >>n;
   int a[n];int ans=0;
   int b=1;
   for(int i=0;i<n;i++){
    cin >>a[i];
    if(a[i]%2==0)b*=2;
    else b*=1;
   }
   int k=1;
   for(int i=0;i<n;i++){
    k*=3;
   }
   ans+=k;
   ans-=b;
   cout << ans << endl;
    return 0;
}


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

int main(){
   
    int N;
    cin>>N;
    vector<int> S(N);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        S[i]=a-i-1;
    }
    sort(S.begin(),S.end());
    int M=S[N/2];
    long long int ans=0;
    for(int i=0;i<N;i++){
        ans+=abs(S[i]-M);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
f=0
c=0
for i in range(n):
    if(l[i][0]==l[i][1]):
        c+=1
        if(c==3):
            f=1
            break
    else:
        c=0
if(f==1):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 62388
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<pair<long long, long long>>q;
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		q.push(make_pair(a, 1));
	}
	for (int i = 0; i < m; i++) {
		long long b, c;
		cin >> b >> c;
		q.push(make_pair(c,b));
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		auto p = q.top();
		q.pop();
		ans += p.first;
		//cout << p.first<<p.second << endl;
		if (p.second > 1) {
			p.second--;
			q.push(p);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6384
from math import factorial


def comb(n, k, mod):
  if n < 0 or k < 0 or n < k:
      return 0
  if n == 0 or k == 0:
      return 1
  
  a=factorial(n) % mod
  b=factorial(k) % mod
  c=factorial(n-k) % mod
  return (a*power_func(b, mod-2, mod)*power_func(c, mod-2, mod)) % mod


def power_func(a,b,mod):
  if b == 0:
      return 1
  if b % 2 == 0:
    d = power_func(a, b//2, mod)
    return d*d % mod
  if b % 2 == 1:
    return (a*power_func(a, b-1, mod)) % mod


N, M, K = map(int, input().split())
mod = 10**9 + 7


x = N*N*(M*M*(M+1)//2 - M*(M+1)*(2*M+1)//6)
y = M*M*(N*N*(N+1)//2 - N*(N+1)*(2*N+1)//6)
ans = comb(N*M-2, K-2, mod) * (x + y) % mod
print(ans)

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

int main(void){
    int a;
    int b;
    int i;
    int n;
    int count;
    
    cin >> a;
    vector<int> tab(a);
    i = -1;
    while (++i < a)
    {
        cin >> b;
        tab.at(i) = b;
    }
    count = 0;
    n = 0;
    i = -1;
    while (++i < a)
    {
        count++;
        if ((n = tab.at(n) - 1) == 1)
        {
            cout << count << endl;
            return (0);
        }
    }
    cout << -1 << endl;
    return (0); 
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>

typedef long long ll;

ll maximum(ll a, ll b, ll c)
{
  return std::max(a, std::max(b, c));
}

ll minimum(ll a, ll b, ll c)
{
  return std::min(a, std::min(b, c));
}

int main(int argc, char* argv[])
{
  ll h, w;
  std::cin >> h >> w;

  if (h % 3 == 0 || w % 3 == 0) {
    std::cout << 0 << std::endl;
    return 0;
  }

  // X, X or Y, Y
  ll min_val = std::min(h, w);

  // Xで割った後、Yで割る
  for (ll x = 1; x < w; x++) {
      ll a, b, c, val;
      a = x * h;
      b = (w-x) * (h/2);      // 最小面積が最大になるように、最大面積が最小になるようにするため、真ん中あたりが良い
      c = h * w - a - b;
      val = maximum(a, b, c) - minimum(a, b, c);
      min_val = std::min(min_val, val);
  }

  // Yで割った後、Xで割る
  for (ll y = 1; y < h; y++) {
      ll a, b, c, val;
      a = y * w;
      b = (h-y) * (w/2);      // 最小面積が最大になるように、最大面積が最小になるようにするため、真ん中あたりが良い
      c = h * w - a - b;
      val = maximum(a, b, c) - minimum(a, b, c);
      min_val = std::min(min_val, val);
  }

  std::cout << min_val << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int h ,m ,s ,h1 ,m1 ,s1 ,hour=0 ,minute=0 ,second=0;
  while( scanf( "%d %d %d %d %d %d" ,&h ,&m ,&s ,&h1 ,&m1 ,&s1 ) != EOF ){

    /* 秒の計算 */
    if( s1 > s ){
      second = s1 - s;
    }

    else if( s1 < s ){
      m1--;
      s1 += 60;
      second = s1 - s;
    }

    /* 分の計算 */
    if( m1 > m ){
      minute = m1 - m;
    }

    else if( m1 < m ){
      h1--;
      m1 += 60;
      minute = m1 - m;
    }

    /* 時間の計算 */
    hour = h1 - h;

    printf( "%d %d %d\n" ,hour ,minute ,second );
    hour = 0;
    minute = 0;
    second = 0;
  }

  return 0;
}

Measured memory_bytes: 596
/*
 * Author : Sadi
 * Mon 06/07/2020
 * 18:26:23.40
 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    double
    n, d;
    cin >> n >> d;
    cout << ceil(n / (d * 2 + 1)) << endl;

    return 0;
}


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

int main() {
	int N, *A;
	cin >> N;
	A = new int[N];

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

	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < N; j++) {
			if (j != 0) {
				cout << " ";
			}
			cout << A[j];
		}
		cout << "\n";
		if (i == N) break;

		int v = A[i];
		int j = i - 1;

		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
}



Measured memory_bytes: 3132
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

    public static int cnt = 1;

    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader();
        Main main = new Main();
        //Scanner sc = new Scanner(System.in);
        long a = in.nextLong() , b = in.nextLong();
        a = main.GCD(a,b);
        factorial(a);
        System.out.print(cnt);
     }

     public static void factorial(long a){
        if( a%2 == 0 ){
            cnt++;
        }
        while( a%2 == 0 ){
            a /= 2;
        }
         if( a%3 == 0 ){
             cnt++;
         }
         while( a%3 == 0 ){
             a /= 3;
         }
         for(long i = 5 ; i*i <= a ; i += 2 ){
             if(a%i == 0 ){
                 cnt++;
                 while( a%i == 0 ){
                     a /= i;
                 }
             }
         }
         if( a > 2 ){
             cnt++;
         }
     }

    private long GCD(long a, long b) {
        if (b==0) return a;
        return GCD(b,a%b);
    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

int main() {
	int q;
	cin >> q;
	while(q--) {
		int n, cnt=0;
		cin >> n;
		while(n>=10 && cnt<10000) {
			int b = floor(log(n) / log(10.0));
			int maxi = 0;
			for(int i=0; i<b; i++) {
				int p = pow(10,i+1);
				int x = n % p;
				int y = (n-x) / p;
				maxi = max(maxi, x*y);
			}
			n = maxi;
			cnt++;
		}
		cout << (cnt==10000 ? -1 : cnt) << endl;
	}
	return 0;
}

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

  while(true){
    int n;   cin >> n;
    if(n == 0)   break;

    vector<long> a(n);
    for(int i = 0 ; i < n ; i++)   cin >> a[i];
    sort(a.begin() , a.begin() + n);

    long ans = 1000000;
    for(int i = 1 ; i < n ; i++)
      ans = min(ans , a[i] - a[i - 1]);

      cout << ans << endl;
    }

  return 0;
}



Measured memory_bytes: 3152
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	string s;
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 3640
S = input()
ans = "AC"

if S[0] != 'A':
 ans = "WA"

if S[2:-1].count('C') != 1:
 ans ="WA"

err=0
for s in S:
 if s < 'a' or s >'z':
  err +=1
 
if err !=2:
 ans ="WA"

print(ans)
 



Measured memory_bytes: 2940
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	double X[10], Y[10];
	rep(i,0,N) cin >> X[i] >> Y[i];
	vector<ll> v(N);
	iota(v.begin(), v.end(), 0);
	double ans = INF;
	const double PI = atan2(0, -1);
	do{
		double res = 0.0;
		double vy = Y[v[0]], vx = X[v[0]];
		double a1 = atan2(0.0, 1.0);
		double a2 = atan2(vy, vx);
		double diff = abs(a1 - a2);
		// print(diff);
		if(diff > PI) diff = abs(diff - 2*PI);
		res += diff * 180.0 / PI;
		// print(res);
		rep(i,0,N-1){
			double vy2 = Y[v[i+1]] - Y[v[i]];
			double vx2 = X[v[i+1]] - X[v[i]];
			a1 = atan2(vy, vx);
			a2 = atan2(vy2, vx2);
			diff = abs(a1 - a2);
			if(diff > PI) diff = abs(diff - 2*PI);
			res += diff * 180.0 / PI;
			vy = vy2;
			vx = vx2;
		}

		double vy2 = 0 - Y[v[N-1]];
		double vx2 = 0 - X[v[N-1]];
		a1 = atan2(vy, vx);
		a2 = atan2(vy2, vx2);
		diff = abs(a1 - a2);
		if(diff > PI) diff = abs(diff - 2*PI);
		res += diff * 180.0 / PI;

		ans = min(ans, res);


	}while(next_permutation(v.begin(), v.end()));
	cout << setprecision(10) << ans << endl;

}


Measured memory_bytes: 3516
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (W, H, N): (i64, i64, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (x, y, a): (Vec<i64>, Vec<i64>, Vec<usize>) = {
        let (mut x, mut y, mut a) = (vec![], vec![], vec![]);
        for _ in 0..N {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            x.push(iter.next().unwrap().parse().unwrap());
            y.push(iter.next().unwrap().parse().unwrap());
            a.push(iter.next().unwrap().parse().unwrap());
        }
        (x, y, a)
    };

    let l = (0..N).filter(|&i| a[i] == 1).map(|i| x[i]).max().unwrap_or(0);
    let r = (0..N).filter(|&i| a[i] == 2).map(|i| x[i]).min().unwrap_or(W);
    let t = (0..N).filter(|&i| a[i] == 3).map(|i| y[i]).max().unwrap_or(0);
    let b = (0..N).filter(|&i| a[i] == 4).map(|i| y[i]).min().unwrap_or(H);
    let ans = std::cmp::max(0, (r - l)) * std::cmp::max(0, (b - t));

    println!("{}", ans);
}


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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    vector<int> a(3);
    
    rep(i,3)cin>>a.at(i);
    
    sort(a.begin(),a.end());
    
    int co=0;
    rep(i,2){
        if(a.at(i)==a.at(i+1)){
            co++;
        }
    }
    
    if(co==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC156D
//
#include <iostream>
#include<cmath>
using namespace std;
// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
// aのb乗を計算する(MOD p)
long long Rcalc(long long a,long long b, long long p){
    if (b==0) {
        return 1;
    }
    if (b%2==0) {
        long long d=Rcalc(a,b/2,p);
        return (d*d)%p;
    }else{
        return (a*Rcalc(a,b-1,p))%p;
    }
}
int main(int argc, const char * argv[]) {
    const int MOD=1000000007;
    long long n,a,b;
    cin>>n>>a>>b;
    long long a_x=1;
    for (long long i=n; i>=(n-a+1); i--) {
        a_x*=i;
        a_x=a_x%MOD;
    }
    long long a_y=1;
    for (long long j=a; j>0; j--) {
        a_y*=j;
        a_y=a_y%MOD;
    }
    long long b_x=1;
    for (long long i=n; i>=(n-b+1); i--) {
        b_x*=i;
        b_x=b_x%MOD;
    }
    long long b_y=1;
    for (long long j=b; j>0; j--) {
        b_y*=j;
        b_y=b_y%MOD;
    }
    long long a_y_inv=Rcalc(a_y,MOD-2,MOD);
    long long as=a_x*a_y_inv%MOD;
    long long b_y_inv=Rcalc(b_y,MOD-2,MOD);
    long long bs=b_x*b_y_inv%MOD;
    long long ans=mod(mod(Rcalc(2,n,MOD)-1-as,MOD)-bs,MOD);
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  int i;
  int count = 0;
  for(i = 0; i < n; i++)
  {
    cin >> p.at(i);
  }
  for(i = 1; i < n-1; i++)
  {
    if((p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1))||(p.at(i+1) > p.at(i) && p.at(i) > p.at(i-1)))
    {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int  a, b, ab, o, d;
    char x[3];
    
    a = b = ab = o = 0;
      
    while(scanf("%d,%s", &d, x) != EOF)
        if     (x[0] == 'A' && x[1] == 'B')
            ab++;
        else if(x[0] == 'A')
            a++;
        else if(x[0] == 'B')
            b++;
        else
            o++;
            
    printf("%d\n%d\n%d\n%d\n", a, b, ab, o);
 
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	}
	int flag = 1;
	int tmp, time = 0;
	while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	}
	for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	}
	System.out.println("\n" + time);
    }
}



Measured memory_bytes: 26552
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <ctime>

using namespace std;

typedef pair<int, int> P;

const int D = 100;
const int M = 300;
const int S = 100;
const int INF = 1 << 29;

int dp1[S][S+1][M+1], dp2[2][M+1], kind[D], s, d, m;
vector<P> data[S];

main(){
  int t = 1;
  while(cin >> s >> d >> m){
    for(int i=0;i<s;i++){
      int n;
      cin >> n;
      data[i].clear();
      for(int j=0;j<n;j++){
        int a, b;
        cin >> a >> b;
        data[i].push_back(P(b, a));
      }
    }
    for(int i=0;i<d;i++) cin >> kind[i];
    fill(dp1[0][0], dp1[s][0], 0);
    for(int i=0;i<s;i++){
      for(int j=0;j<data[i].size();j++){
        for(int k=0;k<=m;k++){
          dp1[i][j+1][k] = max(dp1[i][j+1][k], dp1[i][j][k]);
          int tmp = data[i][j].first;
          if(k + tmp <= m) dp1[i][j+1][k+tmp] = max(dp1[i][j+1][k+tmp], dp1[i][j][k] + data[i][j].second);
        }
      }
    }
    fill(dp2[0], dp2[2], 0);
    for(int i=0;i<d;i++){
      for(int j=0;j<=m;j++){
        dp2[(i+1)%2][j] = max(dp2[(i+1)%2][j], dp2[i%2][j]);
        for(int k=0;j+k<=m;k++){
          dp2[(i+1)%2][j+k] = max(dp2[(i+1)%2][j+k], dp2[i%2][j] + dp1[kind[i]][data[kind[i]].size()][k]);
        }
      }
    }
    int ans1 = 0, ans2 = 0;
    for(int i=0;i<=m;i++){
      if(ans1 < dp2[d%2][i]){
        ans1 = dp2[d%2][i];
        ans2 = i;
      }
    }
    if(ans1 <= 0) cout << 0 << ' ' << 0 << endl;
    else cout << ans1 << ' ' << ans2 << endl;
  }
}

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

#define MAX_SIZE 1010

int lcm(string X, string Y) {
    int c[MAX_SIZE][MAX_SIZE];
    int m = X.size(), n = Y.size();
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int i = 1; i <= n; i++) c[0][i] = 0;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) c[i][j] = c[i - 1][j - 1] + 1;
            else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
        }
    }

    return c[m][n];
}

int main() {
    int q;
    cin >> q;
    string X, Y;
    for (int i = 0; i < q; i++) {
        cin >> X >> Y;
        cout << lcm(X, Y) << endl;
    }
    return 0;
}


Measured memory_bytes: 7060
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};


int main(){
    int n;
    cin >> n;
    cout << n / 3 << endl;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Text;
using System.Threading.Tasks;

namespace B_coins
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = new int[4];
            for (int i = 0; i < input.Length; i++) {
                input[i] = int.Parse(ReadLine());
            }
            int total = 0;
            int count = 0;
            for (int m = 0; m < input[0]+1; m++) {
              
                for (int n = 0; n < input[1]+1; n++) {
                
                    for (int l = 0; l < input[2]+1; l++) {
                        total = 500*m+100*n+50*l;
                        if (total == input[3]) {
                            count++;
                        }         
                    }
                }
            }
            WriteLine("{0}",count);
            ReadKey();
        }
    }
}


Measured memory_bytes: 13268
#include<cstdio>
using namespace std;
int a[105][105];
int b[10005];
int main() {
	int H, W, n;
	scanf("%d%d", &H, &W);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", b + i);
	}
	int x, y, temp;
	x = y = 0;
	bool right = true;
	for (int i = 1; i <= n; i++) {
		temp = b[i-1];
		while (temp--)
		{
			a[x][y] = i;
			if (right) {
				y++;
				if (y > W-1) {
					y = W-1;
					x++;
					right = false;
				}
			}
			else
			{
				y--;
				if (y < 0) {
					y = 0;
					x++;
					right = true;
				}
			}
		}
	}
	
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
				printf("%d", a[i][j]);
			if (j < W - 1)
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  char c;
  cin >> c;
  cout << (char) (c + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
A, B, K = map(int,input().split( ))
for i in range(K):
	if A%2 ==1:
		A =(A-1)//2 
		B = B + A
		A, B = B, A

	else:
		A = A//2
		B = B+A
		A,B = B,A
if K % 2 ==0:
	print(A,B)
else:
	print(B,A)


Measured memory_bytes: 3060
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        double r = scan.nextDouble();

        System.out.printf("%f %f\n", Math.pow(r, 2)*Math.PI, 2*r*Math.PI);
        scan.close();
    }
}

Measured memory_bytes: 28324
#include<bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    # define ll long long
    # define int long long  //comment it out when MLE
    //# define endl "\n"
    #define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //# define m 163577857
    # define mo 1000000007
    # define pi acos(-1)
    # define fi first
    # define se second
    #define REP(i,n) for (int i = 1; i <= n; i++)
    const ll mod = 998244353;
    //const int K = 2;
    //typedef vector<vector<int> > matrix;
    /*
    int add(int a, int b,int mod) {
        a%=mod;
        b%=mod;
        a += b;
        if (a >= mod) a -= mod;
        if(a<0)
        {
            a += mod;
            a %= mod;
        }
        return a;
    }

    int mul(ll a, int b,int mod) {
        a%=mod;
        b%=mod;
        a *= b;
        a += mod;
        return a % mod;
    }
    int po(int a,int b,int mod)
    {
        if(b==0)
            return 1;
        if(b%2==0)
            return po(mul(a,a,mod),b/2,mod);
        return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
    }


    ll fact[1000003];
    ll inv[1000003];

    void fact0()
    {
        int i,j;
        fact[0]=1;
        for(i=1;i<=600000;i++)
        {
            fact[i]=i*fact[i-1]%mod;
        }
        inv[0]=1;
        inv[1]=1;
        ll p=mod;
        for (i=2; i<=600000; i++)
            inv[i] = (p - (p/i) * inv[p%i] % p) % p;

        for(i=2;i<=600000;i++)
        {
            inv[i]*=inv[i-1];
            inv[i]%=mod;
        }
    }
    int help(int a,int b)
    {
       // cout<<a<<" "<<b<<endl;
        int an = fact[a];
        //cout<<an<<endl;
        an *= inv[b];
        an %= mod;
        an *= inv[a-b];
        an %= mod;
        return an;
    }
    */

signed main(){
       gok

  int n;
  cin>>n;
  int a[n+1];
  for(int i=0;i<=n;i++)
    cin>>a[i];
  int an=0;
  if(n==0)
  {
      if(a[0]==1)
        cout<<1;
      else
        cout<<-1;
  }
  else
  {
      if(a[0]==1)
        cout<<-1;
      else
      {
          bool ch=false;
          int dp[n+1]={0};
          for(int i=n;i>=0;i--)
          {
              if(i<n)
                dp[i]=dp[i+1];
              dp[i]+=a[i];
          }
          int an=0,li=1;
          for(int i=0;i<=n;i++)
          {
              if(li<a[i]){
                ch=true;
                break;
              }
               li = min(li,dp[i]);
              an += li;
              li -= a[i];
              li*=2;
          }
          if(ch)
            cout<<-1;
          else
          cout<<an;
      }
  }




















        return 0;
    }


Measured memory_bytes: 5208
// Ryo Kamoi
#define DEBUG

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>

using namespace std;

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int INF = 1000000000;

int n;
int w[110];
int rt, lt, output;
int main(){
  cin >> n;
  REP(i, n) {
    cin >> w[i];
  }

  rt = 0;
  REP(i, n) {
    rt += w[i];
  }

  lt = 0;
  output = rt;
  REP(i, n) {
    lt += w[i];
    rt -= w[i];
    output = min(output, abs(rt-lt));
  }
  cout << output << endl;
}


Measured memory_bytes: 256
import math

n,_,*a=map(int,open(0).read().split())
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a=sorted(a)

num=[0]*8

for d in a:
    num[match[d]]=d

dig=set(num)
dig.remove(0)
dig=sorted(list(dig),reverse=True)

dp=[-10**10]*(n+1)
dp[0]=0

for i in range(n+1):
    for d in dig:
        if i-match[d]<0:
            continue

        dp[i]=max(dp[i],dp[i-match[d]]+1)

ans=''

i=n
while i>0:
    for d in dig:
        if i-match[d]<0:
            continue
        if dp[i]==dp[i-match[d]]+1:
            ans=ans+str(d)
            break
    
    i-=match[d]

print(ans)

Measured memory_bytes: 73728
import java.util.Scanner;

public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int ans = solve(N, A);

        System.out.println(ans);
    }

    private static int solve(int N, int A) {
        int count = N*N - A;

        return count;
    }

}


Measured memory_bytes: 21844
#include <cstdio>
#include <vector>
#include <string>
#include <set>

bool valid(int R, int C, int S,
           const std::vector<int>& ind, const std::vector<int>& rou,
           const std::vector<int>& cur, const std::vector<int>& squ) {

  int r = 0;
  int c = 0;
  int s = 0;

  for (size_t i=0; i<ind.size(); ++i) {
    if (ind[i] != R*r + C*c + S*s) return false;
    r += rou[i];
    c += cur[i];
    s += squ[i];
  }
  return true;
}

int det(int r, int c, int s, const std::set<std::vector<int>>& sol) {
  int x = -2;
  for (const auto& v: sol) {
    int R = v[0];
    int C = v[1];
    int S = v[2];
    int y = R*r + C*c + S*s;
    if (x < -1) {
      x = y;
    } else if (x != y) {
      return -1;
    }
  }
  return x;
}

int testcase_ends() {
  size_t P, Q;
  scanf("%zu %zu", &P, &Q);

  if (P == 0 && Q == 0) return 1;

  std::vector<std::string> S(P), T(Q);
  for (size_t i=0; i<P; ++i) {
    char buf[96];
    scanf("%s", buf);
    S[i] = buf;
  }
  for (size_t j=0; j<Q; ++j) {
    char buf[96];
    scanf("%s", buf);
    T[j] = buf;
  }

  std::vector<int> ind(P), rou(P), cur(P), squ(P);
  for (size_t i=0; i<P; ++i) {
    size_t j = 0;
    while (S[i][j] == '.') ++j;
    ind[i] = j;

    for (; j<S[i].length(); ++j) {
      if (S[i][j] == '(') ++rou[i];
      if (S[i][j] == ')') --rou[i];
      if (S[i][j] == '[') ++cur[i];
      if (S[i][j] == ']') --cur[i];
      if (S[i][j] == '{') ++squ[i];
      if (S[i][j] == '}') --squ[i];
    }
  }

  std::set<std::vector<int>> sol;
  for (int R=1; R<=20; ++R)
    for (int C=1; C<=20; ++C)
      for (int S=1; S<=20; ++S)
        if (valid(R, C, S, ind, rou, cur, squ))
          sol.insert({R, C, S});

  int r = 0;
  int c = 0;
  int s = 0;
  for (size_t i=0; i<Q; ++i) {
    printf("%d%c", det(r, c, s, sol), i+1<Q? ' ':'\n');

    for (size_t j=0; j<T[i].length(); ++j) {
      if (T[i][j] == '(') ++r;
      if (T[i][j] == ')') --r;
      if (T[i][j] == '[') ++c;
      if (T[i][j] == ']') --c;
      if (T[i][j] == '{') ++s;
      if (T[i][j] == '}') --s;
    }
  }
  
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3416
#include<iostream>
#include <string.h>
#include <algorithm>
#include<cstdlib>
typedef long long ll;
using namespace std;

int main()
{
    int a[1000],b[1000],n,h,w,ans=0;
    cin >> n >> h >> w;

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

        if(a[i] >= h && b[i] >= w){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int p,q,r,min;
  cin >> p >> q >> r;
  min = p + q;
  if(min > q + r) min = q+r;
  if(min > p + r) min = p+r;
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 200010
int n,a[N],b[N],c[N],d[N];
int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n+1)c[i]=d[i]=0;
    rep(i,n)c[a[i]]++,d[b[i]]++;
    rep(i,n+1){
	if(c[i]+d[i]>n){
	    cout<<"No\n";
	    return 0;
	}
    }
    for(int i=1;i<=n;i++){
	c[i]+=c[i-1];
	d[i]+=d[i-1];
    }
    int x=0;
    for(int i=1;i<=n;i++)x=max(x,c[i]-d[i-1]);
    cout<<"Yes\n";
    rep(i,n){
	if(i)cout<<" ";
	cout<<b[(i+n-x)%n];
    }
    cout<<"\n";
}

Measured memory_bytes: 6680
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int r1, c1, r2, c2;
    scan(r1, c1, r2, c2);

    auto mc = ModComb(2 * 10^^6 + 100);

    long ans;

    foreach (i ; c1 .. c2 + 1) {
        ans += mc.c(r2 + i + 1, r2) - mc.c(r1 + i, r1 - 1) + mod;
        ans %= mod;
    }

    writeln(ans);
}


struct ModComb {
    int _N;
    long[] _fact, _factinv;
    long _mod;

    this(int n, long mod = 1_000_000_007L) {
        _N = n;
        _fact = new long[](_N + 1);
        _factinv = new long[](_N + 1);
        _mod = mod;

        _fact[0] = 1;
        foreach (i ; 1 .. _N + 1) {
            _fact[i] = (_fact[i-1] * i) % mod;
        }

        _factinv[_N] = _powmod(_fact[_N], mod - 2);
        foreach_reverse (i ; 0 .. _N) {
            _factinv[i] = (_factinv[i+1] * (i+1)) % mod;
        }
    }

    long c(int n, int k) {
        if (k < 0 || k > n) return 0;
        return f(n) * finv(n - k) % _mod * finv(k) % _mod;
    }

    long p(int n, int r) {
        if (r < 0 || r > n) return 0;
        return f(n) * finv(n - r) % _mod;
    }

    long f(int n) {
        return _fact[n];
    }

    long finv(int n) {
        return _factinv[n];
    }

    long _powmod(long x, long y) {
        return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
    }
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 34684
#include<bits/stdc++.h>
using namespace std;
long long f(long long t){
  if(t%4==0){
    return 0^t;
  }
  else if(t%4==1){
    return 1;
  }
  else if(t%4==2){
    return 1^t;
  }
  else{
    return 0;
  }
}
int main(){
  long long a,b,ans;
  cin >> a >> b;
  ans=f(a-1)^f(b);
  cout << ans << endl;
}

Measured memory_bytes: 256