akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
int count=0,j,n;
char moji[11];
char text[50];
scanf("%s",moji);
 while(1){
  scanf("%s",text);
  if(strcmp(text,"END_OF_TEXT")==0) break;
  n=strlen(text);
   for(j=0;j<n;j++){
    text[j]=tolower(text[j]);
  }
  if(strcmp(moji,text)==0) count++;
 }
printf("%d\n",count);
return 0;
}



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

int main(){
  string N;

  cin >> N;
  int s = N.size();
  vector<long long int> v(s);

  for(int i =0; i < N.size();i++){
    v[i] = (long long int)(N[i] - '0');
  }

  long long int sum = 0;

  for(int bit=0; bit < (1 << (N.size()-1)); bit++){
    vector<long long int> v_tmp = v;

    long long int sum_tmp = 0;

    for(int i = 0; i < N.size()-1; i++){
      if(bit & (1 << i)){
        //sum_tmp += v_tmp[i];
      } else {
        v_tmp[i+1] += 10*v_tmp[i];
        v_tmp[i] = 0;
      }
    }
    for(int i = 0; i < N.size(); i++){
      sum += v_tmp[i];
    }
    cerr << "bit: " << bitset<10>(bit) << ", sum_tmp: " << sum_tmp << endl;
  }

  cout << sum << endl;


}

Measured memory_bytes: 256
N = int(input());
s = [];
ans = 0;
for i in range(N) :
    s.append(int(input()));
    ans += s[i];

if ans % 10 == 0 :
    s.sort();
    for i in range(N) :
        if s[i] % 10 != 0 :
            ans -= s[i];
            break;
        elif i == N-1 :
            ans = 0;

print(ans);

Measured memory_bytes: 9196
# -*- coding: utf-8 -*-

