akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while (true) {
			String x = sc.nextLine();
			int y = 0;
			if (x.equals("0") == true) {
				break;
			}
			for (int i = 0; i < x.length(); i++) {
				y += x.charAt(i) - '0';
			}
			System.out.println(y);
		}
		sc.close();
	}

}


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

typedef long long ll;

int main()
{
    int i,j;
    int n;
    cin >> n;
    int ans = 0;
    for(i = 105;i <= n;i += 2){
        int temp = 0;   
        for(j = 1;j <= i;++j){
            if(i%j == 0 && i/j != j){
                ++temp;
            }
        }
        if(temp == 8){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int s = scan.nextInt();
    difficulty(s, 4);
  }

  public static void difficulty(int num, int left) {
    int last = num % 10;
    int rest = num / 10;

    if (rest == 0 && left == 1) {
      System.out.println("Good");
    } else if (last == rest % 10) {
      System.out.println("Bad");
    } else {
      difficulty(rest, left - 1);
    }
  }
}


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

int main(void) {
	char words[1200];
	//??????????????\???
	fgets(words, sizeof(words), stdin);
	int i;
	//????????°???????????????
	int cnt=0;
	for (i = 0; i < strlen(words); i++) {
		//??§?????????????°??????????????°???????????????§???????????????
		if (words[i] >= 'a') {
			words[i] = toupper(words[i]);
		}
		else if (words[i] <= 'Z'){
			words[i] = tolower(words[i]);
		}
	}
	printf("%s",words);
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    ll n;
    std::cin >> n;
    std::vector<ll> sum(n, 0);
    std::cin >> sum[0];
    for(int i = 1; i < n; i++){
        std::cin >> sum[i];
        sum[i] += sum[i - 1];
    }

    ll minVal = 100000000000000000;
    for(int i = 0; i < n - 1; i++){
        ll x = sum[i];
        ll y = sum[n - 1] - sum[i];
        minVal = std::min(minVal, std::abs(x - y));
    }
    std::cout << minVal << std::endl;
    return 0;
}


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        int[] ary=new int[10000];
        boolean big=false,flag=true;
        ary[0]=2;
        int i=3,j=0;
        for(;i<1000000;i++){
            flag=true;
            if(ary[j]>=x)break;
            for(int k=0;k<=j;k++){
                if(i%ary[k]==0){
                    flag=false;
                    break;
                }
            }
            if(flag){
                j++;
                ary[j]=i;
            }
        }
        System.out.println(ary[j]);
    }
}

Measured memory_bytes: 23636
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod=1e9+7;
ll inf=1e18;

/*
AC
*/

struct d{
	ll a,b,c;
};

