akhauriyash/Code-Regression huggingface dataset:
def modInv(a,mod):
    return pow(a,mod-2,mod)

def nCr(n,r,mod):
    r=min(r,n-r)
    if r==0: return 1
    if r==1: return n
    numer=1
    denom=1
    for i in range(r):
        numer=(n-i)*numer%mod
        denom=(i+1)*denom%mod
    return numer*modInv(denom, mod)%mod
        
n,a,b=map(int,input().split())
mod=10**9+7
f=pow(2,n,mod)-1
A=nCr(n,a,mod)
B=nCr(n,b,mod)
print((f-A-B)%mod)

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  vecb seki(100001, false);
  rep(i,n){
    int l, r;
    cin >> l >> r;
    REP(j,l,r+1){
      seki[j]=true;
    }
  }

  int ans=0;
  rep(i,100001){
    if(seki[i]) ans++;
  }

  prt(ans);

}


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

int main(){
	char b;
	cin >> b;
	 if(b == 'A'){
	 	cout << 'T' << endl;
	 }
	 if(b == 'T'){
	 	cout << 'A' << endl;
	 }
	 if(b == 'C'){
	 	cout << 'G'<< endl;
	 }
	if(b == 'G'){
		cout << 'C' << endl;
	}

}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){    
  int N,D,a;
  cin >> N >> D;

  int X[N][D],count=0,sum=0;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> X[i][j];
    }
  }
  
  
  for(int k=0;k<N-1;k++){
    for(int i=1;i<N-k;i++){
      for(int j=0;j<D;j++){
  	sum += pow(X[k][j] - X[k+i][j],2);
      }
      if(pow(sum,0.5) == (int)pow(sum,0.5)){
	count++;
      }
      sum = 0;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

template <int mod = (int)(998244353)>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

const int MOD = 998244353;

using mint = ModInt<MOD>;

ll n;


int main(){
    int k;
    cin >> n >> k;
    vector<mint> a(n+1, 0);
    a[2] -= 1;
    vector<P> lr;
    rep(i, k){
        int l, r;
        cin >> l >> r;
        lr.push_back(make_pair(l, r));
    }
    mint res=1;
    rep2(i, 1, n){
        res += a[i];
        rep(j, k) {
            if (i + lr[j].first <= n) {
                a[i + lr[j].first] += res;
            }
            if (i + lr[j].second < n) {
                a[i + lr[j].second + 1] -= res;
            }
        }
    }
    cout << res + a[n] << endl;
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=510*510;
int n,m,e[510][510],tot;
int a[maxn],b[maxn],c[maxn],d[maxn];
void add(int A,int B,int C,int D) {
	a[++tot]=A;
	b[tot]=B;
	c[tot]=C;
	d[tot]=D;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) read(e[i][j]);
	for (int i=1;i<=n;i++) {
		for (int j=1;j<m;j++) {
			if (e[i][j]%2==1) e[i][j+1]++,add(i,j,i,j+1);
		}
	}
	for (int i=1;i<n;i++)
		if (e[i][m]%2==1)
			e[i+1][m]++,add(i,m,i+1,m);
	printf("%d\n",tot);
	for (int i=1;i<=tot;i++)
		printf("%d %d %d %d\n",a[i],b[i],c[i],d[i]);
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

int main(){
  string s; cin >> s;
  int x, y; cin >> x >> y;
  int d = 0;
  vector<vector<int>> a(2);
  rep(i,s.size()){
    int t=0;
    while(s[i]=='F'&&i<s.size()){
      t++; i++;
    }
    a[d].push_back(t);
    d=1-d;
  }
  int g = 8000;
  bool dx[2][2*g], dy[2][2*g];
  fill(dx[0],dx[2],false);fill(dy[0],dy[2],false);
  dx[0][g] = dy[0][g] = true;
  
  rep(i,a[0].size()){
    rep(j,2*g){
      if(dx[i%2][j]){//もしここにjに到達できるなら
        dx[(i+1)%2][j+a[0][i]] = true; //iだけ移動した先をtrueにする
        if(i>0){//1回目以降はマイナス方向も移動可能
          dx[(i+1)%2][j-a[0][i]] = true; //-iだけ移動した先をtrueにする
        }
        dx[i%2][j] = false;//jは次のためにfalseにする
      }
    }
  }
  rep(i,a[1].size()){
    rep(j,2*g){
      if(dy[i%2][j]){//もしここにjに到達できるなら
        dy[(i+1)%2][j+a[1][i]] = true; //iだけ移動した先をtrueにする        
        dy[(i+1)%2][j-a[1][i]] = true; //-iだけ移動した先をtrueにする
        dy[i%2][j] = false;//jは次のためにfalseにする
      }
    }
  }
    
  if(dx[a[0].size()%2][x+g] && dy[a[1].size()%2][y+g]){
    cout << "Yes" << endl;
  }else cout << "No" << endl;

  
  return 0;
}

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

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  for(int i=0; i<n; ++i){
    cin >> a[i];
    sum += a[i];
  }
  ll x = a[0], y = sum - a[0];
  ll res = abs(x - y);
  for(int i=1; i<n-1; ++i){
    x += a[i]; y -= a[i];
    if(abs(x - y) < res) res = abs(x - y);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int num[1000000+10];
vi edge[1000000+10];
void dfs(int rt,int fi){
	num[rt]=1;
	for(auto i:edge[rt]){
		if(i==fi) continue;
		dfs(i,rt);
		num[rt]+=num[i];
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	rep(i,2,n+1){
		int x;
		cin >> x;
		edge[x].pb(i);
		edge[i].pb(x);
	}
//	dfs(1,0);
	rep(i,1,n+1){
	//	cout<<num[i]-1<<endl;
		if(i==1) cout<<edge[i].size()<<endl;
		else cout<<edge[i].size()-1<<endl;
	}
	return 0;
}



Measured memory_bytes: 33940
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

  val Array(n,m,x) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val bookCostAndSkills = Array.fill(n)(scala.io.StdIn.readLine().split(" ").map(_.toInt))
  val bookCosts = bookCostAndSkills.map(_.head)
  val bookSkills = bookCostAndSkills.map(_.drop(1))

  def solve() = {
    var ans = Long.MaxValue
    for(i <- 0 until 1 << n) {
      var cost = 0
      val skillArr = Array.fill(m)(0)
      for(j <- 0 until n) {
        if(isBitOn(i, j)) {
          cost += bookCosts(j)
          for(k <- 0 until m) skillArr(k) += bookSkills(j)(k)
        }
      }
      if(skillArr.forall(_ >= x)) ans = Math.min(ans, cost)
    }

    if(ans == Long.MaxValue) -1L else ans
  }

  def isBitOn(num: Int, digit: Int): Boolean =
    (num & (1 << digit)) != 0

  println(solve())

}



Measured memory_bytes: 55168
#include<iostream>
#include<cstring>
using namespace std;
char s[101];
int f=0;
int main(){
	cin>>s;
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='C') {
			f=1;
		}
		if(s[i]=='F'&&f==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t, a;
    a = A/D;
    t = C/B;
    if(A%D > 0)
        a++;
    if(C%B > 0)
        t++;

    if(t <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>

int main(void){
	int c[]={10,50,100,500};
	int cost,sum;
	int coin[4],d[4];
	int i,flg=0;
	
	while(1){
		scanf("%d",&cost);
		if(cost==0)return 0;
		if(flg)printf("\n");
		fflush(stdin);
		scanf("%d %d %d %d",&coin[0],&coin[1],&coin[2],&coin[3]);
		sum=0;
		for(i=0;i<4;i++){
			sum+=coin[i]*c[i];
		}
		sum-=cost;
		for(i=0;i<4;i++){
			d[i]=0;//ツ渉可甘コツ可サ
		}
		for(i=3;i>=0;i--){
			while(sum>=c[i]){
				sum-=c[i];
				d[i]++;
			}
			if(sum<0)break;
		}
		for(i=0;i<4;i++){
			if(coin[i]-d[i]>0){
				printf("%d %d\n",c[i],coin[i]-d[i]);
				flg=1;
			}
		}
	}
}

Measured memory_bytes: 0
//temp##############################################

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

void strInit(char str[]);//str[]を0で初期化
void extIntStr(char str[],int data[]);//str[]から数値(int)を抽出しdata[]に順次格納
void incsort(int data[],int len);//data[]を昇順ソート
void decsort(int data[],int len);//data[]を降順ソート
void printIntArray(int data[],int len);//data[]をprint
int* inputArray(int n);//文字列を受け取り数値を抽出、n個の数値(int)を格納した配列のポインタをreturn
int* cpyArray(int data[],int len);//配列(int)を複製した配列のポインタをreturn

void strInit(char str[]){
    int len=strlen(str);
    for(int i=0;i<len;i++){
        str[i]=0;
    }
}

void extIntStr(char str[],int data[]){
    int length=strlen(str);
    str[length-1]=' ';
    char buff[12];
    int j,index;
    index=j=0;
    for(int i=0;i<length;i++){
        if(str[i]!=' '){
            buff[j++]=str[i];
        }else{
            data[index++]=atoi(buff);
            strInit(buff);
            j=0;
        }
    }
}

void incsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]>data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void decsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]<data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

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

int* inputArray(int n){
    int *data;
    data=(int*)malloc(sizeof(int)*n);
    char *get;
    get=(char*)malloc(sizeof(char)*11*n+1);
    fgets(get,11*n+1,stdin);
    extIntStr(get,data);
    free(get);
    return data;
}

int* cpyArray(int data[],int len){
    int *cp;
    cp=(int*)malloc(sizeof(int)*len);
    for(int i=0;i<len;i++){
        cp[i]=data[i];
    }
    return cp;
}

//temp##############################################

//don't forget free(data);

int main(){
    int n;
    scanf("%d ",&n);
    int *data;
    int *sa;
    int max=0;
    int nxt=0;
    data=(int*)malloc(sizeof(int)*n);
    char buff[12];
    for(int i=0;i<n;i++){
        fgets(buff,11,stdin);
        data[i]=atoi(buff);
        strInit(buff);
        if(max<data[i])max=data[i];
        else if(data[i]>nxt)nxt=data[i];
    }
    for(int i=0;i<n;i++){
        if(max==data[i])printf("%d\n",nxt);
        else printf("%d\n",max);
    }
    free(data);
    free(sa);
    return 0;
}

Measured memory_bytes: 2304
def f(x,y,a):
    a[y][x]='0'
    for dx,dy in [[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]:
        if 0<=x+dx<8 and 0<=y+dy<8 and a[y+dy][x+dx]=='1':f(x+dx,y+dy,a)
    return a

for i in range(int(input())):
    print('Data %d:'%(i+1))
    input()
    a=[list(input()) for _ in [0]*8]
    [print(*x,sep='')for x in f(int(input())-1,int(input())-1,a)]

Measured memory_bytes: 7604
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, K);
    AIN(ll, p, N);
    double s = 0;
    REP(i, K)
    {
        s += (1 + p[i]) / 2.0;
    }
    double ans = s;
    for (ll i = K; i < N; ++i)
    {
        s += (p[i] - p[i - K]) / 2.0;
        CH(max, ans, s);
    }
    FOUT(ans);
}

Measured memory_bytes: 4760
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, S: str):
    if N % 2 != 0:
        print(NO)
        exit()
    
    num = int(N/2)
    if S[:num] == S[num:]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, a[100009], b[100009];
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	long long ret = 0;
	for (int i = 29; i >= 0; i--) {
		if (K & (1 << i)) {
			long long sum = 0;
			for (int j = 0; j < N; j++) {
				if ((((a[j] >> i) | (K >> i)) == (K >> i)) && !(a[j] & (1 << i))) sum += b[j];
			}
			ret = max(ret, sum);
		}
	}
	long long sum2 = 0;
	for (int i = 0; i < N; i++) {
		if ((a[i] | K) == K) sum2 += b[i];
	}
	cout << max(ret, sum2) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N]; 
int main(){
	int n,k,c;
	string s;
	cin>>n>>k>>c>>s;
	for(int i=0,id=0;i<n;i++) if(s[i]=='o') a[id++]=i,i+=c;
	for(int i=n-1,id=k-1;i>=0&&id>=0;i--) if(s[i]=='o') b[id--]=i,i-=c;//这id要从k-1开始因为最多有k天工作. 
	for(int i=0;i<k;i++) if(a[i]==b[i]) cout<<a[i]+1<<endl;//由于开始下标为0,所以要加1 
	return 0; 
}

Measured memory_bytes: 3332
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    int n;
    cin>>n;
    vll a(n);
    int cnt=0;
    ll ans=0;
    ll mn=1e9;
    rep(i,n){
      cin>>a[i];
      if(a[i]<0) cnt++;
      a[i]=abs(a[i]);
      ans+=a[i];
      mn = min(mn,a[i]);
    }

    if(cnt%2==1) cout<<ans-mn*2<<endl;
    else cout<<ans<<endl;
    
}