"""
・ベルマンフォード
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())

edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    # 0-indexed
    # コストの正負を逆転させれば最短経路問題として処理できる
    edges[i] = (a-1, b-1, -c)

def bellman_ford(N: int, edges: list, start: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    verts = [float('inf')] * N
    verts[start] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            verts[dest] = min(verts[src] + cost, verts[dest])
    # 無限に減らせる場所がないか確認
    for src, dest, cost in edges:
        if verts[src] + cost < verts[dest]:
            verts[dest] = verts[src] + cost
            if dest == N-1:
                # 頂点Nがそれに該当していたら空リストを返却
                return []
    # 問題なければ頂点リストを返却
    return verts

verts = bellman_ford(N, edges, 0)
if not verts:
    print('inf')
else:
    # 正負を戻して出力
    print(-verts[N-1])


Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
 
  vector<string> vec(H + 2, "#");
 
  string sharp = "";
 
  for (int i = 0; i < W; i++) {
    sharp += "#";
  }
 
  for (int i = 0; i < H + 2; i++) {
    if (i == 0 || i == H + 1) {
      vec.at(i) = sharp;
    }
    else {
      cin >> vec.at(i);
    }
 
    cout << "#" << vec.at(i) << "#" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
string str;
LL fun(LL from, LL to) {
  LL ans = 0, counter = 1;
  for(LL i = from + 1; i <= to; i++) {
      if(str[i] == str[i - 1]) {
          counter++;
      }
      else {
          ans += (counter / 2);
          counter = 1;
      }
  }  
  ans += (counter / 2);
  return ans;
}
int main() {
    cin >> str;
    LL k, len = str.length();
    cin >> k;
    if(str[len - 1] != str[0]) {
        LL ans = 0, counter = 1;
        for(int i = 1; i < len; i++) {
            if(str[i] == str[i - 1]) {
                counter++;
            }
            else {
                ans += (counter / 2);
                counter = 1;
            }
        }
        ans += (counter / 2);
        cout << ans * k << endl;
    }
    else {
        LL counter = 1;
        for(int i = 1; i < len; i++) {
            if(str[i] == str[i - 1]) counter++;
            else counter = 1;
        }
        if(counter == len) {
            LL t = len * k;
            cout << t / 2LL << endl;
            return 0;
        }
        LL cur = fun(0, len - 1), left = fun(1, len - 1) + 1, right = fun(0, len - 2) + 1;
        if(k == 1) {
            cout << cur << endl;
            return 0;
        }
        LL ans1 = min(cur, left) + left * (k - 1), ans2 = min(cur, right) + right * (k - 1);
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
grid = [list(map(int,input().split()))for i in range(2)]

#dp[i][j] = grid[i][j]のまでの獲得した飴の最大値。
dp = [[0]*(n+1)for i in range(2)]
dp[0][0] = grid[0][0]
for i in range(1,n):
    dp[0][i] = dp[0][i-1] + grid[0][i]
dp[1][0] = grid[0][0] + grid[1][0]
for i in range(2):
    for j in range(1,n):
        if i == 0:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-1]) + grid[i+1][j]

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


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

int main(){
	int N;
	cin >> N;
	vector<int> V(N);
	vector<int> C(N);
	rep(i,N){
		cin >> V[i];
	}
	rep(i,N){
		cin >> C[i];
	}
	
	int ans = 0;
	
	rep(i,N){
		if(V[i]-C[i] > 0){
			ans += V[i]-C[i];
		}
	}
	
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n;
string s;

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

ll fac(int n){
    if(n==0||n==1) return 1;
    return n*fac(n-1);
}

int main(){
    int x;
    cin>>x;
    int t=0;
    while((t*(t-1))/2>=x||(t*(t+1))/2<x){
        t++;
    }
    cout<<t<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    char ch[n+1];
    int a[n+1], b[n+1], c[n+1], s1=0, s2=0, s3=0;
    long long t=0;
    for (register int i=1; i<=n; i++)
    {
        cin >> ch[i];
        if (ch[i]=='R')
        {
            s1++;
            a[s1]=i;
        }
        if (ch[i]=='G')
        {
            s2++;
            b[s2]=i;
        }
        if (ch[i]=='B')
        {
            s3++;
            c[s3]=i;
        }
    }
    for (register int i=1; i<=s1; i++)
        for (register int j=1; j<=s2; j++)
        {
            int maxx=max(a[i], b[j]), minn=min(a[i], b[j]);
            int dif=maxx-minn;
            t+=s3;
            if (minn-dif>=1)
                if (ch[minn-dif]=='B') t--;
            if (maxx+dif<=n)
                if (ch[maxx+dif]=='B') t--;
            if (dif%2==0)
                if (ch[minn+dif/2]=='B') t--;
        } 
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <valarray>

using namespace std;

int main() {
    int n;
    cin >> n;
    int mx = 0;
    int ans = 1;
    for (int i = 1; i <= n; i++) {
      int x = i;
      int cnt = 0;
      while (x > 0) {
        x /= 2;
        cnt++;
      }
      if (cnt > mx) {
        mx = cnt;
        ans = i;
      }
    }
    cout << ans;
    return 0;
}


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

const int sz=500010;
struct node
{
    int ara[26];
    int mark;
};

node tree[sz*4];

void update(int l,int r,int tar,char ch,int pos)
{
    if(l==r && l==tar)
    {
        if(tree[pos].mark != -1) tree[pos].ara[tree[pos].mark]=0;
        tree[pos].ara[ch-'a']=1;
        tree[pos].mark=ch-'a';
        return ;
    }
    int mid=(l+r)/2;
    int lc=pos*2+1;
    int rc=lc+1;
    if(tar<=mid) update(l,mid,tar,ch,lc);
    else update(mid+1,r,tar,ch,rc);

    for(int i=0;i<26;i++) tree[pos].ara[i]=(tree[lc].ara[i] || tree[rc].ara[i]) ? 1 : 0 ;
}

node query(int l,int r,int p,int q,int pos)
{
    node temp;
    for(int i=0;i<26;i++) temp.ara[i]=0;
    if(r<p || q<l) return temp;
    if(p<=l && r<=q) return tree[pos];
    int mid=(l+r)/2;
    int lc=pos*2+1;
    int rc=lc+1;
    node L=query(l,mid,p,q,lc);
    node R=query(mid+1,r,p,q,rc);
    for(int i=0;i<26;i++) L.ara[i]=(L.ara[i] || R.ara[i]) ? 1 : 0;
    return L;
}

int main()
{
    int n,m,p,q,x,y,i,j;
    string str;
    char ch;

    for(i=0;i<4*sz;i++) {
            tree[i].mark=-1;
            for(j=0;j<26;j++) tree[i].ara[j]=0;
    }

    cin>>n>>str;
    for(i=0;str[i];i++){
        update(1,n,i+1,str[i],0);
    }

    cin>>m;
    while(m--)
    {
        int mark;
        cin>>mark;
        if(mark==1){
            cin>>x>>ch;
            update(1,n,x,ch,0);
        }
        else{
            cin>>p>>q;
            node temp=query(1,n,p,q,0);
            int ans=0;
            for(i=0;i<26;i++) if(temp.ara[i]) ++ans;
            cout<<ans<<'\n';
        }
    }
}


Measured memory_bytes: 211844
package main

import (
	"fmt"
	"sort"
)

type Ints []int

func (ints Ints) Len() int {
	return len(ints)
}

func (ints Ints) Less(i, j int) bool {
	return ints[i] < ints[j]
}

func (ints Ints) Swap(i, j int) {
	ints[i], ints[j] = ints[j], ints[i]
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make(Ints, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(a)

	max := a[n-1]
	r := 0
	for _, v := range a {
		if abs(v*2-max) < abs(r*2-max) {
			r = v
		}
	}

	fmt.Println(max, r)
}


Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

lint culc(lint n, lint k) {
  return (lint)abs(n - k);
}

int main() {
    
  lint n, k; cin >> n >> k;

  if (n < k) {
    cout << min(n, k - n) << endl;
  } else {
    lint diff = n - k;
    lint step = diff / k;
    n -= step * k;
    lint ans = n;
    n = culc(n, k);
    ans = min(ans, n);
    n = culc(n, k);
    ans = min(ans, n);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int f(int);

int main()
{
    int n;
    long sum{0};
    
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++)
        cin >> vec[i];
    std::sort(vec.begin(), vec.end());
    /*
    for(int i = 0; i < n; i++)
        cout << vec[i] << " ";
    cout << endl;
    */
    sum += vec[n - 1];
    //cout << sum << endl;
    for(int i = 1; i < n/2; i++)
        sum += 2*vec[n - 1 - i];
    //cout << sum << endl;
    if(n % 2 == 1)
        sum += vec[n/2];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4008
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	A := readInt()
	B := readInt()
	if 1 <= A && A <= 9 && 1 <= B && B <= 9 {
		println(A * B)
	} else {
		println(-1)
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,a,x=INT_MAX,z=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a;
        while(a%2 == 0){
            a = a/2;
            z++;
        }
        
        if(z<x){
            x=z;
        }
        z=0;
    }
    
    cout<< x <<endl;
}


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

int N, P;
int A[50];

long long int ans;

int i;

int main(void)
{
	int even, odd;

	scanf("%d %d", &N, &P);

	even = 0;
	odd = 0;
	for (i = 0; i < N; i++){
		scanf("%d", &A[i]);

		if (A[i] % 2 == 0){
			even++;
		} else {
			odd++;
		}
	}

	ans = 0;
	if (P == 1){
		if (odd == 0){
			ans = 0;
		} else {
			ans = pow(2, even + odd - 1);
		}
	} else {
		ans = pow(2, even);

		if (odd >= 2){
			ans *= pow(2, odd - 1);
		}
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=228;
char a[N];
int32_t main(){
    srand(228);

    int n;
    string s,s2;
    cin>>n;
    if(n==1){
        cout<<"? 1"<<std::endl;
        cin>>s;
        if(s=="Red"){
            cout<<"! RB\n";
        }else{
            cout<<"! BR\n";
        }
    }else{
        vector<int> q,b,v;
        cout<<"? ";
        for(int i=1;i<=n;++i)cout<<i<<' ';
        cout<<std::endl;
        cin>>s;
        int l=1,r=n+1;
        while(r-l>1){
            int m=(l+r)/2;
            cout<<"? ";
            for(int i=m;i<m+n;++i)cout<<i<<' ';
            cout<<std::endl;
            cin>>s2;
            if(s2==s)l=m;
            else r=m;
        }
        for(int i=l+1,j=0;j<n-1;i++,j++){
            a[i]='V';
            v.pb(i);
        }
        for(int i=1;i<=n+n;++i){
            if(a[i]=='V')continue;
            cout<<"? "<<i<<' ';
            for(int j:v)cout<<j<<' ';
            cout<<std::endl;
            cin>>s;
            if(s[0]=='R'){
                a[i]='R';
                if(q.size()<(n-1)/2)q.pb(i);
            }else{
                a[i]='B';
                if(b.size()<(n-1)/2)b.pb(i);
            }
        }

        for(int i:v){
            cout<<"? "<<i<<' ';
            for(int j:q)cout<<j<<' ';
            for(int j:b)cout<<j<<' ';
            cout<<std::endl;
            cin>>s;
            if(s[0]=='R')a[i]='R';
            else a[i]='B';
        }
        cout<<"! ";
        for(int i=1;i<=n+n;++i)cout<<a[i];
        cout<<'\n';
    }


    return 0;
}


Measured memory_bytes: 724
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

signed main(){
    string A,B,C;cin>>A>>B>>C;
    cout<<(char)(A[0]+('A'-'a'))<<(char)(B[0]+('A'-'a'))<<(char)(C[0]+('A'-'a'))<<endl;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
int inv[10004];
int C(int n,int r){
    int res=1,cur=1;
    for(int i=n;i>r;i--){
        res=res*i%hell;
        res=res*inv[cur]%hell;
        cur++;
    }
    return res;
}
void solve(){
    int n,ans=0;
    cin>>n;
    if(n<5){
        cout<<0<<endl;
        return;
    }
    n-=5;
    rep(i,0,12){
        int r=n-i;
        if(r<0) break;
        if(r%2) continue;
        r/=2;
        ans=(ans+C(11,i)*C(15+r,r)%hell)%hell;
    }
    cout<<ans<<endl;
}

signed main(){
    rep(i,1,102) inv[i]=expo(i,hell-2,hell);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
import java.io.*;
import java.util.*;
 
 
public class Main {
	public static void main(String[] args) throws Exception {
		MScanner sc=new MScanner(System.in);
		//MScanner sc=new MScanner("portals.in");
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int[]a=new int[n-1];
		for(int i=0;i<n-1;i++) {
			a[i]=sc.nextInt();
		}
		int sum=a[0]+a[n-2];
		for(int i=0;i<a.length-1;i++) {
			sum+=Math.min(a[i], a[i+1]);
		}
		pw.println(sum);
		pw.flush();
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21076
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> T>>p>>Q;
	cout << T[0] << p[1] << Q[2];
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int H, W, i, j;
    
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0){
            break;
        }
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2052
N,K,Q=map(int,input().split())
ans=[K for i in range(N)]
ans=list(map(lambda x:x-Q,ans))
for i in range(Q):
  A=int(input())
  ans[A-1]=ans[A-1]+1
for i in range(N):
  if ans[i]>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 7884
def main(argv)
  (n, k, q) = gets.chomp.split(' ').map(&:to_i)
  
  a = [0] * q
  q.times{|i| a[i] = gets.chomp.to_i}
  
  c = [0] * n
  a.each{|a_i| c[a_i - 1] += 1}
  
  m = q - k
  c.map!{|x| x - m}
  
  c.each do |x|
    puts (x > 0 ? 'Yes' : 'No')
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 3708
# C
N, Q = map(int, input().split())
S = input()

# cumsum
A_list = [0]*(N+1)
C_list = [0]*(N+1)
for i in range(N-1):
    if S[i:i+2] == "AC":
        A_list[i+1] = 1
        C_list[i+2] = 1
A_ = 0
C_ = 0
for i in range(N+1):
    A_ += A_list[i]
    A_list[i] = A_
    C_ += C_list[i]
    C_list[i] = C_
    
res_list = []
for _ in range(Q):
    i, j = map(int, input().split())
    a_cnt = A_list[j] - A_list[i-1]
    c_cnt = C_list[j] - C_list[i-1]
    res_list.append(C_list[j] - A_list[i-1])
    
for r in res_list:
    print(r)

Measured memory_bytes: 15864
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

import heapq

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

def warshall_floyd(n,d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d





n,x,y = m()

dp = [[mod for i in range(n)] for j in range(n)]

for i in range(n):
    dp[i][i] = 0

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

dp[x-1][y-1] = 1

dp[y-1][x-1] = 1


po = dijkstra(x-1,n,n,dp)

ppo = dijkstra(y-1,n,n,dp)

ans = [0 for i in range(n)]

for i in range(n):
    for j in range(n):
        on = min(abs(i-j),po[i]+po[j],ppo[i]+ppo[j],po[i]+ppo[j] + 1,ppo[i]+po[j] + 1)
            #print(i,j,on)
            #print(ppp[i][j])
        ans[on] += 1
for i in range(1,n):
    print(ans[i]//2)




Measured memory_bytes: 85084
def main():
    N = int(input())
    L = list(map(int,input().split()))
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                l = [L[i], L[j], L[k]]
                l.sort()
                if l[0] == l[1] or l[1] == l[2] :
                    continue
                if l[0]+l[1] > l[2] :
                    count+=1
    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include <algorithm>
#include <cstdio>
int x[505],id[505],ans[250005];
bool cmp(int a,int b){return x[a]<x[b];}
int main(){
	int n;bool flag=1;
	scanf("%d\n",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x[i]);
		if (!ans[x[i]]) ans[x[i]]=i;
			else flag=0;
		id[i]=i;
	}
	std::sort(id+1,id+n+1,cmp);
	for (int i=1,j=1;i<=n && flag;i++){
		for (int k=1;k<id[i];j++)
			if (!ans[j]) ans[j]=id[i],k++;
		if (j>x[id[i]]) flag=0;
	}
	for (int i=n,j=n*n;i>=1 && flag;i--){
		for (int k=id[i];k<n;j--)
			if (!ans[j]) ans[j]=id[i],k++;
		if (j<x[id[i]]) flag=0;
	}
	if (flag){
		printf("Yes\n");
		for (int i=1;i<=n*n;i++) printf("%d ",ans[i]);
	}
	else printf("No\n");
}

Measured memory_bytes: 2048
#include<stdio.h>
#define MAX 100001
#define NIL -1
struct Node
{
  int A;
  int B;
  int C;
};
 
struct Node Three[MAX];
 
int getDepth(int K)
{
  int dep = 0;
   
  for(dep = 0; Three[K].A != NIL; dep++)
  {
    K = Three[K].A;
  }
  return dep;
}
 
int main()
{
  int i,j,n;
  int num,deg,child,l = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      Three[i].A = NIL;
      Three[i].B = NIL;
      Three[i].C = NIL;
    }
     
 
    for(i = 0; i < n; i++)
    {
 
      scanf("%d%d",&num,&deg);

      for(j = 0; j < deg; j++)
      {
        scanf("%d",&child);
 
        if(j == 0) Three[num].B = child;
        else Three[l].C = child;
 
        l = child;
        Three[child].A = num;
      }
 
    }
     
    for(i = 0; i < n; i++)
    {
      printf("node %d: parent = %d, depth = %d",i,Three[i].A,getDepth(i));
       

      if(getDepth(i) == 0)
      {
 
        printf(", root, [");
 
      }
      else if(Three[i].B == NIL)
      {
 
        printf(", leaf, [");
 
      }
 
      else
      {
        printf(", internal node, [");
      }
       
      j = Three[i].B;
       
      while(j != NIL)
      {
        printf("%d", j);
 
        j = Three[j].C;
         
        if(j != NIL)
        {
 
          printf(", ");
          
        }
 
      }
 
 
      printf("]\n");
 
    }
 
     
    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, lim, s = 0;
    constexpr i64 inf = 1000000000000000;
    std::cin >> n >> lim;
    std::vector<i64> w(n), v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> w[i] >> v[i];
        s += v[i];
    }

    std::vector<i64> dp(s + 1, inf);
    dp[v[0]] = w[0];
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        auto tmp(dp);
        for (int val = v[i]; val <= s; val++) {
            tmp[val] = std::min(tmp[val], dp[val - v[i]] + w[i]);
        }
        std::swap(dp, tmp);
    }

    int ret = s;
    while (dp[ret] > lim) ret--;
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

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

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

const int N = 100010;
const int INF = 0x3f3f3f3f;

pii v[N];

int main()
{
	ios_base::sync_with_stdio(false);
	
	int n, ans;

	cin >> n;
	for(int i = 0; i < n; ++i) cin >> v[i].fi >> v[i].se;

	int l1 = 0, l2 = 0, r1 = INF, r2 = INF;
	for(int i = 0; i < n; ++i) {
		if(v[i].fi > l1) l2 = l1, l1 = v[i].fi;
		else l2 = max(l2, v[i].fi);

		if(v[i].se < r1) r2 = r1, r1 = v[i].se;
		else r2 = min(r2, v[i].se);
	}

	ans = 0;
	for(int i = 0; i < n; ++i) {
		int l = (v[i].fi == l1 ? l2 : l1);
		int r = (v[i].se == r1 ? r2 : r1);
		ans = max(ans, v[i].se - v[i].fi + 1 + (l <= r ? r - l + 1 : 0));
	}

	sort(v, v + n, [](const pii &a, const pii &b) { return a.se < b.se || (a.se == b.se && a.fi > b.fi); });

	int maxl = 0;
	vector<pii> vec;
	for(int i = 0; i < n; ++i) {
		if(v[i].fi <= maxl) continue;
		vec.push_back(v[i]);
		maxl = max(maxl, v[i].fi);
	}

	n = vec.size();
	for(int i = 0; i + 1 < n; ++i) {
		int l1 = vec[i].fi;
		int r1 = vec[0].se;
		int l2 = vec[n - 1].fi;
		int r2 = vec[i + 1].se;
		if(l1 <= r1 && l2 <= r2) ans = max(ans, r1 - l1 + 1 + r2 - l2 + 1);
	}

	cout << ans << '\n';

	return 0;
}


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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

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

    long long int k, n;
    n = 2;
    long long int a[50];
    cin >> k;
    int ama = k % 50;
    int count = 0;
    if(k < 50){
        for(int i = 0; i < 50; i++){
            a[i] = 0;
        }
        a[0] = k*50;
    }
    else{
        if(ama == 0){
            for(int i = 0; i < 50; i++){
                a[i] = k/50+49;
            }
        }else{
            for(int i = 0; i < 50; i++){
                if(i < ama){
                    a[i] = (k-k%50)/50+49 - k%50 + 50 + 1 - count;
                    count++;
                }else{
                    a[i] = (k-ama)/50+49 - ama;
                }
            }   
        }
    }
    cout << "50\n";
    for(int i = 0; i < 50; i++){
        cout << a[i] << ' ';
    }
    cout << '\n';

    return 0;
}

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

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


int gcd(long long x, long long y) {
	if (y == 0) {
		return x;
	}

	gcd(y, x % y);
}


int main() {
	int N; cin >> N;
	vector<int> a(N);

	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	// 第２引数はデフォルト値
	vector<int> left(N + 1, 0), right(N + 1, 0);
	for (int i = 0; i < N; ++i) left[i + 1] = gcd(left[i], a[i]);
	for (int i = N - 1; i >= 0; --i) right[i] = gcd(right[i + 1], a[i]);

	int res = 0;
	for (int i = 0; i < N; ++i) {
		int left_gcd = left[i];
		int right_gcd = right[i+1];
		chmax(res, gcd(left_gcd, right_gcd));

	}

	cout << res << endl;
}


Measured memory_bytes: 1408
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N,A;
	cin >> N >> A;
	if (N % 500 <= A) {
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

typedef unsigned long long ull;

ull XOR(ull n){
    switch (n % 4) {
    case 0: return n;
    case 1: return 1;
    case 2: return n+1;
    case 3: return 0;
    }
}

int main(){
    ull a, b;
    std::cin >> a >> b;
    ull ans = XOR(a-1) ^ XOR(b);
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
def isStable(in_lst,out_lst):
    for i in range(n):
        for j in range(i+1,n):
            for a in range(n):
                for b in range(a+1,n):
                    if in_lst[i][1] == in_lst[j][1] and in_lst[i] == out_lst[b] and in_lst[j] == out_lst[a]:
                        return False
    return True

def isStable1(in_lst,out_lst):
    tmp = isStable(in_lst,out_lst)
    if tmp == True:
        print('Stable')
    else:
        print('Not stable')

n = int(input())
lst = list(map(str,input().split()))
ans_lst = lst.copy()
for i in range(0,n):
    for j in range(n-1,i,-1):
        if lst[j][1] < lst[j-1][1]:
            lst[j],lst[j-1] = lst[j-1],lst[j]

print(' '.join(lst))
isStable1(ans_lst,lst)

lst = ans_lst.copy()
for i in range(n):
    minj = i
    for j in range(i,n):
        if lst[j][1] < lst[minj][1]:
            minj = j
    lst[i],lst[minj] = lst[minj],lst[i]

print(' '.join(lst))
isStable1(ans_lst,lst)






Measured memory_bytes: 5608
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int rip[60] = {};
    int sei[100] = {};

    rep(i,0,60){
        rip[i] = i * i * i;
    }
    rep(i,0,100){
        sei[i] = i * (i + 1) * (i + 2) / 6;
    }

    while(true){
        int in;
        cin >> in;
        if(in == 0) break;
        int ans = 0;
        for(int i = 0; i < 60; i++){
            for(int j = 0; j < 100 ; j++){
                if(rip[i] + sei[j] <= in && ans < rip[i] + sei[j]){
                    ans = rip[i] + sei[j];
                }
            }
        }
        cout << ans << endl;
    }





    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL pow(int a,int b){
  LL ans=1;
  while (b){
    if (b&1)ans*=a;
    a*=a;
    b/=2;
  }
  return ans;
}
bool flag[15];
char str[15];
int main(){
  scanf("%s",str);
  int l=strlen(str);
  LL ans=0;
  for (int i=0; i<pow(2,l-1); ++i){
    memset(flag,0,sizeof flag);
    for (int j=0; j<l-1; ++j){
      if (pow(2,j)&i)flag[j]=1;
    //  if (flag[j])printf("%d ",j);
    }
/*    printf("\n");
    for (int i=0; i<l; ++i)printf("%d ",flag[i]);
    printf("\n");*/
    LL sum=0;
    for (int j=0; j<l; ++j){
      if (flag[j]){
       // printf("%lld\n",sum*10+str[j]-'0');
        ans+=sum*10+str[j]-'0';
        sum=0;
      }
      else{
        sum*=10;
        sum+=str[j]-'0';
      }
    }
    ans+=sum;
   // printf("%lld\n",ans);
  }
  printf("%lld\n",ans);
}

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

int main()
{
	int n;
	cin >> n;
	
	int hei[n], dp[n];
	for (int i = 0; i < n; i++) {
		cin >> hei[i];
	}
	
	dp[0] = 0;
	dp[1] = abs(hei[1]-hei[0]);
	
	for (int i = 2; i < n; i++)
	{
		dp[i] = min(abs(hei[i]-hei[i-1])+dp[i-1], abs(hei[i]-hei[i-2])+dp[i-2]);
	}
	
	cout << dp[n-1] << "\n";
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int N,M;
	
	scanf("%d %d",&N, &M);
	
	if (N <= 1 && M <=1){
		printf("0");
	}
	else {
		printf("%d",(N*(N-1)/2) + (M*(M-1)/2));
	}

	return 0;
}

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

typedef vector<int> vi;
int main() {
	int N, M;
	cin >> N;
	vi vec1(N);
	rep(i, N)
		cin >> vec1.at(i);
	cin >> M;
	vi vec2(M);
	rep(i, M)
		cin >> vec2.at(i);
	vi vec3(N + M);
	vi::iterator	it;
	it = set_difference(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), vec3.begin());
	vec3.resize(it - vec3.begin());
	for (it = vec3.begin(); it != vec3.end(); it++)
		cout << *it << endl;
}



Measured memory_bytes: 5908
S = input()

def get_dif(length, str1, str2):
    c = 0
    for i in range(length):
        if str1[i] != str2[i]:
            c += 1
    return c

l = len(S)
if l % 2 == 0:
    S1 = "01" * (l // 2)
    S2 = "10" * (l // 2)
else:
    S1 = "01" * ((l - 1) // 2) + "0"
    S2 = "10" * ((l - 1) // 2) + "1"

c1 = get_dif(l, S, S1)
c2 = get_dif(l, S, S2)

if c1 <= c2:
    print(c1)
else:
    print(c2)

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

int main() {
	int N, ans = 0, tmp = 0;
	string S;
	cin >> N >> S;
	for (char& i : S) {
		if (i == '#') ++tmp;
		else {
			if (tmp) {
				++ans;
				--tmp;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};

vector<int> par(0),depth(0),siz(0);
void init(int n){
    par.resize(n);
    depth.resize(n,0);
    siz.resize(n,1);
    rep(i,n) par[i]=i;
}

int find(int n){
    if(par[n]==n) return n;
    return par[n]=find(par[n]);
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(par[x]==par[y]) return;
    siz[x]+=siz[y];
    siz[y]=siz[x];
    if(depth[x]<depth[y]) par[x]=par[y];
    else{
        par[y]=par[x];
        if(depth[x]==depth[y]) depth[x] ++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}

int size(int x){
    return siz[find(x)];
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n,m;
    cin>>n>>m;
    init(n);
    vector<P> x(m);
    int a,b;
    rep(i,m){cin>>a>>b;a--,b--;x[i]=P(a,b);}
    vector<in> ans(m,0);
    ans[m-1]=n*(n-1)/2ll;
    for(in i=m-1;i>0;i--){
        if(same(x[i].first,x[i].second)) ans[i-1]=ans[i];
        else ans[i-1]=ans[i]-size(x[i].first)*size(x[i].second);
        unite(x[i].first,x[i].second);
    }
    rep(i,m) cout<<ans[i]<<endl;
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  string s;cin>>s;
  ll n=s.size();
  ll P=2019;
  map<ll,ll>mp;
  mp[0]=1;
  ll now=0;
  ll mul=1;
  repr(i,n-1,0){
    now=(now+(s[i]-'0')*mul)%P;
    mul*=10;
    mul%=P;
    mp[now]++;
  }
  ll ans=0;
  each(e,mp){
    ans+=e.second*(e.second-1)/2;
  }

  out(ans);

  return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int A, B, C, D, E;
    if (a%10 == 0){
        A = a;
    } else {
        A = (a/10+1)*10;
    }
    if (b%10 == 0){
        B = b;
    } else {
        B = (b/10+1)*10;
    }
    if (a%10 == 0){
        C = c;
    } else {
        C = (c/10+1)*10;
    }
    if (a%10 == 0){
        D = d;
    } else {
        D = (d/10+1)*10;
    }
    if (e%10 == 0){
        E = e;
    } else {
        E = (e/10+1)*10;
    }
    int mi = 10;
    if (mi > a%10 && a%10 > 0){
        mi = a%10;
    }
    if (mi > b%10 && b%10 > 0){
        mi = b%10;
    }
    if (mi > c%10 && c%10 > 0){
        mi = c%10;
    }
    if (mi > d%10 && d%10 > 0){
        mi = d%10;
    }
    if (mi > e%10 && e%10 > 0){
        mi = e%10;
    }
    cout << A+B+C+D+E-10+mi << endl;
    return 0;
}


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

int main(){
    int x,k;
    cin>>k>>x;

    for(int i=x-k+1; i<k+x; i++){
        if(i < -1000000  || i > 1000000)
            continue;
        cout<<i<<" ";
    }

}


Measured memory_bytes: 256
n=int(input())
multi3 = [int(x.strip()) for x in input().split()]
ans=1
flag=True
for i in multi3:
    if ans*i>10**18:
        flag=False
    elif i==0:
        flag=True
        ans=0
        break
    else:
        ans*=i
if(flag):
    print(ans)
else:
    print(-1)


Measured memory_bytes: 21576
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, k;

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> k;
    cout << k * (int)pow(k-1,n-1) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int A,B,C,D;
  	cin >> A >> B >> C >> D;
 	while(A>0 && C>0) {
    	C-=B;
      	if(C<=0) break;
      	A-=D;
    }
  	cout << (A>0 ? "Yes":"No") << endl;
}

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

#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");

int main() {
  int n, k;
  cin >> n >> k;

  map<int, int> Map;
  for (int i = 1; i <= n; i++) Map.insert(make_pair(i, 0));

  for(int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      Map.at(a) += 1;
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (Map.at(i) == 0) ++ans;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3536
#include <iostream>
using namespace std;
int a[1010];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a[i];
  }
  int ans=0;
  for(int i=0;i<n;++i){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        ans+=1;
      }
    }
  }
  if(ans>0){
    cout<<"DENIED"<<endl;
  }
  else{
    cout<<"APPROVED"<<endl;
  }
        
  
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n = 0, a;
	for (int h = 0; h < 10; h++) {
		cin >> a;
		n += a;
	}
	cout << n << endl;
	cin >> n;
}


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

int main(){
    int a,b;
    cin>>a>>b;
    if(b%a)cout<<b-a<<endl;
    else cout<<a+b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef double Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={-1,1,0,0,0,0};
int dy[]={0,0,-1,1,0,0};
int dz[]={0,0,0,0,-1,1};
//int dx[]={0,1,0,-1};
//int dy[]={1,0,-1,0};
int main(){
	ll x,y,z,n;
	cin>>x>>y>>z>>n;
	vvi in(n,vi(3));
	rep(i,n)rep(j,3)cin>>in[i][j];
	ll out=2*x*y+2*y*z+2*z*x;
	rep(i,n)rep(j,6){
		int a=in[i][0]+dx[j];
		int b=in[i][1]+dy[j];
		int c=in[i][2]+dz[j];
		if(a<0||a>=x||b<0||b>=y||c<0||c>=z){
			out--;
		}else{
			bool h=false;
			rep(k,n)if(in[k][0]==a&&in[k][1]==b&&in[k][2]==c){
				h=true;
			}
			if(!h)out++;
		}
	}
	
	cout<<out<<endl;
}

Measured memory_bytes: 3316
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

ans = p[:x] + q[:y] + r[:x+y]
ans.sort(reverse=True)

print(sum(ans[:x+y]))


Measured memory_bytes: 113004
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int a[4],b[4],res;
	scanf("%d%d%d%d",a,a+1,a+2,a+3);
	scanf("%d%d%d%d",b,b+1,b+2,b+3);
	res = max(*a+a[1]+a[2]+a[3],*b+b[1]+b[2]+b[3]);
	printf("%d\n",res);
}

Measured memory_bytes: 0