int main(void){
	ll n,r,sum=0;
	vector<d> ans;
	cin>>n;
	irep(i,20){
		if(n-1 >= (1<<i)-1){
			r = i+1;//r=点の数
			n -= 1<<i;
			sum += 1<<i;
			break;
		}
	}
	while(n>0){
		irep(i,20){
			if(n-1 >= (1<<i)-1){
				ans.push_back({r-2,i-1,sum});
				n -= 1<<i;
				sum += 1<<i;
				break;
			}
		}
	}
	reg(i,-1,r-2){
		if(i!=-1){
			ans.push_back({i,i-1,1<<i});
			ans.push_back({i,i-1,0});
		}
	}
	rep(i,ans.size()){
		ans[i].a=r-ans[i].a-1;
		ans[i].b=r-ans[i].b-1;
	}
	printf("%lld %lu\n",r,ans.size());
	rep(i,ans.size()){
		printf("%lld %lld %lld\n",ans[i].a,ans[i].b,ans[i].c);
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef long long LL;

int read()
{
    int x=0,flag=1;
    char c=getchar ();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

typedef pair<LL,LL> P;
P a[105];
int n;

int main()
{
    //freopen("input.txt","r",stdin);
    n=read();
    REP(i,1,n)
    {
        int x=read(),y=read();
        a[i]=P(x,y);
    }
    sort(a+1,a+n+1,[&](P x,P y) {
         return atan2(x.second,x.first)<atan2(y.second,y.first);});
    LL ans=0;
    REP(i,1,n)
    {
        int j=i;
        LL x=0,y=0;
        REP(k,1,n)
        {
            x+=a[j].first;
            y+=a[j++].second;
            if(j>n) j=1;
            ans=max(ans,x*x+y*y);
        }
    }
    printf("%.12f",sqrt(ans));

	return 0;
}


Measured memory_bytes: 256
// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int t, s, d; } T;
T tbl[20002];
char f[20002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define THRESHOLD 10
#define STACKSIZE 35		// 2^32 for int

void quicksort(T *a, int n)
{
	int i, j, l, r, p;
	int lsp[STACKSIZE], rsp[STACKSIZE];
	T t, *m;
	
	l = 0, r = n-1, p = 0;
	while (1) {
		if (r-l <= THRESHOLD) {
			if (!p--) break;
			l = lsp[p], r = rsp[p];
		}
		m = a + ((l+r)>>1);
		i = l, j = r;
		while (1) {
			while (a[i].t < m->t) i++;
			while (m->t < a[j].t) j--;
			if (i >= j) break;
			t = a[i], a[i] = a[j], a[j] = t;
			i++, j--;
		}
		if (i-l > r-j) {
			if (i-l > THRESHOLD) {
				lsp[p] = l;
				rsp[p] = i-1;
				p++;
			}
			l = j+1;
		} else {
			if (r-j > THRESHOLD) {
				lsp[p] = j+1;
				rsp[p] = r;
				p++;
			}
			r = i-1;
		}
	}
	
	// insert sorting
	for (i = 1; i < n; i++) {
		t = a[i];
		for (j = i-1; j >= 0 && a[j].t > t.t; j--) a[j+1] = a[j];
		a[j+1] = t;
	}
}

int main()
{
	int n, m, i, ans;
	register T *t;
	char *q;

	while (n = in()) {
		m = in();
		memset(f, 0, n+1);
		t = tbl, i = m; while (i--) {
			t->t = in(), t->s = in(), t->d = in();
			t++;
		}
		quicksort(tbl, m);
		f[1] = 1, t = tbl, i = m;
		while (i--) f[t->d] |= f[t->s], t++;
		ans = 0, q = f+1, i = n; while (i--) ans += *q++;
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 1984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var n = Console.ReadLine();
        long sum = n.ToCharArray().Select(e => int.Parse(e.ToString())).Sum();
        if (sum % 9 == 0)
        {
            Console.WriteLine("Yes");
            return;
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 33832
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        300005
#define mod         998244353  
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,y,count=0;
    cin>>n;
    ll x=100;
    while(x<n){
        count++;
        y=x+x/100;
        x=y;
    }
    cout<<count;
}

Measured memory_bytes: 3608
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let S = xs[0].split('');
   let w = parseInt(xs[1]);
   let str =[];
   for(let i=0; i<S.length; i++){
      if(i%w==0){
      str.push(S[i]);
      }
   }
   let ans ='';
   str.forEach(element => ans+=(element));
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 9420
#include <iostream>

using namespace std;
const int mxn=1e5+100;
int a[mxn],dp[mxn],n,k;
bool cal[mxn];
int abs (int x)
{
    return (x>0?x:-x);
}
int dpf (int x)
{

    if (cal[x]==true)
        return dp[x];
    cal[x]=true;
    dp[x]=dpf(x-1)+abs(a[x]-a[x-1]);
    for (int i=1;i<=k;i++)
        if (x>i-1)
            dp[x]=min(dp[x],dpf(x-i)+abs(a[x]-a[x-i]));
    return dp[x];
}
int main()
{
    cin>>n>>k;
    cal[0]=true;
    for (int i=0;i<n;i++)
        cin>>a[i];
    cout<<dpf(n-1);
    return 0;
}


Measured memory_bytes: 5888
#include <iostream>

#define MAX (1000000)
#define NIL (-1) // 番兵用node id

using namespace std;

struct Node {
	int parent, left, right;
};

struct Node T[MAX];
int n, D[MAX];

void print(int u) {
	int i,c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].parent << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].parent == NIL) cout << "root, ";
	else if (T[u].left == NIL) cout << "leaf, ";
	else cout << "internal node, ";

	cout << "[";
	for (int i=0, c = T[u].left; c != NIL; ++i, c = T[c].right) {
		if (i) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

/// 深さの決定
int rec(int u, int p) {
	D[u] = p;
	if (T[u].right != NIL) rec(T[u].right, p); // 右の兄弟に同じ深さを設定
	if (T[u].left  != NIL) rec(T[u].left, p+1);// 最も左の子に自分の深さ+1を設定
}

int main() {
	int n;
	cin >> n;
	for (int i=0; i<n; ++i) {
		T[i].parent = T[i].left = T[i].right = NIL; 
	}
	/// 順番に処理
	for (int i=0; i<n; ++i) {
		// id vとchildの個数kを読み込み
		int v,k; 
		cin >> v >> k; 
		for (int j=0;j<k; ++j) {
			// childがあるときにchild idを読み込み
			int child_id;
			cin >> child_id;
			int l;
			// このnode vのmost left child に対して child_idを設定
			if (j == 0) T[v].left = child_id;
			// ひとつ前のchild idの1つ右の兄弟として, このchild_idを設定
			else T[l].right = child_id;
			// node vのchild idを取っておく
			l = child_id;
			// node vのchild のparentはnode vである
			T[child_id].parent = v;
		}
	}
	/// root nodeの決定 
	int root_node = 0;
	for (int i=0; i<n; ++i) {
		if (T[i].parent == NIL) root_node = i; 
	}
	/// root nodeからのdepthの決定
	rec(root_node, 0); // root_nodeのdepth = 0
	// print
	for (int i=0;i<n;++i) print(i);
	return 0;
}



Measured memory_bytes: 7664
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007



using namespace std;

int main()
{
    char tab[51];
    int n,rep=0;
    cin>>n;
    for(int i=0;i<n;i++)cin>>tab[i];
    for(int i=0 ; i<n-2 ;i++){
      if(tab[i]=='A' && tab[i+1]=='B' && tab[i+2]=='C'){
        rep++;
        i+=2;
       }
    }
    cout<<rep;

  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n);

  map<i64, i64> mp;
  for (i64 x : a) mp[x]++;

  i64 ans = 0;
  for (auto it = mp.rbegin(); it != mp.rend(); ++it) {
    i64 x, c;
    tie(x, c) = *it;
    i64 y = 1;
    for (; y <= x; y <<= 1);
    if (2 * x == y) {
      i64 s = c / 2;
      ans += s;
      mp[x] -= 2 * s;
    } else {
    i64 s = min(c, mp[y - x]);
      ans += s;
      mp[y - x] -= s;
    }
  }

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

Measured memory_bytes: 87168
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x;
    cin>>x;
    if(x>=30)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>


using namespace std;
typedef long long int lli;

int main() {
	int N, C;

    cin >> N >> C;

	vector<vector<lli>> D;
	for(int i=0; i<C; i++) {
		vector<lli> di;
		for(int j=0; j<C; j++) {
			lli dij;
			cin >> dij;
			di.push_back(dij);
		}
		D.push_back(di);
	}

	vector<vector<int>> c_dist;
	for(int i=0; i<3; i++) {
		vector<int> ccc(C, 0);
		c_dist.push_back(ccc);
	}

	for(int i=0; i<N; i++) {
		for(int j=0; j<N; j++) {
			int cij;
			cin >> cij;
			c_dist[(i+1+j+1)%3][cij-1]++;
		}
	}

	lli ans = numeric_limits<lli>::max();
	for(int c1=0; c1<C; c1++) {
		for(int c2=0; c2<C; c2++) {
			for(int c3=0; c3<C; c3++) {
				if(c1 == c2 || c2 == c3 || c3 == c1) {
					continue;
				}
				lli incomp = 0;
				for(int cc=0; cc<C; cc++) {
					incomp += c_dist[0][cc] * D[cc][c1];
					incomp += c_dist[1][cc] * D[cc][c2];
					incomp += c_dist[2][cc] * D[cc][c3];
				}
				ans = min(incomp, ans);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main(){
    int n;
    cin>>n;
    int res=n%1000;
    if (res==0){
        cout<<0<<endl;
    }
    else{cout<<1000-n%1000<<endl;}
    
    return 0;
}

Measured memory_bytes: 3620
N= int(input())
l=list(map(int,input().split()))
if N == 2:
   if l[0] == l[1]:
      print(1)
      exit()
   else:
      print(0)
      exit()
l1=[l[i] for i in range(N) if i%2==0]
l2=[l[i] for i in range(N) if i%2==1]
import collections
flag=0
l1=collections.Counter(l1).most_common()
l2=collections.Counter(l2).most_common()
if l1[0][0] == l2[0][0]:
   if l1[0][1] == l2[0][1]:
      try:
         ans=N-l1[0][1]-max(l1[1][1],l2[1][1])
      except IndexError:
         ans=N//2
      print(ans)
   elif l1[0][1] > l2[0][1]:
      print(N-l1[0][1]-l2[1][1])
   elif l1[0][1] < l2[0][1]:
      print(N-l1[1][1]-l2[0][1])
else:
   print(N-l1[0][1]-l2[0][1])

Measured memory_bytes: 20596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, u, v, res, d[100000];
vector<int>V[100000];

void dfs(int x, int from, int dist) {
	d[x] = dist;
	for (int i : V[x]) {
		if (i == from)continue;
		dfs(i, x, dist + 1);
	}
}

void dfs2(int x, int from, int dist) {
	if (dist < d[x])res = max(res, d[x] - 1);
	for (int i : V[x]) {
		if (i == from || i == v)continue;
		dfs2(i, x, dist + 1);
	}
}

int main() {
	cin >> N;
	cin >> u >> v;
	u--;
	v--;
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	if (u == v) {
		cout << 0 << endl;
	}
	else {
		dfs(v, -1, 0);
		dfs2(u, -1, 0);
		cout << res << endl;
	}
}



Measured memory_bytes: 9984
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int cap[110], value[110];
int dp[110][10010];

int main() {
    int N, C; scanf("%d%d", &N, &C);
    for(int i=1; i<=N; i++) {
        scanf("%d%d", &value[i], &cap[i]);
    }

    // dp 配列を -1 埋めする (-1 はありえない状態を表す)
    memset(dp, -1, sizeof(dp));

    // 何も足しあわせないと価値合計は 0
    dp[0][0] = 0;

    for(int i=1; i<=N; i++) {
        for(int j=0; j<=C; j++) {
            // i 番目までの要素を組み合わせて容量合計が j である状態

            // 足しあわせない (前で合計が j の状態を参照)
            dp[i][j] = max(dp[i][j], dp[i-1][j]);

            // 足し合わせる (前で合計が j - value[i] の状態を参照)
            // 合計が負の状態はありえない！
            if(j - cap[i] >= 0 && dp[i-1][j - cap[i]] != -1) {
                dp[i][j] = max(dp[i][j], dp[i-1][j - cap[i]] + value[i]);
            }
        }
    }

    // 各容量合計における最大値をすべてみて、その最大値を答えとする
    int ans = 0;
    for(int i=0; i<=C; i++) {
        ans = max(ans, dp[N][i]);
    }
    printf("%d\n", ans);
    return 0;
}




Measured memory_bytes: 7064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B;
    cin >> A >> B;
    cout << (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0 ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,w[200],cnt=0;
int sum=0,minv=INF;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>w[i];
        sum+=w[i];
    }
    rep(i,n){
        minv=min(minv,abs(sum-2*cnt));
        cnt+=w[i];
    }
    cout<<minv<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll k,x,y;
cin >> k >>x>>y;
if(k%2==0&&abs(x+y)%2==1){
cout << -1 << endl;
return 0;
}
ll xx=1,yy=1;
if(x<0){x=-x;xx=-1;}
if(y<0){y=-y;yy=-1;}

vector<ll> vx,vy;
ll nowx=0,nowy=0;
ll zan=abs(x-nowx)+abs(y-nowy);
//assert(zan>=k*2||k%2==0);


while(zan>2*k || zan%2==1 ){
  if(nowx==x){
    nowy+=k;
  }
  else if(nowx+k<=x){
    nowx+=k;
  }
  else{
    nowy+=k-x+nowx;
    nowx=x;
  }
  zan=abs(x-nowx)+abs(y-nowy);
  if(zan==0){
    cout << 1 << endl;
    cout << x*xx << " " << y*yy << endl;
    return 0;
  }
  vx.push_back(nowx);
  vy.push_back(nowy);
}
if(nowy>y&&zan!=k){
  vx.push_back(nowx-k+zan/2);
  vy.push_back(nowy-zan/2);
}
else if(abs(x-nowx)>abs(y-nowy)&&zan!=k){
  vx.push_back(nowx+zan/2);
  vy.push_back(nowy-k+zan/2);
}
else if(abs(x-nowx)<=abs(y-nowy)&&zan!=k){
  vx.push_back(x+k-zan/2);
  vy.push_back(y-zan/2);
}
vx.push_back(x);
vy.push_back(y);


cout << vx.size() << endl;
rep(i,vx.size()){
cout << vx[i]*xx << " " << vy[i]*yy << endl;
}
return 0;
}


Measured memory_bytes: 5604
from collections import defaultdict

S=input()
T=input()
L=len(S)

dds=defaultdict(int)
ddt=defaultdict(int)

for i in range(L):
    s=S[i]
    t=T[i]
    if dds[s]==0:
        dds[s]=t
    else:
        if dds[s]!=t:
            print("No")
            exit()
    if ddt[t]==0:
        ddt[t]=s
    else:
        if ddt[t]!=s:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 4144
#23:29
n,m = map(int,input().split())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
cnt = [0 for _ in range(n)]
for _ in range(m):
  a,x = map(int,input().split())
  a -= 1
  cnt[a] += x
now = [0]
seen = [0 for _ in range(n)]
seen[0] = 1
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if seen[y] == 0:
        seen[y] = 1
        now.append(y)
        cnt[y] += cnt[x]
print(' '.join(list(map(str,cnt))))

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pii pair<int, pi>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 3001

signed main()
{
  lli n, k;
  cin >> n >> k;
  cout << min(n, min(abs(n - k), min(n % k, k - (n % k)))) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>

using namespace std;

#define int long long
#define MAX 1e18

signed main() {
    int n;
    cin >> n;
    

    if(n % 10 == 3) {
        cout << "bon" << endl;
        return 0;
    } else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
        cout << "pon" << endl;
        return 0;
    } else {
        cout << "hon" << endl;
        return 0;
    }
}

Measured memory_bytes: 3572
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++)
			h[i] = sc.nextInt();
		int ans = h[0];
		for (int i = 0; i < N - 1; i++) {
			if (h[i + 1] > h[i])
				ans += h[i + 1] - h[i];
		}
		System.out.println(ans);
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


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

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


Measured memory_bytes: 256
n = map(int, raw_input().split())
x = map(int, raw_input().split())
x.sort(reverse = True)
#print x
sum = 0
if n[0]%2==0:
    for i in range(0, n[0]):
        sum = sum +x[i*2+1]
        #print i
elif n[0]%2!=0:
    for i in range(0, (n[0]-1+1)):
        sum = sum +x[i*2+1]
print sum


Measured memory_bytes: 28752
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N - 1, 1, -1):
    for j in range(i - 1, 0, -1):
        x = bisect.bisect(L, L[i] - L[j])
        ans += max((j - x), 0)

print(ans)


Measured memory_bytes: 9248
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        //string[] arr = Console.ReadLine().Split(' ');
        int N = int.Parse(Console.ReadLine());
        string[] arr = Console.ReadLine().Split(' ');
        int cnt = 0;
        int min = int.Parse(arr[0]);
        for (int i = 0; i < N; i++)
        {
            int a = int.Parse(arr[i]);

            if(a <= min)
            {
                cnt++;
                min = a;
            }
        }

        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 32220
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int N;
    scanf("%d", &N);
    vector<vector<int> > abc(N+1, vector<int>(3));
    rep(i, N) scanf("%d%d%d", &abc[i][0], &abc[i][1], &abc[i][2]);
    int dp[N+1][3] = {};
    rep(i, N){
        dp[i+1][0] = max(dp[i][1]+abc[i][0], dp[i][2]+abc[i][0]);
        dp[i+1][1] = max(dp[i][0]+abc[i][1], dp[i][2]+abc[i][1]);
        dp[i+1][2] = max(dp[i][0]+abc[i][2], dp[i][1]+abc[i][2]);
    }
    int ans = max(dp[N][0], max(dp[N][1], dp[N][2]));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <vector>

using namespace std;
int main()
{
    int N,H,W;
    
    cin >> N >> H >> W;
    
    vector<int> A(N);
    vector<int> B(N);
    int c=0;
    
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
        if(A[i] >= H && B[i] >=W)c++;
    }

    cout << c <<endl;
    return 0;
    
}


Measured memory_bytes: 256
S = input()

length_S = len(S)

S_check = []

count = 0

for i in range(length_S):
  if i % 2 == 0:
    S_check.append("0")
  else:
    S_check.append("1")

for i in range(length_S):
  if S[i] == S_check[i]:
    count += 1

print(min(count, length_S-count))

Measured memory_bytes: 3956
fun main(args: Array<String>) {
    abc153e()
}

fun abc153e() {
    val (h, n) = readLine()!!.split(' ').map { it.toInt() }
    val magics = (1..n)
        .map { readLine()!!.split(' ').map { it.toInt() }.let { Magic(it[0], it[1]) } }

    val dp = Array(n + 1) { IntArray(h + 1) { Int.MAX_VALUE / 10 } }
    dp[0][0] = 0

    for (i in 0 until n) {
        val (dmg, mp) = magics[i]
        for (j in 0..h) {
            dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j])
            val next = Math.min(j + dmg, h)
            dp[i + 1][next] = Math.min(dp[i + 1][next], dp[i + 1][j] + mp)
        }
    }

    val answer = dp[n][h]

    println(answer)
}

private data class Magic(val damage: Int, val mp: Int)


Measured memory_bytes: 87424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int A[100000], B[100000];
	rep(i, N) cin >> A[i] >> B[i];

	ll kotae = 0;
	for(int i = N - 1; i >= 0; i--) {
		ll k = (A[i] + kotae + B[i] - 1) / B[i] * B[i];
		kotae += k - A[i] - kotae;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n, m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x, y) memset((x),(y),sizeof (x))
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define    outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a, b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double> point;
typedef tuple<int, int, int> line;
typedef pair<point, point> segment;
typedef vector<point> polygon;
const int N = 1e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
int n, k, memo[N][2], arr[105];
bool solve(int rem, int plyr)
{
    if(!rem && plyr == 1)
        return true;
    else if(!rem)
        return false;
    int &ret = memo[rem][plyr];
    if(~ret)
        return ret;
    ret = plyr;
    bool one = false;
    for(int i = 0 ; i < n ; i++)
        if(rem >= arr[i])
            one = true, ((!plyr)? ret |= solve(rem - arr[i], 1 - plyr) : ret &= solve(rem - arr[i], 1 - plyr));
    if(!plyr)
        ret &= one;
    return ret;
}
int main()
{
    MuhammedAly
    mem(memo, -1);
    cin >> n >> k;
    for(int i = 0 ; i < n ; i++)
        cin >> arr[i];
    if(solve(k, 0))
        cout << "First";
    else
        cout << "Second";
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  set<int> prime_list;
  for(int i = 2; i <= 100000; ++i){
    bool f = true;
    for(auto e:prime_list){
      if(e*e > i)break;
      f &= i % e != 0;
    }
    if(f){
      prime_list.insert(i);
    }
  }
  vector<int> v(100001);
  for(int i = 1; i <= 100000; ++i){
    v[i] = v[i-1] + (i%2==1&&prime_list.count(i)&&prime_list.count((i+1)/2));
  }
  int q; cin >> q;
  for(int i = 0; i < q; ++i){
    int l,r; cin >> l >> r;
    cout << v[r] - v[l-1] << endl;
  }
}



Measured memory_bytes: 4068
N = int(input())

heights = list(map(int, input().split()))


cnt_height_plus_ind = {}
cnt_ind_minus_height = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

ans = 0
for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

print(ans)

Measured memory_bytes: 57532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int x;
	cin >> x;
	cout << 1 - x << endl;

	return 0;
}

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

int main() {
    int L,R,d;
    int cnt = 0;
    cin>> L >> R >> d;

    for (int i=L;i<=R;i++){
        if (i % d == 0){
            cnt++;
        }
    }

    cout << cnt << endl;


}


Measured memory_bytes: 3588
#include <stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0
  
int  b[N][N] = {};
int r[N] = {}, c[N] = {}, dpos[2*N-1] = {}, dneg[2*N-1] = {};
int pQ(int i){
  int j, k, l;
  if(i == N){
      for(k = 0; k < N; k++){
      for(l = 0; l < N; l++){
	if(b[k][l] == FREE){
	  printf(".");
	}
	else{
	  printf("Q");
	}
	}
      printf("\n");
    }
      return;
    }
  if(r[i] == NOT_FREE){
    pQ(i+1);
  }
    else{
      for(j = 0; j < N; j++){
	if(c[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
	  continue;
	}
	  c[j] = dpos[i+j] = dneg[i-j+N-1] = b[i][j] = NOT_FREE;
      pQ(i+1);
      c[j] = dpos[i+j] = dneg[i-j+N-1] = b[i][j] = FREE;
    }
    }
}

int main(){
  int i, j;
  int k, r1, c1;
  scanf("%d", &k); 
  for(i = 0; i < k; i++){
      scanf("%d %d", &r1, &c1); 
      b[r1][c1] = r[r1] = c[c1] = dpos[r1+c1] = dneg[r1-c1+N-1] = NOT_FREE;
    }   
  pQ(0);
  return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

class Main {
	public static void main(String... args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long somma = 0;
		for(int i=1; i<=N; ++i){
			if(i%3!=0 && i%5!=0) somma+=i;
		}
		System.out.print(somma);
	}
}


Measured memory_bytes: 35728
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <int> v(n);
    generate(all(v),nxt);
    int test=-1;
    int cur=1;
    for(int i=1;i<1e5+1;i++)
    {
        cur=v[cur-1];
        if(cur==2)
        {
            test=i;
            break;
        }
    }
    cout<<test<<endl;
    
    
    return 0;   
}




 
 


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    print1(n+n*n+n*n*n);
    return 0;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 102;
bool v[T];

int main() {
    ios_base::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    while(k--) {
        int x; cin >> x;
        while(x--) {
            int y; cin >> y;
            if(!v[y]) n--;
            v[y] = 1;
        }
    }
    cout << n << endl;
    return 0;
}



Measured memory_bytes: 3592
class SegTree:
    X_unit = 1 << 30
    X_f = min

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)
      
N, Q=map(int,input().split())
S1=SegTree(N)
S2=SegTree(N)

S1.build([N]*N)
S2.build([N]*N)
ans=(N-2)**2

for i in range(Q):
  j, x=map(int,input().split())
  if j==1:
    l=S2.fold(x-1,N)
    ans-=l-2
    S1.set_val(l-1,min(x,S1.X[l-1+N]))
  if j==2:
    l=S1.fold(x-1,N)
    ans-=l-2
    S2.set_val(l-1,min(x,S2.X[l-1+N]))
    
print(ans)

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


int main()
{
	int a, b, c, x;
	cin >> a;
	cin >> b;
	cin >> c;
	x = (a + b);
	if (x >= c)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
    return 0;
}



Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

min_diff = 10**9
for i in range(n):
    diff = abs(a - (t - h[i]*0.006))
    if min_diff > diff:
        min_diff = diff
        ans = i
print(ans+1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007;
const int maxn = 1e5+1000;
int n,m,a;
struct node 
 {
 	ll tt;
 	int pp;
 	int id;
 } t[maxn];
 bool cmp(node a,node b)
 {
 	return a.tt <= b.tt;
 }
ll p,y;
int s[maxn];
int pre[maxn];
int  en[maxn];
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(s,0,sizeof s);
	  for(int i=0;i<m;i++)
		{
			cin>>p>>y;
			t[i].tt = y; 
			t[i].pp = p;
			t[i].id = i;
		}
		sort(t,t+m,cmp);
	  for(int i=0;i<m;i++)
		{
			pre[t[i].id] = t[i].pp;
			en[t[i].id] = ++s[t[i].pp]; 
		}
	 for(int i=0;i<m;i++)
		{
			printf("%06d%06d\n",pre[i],en[i]);
		}
 
	}
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


struct UnionFind {
	vector<int> par;
  
  UnionFind(int N): par(N){
  	for(int i=0;i<N;i++) par[i] =i;
  }
};





int main(){
  ios::sync_with_stdio(false);
  
  int N;
  cin>>N;
  bool ans = false;
  
  rep(i,9){
  	rep(j,9){
    	if((i+1)*(j+1)==N) ans=true;
    }
  }
  if(ans) cout<<"Yes";
  else cout<<"No";
  
}

Measured memory_bytes: 256
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cin4(x, y, z, _) cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q) cin >> x >> y >> z >> p >> q
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t cin1(_t); rep(i, 0, _t)

struct point{    int x, y, ind;   char ch;  };
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
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;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
bool cmp(point A, point B){   if(A.x != B.x) ret(A.x < B.x);  ret(A.y < B.y);   }
// head collected

ll n, m, _, __, u, v;
char ara_a[55][55];
char ara_b[55][55];

bool check(ll u, ll v){
    rep(i, 1, m+1)
        rep(j, 1, m+1)
            if( ara_b[ i ][ j ] != ara_a[ i + u - 1 ][ j + v - 1 ] )
                ret(false);

    ret(true);
}

bool solve()
{
    rep(i, 1, n-m+2)
        rep(j, 1, n-m+2)
            if ( ara_a[ i ][ j ] == ara_b[ 1 ][ 1 ] )
                if( check(i, j) )
                    ret(true);

    ret(false);
}

start;

    cin2(n, m);

    rep(i, 1, n+1)
        rep(j, 1, n+1)
            cin1(ara_a[ i ][ j ]);

    rep(i, 1, m+1)
        rep(j, 1, m+1)
            cin1(ara_b[ i ][ j ]);


    if( solve() )
        coul("Yes");
    else
        coul("No");


finish


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

AB = [(a, b) for a, b in zip(A, B)]
AB.sort(key=lambda D: D[1] - D[0])

ans = 0
plus = 0
for a, b in AB[:: -1]:
    if a - b >= 0:
        break
    plus += b - a
    ans += 1

for a, b in AB:
    if a - b <= 0 or plus <= 0:
        break
    plus -= a - b
    ans += 1

if plus > 0:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 22964
f = lambda: list(map(int,input().split()))

n,a = f()
x = [int(x)-a for x in input().split()]
w = max(max(x),abs(min(x)),a)*n
dp = [[0 for _ in range(2*w + 1)] for _ in range(n+1)]
dp[0][w] = 1
for i in range(n):
    for j in range(2*w + 1):
        if 0 <= j-x[i] <= 2*w:
            dp[i+1][j] = dp[i][j-x[i]] + dp[i][j]
        else:
            dp[i+1][j] = dp[i][j]

print(dp[n][w]-1)

Measured memory_bytes: 5232
n = input()
ain = input()
a = ain.split()
count = 0.0

for i in range(int(n)):
    if(int(a[i]) % 4 == 0):
        count += 1
    elif(int(a[i]) % 2 == 0):
        count += 0.5

if(int(count) >= (int(n) // 2)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 11100
#ABC150C
import itertools
n = int(input())
ls = [i+1 for i in range(n)]
p = list(map(int,input().split()))
q = list(map(int,input().split()))
v = [ list(v) for v in itertools.permutations(ls, n)]
a, b = v.index(p), v.index(q)
print(abs(a-b))

Measured memory_bytes: 10228
# coding: utf-8
# Your code here!
N = int(input())

m = {}
for i in range(0,N):
    S = input()
    if S in m:
        m[S] = m[S] + 1
    else:
        m[S] = 1

top = 0
r = list()
for k,v in sorted(m.items(), key=lambda x: -x[1]):
    if top == 0:
        top = v
    if top != v:
        break
    r.append(k)

for s in sorted(r):
    print(s)


Measured memory_bytes: 43228
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	sunuke := make([]int, n)
	k := nextInt()

	for i := 0; i < k; i++ {
		d := nextInt()
		for l := 0; l < d; l++ {
			a := nextInt() - 1
			sunuke[a]++
		}
	}

	count := 0
	for i := 0; i < n; i++ {
		if sunuke[i] == 0 {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1776