Measured memory_bytes: 3928
def main113my():
    N, M = (int(x) for x in input().split())

    answer = [0] * M
    pre = [0] * N

    for m in range(M):
        p, y = (int(x) for x in input().split())
        answer[m] = [m, p, y, 0]

    answer = sorted(answer, key=lambda x: x[2])  #  誕生した年でソート

    for a in answer:
        pre[a[1]-1] += 1
        a[3] = pre[a[1]-1]

    answer = sorted(answer, key=lambda x: x[0])  #  市の番号順にソート

    for a in answer:
        print("{:06d}{:06d}".format(a[1], a[3]))

main113my()

Measured memory_bytes: 30608
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    loop {
        let v = read_vec::<u32>();
        let a = v[0];
        let b = v[1];
        if a == 0 && b == 0 {
            break;
        }

        for i in 0..a {
            let line = match i {
                x if x % 2 == 0 => (0..b)
                    .map(|i| if i % 2 == 0 { '#' } else { '.' })
                    .collect::<String>(),
                _ => (0..b)
                    .map(|i| if i % 2 == 0 { '.' } else { '#' })
                    .collect::<String>(),
            };
            println!("{}", line);
        }
        println!("");
    }
}



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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    string s;
    cin>>s;
    int n = s.size();
    string tmp = s;
    reverse(all(s));
    int ans = (s == tmp);
    string s1 = s.substr(0, n/2);
    string tmp1 = s1;
    string s2 = s.substr(n/2+1, n/2);
    string tmp2 = s2;
    reverse(all(s1));
    reverse(all(s2));
    ans &= (s1 == tmp1);
    ans &= (s2 == tmp2);
    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
  cin>>N;
  int a=N%1000;
  int b=a%111;
  int c=N/10;
  int d=c%111;
  if(b==0)cout<<"Yes"<<endl;else{if(d==0)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  stack <ll> s;
  ll a, b;
  string str;
  while (cin >> str) {
    if (str.at(0) == '+') {
      a = s.top(); s.pop();
      b = s.top(); s.pop();
      s.push(a+b);
    } else if (str.at(0) == '-') {
      a = s.top(); s.pop();
      b = s.top(); s.pop();
      s.push(b-a);
    } else if (str.at(0) == '*') {
      a = s.top(); s.pop();
      b = s.top(); s.pop();
      s.push(a*b);
    } else {
      s.push(stoi(str));
    }
  }
  cout << s.top() << endl;
}


