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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long lint;

int N, M, P[100005];
lint cnt[100005];

int main() {
	cin >> N >> M;
	for_(i,0,M) {
		cin >> P[i];
		--P[i];
	}
	
	memset(cnt, 0, sizeof(cnt));
	for_(i,1,M) {
		int x = P[i-1], y = P[i];
		if (x > y) swap(x, y);
		for_(j,x,y) ++cnt[j];
	}
		
	lint ans = 0;
	for_(i,0,N-1) {
		lint A, B, C;
		cin >> A >> B >> C;
		ans += min(cnt[i] * A, cnt[i] * B + C);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4268
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef pair<double, P> E;
const int NN=10001;
int rep[NN];
int weight[NN];
P pos[NN];
int Find(int i){
	while(i!=rep[i]){
		i=rep[i]=rep[rep[i]];
	}
	return i;
}
void Union(int i, int j){
	if(weight[i]<weight[j]){
		swap(i,j);
	}
	rep[j]=i;
	weight[i]+=weight[j];
}
inline double len(P a, P b){
	double s=a.first-b.first;
	double t=a.second-b.second;
	return sqrt(s*s+t*t);
}
int main() {
	int N,M;
	cin >> N >> M;
	for(int i=1;i<=N;i++){
		rep[i]=i;
		weight[i]=1;
		cin >> pos[i].first >> pos[i].second;
	}
	vector<E> edge(M);
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		edge[i]=E(len(pos[a],pos[b]),P(a,b));
	}
	double ret=0;
	sort(edge.begin(),edge.end(),greater<E>());
	for(int i=0;i<edge.size();i++){
		int a=edge[i].second.first;
		int b=edge[i].second.second;
		a=Find(a);
		b=Find(b);
		if(a!=b){
			Union(a,b);
		}
		else
		{
			ret+=edge[i].first;
		}
	}
	printf("%.3lf\n",ret);
}

Measured memory_bytes: 1796
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n;
char s[MAXN+1];

ll solve() {
	ll ret=0;
	int nblack=0;
	REP(i,n) if(s[i]=='B') ++nblack; else ret+=nblack;
	return ret;
}

void run() {
	scanf("%s",s); n=strlen(s);
	printf("%lld\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,a[75];
int main() {
    cin>>n;
    if(n==0) {
        cout<<0<<endl;
        return 0;
    }
    int id=0,tmp=0;
    while(n!=0){
        if(n%-2<0) {
            a[id++]=1;
            n=n/-2+1;
        }
        else {
            a[id++]=n%-2;
            n/=-2;
        }
    }
    reverse(a,a+id);
    for(int i=0;i<id;i++) cout<<a[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
// 3_abc062_c
#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>// C++
#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>

using namespace std;
#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 SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w;
    cin >> h >> w;
    ll ans;
    if(w % 3 == 0 || h % 3 == 0){
        cout << 0 << endl;
        return 0;
    }
    ans = min(h, w);

    ll a, b, c;
    for(int i = 1; i <= h - 1; i++){
        a = w * i;
        if(w % 2 == 0){
            b = (h - i) * w / 2;
            c = b;
        }else{
            b = (h - i) * (w / 2 + 1);
            c = (h - i) * (w / 2);
        }
        ll diff = max(abs(b - a), abs(c - b));
        diff = max(diff, abs(a - c));
        if(ans > diff) ans = diff;
    }

    for(int i = 1; i <= w - 1; i++){
        a = h * i;
        if(h % 2 == 0){
            b = (w - i) * h / 2;
            c = b;
        }else{
            b = (w - i) * (h / 2 + 1);
            c = (w - i) * (h / 2);
        }
        ll diff = max(abs(b - a), abs(c - b));
        diff = max(diff, abs(a - c));
        if(ans > diff) ans = diff;
    }

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


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

// Counter ...
type Counter struct {
	s   string
	cnt int
}

var counters []Counter

func main() {
	var w string
	fmt.Scan(&w)
	// fmt.Printf("w = %s\n", w)

	var str string
	for i := 0; i < len(w); i++ {
		s := w[i : i+1]
		if !strings.Contains(str, s) {
			str += s
			counters = append(counters, Counter{s: s, cnt: 1})
		} else {
			for j, c := range counters {
				if c.s == s {
					counters[j] = Counter{s: s, cnt: c.cnt + 1}
					break
				}
			}
		}
		// fmt.Printf("s = %s, counters = %v\n", s, counters)
	}

	result := true
	for _, c := range counters {
		if c.cnt%2 != 0 {
			result = false
			break
		}
	}
	if result {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;
class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        long x=Math.abs(Long.parseLong(s[0])),k=Long.parseLong(s[1]),d=Long.parseLong(s[2]);
        long moves=x/d;
        if(moves>=k)
        {
            x-=d*k;
            sb.append(x);
        }
        else
        {
            k-=moves;
            x-=d*moves;
            k%=2;
            if(k==1) x=Math.min(Math.abs(x-d),Math.abs(x+d));
            sb.append(x);
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 32636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 26024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc100/abc100_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int a, b;
  cin >> a >> b;

  cout << ((a > 8 || b > 8) ? ":(" : "Yay!") << endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        Arrays.sort(A);
        int ba = -1;
        int cnt = 0;
        for (int a : A) {
            if(ba == a){
                cnt++;
            } else {
                ba = a;
            }
        }

        cnt = (int)Math.ceil(cnt / 2.0) * 2;
        out.println(N - cnt);
    }
}

Measured memory_bytes: 50712
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n = int(ipt())
    for i in range(n):
        a = int(ipt())
        if a%2:
            print("first")
            exit()
    print("second")

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 9696
#include <iostream>

using namespace std;
int main()
{
    long long int i,n,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
           sum+=i;
    }
    cout<<sum;

   return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

vector<int> G[100010];
int dp[100010],sum[100010],cnt[100010],ans[100010];

void dfs(int v,int par){
	for(int to : G[v]){
		if(to != par){
			dfs(to,v);
			sum[v] += dp[to];
			if(!dp[to]) cnt[v]++;
		}
	}
	dp[v] = sum[v] + max(cnt[v] - 1,0ll);
}

void dfs2(int v,int par){
	if(par == -1) ans[v] = dp[v];
	else{
		int pcnt = cnt[par],psum = sum[par];
		if(!dp[v]) pcnt--;
		psum -= dp[v];
		int pans = psum + max(pcnt - 1,0ll);
		if(!pans) cnt[v]++;
		sum[v] += pans;
		ans[v] = sum[v] + max(cnt[v] - 1,0ll);
	}
	for(int to : G[v]){
		if(to != par) dfs2(to,v);
	}
}

signed main(){
	int n,mi = INF;
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0,-1);
	dfs2(0,-1);
	for(int i = 0;i < n;i++){
		mi = min(mi,ans[i] + 1);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 13440
#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>;


int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans=a[0]+k-a[n-1];
  rep(i,n-1) {
    ans=max(ans,a[i+1]-a[i]);
  }
  cout << k-ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 100000;
const int M = 1000;

int x[N], y[N], c[N], cnt[M * 2];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        static char buf[2];
        scanf("%d%d%s", x + i, y + i, buf);
        x[i] %= 2 * m;
        y[i] %= 2 * m;
        c[i] = *buf == 'B';
    }
    int result = 0;
    for (int dx = 0; dx < 2 * m; ++ dx) {
        memset(cnt, 0, sizeof(cnt));
        int s = 0;
        for (int i = 0; i < n; ++ i) {
            x[i] ++;
            if (x[i] == 2 * m) {
                x[i] = 0;
            }
            int cc = c[i] ^ (x[i] >= m);
            if (cc) {
                cnt[y[i]] ++;
            } else {
                s ++;
                cnt[y[i]] --;
            }
        }
        for (int j = 0; j < m; ++ j) {
            s += cnt[j];
        }
        for (int j = 0; j < 2 * m; ++ j) {
            result = std::max(result, s);
            s += cnt[(j + m) % (2 * m)] - cnt[j];
        }
    }
    printf("%d\n", result);
}

Measured memory_bytes: 1280
#if 0
はじめ、i番目の荷物が入れられるときに何個入れるかを計算するためにwhile文を用いたためO(NW^2)かかりTLEになってしまったが、授業中に質問し改めて考えることで解くことができた。
#endif

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

int N, W;
int v[110]; int w[110];
int V[110][10010];

int main() {
  cin >> N >> W;
  for (int i = 1; i <= N; i++)
    cin >> v[i] >> w[i];
  for (int i = 0; i <= N; i++) {
    for (int c = 0; c <= W; c++) {
      if (i == 0 || c == 0)
        V[i][c] = 0;
      else if (c-w[i] < 0)
        V[i][c] = V[i-1][c];
      else {
        int a[3] = {v[i] + V[i][c-w[i]],v[i] + V[i-1][c-w[i]], V[i-1][c]};
        V[i][c] = *max_element(a, a+3);
      }
    }
  }
  cout << V[N][W] << endl;
}



Measured memory_bytes: 7076
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String p = sc.next();

        String ring = s + s;
        if(ring.indexOf(p) != -1){System.out.println("Yes");}
        else{System.out.println("No");}
    }
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);

	int res = 0;
	while(true){
		bool exist_odd = false;
		rep(i, n){
			if(a.at(i)%2 != 0)
				exist_odd = true;
		}

		if(exist_odd) break;

		rep(i, n)
			a.at(i) /= 2;
		res++;
	}

	cout << res << endl;
}


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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  string b; cin>>b;
  char ans = ' ';
  switch (b[0]) {
  case 'A': ans = 'T'; break;
  case 'T': ans = 'A'; break;
  case 'C': ans = 'G'; break;
  case 'G': ans = 'C'; break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
x,y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and y in a:
    print('Yes')
elif x in b and y in b:
    print('Yes')
elif x in c and y in c:
    print('Yes')
else:
    print('No')

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 200010

ll N;
vector<ll> A;


// 文字種 alph_max で A を乗り切れるなら true
bool check(ll alph_max) {

    // 現在の文字列
    // first: インデックス second: 値
    // 未入力部分は基本 1 が入ることになる
    vector< pair<ll, ll> > cur;
    for(ll i = 1; i < N; ++i) {
        // 長くなるなら、後ろに最小文字 1 が入るだけ
        if(A[i - 1] < A[i]) { continue; }
        // 文字種が 1 つなら、A が単調増加じゃないと構築不可能
        if(alph_max == 1) { return false; }

        // 見る必要のないインデックスの値は捨てる
        while(cur.size() > 0 && cur[cur.size()-1].first > A[i]) { cur.pop_back(); }
        if(cur.size() == 0) {
            cur.push_back(make_pair(A[i], 2));
            continue;
        }

        bool isOk = false;
        ll ind = A[i];
        for(ll j = cur.size()-1; j >= 0; --j) {
            if(cur[j].first != ind) {
                assert(cur[j].first < ind);
                // 自分より後ろをクリア
                while(cur.size() > j + 1) { cur.pop_back(); }
                cur.push_back(make_pair(ind, 2));
                isOk = true;
                break;
            }
            else if(cur[j].second < alph_max) {
                cur[j].second += 1;
                // 自分より後ろをクリア
                while(cur.size() > j + 1) { cur.pop_back(); }
                isOk = true;
                break;
            }
            ind--;
        }
        if(!isOk) {
            if(ind > 0) {
                cur.clear();
                cur.push_back(make_pair(ind, 2));
            }
            else {
                return false;
            }
        }
    }
    return true;
}

ll solve() {
    ll lb = 1;
    ll ub = N;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(check(mid)) { ub = mid; }
        else { lb = mid + 1; }
    }
    if(check(lb)) { return lb; }
    assert(check(ub));
    return ub;
}

signed main()
{
    cin >> N;
    A.resize(N);
    REP(i, N) { cin >> A[i]; }
    ll ans = solve();
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

struct Cake {
  int64_t specs[3];

  int64_t sum() const { return specs[0] + specs[1] + specs[2]; }
};

int64_t calc_sub(std::vector<Cake> cakes, int m) {
  std::sort(
      cakes.begin(), cakes.end(),
      [](const Cake& x, const Cake& y) -> bool { return x.sum() > y.sum(); });
  std::array<int64_t, 3> specs = {};
  for (int c = 0; c < m; ++c) {
    const Cake& cake = cakes[c];
    specs[0] += cake.specs[0];
    specs[1] += cake.specs[1];
    specs[2] += cake.specs[2];
  }
  return abs(specs[0]) + abs(specs[1]) + abs(specs[2]);
}

int64_t calc(const std::vector<Cake>& cakes, int m) {
  if (m == 0) {
    return 0;
  }

  int64_t ret = 0;
  int const n = cakes.size();
  std::vector<Cake> positive_cakes(n);
  for (int i = 0; i < 2; ++i) {
    if (i == 0) {
      for (int c = 0; c < n; ++c) {
        positive_cakes[c].specs[0] = cakes[c].specs[0];
      }
    } else {
      for (int c = 0; c < n; ++c) {
        positive_cakes[c].specs[0] = -cakes[c].specs[0];
      }
    }
    for (int j = 0; j < 2; ++j) {
      if (j == 0) {
        for (int c = 0; c < n; ++c) {
          positive_cakes[c].specs[1] = cakes[c].specs[1];
        }
      } else {
        for (int c = 0; c < n; ++c) {
          positive_cakes[c].specs[1] = -cakes[c].specs[1];
        }
      }
      for (int k = 0; k < 2; ++k) {
        if (k == 0) {
          for (int c = 0; c < n; ++c) {
            positive_cakes[c].specs[2] = cakes[c].specs[2];
          }
        } else {
          for (int c = 0; c < n; ++c) {
            positive_cakes[c].specs[2] = -cakes[c].specs[2];
          }
        }
        ret = std::max(calc_sub(positive_cakes, m), ret);
      }
    }
  }
  return ret;
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<Cake> cakes(n);
  for (int i = 0; i < n; ++i) {
    Cake& cake = cakes[i];
    std::cin >> cake.specs[0];
    std::cin >> cake.specs[1];
    std::cin >> cake.specs[2];
  }
  std::cout << calc(cakes, m) << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>

#define ACL "ACL"

int main()
{
    int k;
    char strings[20] = "";

    scanf("%d", &k);

    for (int i = 0; i<k; i++)
    {
        strcat(strings, ACL);
    }

    printf("%s", strings);

    return 0;
}

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

int main(){
    int H,W;
    char a[100][100];
    int row[100];
    int column[100];
    int counter = 0;

    scanf("%d%d",&H,&W);
    for(int i = 0;i <H;i++){
        counter = 0;
        for(int j = 0;j <W;j++){
            scanf(" %c",&a[i][j]);
            if(a[i][j] == '.'){
                counter++;
            }
        }
        if(counter == W){
            row[i] = 1;
        }else{
            row[i] = 0;
        }
    }
    for(int i = 0;i < W;i++){
        counter = 0;
        for(int j = 0;j < H;j++){
            if(a[j][i] == '.'){
                counter++;
            }
        }
        if(counter == H){
            column[i] = 1;
        }else{
            column[i] = 0;
        }
    }
    for(int i = 0;i < H;i++){
        if(row[i] == 1)continue;
        for(int j = 0;j<W;j++){
            if(column[j] == 1)continue;
            printf("%c",a[i][j]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	string s, t;
	std::cin >> s >> t;

	vector<vll> dp(s.size() + 1, vll(t.size() + 1, 0));
	vector<vector<string>> ans(2, vector<string>(t.size() + 1, ""));
	rep(i, 0, s.size()) {
		rep(j, 0, t.size()) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
				ans[1][j + 1] = ans[0][j] + s[i];
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				if (dp[i + 1][j] > dp[i][j + 1]) {
					ans[1][j + 1] = ans[1][j];
				}
				else {
					ans[1][j + 1] = ans[0][j + 1];
				}
			}
		}
		ans[0] = ans[1];
	}
	std::cout << ans[0][t.size()] << endl;

	return 0;

}


Measured memory_bytes: 88260
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int num=0;  
    for(int i=0;i<a.size();i++){
        if(a[i]=='C'){
            num=1;
        }
        if(a[i]=='F'&&num==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
ll k;
int a[200100]; 
int D[200100][111];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k;
	rep(i,n)
	{
		int b;
		cin>>b;
		b--;
		D[i][0]=b;
	}
	forn(i,1,65)
	{
		rep(j,n)
		{
			D[j][i]=D[D[j][i-1]][i-1];
		}
	}
	int now=0;
	int  cnt=-1;
	while(k>0)
	{
		cnt++;
		if(k%2)
		{
			now=D[now][cnt];
			k--;
		}
		k/=2;
	}
	cout<<now+1<<endl;
	return 0;
} 

Measured memory_bytes: 90336
import java.util.Scanner;


public class Main {
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            int n = s.nextInt();
            if (n == 0) break;

            int[] key = new int[n];

            for (int i = 0; i < n; i++) {
                key[i] = s.nextInt();
            }

            String station = s.next();
            int num = 0;

            for (int i = 0; i < station.length(); i++) {
                int ans = station.charAt(i);
                if (ans > 96) {
                    ans -= key[num];
                    if (ans < 97) {
                        ans -= 6;
                        if (ans < 65)
                            ans += 58;
                    }
                } else {
                    ans -= key[num];
                    if (ans < 65) {
                        ans += 58;
                        if (ans < 97)
                            ans -= 6;
                    }
                }

                num++;
                if(num==n)num=0;

                System.out.print((char) ans);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 24532
#include<bits/stdc++.h>
using namespace std;
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
bool isprime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res=((res%mod)*((n-i)%mod))%mod;res=((res%mod)*(power(i+1,mod-2))%mod)%mod;}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll sol=a>b?a:b;return sol;}
ll min(ll a,ll b){ll sol=a<b?a:b;return sol;}
int main()
{
   bolt;
   ll n,k;
   cin>>n>>k;
   ll a[n];
   for (ll i=0;i<n;i++)
   {
      cin>>a[i];
   }
   ll s=0;
   sort(a,a+n);
   for (ll i=0;i<n-k;i++)
   {
      s+=a[i];
   }
   cout<<s;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  int a,b,ans;
  cin>>a>>b;
  if(a==0 || b==0){
    if(a==0){
      if(b>0)ans=b;
      else ans=abs(b)+1;
    }
    else{
      if(a>0)ans=a+1;
      else ans=abs(a);
    }
  }
  else if(a>0 && b>0){
      if(a>b){
        ans=a-b+2;
      }
      else{
        ans=b-a;
      }
  }
  else if(a<0 && b<0){
    if(a>b){
      ans=a-b+2;
    }
    else{
      ans=b-a;
    }
  }
  else if(a>0){
    b=abs(b);
    if(a>b){
      ans=a-b+1;
    }
    else{
      ans=b-a+1;
    }
  }
  else{
    a=abs(a);
    if(a<b){
      ans=b-a+1;
    }
    else{
      ans=a-b+1;
    }
  }
  out(ans);
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
const int maxn = 2e5 +5;
const int inf = 1e9 + 1;
const ll llinf = 1e18 + 5;
int n, a[maxn] , b[maxn];
bool check(int val){
    for(int i = 1 ; i <= 2 * n - 1 ; ++i){
        b[i] = (a[i] > val);
    }
    for(int i = 0 ; i < n - 1 ; ++i){
        if((b[n - i] && b[n - i - 1]) || (b[n + i] && b[n + i + 1]))return 1;
        if((!b[n - i] && !b[n - i - 1]) || (!b[n + i] && !b[n + i + 1]))return 0;
    }
    return b[1];
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n * 2 - 1 ; ++i){
        cin >> a[i];
    }
    int l = 1;
    int h = n * 2 - 1;
    while(l <= h){
        int mid = l + h >> 1;
        if(check(mid))l = mid + 1;
        else h = mid - 1;
    }
    cout << l;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define MOD 1000000007
#define ms(a,x) memset(a,x,sizeof(a))


int main() 
{ 
    run;
   ll n,i,ans=0;
   cin>>n;
   ll a[n], b[n+1]={0};
   for(i=0;i<n;i++)
   {
      cin>>a[i];
     b[i+1]+=b[i]+a[i];
    }
      for(i=0;i<n;i++)
      {
     ll sum=(b[n]-b[i+1])%MOD;
    	ans+=a[i]*sum;
    	ans%=MOD;
      }
      cout<<ans<<endl;
      
      
} 


Measured memory_bytes: 6784
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 ll INF = 1LL << 60;

int main() {
    double l; cin >> l;
    cout << setprecision(8) <<(l/3) * (l/3) * (l/3) << endl;
}


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int n;cin>>n;
   vector<int> nums(n);
   for(int i=0;i<n;i++){
      cin>>nums[i];
   }
   int ans=0;
   for(int i=1;i<n-1;i++){
      int mi=min({nums[i-1], nums[i+1]});
      int ma=max({nums[i-1], nums[i+1]});
      if(nums[i]>=mi&&nums[i]<=ma) ans++;
   }
   cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll gcd(ll a, ll b){     
   if(b == 0) return a;
   
   return gcd(b, a % b);
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<bool> b(10,false);
  for(int i=0; i<K; i++){
    int k; cin >> k;
    b[k] = true;
  }
  for(int i=N; i<=10*N; i++){
    bool f=true;
    int tmp = i;
    while(tmp>0){
      if(b[tmp%10]){
        f=false;
        break;
      }
      tmp/=10;
    }
    if(f){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n, k = [int(item) for item in input().split()]
sushi = [[int(item) for item in input().split()] for _ in range(n)]
sushi.sort(key=lambda x: x[1], reverse = True)

kind = set()
changeable = []

points = 0
for i in range(k):
  points += sushi[i][1]
  if sushi[i][0] in kind:
    changeable.append(sushi[i][1])
  else:
    kind.add(sushi[i][0])

points += len(kind)**2
ans = points

for i in range(k, n):
  if not changeable:
    break
  if sushi[i][0] not in kind:
    kind.add(sushi[i][0])
    points += sushi[i][1] - (len(kind)-1)**2 + len(kind)**2 - changeable.pop()
    ans = max(ans, points)

print(ans)
  

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

int main() {
  char str[20][20];
  while(1) {
    for ( int i = 4; i < 12; i++ ){
      for ( int j = 4; j < 12; j++ ) {
      cin >> str[i][j];
      if ( cin.eof() ) return 0;
      }
    }
    char ans;
    for ( int i = 4; i < 12; i++ ) {
      for ( int j = 4; j < 12; j++ ) {
      if ( str[i][j] == '1' && str[i][j+1] == '1' && 
	   str[i+1][j] == '1' && str[i+1][j+1] == '1' ) ans = 'A';
      else if ( str[i][j] == '1' && str[i+1][j] == '1' &&
		str[i+2][j] == '1' && str[i+3][j] =='1' ) ans = 'B';
      else if ( str[i][j] == '1' && str[i][j+1] == '1' &&
		str[i][j+2] == '1' && str[i][j+3] == '1' ) ans = 'C';
      else if ( str[i][j] == '1' && str[i+1][j-1] == '1' &&
		str[i+1][j] == '1' && str[i+2][j-1] == '1' ) ans = 'D';
      else if ( str[i][j] == '1' && str[i][j+1] == '1' &&
		str[i+1][j+1] == '1' && str[i+1][j+2] == '1' ) ans = 'E';
      else if ( str[i][j] == '1' && str[i+1][j] == '1' &&
		str[i+1][j+1] == '1' && str[i+2][j+1] == '1' ) ans = 'F';
      else if ( str[i][j] == '1' && str[i][j+1] == '1' &&
		str[i+1][j-1] == '1' && str[i+1][j] == '1' ) ans = 'G';
							 
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
ll mod = 1e9+7;

int main() 
{ 
/*	ll n;
	cin>>n;
	ll s = (25*n)/26;
	ll x = log(s+1)/log(26);
	ll y = (26*(pow(26,x)-1))/25;
	ll z = n - y;
	cout<<z;
	if(y==n) {
		for(int i=0; i<x; i++)
			cout<<"z";
	}
	// final digits = x+1;
	else {
		while() {
			ll r = z/26;
			ll c = z - pow(26,r);
		}
	}
*/
	ll n;
	cin>>n;
	ll a[n];
	vector<ll> mp(100010,0);
	ll sum = 0;
	for(int i=0; i<n; i++)  {
		cin>>a[i];
		mp[a[i]]++;
		sum += a[i];
	}

	int q;
	cin>>q;
	for(int i=0; i<q; i++) {
		ll b,c;
		cin>>b>>c;
		sum -= mp[b]*b;
		sum += mp[b]*c;
		mp[c] += mp[b];
		mp[b] = 0;
		cout<<sum<<"\n";
	}

    return 0; 
} 

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

int main() {
  long long h, w;
  cin>>h>>w;
  if (w == 1 || h == 1) {
    cout<<1<<endl;
    return 0;
  }
  long long w1 = (w - 1) / 2 + 1;
  long long w2 = (w - 2) / 2 + 1;
  long long h1 = (h - 1) / 2 + 1;
  long long h2 = (h - 2) / 2 + 1;
  cout<<w1 * h1 + w2 * h2<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
      Scanner sc=new Scanner(System.in);
      int S=sc.nextInt();
      int h=S/3600;
      int m=(S-h*3600)/60;
      int s=S-h*3600-m*60;
      System.out.println(h+":"+m+":"+s);
      }
    }


Measured memory_bytes: 26404
def su(s, k):
    count = 0
    for i in range(0, len(s)-1):
        tmp = k % 2
        k //= 2
        if(tmp == 1):
            s = s[:i+1+count] + '+' + s[i+1+count:]
            count += 1
    arr = s.split("+")
    arr = list(map(int, arr))
    return sum(arr)

s = input()
ans = 0
for i in range(0, (2 ** (len(s) - 1))):
    ans += su(s, i)
print(ans)


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

//最大公約数を求める関数
int64_t gcd(int64_t a, int64_t b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
//最小公倍数を求める関数
int64_t lcm(int64_t a, int64_t b){
    return a/gcd(a, b)*b;
}

int main(){
    int64_t n;
    cin >> n;
    int64_t t[200];
    for(int64_t i=1; i<=n; i++){
        cin >> t[i];
    }
    int64_t ans = lcm(1, t[1]);
    for(int64_t i=2; i<=n; i++){
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    string s;
    cin >> s ;

    ll n = s.size();
    vector<vector<ll>> dp(n+1, vector<ll>(2,0));
    dp[0][0] = 0;
    dp[0][1] = 1;
    for(int i = 1; i <= n; i++){
        ll d = s[i-1]-'0';
        dp[i][0] = min(dp[i-1][0] + d, dp[i-1][1] + (10-d));
        dp[i][1] = min(dp[i-1][0] + (d+1), dp[i-1][1] + (9-d));
    }
    cout << dp[n][0] << endl;


    return 0;

}


Measured memory_bytes: 55940
import copy
s = list(input())
t = list(input())
bool = False
for i in range(len(s)):
    temp = copy.copy(s)
    if s == t:
        bool = True
    for j in range(len(s)):
        if j == 0:
            s[0] = temp[len(s) - 1]
        else:
            s[j] = temp[j - 1]
if bool:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string str;
  cin>>str;
  if(str=="RRR"){
    cout<<"3"<<endl;
  }
  else if(str=="RRS"||str=="SRR"){
    cout<<"2"<<endl;
  }
  else if(str=="SSS"){
    cout<<"0"<<endl;
  }
  else{
    cout<<"1"<<endl;
  }
}

Measured memory_bytes: 3592
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int prime[10000] = {0};
	prime[0] = 2;
	prime[1] = 3;
	int count=2;
	int i=4;
	while(count<10000){
		bool flag = true;
		for(int j=2;j*j<=i;j++){
			if(i%j == 0){
				flag = false;
			}
		}
		if(flag){
			prime[count] = i;
			count++;
		}
		i++;
	}
	
	int n;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		int ans = 0;
		for(int j=0;j<n;j++){
			ans += prime[j];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1208
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printl(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}

signed main (){
    int n;cin>>n;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    vector<int> ans;
    while(!v.empty()){
        //print(v);
        int ind=-1;
        rep(i,0,v.size()){
            if(v[i]==i+1)ind=i;
        }
        if(ind==-1){
            cout<<-1<<endl;
            return 0;
        }
        ans.push_back(v[ind]);
        v.erase(v.begin()+ind);
    }
    reverse(all(ans));
    printl(ans);
}

/*

*/


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

int main(){
    bool a1 = false;
    bool a2 = false;
    bool a3 = false;
    bool a = false;
    string ans = "No";

    int N;
    cin >> N;

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

    int i = 0;
    //N回繰り返す
    while(i < N){
        /*
        //3回続けてがあるならば
        if(a == true){   
            break;
        }
        */
        //ぞろ目なら
        if(D[0][i] == D[1][i]){
            //1回目
            if((a1 == false)&&(a2 == false)&&(a3 == false)){
                a1 = true;
            //2回目
            }else if((a1 == true)&&(a2 == false)&&(a3 == false)){
                a2 = true;
            //3回目
            }else if((a1 == true)&&(a2 == true)&&(a3 == false)){
                a3 = true;
            }
            //3回続けてなら
            if((a1 == true)&&(a2 == true)&&(a3 == true)){
                a = true;
                break;
            }

        //ぞろ目でなければ
        }else{
            a1 = false;
            a2 = false;
            a3 = false;
            a = false;
        }
        i++;
    }

    if(a == true){
        ans = "Yes";
    }


    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, sum = 0, count = 0;
    cin >> N;
    vector<int> A(N);

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

    sum = N;
    while(sum == N) {
        sum = 0;
        for (int i = 0; i < N; i++) {
            if (A.at(i)%2 == 0) {
                sum++;
                A.at(i) /= 2;
            }
            else {
                break;
            }
        }
        if (sum == N) {
            count++;
        }
    }
    cout << count << endl; 
}

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

#define endl "\n"
#define FSP(n) cout << fixed << setprecision(n);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
static inline ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b);}
static inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

signed main() {
    prepare
    int N, K;
    cin >> N >> K;
    vector<bool> T(N, false);

    for (int j = 0; j < K; ++j) {
        int D = 0;
        cin >> D;
        vector<int> A(D, 0);
        for (int i = 0; i < D; ++i) {
            cin >> A[i];
            if (T[A[i] - 1] == false) {
                T[A[i] - 1] = true;
            }
        }
    }

    int ans = 0;
    for (int k = 0; k < N; ++k) {
        if (T[k] == false) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>

int main()
{
    long long n;
    while (std::cin >> n) {
        for (int a = 1; a <= 3500; ++ a) {
            for (int b = 1; b <= a; ++ b) {
                auto p = 4 * a * b - n * a - n * b;
                auto q = n * a * b;
                if (p > 0 && q % p == 0) {
                    auto c = q / p;
                    printf("%lld %lld %lld\n", a, b, c);
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
A = [int(x) for x in input().split()]
UV = [[int(x)-1 for x in row.split()] for row in sys.stdin.readlines()]

if N == 2:
    x,y = A
    answer = 'YES' if x == y else 'NO'
    print(answer)
    exit()

graph = [[] for _ in range(N)]
for u,v in UV:
    graph[u].append(v)
    graph[v].append(u)

def dfs(v,parent=None):
    x = A[v]
    if len(graph[v]) == 1:
        return x
    s = 0
    for w in graph[v]:
        if w == parent:
            continue
        ret = dfs(w,v)
        if ret == None:
            return None
        if x < ret:
            return None
        s += ret
    if 2*x-s > s:
        return None
    if 2*x < s:
        return None
    return 2*x-s

v=0
while len(graph[v]) == 1:
    v += 1

ret = dfs(v)
bl = (ret == 0)

answer = 'YES' if bl else 'NO'
print(answer)

Measured memory_bytes: 125216
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()

a = inlist()
b = [0]
b += a
p = 0
for i in range(1, n+1):
    if b[b[i]] == i and b[i] > 0:
        p += 1


print(p//2)


Measured memory_bytes: 13812