Measured memory_bytes: 3168
#include <iostream>

using namespace std;

int main(){
  int n, m;
  while(true){
    cin >> n >> m;
    if(!n && !m){
      break;
    }

    // [自分][相手] = 友達か否か
    bool friendList[512][512];
    // 友達
    bool isFriend[512];
    // アルカイダ
    bool isFriends[512];

    // 初期化
    for(int i = 0; i < n; i++){
      isFriend[i] = isFriends[i] = false;
      for(int j = 0 ; j < n; j++){
	friendList[i][j] = false;
      }
    }
    

    for(int i = 0; i < m; i++){
      int my, you;
      cin >> my >> you;
      // 友達フラグ
      friendList[my - 1][you - 1] = true;
    }

    for(int i = 0; i < n; i++){
      // 友達
      if(friendList[0][i] || friendList[i][0]){
	isFriend[i] = true;
	// 友達の友達探し
	for(int j = 0;j < n; j++){
	  if(friendList[i][j] || friendList[j][i]){
	    isFriends[j] = true;
	  }
	}
      }
    }
    
    int ans;
    ans = 0;
    for(int i = 1; i < n; i++){
      if(isFriend[i] || isFriends[i]){
	ans++;
      }
    }

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

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int test[123];
signed main() {
	int n, a, ans = 0;
	for (int h = 0; h < 12; h++) {
		cin >> n;
		test[n]++;
	}
	for (int h = 1; h <= 100; h++) {
		ans = max(ans, test[h]);
	}
	for (int h = 1; h <= 100; h++) {
		if (test[h] == ans) {
			cout << h << endl;
		}
	}
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll a,b;
long long clcu(ll n){
    if(n % 4 == 0) return n;
    if(n % 4 == 1) return 1;
    if(n % 4 == 2) return n+1;
    else return 0;
}
int main(){
    cin >> a >> b;
    ll ans = clcu(b)^clcu(a-1);
    cout << ans << endl;
}

 

Measured memory_bytes: 384
def main():
    n=int(input())
    if n==3:
        print(2,5,63)
        return 0
    ans=[2,3]
    cnt=0
    i=10
    while cnt<n-4:
        if i%2==0 or i%3==0:
            ans.append(i)
            cnt+=1
        i+=1
    a=sum(ans)
    if n==20000:
        ans.pop()
        ans.pop()
        ans.append(8)
        ans.append(9)
    elif n==19999:
        ans.pop()
        ans.append(8)
    if a%6==0:
        ans.append(4)
        ans.append(8)
    elif a%6==1:
        ans.append(8)
        ans.append(9)
    elif a%6==2:
        ans.append(4)
        ans.append(6)
    elif a%6==3:
        ans.append(6)
        ans.append(9)
    elif a%6==4:
        ans.append(8)
        ans.append(6)
    elif a%6==5:
        ans.append(9)
        ans.append(4)
    print(*ans)
main()

Measured memory_bytes: 4560
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 101010;
int dp[MAX_N];
int h[MAX_N];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	rep(i, MAX_N)dp[i] = INF;
	dp[0] = 0;
	rep(i, n)cin >> h[i];
	rep(i, n) {
		rep(j, k) {
			chmin(dp[i + j + 1], dp[i] + abs(h[i] - h[i + j + 1]));
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}


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

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

long N;
string S;
int main(){
	cin >> N;
	cin >> S;
	if (N%2 != 0){
		cout << "No" << endl;
		exit(0);
	}
	long x = N/2;
	int isOK = 1;
	rep(i, x){
		if (S.at(i) != S.at(i+x)){
			isOK = 0;
			break;
		}
	}
	if (isOK) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1000000001;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k,c;cin>>n>>k>>c;
    string s;cin>>s;
    int num=1000000000;
    int cnt=k;
    int sai[n];
    fill(sai,sai+n,-1);
    rrep(i,n-1,0){
        if(s[i]=='x')continue;
        if(num-i>c){
            sai[i]=cnt;
            num=i;
            cnt--;
        }
        if(cnt==0)break;
    }
    int sai2[n];
    fill(sai2,sai2+n,-1);
    cnt=1;
    num=-1000000000;
    rep(i,0,n){
        if(s[i]=='x')continue;
        if(i-num>c){
            sai2[i]=cnt;
            cnt++;
            num=i;
        }
        if(cnt==k+1)break;
    }
    rep(i,0,n){
        if(sai[i]==sai2[i]&&sai[i]>0)cout<<i+1<<endl;
    }
    
}



Measured memory_bytes: 3476
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i; 
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void sout(char *s) {
    printf("%s\n", s);
}

void iArrayInit(int* array, int len) {
    for (int i = 0; i < len; i++) {
        array[i] = 0;
    }
 }

int main() {
    int N = iin(), M = iin();
    int love[M];
    int i, j, tmp;
    iArrayInit(love, M);
    for (i = 0; i < N; i++) {
        j = iin();
        for(; j > 0; j--) {
            tmp = iin();
            love[tmp - 1]++;
        }
    }
    int count = 0;
    for (i = 0; i < M; i++) {
//        iout(love[i]);
        if (love[i] == N) {
            count++;
        }
    }
    
    iout(count);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int H;
int A[500000];

int L(int i){
        return 2*i;
}
int R(int i){
        return 2*i+1;
}
void maxHeapify(int i){
        int Large,swap;
        int l=L(i);
        int r=R(i);
        if(l<=H&&A[l]>A[i]) {
                Large=l;
        }
        else{
                Large=i;
        }
        if(r<=H&&A[r]>A[Large]) {
                Large=r;
        }
        if(Large!=i) {
                swap=A[i];
                A[i]=A[Large];
                A[Large]=swap;
                maxHeapify(Large);
        }
}
/*void buildmaxHeap(A[]){
   for(int i=H/2;i>1;i--){
    maxHeapify( A[],i)
   }*/
int main(){
        int i;
        scanf("%d",&H);
        for (i=1; i<=H; i++) {
                scanf("%d",&A[i]);
        }
        for(i=H/2; i>=1; i--){
          maxHeapify(i);
        }

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




Measured memory_bytes: 3676
#include <iostream>
#include <deque>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int chair[17];
int ans[100];

//øÌA±µÄ¢éÀÈÌÅ¬ÔðÔ·
int isempty(int arg){
	int ret=-1;
	int num=0;
	int maxi = 0;
	int begin=0;
	for(int i=0;i<17;i++){
		if(chair[i] == 0){
			if(num == 0) begin = i;
			num++;
		}else{
			if(num >= arg) return begin;
			num = 0;
		}
	}
	if(num >= arg) return begin;
	return -1;
}

int main(){
	memset(chair, 0, sizeof(chair));
	deque<int> waiting;
	for(int t=0;t<600;t++){
		int n;
		for(int i=0;i<17;i++){
			if(chair[i] != 0) chair[i]--; //cèÔð¸ç·
		}
		if(t%5 == 0){ //q`FbN
			waiting.push_back(t/5);
		}
		while(!waiting.empty()){ //È`FbN
			if(waiting.front()%5==1){
				n=5;
			}else{
				n=2;
			}
			int place = isempty(n);
			if(place == -1) break;
			//ÈÉÂ¯é
			for(int j=0;j<n;j++){
				chair[place+j] = 17 * (waiting.front()%2) + 3 * (waiting.front()%3) + 19;
			}
			ans[waiting.front()] = t - waiting.front() * 5;
			waiting.pop_front();
		}
	}
	int q;
	
	while(cin >> q){
		cout << ans[q] << endl;
	}
}

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




void sleek()
{
    int n;
	cin >> n;
	
	
	string s;
	cin >> s;
	if(s.size() <= n)
		cout<<s ;
	else
	{
		s=s.substr(0,n) + "...";
		cout<<s;
	}
	
    
    
    
}


int main() {
    ios:: sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int t=1; 
    //cin >> t;
    while(t--)
    {
        sleek();
    }
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if (a+b==c){
    cout <<"Yes"<<endl;
  }
  else if(a+c==b){
    cout <<"Yes"<<endl;
  }
  else if(b+c==a){
    cout <<"Yes"<<endl;
  }
  else {
    cout <<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int i, j;
	int H, W;

	cin >> H >> W;

	char **map = new char*[H + 1];
	for (i = 0; i <= H; i++) {
		map[i] = new char[W + 1];
	}

	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			cin >> map[i][j];
		}
	}

	int **DP = new int*[H + 1];
	for (i = 0; i <= H; i++)
		DP[i] = new int[W + 1];

	for (i = 0; i <= H; i++)
		DP[i][0] = 0;
	for (i = 0; i <= W; i++)
		DP[0][i] = 0;

	DP[0][1] = 1;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (map[i][j] == '#')
				DP[i][j] = 0;
			else
				DP[i][j] = (DP[i - 1][j] + DP[i][j - 1])%(int)(1e9 + 7);
		}
	}

	cout << DP[H][W] << endl;

	for (i = 0; i <= H; i++) {
		delete[] map[i];
		delete[] DP[i];
	}
	delete[] map;
	delete[] DP;

	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 n;
vector<vector<PLL>> G;

PLL diameter(const vector<vector<PLL>> &G, int64 v, int64 p) {
  PLL res(0, 0);
  vector<int64> r;
  REP(i, G[v].size()) {
    if (G[v][i].sc == p) continue;
    PLL ret = diameter(G, G[v][i].sc, v);
    r.push_back(ret.fs+G[v][i].fs);
    chmax(res.sc, ret.sc);
    chmax(res.fs, ret.fs+G[v][i].fs);
  }
  sort(all(r), greater<int64>());
  if (r.size() > 1)
    chmax(res.sc, r[0]+r[1]);
  return res;
}

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

  while (cin >> n && n) {
    vector<int64> p(n), d(n);
    REP(i, n-1) { cin >> p[i]; p[i]--; }
    REP(i, n-1) cin >> d[i];
    G = vector<vector<PLL>>(n);
    int64 res = 0;
    REP(i, n-1) {
      G[i+1].emplace_back(d[i], p[i]);
      G[p[i]].emplace_back(d[i], i+1);
    }
    REP(i, n-1) {
      res += d[i];
    }
    vector<vector<PLL>> G2(n);
    REP(i, n) {
      if (G[i].size() == 1) continue;
      REP(j, G[i].size()) {
        if (G[G[i][j].sc].size() == 1) continue;
        G2[i].push_back(G[i][j]);
        res += G[i][j].fs;
      }
    }

    REP(i, n) {
      if (G2[i].size()) {
        PLL dia = diameter(G2, i, -1);
        res -= max(dia.fs, dia.sc);
        break;
      }
    }
    cout << res << endl;
  }
}


Measured memory_bytes: 3412
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define rep(i, n) for (signed i = 0; i < signed(n); i++)
#define REP(i, s, n) for (signed i = signed(s); i < signed(n); i++)
#define rrep(i, n) for (signed i = signed(n) - 1; i >= 0; i--)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

void calc() {
	int N; cin >> N;
	V v(N); input(v);
	int sum = accumulate(all(v), 0ll);
	int ans = sum % 10 == 0 ? 0 : sum;
	rep(i, N) {
		int x = sum - v[i];
		int a = x % 10 == 0 ? 0 : x;
		ans = max(ans, a);
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

Measured memory_bytes: 256
N=input()
s=len(N)
mod=10**9+7
dp=[[0]*2 for i in range(s)]
dp[0]=[2,1]
#print(N,s)
for i in range(s-1):
  if N[i+1]=="1":
    dp[i+1][0]=(dp[i][0]*2)%mod
    dp[i+1][1]=(dp[i][0]+3*dp[i][1])%mod
  if N[i+1]=="0":
    dp[i+1][0]=(dp[i][0])%mod
    dp[i+1][1]=(dp[i][1]*3)%mod
#print(dp)    
print((dp[s-1][0]+dp[s-1][1])%mod)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (ll i = 0; i < n - k; ++i) {
        if (a[i] < a[i + k]) {
            puts("Yes");
        } else {
            puts("No");
        }
    }
}

Measured memory_bytes: 4816
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        var points = new List<Bar>[n];
        for (int i = 0; i < n; i++) points[i] = new List<Bar>();

        for(int i=0; i<n-1; i++) {
            var spl   = input.ReadLine().Split(' ');
            var v1     = int.Parse(spl[0]) -1;
            var v2     = int.Parse(spl[1]) -1;
            var w      = int.Parse(spl[2]);

            points[v1].Add(new Bar { to = v2, w = w });
            points[v2].Add(new Bar { to = v1, w = w });
        }

        var colors = new bool[n];
        Paint(points, colors, 0, -1, 0);

        var buil = new StringBuilder();
        foreach(var i in colors) {
            buil.AppendLine(i ? "1" : "0");
        }

        return buil.ToString();
    }

    static void Paint(List<Bar>[] points, bool[] colors, int p, int from, int w) {
        if (p > 0) {
            colors[p] = w % 2 == 0 ? colors[from] : !colors[from];
        }

        foreach(var bar in points[p]) {
            if (bar.to == from) continue;
            Paint(points, colors, bar.to, p, bar.w);
        }
    }

    class Bar
    {
        public int to;
        public int w;
    }
}

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

int main()
{
    long n, k; cin>>n>>k;
    map<int, long> v;
    while (n--) {
        int a, b; cin>>a>>b;
        v[a]+=b;
    }
    for(auto& e: v) {
        k-=e.second;
        if (k<=0) {
            cout<<e.first<<endl;
            break;
        }
    }
}


Measured memory_bytes: 4224
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> s;
  REP(i, s.length()) {
    if(90 < s[i] + n) printf("%c", 'A' + ((s[i] + n) - 91));
    else printf("%c", s[i] + n);
  }
  printf("\n");
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc143
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc143B();
        }

        public static void solve_abc143B()
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int[] d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

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

            Console.WriteLine(sum);
        }

        public static void solve_abc143A()
        {
            int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int a = ab[0];
            int b = ab[1];

            Console.WriteLine(a > 2 * b ? a - 2 * b : 0);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#define inf 1000000
#define N 100
#define BLACK 0
#define WHITE 1


int d[N],pi[N],color[N],a[N][N];
int num,i,j,u,v,mincost,count=0;


void prim(int num,int w[N][N],int r){


    for(u=0;u<num;u++){
      d[u] = inf;
      // pi[u] = NULL;
      color[u] = WHITE;
    }
    d[r] = 0;

  while(1){
    mincost = inf;
    for(i=0;i<num;i++){
      if(color[i] != BLACK && d[i]< mincost){
        mincost = d[i];
        u = i;
      }
    }
    if(mincost == inf)break;
    color[u] = BLACK;
    count +=mincost;

    for(v=0;v<num;v++){
      if(w[u][v] == -1)continue;
      if(d[v]>w[u][v])d[v] =w[u][v];
    }
}
printf("%d\n",count);
}

int main(){
  scanf("%d",&num);
  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      scanf("%d",&a[i][j]);
    }
  }
  prim(num,a,0);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxlen=1000000;

int n,num;
int a[1000005],v[1000005];

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)  v[a[i]]++;
	
	num=a[1];
	for (int i=2;i<=n;i++)  num=__gcd(num,a[i]);
	if (num>1)  return cout<<"not coprime"<<endl,0;
	else
	{
		for (int i=2;i<=maxlen;i++)
		{
			int cnt=0;
			for (int j=i;j<=maxlen;j+=i)
			{
				if (v[j]==1)  cnt++;
				if (cnt>1)  return cout<<"setwise coprime"<<endl,0;
			}
		}
		cout<<"pairwise coprime"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 19192