akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod = 1000000007;
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

int main(void){
    int n,m;
    cin >> n >> m;
    vector<string> A_nn;
    vector<string> B_mm;
    for(int i=0; i<n; i++){
        string x;
        cin >> x;
        A_nn.push_back(x);
    }
    for(int i=0; i<m; i++){
        string x;
        cin >> x;
        B_mm.push_back(x);
    }

    int flag; //flag==m*mならok
    int ok=0;
    for(int i=0; i<=(n-m); i++){
        for(int j=0; j<=(n-m); j++){
            flag = 0;
            for(int tmp_i=0; tmp_i<m; tmp_i++){
                for(int tmp_j=0; tmp_j<m; tmp_j++){
                    if(A_nn[i+tmp_i][j+tmp_j] == B_mm[tmp_i][tmp_j]){
                        flag += 1;
                    }
                }
            }
            if(flag == m*m){
                ok = 1;
                break;
            }
        }
    }
    if(ok==1) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    double n;
    cin >> n;
    double x;
    for (int i = 1; i <= n; i++){
        if (i%2 == 1){
            x++;
        }
    }
    cout << x/n << endl;

    return 0;
}


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

int cal(char *s){
	int l=strlen(s);
	int p=0;
	int q;
	for(int i=0;i<l;i++){
		q=1;
		if(s[i]>=0x32 && s[i]<=0x39){
			q=s[i++]-0x30;
		}
		if(s[i]=='m') p+=q*1000;
		else if(s[i]=='c') p+=q*100;
		else if(s[i]=='x') p+=q*10;
		else if(s[i]=='i') p+=q;
	}
	return p;
}

void i2str(int p,char *str){
	int q;
	int count=0;
	if(p>=1000){
		q=p/1000;
		p%=1000;
		if(q!=1){
			str[count++]=0x30+q;
		}
		str[count++]='m';
	}
	if(p>=100){
		q=p/100;
		p%=100;
		if(q!=1){
			str[count++]=0x30+q;
		}
		str[count++]='c';
	}
	if(p>=10){
		q=p/10;
		p%=10;
		if(q!=1){
			str[count++]=0x30+q;
		}
		str[count++]='x';
	}
	if(p>=1){
		if(p!=1){
			str[count++]=0x30+p;
		}
		str[count++]='i';
	}
	str[count]=0;
}

int main(){
	int n;
	char str1[10],str2[10];
	int ians;
	char ans[10];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>str1>>str2;
		ians=cal(str1);
		ians+=cal(str2);
		i2str(ians,ans);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
using namespace std;

int main(){
    int K,X;
    cin >> K>> X;
    if(500*K >= X){
        cout << "Yes" << endl;
    } else {
        cout <<"No" << endl;
    }
}


Measured memory_bytes: 256
from collections import deque
import sys
 
sys.setrecursionlimit(2000000000)
 
n = int(input())
nodes = []
done = [0 for _ in range(n)]
par = {}
for _ in range(n):
    x, y = map(int,input().split())
    nodes.append((x,y))
    par[(x,y)]=(x,y)
nodesx = sorted(nodes)
nodesy = sorted(nodes,key=lambda z:z[1])
s = []
m = len(set(nodes))
for i in range(n-1):
    xcost =nodesx[i+1][0]-nodesx[i][0]
    ycost =nodesy[i+1][1]-nodesy[i][1]
    s.append((xcost,(nodesx[i+1],nodesx[i])))
    s.append((ycost,(nodesy[i+1],nodesy[i])))
s.sort()
s = deque(s)
def root(node,par):
    if node == par[node]:
        return node
    else:
        par[node] =root(par[node],par)
        return par[node]
def unite(node1,node2,par):
    par[root(node1,par)] = root(node2,par)
ans = 0
count =0
while count < m-1 :
    cost,(node1,node2) = s.popleft()
    root1 =root(node1,par)
    root2 =root(node2,par)
    if root1 != root2:
        unite(node1,node2,par)
        ans +=cost
        count += 1
print(ans)

Measured memory_bytes: 73080
import java.io.BufferedReader;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.stream.IntStream;

public final class Main {

  public static void main(String[] args) throws Exception {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
      final String source = reader.readLine();
      try {
        int input = Integer.parseInt(source);

        int result = IntStream.iterate(1, i -> i + 1)
            .parallel()
            .map(i -> i * input)
            .filter(i -> (i & 1) == 0)
            .findFirst()
            .orElseThrow(RuntimeException::new);

        System.out.println(result);
      } catch (NumberFormatException exception) {
        throw new InternalError("\"" + source + "\" is not a valid number.");
      }
    }
  }

}


Measured memory_bytes: 29140
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<tuple>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	ll s, c;
	cin >> s >> c;
	ll ans = min(s, c/2);
	if(2*s < c) ans += (c-2*s) / 4;
	cout << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
char s[55][55];
int num[26];
int tmp[26];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for (int i=0;i<26;i++)
    {
        num[i]=100;
    }
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<26;j++)
            tmp[j]=0;
        for (int j=0;s[i][j];j++)
        {
            tmp[s[i][j]-'a']++;
        }
        for (int j=0;j<26;j++)
            num[j]=min(num[j],tmp[j]);
    }
    for (int i=0;i<26;i++)
    {
        if (!num[i])
            continue;
        for (int j=0;j<num[i];j++)
        {
            cout<<(char)('a'+i);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

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

	int result[] = { a + b, a - b, a * b };
	if (result[0] >= result[1] and result[0] >= result[2])
		cout << result[0] << endl;
	else if (result[1] >= result[2])
		cout << result[1] << endl;
	else
		cout << result[2] << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8
N = 0
C = []
S = []
F = []

# i駅での到着時間を指定すると、次の乗車時間が帰ってくる
def getNextTrain(i, time):
  # t = S[i]
  if time <= S[i]:
    return S[i]
  else:
    n = time / F[i]
    m = time % F[i]
    t = F[i] * n
    if m != 0:
      t += F[i]
    # while(1):
    #   if t >= time:
    #     break
    #   t += F[i]

    return t

# 入力部分
N = int(raw_input())
for i in range(N-1):
  c, s, f = map(int, raw_input().split())
  C.append(c)
  S.append(s)
  F.append(f)

# 処理部分
for k in range(N):
  arrive = 0
  for p in range(k, N-1): 
    # p駅から出発して
    arrive = getNextTrain(p, arrive)
    #print str(arrive) + '-> ' + str(p),
    arrive += C[p]
    #print '->' + str(arrive)
  print arrive

# 出力部分

Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 100000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double PI = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;


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

	ll n, m, ans = 0;
	cin >> n;
	string s;
	map<string, int> a, b;
	rep(i, n) {
		cin >> s;
		a[s]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> s;
		a[s]--;
	}
	map<string, int>::iterator it;
	for (it = a.begin(); it != a.end(); it++) {
		if (ans < it->second) ans = it->second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def can_merge(K: int, prev_cnt: list, cur_cnt: list) -> bool:
    ret = True
    for i, _ in enumerate(cur_cnt):
        if prev_cnt[i] + cur_cnt[i] > K:
            ret = False
            break
    return ret

def merge(prev_cnt: list, cur_cnt: list):
    for i, _ in enumerate(cur_cnt):
        prev_cnt[i] += cur_cnt[i]

def main():
    H, W, K = map(int, input().split())
    S = []
    for i in range(H):
        S.append(input())

    min_split_num = 999+9
    for hbitv in range(2**(H-1)):
        split_num = bin(hbitv).count('1')
        region_num = split_num + 1
        prev_cnt = [0] * region_num

        # ->
        for w in range(W):
            impossible_hbitv = False
            cur_cnt = [0] * region_num

            # |
            # v
            ri = 0
            for h in range(H):
                if S[h][w] == '1':
                    cur_cnt[ri] += 1
                    if cur_cnt[ri] > K:
                        impossible_hbitv = True
                        break

                if (hbitv >> h) % 0b10 == 1:
                    ri += 1

            if impossible_hbitv:
                break

            if can_merge(K, prev_cnt, cur_cnt):
                merge(prev_cnt, cur_cnt)
            else:
                split_num += 1
                prev_cnt, cur_cnt = cur_cnt, prev_cnt
        
        if not impossible_hbitv:
            min_split_num = min(min_split_num, split_num)

    print(min_split_num)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 48988
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long int
void findAns()
{
    int n;
    cin >> n;

    int data[n + 1];

    for (int i = 1; i <= n; i++) cin >> data[i];

    int count = 0;

    for (int i = 1; i <= n; i++)
    {
        if (data[i] != i) count++;
    }
    if (count <= 2) cout << "YES";
    else
        cout << "NO";
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
//     cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s" << "\n";
// #endif

    FAST;
    ll  t = 1;
    //cin >> t;

    while (t--) findAns();
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
static const int MAX_N = 1e5;

int main()
{
	double w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(15) << h * w / 2.0 << endl;
	if (x == w / 2 && y == h / 2)
	{
		cout << '1' << endl;
	}
	else
	{
		cout << '0' << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
s = input()

cnt = 0
for i in range(1, n-1):
    tmp = 0
    r, l = s[:i], s[i:]
    rs = list(set(r))
    for ri in rs:
        if l.count(ri) > 0:
            tmp += 1
    cnt = max(cnt, tmp)

print(cnt)

Measured memory_bytes: 9128
#include<stdio.h>
#include<math.h>
int main(void){
int N,i;
  scanf("%d",&N);
 
 while(1){int M=sqrt(N);
    for(i=2;i<=M;i++){
      if(N%i==0)break;
    }
    if(i==M+1){
      printf("%d",N);
      return 0;
    }
    N++;
}
  return 0;
}

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

int main(){
  int a,b,k;
  cin>> a >> b >> k;
  int cnt=0;
  
  for(int i=100;i>0;i--){
    if(a%i==0&&b%i==0){
      cnt++;
      if(cnt==k){
        cout << i << endl;
        break;
      }
    }
  }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A > B) {
    cout << 2 * A - 1 << endl;
  }
  else if(A == B) {
    cout << 2 * A << endl;
  }
  else {
    cout << 2 * B - 1 << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main() {
	int H, W, N;
	cin >> H >> W >> N;
	vector<set<int>> a(W+1);
	for (int i = 0; i < N; ++ i) {
		int x, y;
		cin >> x >> y;
		a[y].insert(x);
	}
	for (int i = 1; i <= W; ++ i) a[i].insert(H+1);
	int r = H;
	int p = 1;
	for (int j = 1; ; ++ j) {
		r = min(r, *a[j].lower_bound(p) - 1);
		if (j == W) break;
		for (;;) {
			++ p;
			if (!a[j+1].count(p)) break;
		}
		if (p > H) break;
	}
	cout << r << endl;
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main(){
	int n;
	cin>>n;
	vector<int> in(n);
	for(int i = 0 ; i < n ; i++) cin>>in[i];
	int mx = in[0] , ans = 0;
	for(int i = 1 ; i < n ; i++){
		if(in[i] < mx) ans += mx - in[i];
		mx = max(mx , in[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4832
import java.util.Scanner;
import java.util.BitSet;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		while (true) {
			int width = stdin.nextInt();
			int height = stdin.nextInt();
			if (width == 0 && height == 0) break;
			stdin.nextLine();
			Map map = new Map(width, height);
			for (int i = 0; i < height; i++) {
				map.readMap(stdin.nextLine(), i);
			}
			System.out.println(map.islands());
		}
		System.exit(0);
	}
}

class Map {
	private BitSet land;
	private int width, height;
	public Map(int width, int height) {
		this.width = width;
		this.height = height;
		land = new BitSet(width * height);
	}

	public void readMap(String line, int i) {
		String[] l = line.split(" ");
		for (int j = 0; j < width; j++)
			if (l[j].equals("1")) land.set(i * width + j);
	}

	public int islands() {
		int n = 0;
		for (int i = 0; i < land.size(); i++) {
			if (land.get(i)) {
				n++;
				paint(i);
			} 
		}
		return n;
	}

	private void paint(int i) {	
		land.set(i, false);
		boolean islefterbound = i % width == 0;
		boolean isupperbound = i < width;
		boolean isrighterbound = i % width == width - 1;
		boolean islowerbound = i / width == height - 1;
		if (! islefterbound && ! isupperbound && land.get(i-width-1)) paint(i-width-1);
		if (! isupperbound && land.get(i-width)) paint(i-width);
		if (! isrighterbound && ! isupperbound && land.get(i-width+1)) paint(i-width+1);
		if (! islefterbound && land.get(i-1)) paint(i-1);
		if (! isrighterbound && land.get(i+1)) paint(i+1);
		if (! islefterbound && ! islowerbound && land.get(i+width-1)) paint(i+width-1);
		if (! islowerbound && land.get(i+width)) paint(i+width);
		if (! isrighterbound && ! islowerbound && land.get(i+width+1)) paint(i+width+1);
	}
}

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

int main() {
    int n;

    cin >> n;

    bool yes = false;

    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i*j == n) {
//                cout << "Yes";
                yes = true;
            }
        }
    }

    if (yes == false) {
        cout << "No";
    } else if (yes == true) {
        cout << "Yes";
    }

//    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Measured memory_bytes: 888
function main(input) {
  const x = Number(input.trim());
  let result = 0;
  for (let b = 1; b <= x; b++) {
    for (let p = 2; p <= x; p++) {
        const num = b**p;
    	if (num <= x && result < num) result = num;
      	if (x < num) break;
    }
  }
  if (x === 1) result = 1;
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <cassert>
#include <functional>
using namespace std;

typedef unsigned long long int llui;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
constexpr double pi = 3.141592653589793238462643383279502884L;

// TODO: Mod class

const int sz = 1e5;

int main() {
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> num(n);
  iota(num.begin(), num.end(), 1);

  auto sr = [&num](int i, int j) {
    while (i < j) {
      swap(num[i], num[j]);
      ++i, --j;
    }
  };


  bool ch = false;
  if (a > b) {
    swap(a, b);
    ch = true;
  }

  int g = 0;
  for (int i = 1; i * b <= n; ++i) {
    if (a - i < 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n - (a - i + b * i) == 0) {
      g = i;
      break;
    }
    if (a - i - 1 < 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n - (a - i - 1 + b * i) < 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n - (a - i - 1 + b * i) < b &&
        n - (a - i - 1 + b * i) != 0) {
      g = i;
      break;
    }
  }
  if (g == 0) {
    cout << -1 << endl;
    return 0;
  }
  int r = 0;
  if (n != (a - g + b * g)) {
    r = n - (a - g - 1 + b * g);
    sr(n - r, n - 1);
  }
  for (int i = n - r - 1; g > 0; --g, i -= b) {
    sr(i - b + 1, i);
  }
  if (ch) {
    sr(0, n - 1);
  }
  for (int v : num) {
    cout << v << " ";
  }
  cout << endl;
}


Measured memory_bytes: 3328
use proconio::input;

macro_rules! chmax {
    ($max_v: expr, $v: expr) => {
        if $v > $max_v {
            $max_v = $v;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i64,
        a: [i64; n],
        b: [i64; m],
    };
    let ca = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, a_i| {
            *acc += a_i;
            Some(*acc)
        }))
        .collect::<Vec<_>>();
    let cb = std::iter::once(0)
        .chain(b.iter().scan(0, |acc, b_i| {
            *acc += b_i;
            Some(*acc)
        }))
        .collect::<Vec<_>>();

    let mut ans = 0;
    let mut max_j = cb.len() - 1;
    for (i, &ca_i) in ca.iter().enumerate() {
        for (j, &cb_i) in cb[0..=max_j].iter().enumerate().rev() {
            if ca_i + cb_i <= k {
                chmax!(ans, i + j);
                max_j = j;
                break;
            }
        }
    }

    // 二分探索 (superslice の upper_bound) を使う方法
    // for i in 0..=n {
    //     let x = k - ca[i];
    //     if x < 0 {
    //         continue;
    //     }
    //     let j = cb.upper_bound(&x);
    //     chmax!(ans, i + j - 1);
    // }

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


Measured memory_bytes: 12788
import java.util.*;

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

        int amountMonster;
        int PPspecatk;

        amountMonster = sc.nextInt();
        PPspecatk = sc.nextInt();

        List<Integer> HP = new ArrayList<>();
        for (int i = 0; i < amountMonster; i++) {
            HP.add(sc.nextInt());
        }
        Collections.sort(HP);

        long sum = 0;
        for (int i = 0; i < HP.size() - PPspecatk; i++) {
            sum += HP.get(i);
        }
        System.out.println(sum);
    }
}

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

int main(){
  int N;
  cin >> N;

  vector<int> h;
  for (int i = 0; i < N; ++i) {
    int hin;
    cin >> hin;
    h.push_back(hin);
  }

  int output = 0;
  // Find the local max and cover the max until every h become 0.
  // At most O(N max(h)) operation is required.
  auto it = max_element(h.begin(), h.end());

  int val = *it;
  int index = it - h.begin();
  // cout << "index, val=" << index << "," << val << endl;
  while (val > 0) {
    // Find if the adjacent value is equal to val.
    h[index]--;
    for (int i = index - 1; i >= 0; i--) {
      if (h[i] == val) {
        h[i]--;
      } else {
        break;
      }
    }
    for (int i = index + 1; i < h.size(); i++) {
      if (h[i] == val) {
        h[i]--;
      } else {
        break;
      }
    }
    output++;

    it = max_element(h.begin(), h.end());

    val = *it;
    index = it - h.begin();
    //  cout << "index, val=" << index << "," << val << endl;
    
  }
  cout << output;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n;
vector<ll> a;
vector<ll> sum;
ll memo[440][440];
ll dp(int i, int j){
    if(i == j) return 0;
    if(memo[i][j] != -1) return memo[i][j];

    ll res = INF;
    for(int k = i; k < j; k++){
        //cout << i << " " << k << " " << j << endl;
        res = min(res, dp(i, k) + dp(k + 1, j) + (sum[j + 1] - sum[i]));
    }

    return memo[i][j] = res;

}
int main(void){
    cin >> n;
    a.resize(n);
    sum.resize(n + 1, 0);
    for(int i = 0; i < n; i++) cin >> a[i];

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            memo[i][j] = -1;
        }
    }

    for(int i = 0; i < n; i++){
        sum[i + 1] = sum[i] + a[i];
        //cout << i + 1 << " " << sum[i + 1] << endl;
    }

    cout << dp(0, n - 1) << endl;
}   

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e5+10, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n;
	cin>>n;
	cout<<(n*n*n);
	
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a;
  cin >> a;
  int ans = 0;
  for (int i = 1; i <= a; i += 2){
    int count = 0;
    for (int j = 1; j <= i; j++){
      if (i % j == 0) count++;
    }
    if (count == 8) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int plus = a + b;
        int minus = a - b;
        int multi = a * b;
        Console.WriteLine(Math.Max(Math.Max(plus,minus),multi));
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

int N;
int a[100];
int ans = 123456789;

int main(){
	scanf("%d" , &N);
	for(int i = 0 ; i < N ; ++i){
		scanf("%d" , a + i);
	}
	for(int i = -100 ; i < 101 ; ++i){
		int s = 0;
		for(int j = 0 ; j < N ; ++j){
			s += (a[j] - i) * (a[j] - i);
		}
		ans = Mn(ans , s);
	}
	printf("%d\n" , ans);
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i];
        cout << t[i];
    }

    return 0;
}

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

int main()
{
  int n;
  int ans = 0;
  cin >> n;
  vector<int> b(n - 1);
  vector<int> a(n);
  rep(i ,n - 1) {
    cin >> b[i];
  }
  rep(i, n) {
    if(i == 0) {
      a[i] = b[i];
    }else if(i == n -1){
      a[i] = b[n - 2];
    }else {
      a[i] = min(b[i], b[i - 1]);
    }
  }
  rep(i ,n) {
    ans += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/dsu>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {
  
  int N, Q;
  cin >> N >> Q;

  dsu d(N);
  rep(qi,Q) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      d.merge(u, v);
    } else {
      cout << (d.same(u, v) ? 1 : 0) << endl;
    }
  }

  return 0;
}

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

long long dp[3010][3010];
constexpr int mod = 998244353;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int A, B, C, D; cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    for (int i = A; i <= C; i++) {
        for (int j = B; j <= D; j++) {
            dp[i][j] %= mod;
            dp[i+1][j] += dp[i][j] * j % mod;
            dp[i][j+1] += dp[i][j] * i % mod;
            dp[i+1][j+1] += mod - dp[i][j] * i % mod * j % mod;
        }
    }
    cout << dp[C][D] % mod << "\n";
    return 0;
}

Measured memory_bytes: 74092
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <cmath>
#include <string>

typedef int64_t lint;
#define LINT_MAX INT32_MAX
#define LINT_MIN INT32_MIN

using namespace std;

int div2(lint n) {
    int ret = 0;
    lint k = n;
    while(k % 2 == 0) {
        k = k / 2;
        ret++;
    }
    return ret;
}

int main(void) {
    int n;
    lint a;
    int d2r[10000];
    cin >> n;
    lint as = 0;
    for(int i = 0;i < n;i++) {
        cin >> a;
        d2r[i] = div2(a);
        as = as + d2r[i];
    }
    if(as == 0)
        cout << "0";
    else
        cout << as;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    int x;
    cin>>x;
    long long a[x];
    long long s=0;
    for(int i=0;i<x;i++)
        {
        cin>>a[i];
        if(i>0&&a[i-1]>a[i])
            {
        s =s+a[i-1]-a[i];
        a[i]=a[i-1];
}
    }
    cout<<s;
    return 0 ;
    }


Measured memory_bytes: 5228
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

int A[200020];
void solve() {
    int N;cin>>N;
    REP(i,N)cin>>A[i];
    int now=1;
    REP(i,N){
        if(now==A[i])now++;
    }
    if(now==1){
        print(-1);
    }
    else{
        print(N-now+1);
    }
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 300000+9;

int n,m;
struct Event{
	int l,r,len;
	inline Event() {}
	inline Event(int _l, int _r) {l = _l; r = _r; len = r - l + 1;}
	inline bool operator < (const Event &B) const {return len < B.len;}
}e[N];

class Fenwick_Tree{
	int cnt[N];
	public:
		inline void modify(int l, int r) {
			for (int i=l-1;i;i-=lowbit(i)) cnt[i]--;
			for (int i=r;i;i-=lowbit(i)) cnt[i]++; 
		}
		inline int query(int p) {
			int ret = 0;
			for (int i=p;i<=m;i+=lowbit(i)) ret += cnt[i];
			return ret;
		}
	private:
		inline int lowbit(int x) {
			return x & -x;
		}
}BIT; 

inline int read() {
	char c=getchar(); int f=1,ret=0;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret * f;
}

int main() {
	//freopen("11input.in","r",stdin);
	n = read(); m = read();
	for (int i=1,l,r;i<=n;i++) {
		l = read(); r = read();
		e[i] = Event(l, r);
	}
	sort(e+1, e+1+n);
	for (int d=1,p=1,sta=n;d<=m;d++) {
		for (;p<=n&&e[p].len==d-1;p++) {
			--sta;
			BIT.modify(e[p].l, e[p].r);
		}
		int vout = 0;
		for (int i=d;i<=m;i+=d) 
			vout += BIT.query(i);
		printf("%d\n",vout+sta);
	}
	return 0;
}


Measured memory_bytes: 4864
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, k;
const int mod = (int)1e9 + 7;

int mult(int a, int b) {
    return (1LL * a * b) % mod;
}

int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}

int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
const int maxN = 2005;

int fact[maxN], invfact[maxN], inv[maxN];

void init() {
    inv[1] = invfact[1] = invfact[0] = fact[0] = fact[1] = 1;
    for (int i = 2; i < maxN; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv[i] = mult(inv[mod % i], mod - mod / i);
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
}

int cnk(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return mult(fact[n], mult(invfact[k], invfact[n - k]));
}


int dp[maxN][maxN];
int cat[maxN];
void solve(int x) {
    dp[1][1] = 1;
    for (int i = 1; i < x; i++) {
        for (int suf = 1; suf <= i; suf++) {
            dp[i + 1][1] = sum(dp[i + 1][1], dp[i][suf]);
            if (suf < i) dp[i + 1][suf + 2] = sub(dp[i + 1][suf + 2], dp[i][suf]);
        }
        for (int suf = 2; suf <= i + 1; suf++) {
            dp[i + 1][suf] = sum(dp[i + 1][suf], dp[i + 1][suf - 1]);
        }
    }
    for (int i = 1; i <= x; i++) {
        for (int j = 1; j <= i; j++) {
            cat[i] = sum(cat[i], dp[i][j]);
        }
    }
    cat[0] = 1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    init();
    cin >> n >> k;
    dp[0][0] = 1;
    int cnt = n - k;
    for (int i = 0; i < (k - 1); i++) {
        for (int suf = 0; suf <= i; suf++) {
            dp[i + 1][1] = sum(dp[i + 1][1], dp[i][suf]);
            if (suf < i) dp[i + 1][suf + 2] = sub(dp[i + 1][suf + 2], dp[i][suf]);
        }
        for (int suf = 2; suf <= i + 1; suf++) {
            dp[i + 1][suf] = sum(dp[i + 1][suf], dp[i + 1][suf - 1]);
        }
        dp[i + 1][i + 1] = sum(dp[i + 1][i + 1], cnk(i + 1 + cnt - 1, cnt - 1));
    }
    int ans = 0;
    for (int i = 0; i <= k - 1; i++) {
        ans = sum(ans, dp[k - 1][i]);
    }
    cout << mult(ans, pw(2, max(0, n - k - 1)));
    return 0;
}

Measured memory_bytes: 15104
#include <stdio.h>
int main(void)
{
    char str1[3];
    scanf("%s",str1);
    if(!strcmp(str1, "ABC"))
    {
        printf("ARC\n");
    }
    if(!strcmp(str1, "ARC"))
    {
        printf("ABC\n");
    }
    return 0;
}

Measured memory_bytes: 1608
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

#include <cassert>
using namespace std;

const char OCCUP = '#';
const char EMPTY = '.';

inline int GetBit(int mask, int num) {
    return (mask >> num) & 1;
}

int n, m;
vector<vector<int>> a;

int main() {
    // freopen("input.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;
    a.assign(n, vector<int>(m, 0));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char c;
            cin >> c;

            if (c == OCCUP) {
                a[i][j] = (1 << 0) + (1 << 1);
            } else {
                a[i][j] = 0;
            }
        }
    }

    for (int j = 0; j < m; ++j) {
        a[0][j] = (1 << 0);
    }
    for (int i = 1; i < n; ++i) {
        a[i][0] = a[i][m - 1] = (1 << 0);
    }

    int baseLen[2];
    baseLen[1] = (m >> 1);
    baseLen[0] = (m - 2 - baseLen[1]);

    int len[2];
    len[0] = baseLen[0];
    len[1] = baseLen[1];

    for (int j = 1; j < 1 + len[0]; ++j) {
        a[n - 1][j] = (1 << 0);
    }
    for (int j = 1 + len[0]; j < 1 + len[0] + len[1]; ++j) {
        a[n - 1][j] = (1 << 1);
    }

    bool left = true;
    for (int i = n - 2; i > 0; --i) {
        if ((m & 1) == 0 && left) {
            len[0] = len[1] = ((m - 2) >> 1);
        } else {
            len[0] = baseLen[0];
            len[1] = baseLen[1];
        }
        if (left) {
            for (int j = 1; j < 1 + len[1]; ++j) {
                a[i][j] |= (1 << 1);
            }
            for (int j = 1 + len[1]; j < 1 + len[1] + len[0]; ++j) {
                a[i][j] |= (1 << 0);
            }
        } else {
            for (int j = 1; j < 1 + len[0]; ++j) {
                a[i][j] |= (1 << 0);
            }
            for (int j = 1 + len[0]; j < 1 + len[0] + len[1]; ++j) {
                a[i][j] |= (1 << 1);
            }
        }
        left ^= true;
    }

    for (int b = 0; b < 2; ++b) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (GetBit(a[i][j], b)) {
                    cout << OCCUP;
                } else {
                    cout << EMPTY;
                }
            }
            cout << endl;
        }

        if (b == 0) {
            cout << endl;
        }
    }

    /*
    cout << endl;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] == 3) {
                cout << OCCUP;
            } else {
                cout << EMPTY;
            }
        }
        cout << endl;
    }
    */

    return 0;
}

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

int main()
{
  char s[200000];
  gets(s);

  int i;
  int sum=0;
  int len=strlen(s);

  for(i=0;i<len;i++)
    {
      sum += s[i]-'0';
    }
  if(sum%9==0)
    {
      printf( "Yes\n" );
    }
  else
    {
      printf( "No\n" );
    }
  
  return 0;
}


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

int main(){

    while(1){

    int n;

    long long int lim;
    
     cin>>n>>lim;

    if(n==0 && lim ==0) break;

    vector<long long int> val(n);

    for(int i=0; i<n; i++) cin>>val[i];

    long long int ans=0;

    bool flag = false;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){

            if(i == j) continue;

            else if(lim >= val[i] + val[j] && val[i] + val[j] >ans ){

                ans = val[i] + val[j];

                flag = true;

            }
        }
    }

    if(flag) cout<<ans<<endl;

    else cout<<"NONE"<<endl;

    }

    return 0;
}


Measured memory_bytes: 3096
import random

def miller_rabin_test(n,k): #n>3,odd number
    d = n-1
    r = 0
    while True:
        if d%2 == 0:
            r += 1
            d //= 2
        else:
            break
    
    for i in range(k):
        a = random.randint(2,n-2)
        x = pow(a,d,n)# same as (a**d)%n  'pow' runs fast if n is large
        if x == 1 or x == n-1:
            continue
        flag = False
        for j in range(r-1):
            x = pow(x,2,n)# same as (x**2)%n
            if x == n-1:
                flag = True
                break
            if x == 1:
                break
        if flag:
            continue
        else:
            return False
        
    return True

n = int(input())
a = [int(input()) for _ in range(n)]

count = 0
for i in range(n):
    if a[i] == 2 or a[i] == 3:
        count += 1
        continue
    if a[i] <= 3 or a[i]%2==0:
        continue
    if miller_rabin_test(a[i],100):
        count += 1
print(count)


Measured memory_bytes: 8532
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=55;
int n,m,a[N],b[N],forbid1,forbid2,ans;
bool visit[N];vi v[N];
void dfs(int now)
{
	visit[now]=true;
	for(int i=0;i<v[now].size();i++)
		if(!visit[v[now][i]]&&!((v[now][i]==forbid1&&now==forbid2)||(now==forbid1&&v[now][i]==forbid2)))
			dfs(v[now][i]);
}
bool check()
{
	dfs(0);
	for(int i=0;i<n;i++)
		if(!visit[i])
			return false;
	return true;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		v[a[i]].pb(b[i]);
		v[b[i]].pb(a[i]);
	}
	for(int i=0;i<m;i++)
	{
		memset(visit,false,sizeof(visit));
		forbid1=a[i];
		forbid2=b[i];
		ans+=!check();
	}
	cout<<ans<<endl;
}

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

void bubble_sort(char **,int);
void select_sort(char **,char **,int);


int main(){

  int i=0,j,element;
  char **matrix_bubble,**matrix_select;

  scanf("%d",&element);

  matrix_bubble = malloc(sizeof(char*) * element);
  matrix_select = malloc(sizeof(char*) * element);

  for(i = 0 ; i < element ; i++){
  matrix_bubble[i] = malloc(sizeof(char) * 3);
  matrix_select[i] = malloc(sizeof(char) * 3);
  }//Dual_pointer

  i =0;

  while(i < element){
    scanf("%s",matrix_bubble[i]);
    strcpy(matrix_select[i],matrix_bubble[i]);
    i++;
  }
  
  bubble_sort(matrix_bubble,element);
  select_sort(matrix_select,matrix_bubble,element);
  
  free(matrix_bubble);
  free(matrix_select);
  return 0;


}




void bubble_sort(char **matrix_b,int element){

  int i=0,j,str=3;//str = string
  char temp[3];
  int nowline=0;

  while( nowline != element){
    for(i = element-1 ; i > 0 ; i--){

      if(matrix_b[i][1] < matrix_b[i-1][1]){   //string comper
	  strcpy(temp,matrix_b[i-1]);
	  strcpy(matrix_b[i-1],matrix_b[i]);
	  strcpy(matrix_b[i],temp);
      }
      /*    else if(matrix_b[i][1] == matrix_b[i-1][1] && i < matrix_b[i-1][0]){
	strcpy(temp,matrix_b[i-1]);
	strcpy(matrix_b[i-1],matrix_b[i]);
	strcpy(matrix_b[i],temp);
	
	}*/
    }
    nowline++;
  }

  i = 0;

  while(i < element){
    printf("%s",matrix_b[i]);
    if(i != element-1){
      printf(" ");

    }

    i++;

  }
    printf("\n");

  printf("Stable\n");
}



void select_sort(char **matrix_c,char **matrix_b,int element){
  int i=0;//temp = temporary
  int nowline=0,exchangeline=0,flag=0;
  char min[3],temp[3];

while(nowline != element){ //element = endline

    for( i = nowline ; i < element-1 ; i++){
      
      if( i == nowline ) strcpy(min, matrix_c[i]);//startline

      if( min[1] > matrix_c[i+1][1]){
	strcpy(min,matrix_c[i+1]);
	exchangeline = i+1;
      }
      /*      else if( min[1] == matrix_c[i+1][1]&& min[0] > matrix_c[i+1][0]){
	strcpy(min,matrix_c[i+1]);
	exchangeline = i+1;
	}*/
    }
      if(exchangeline != nowline){
      strcpy(temp,matrix_c[nowline]);
      strcpy(matrix_c[nowline],matrix_c[exchangeline]);
      strcpy(matrix_c[exchangeline],temp);
    }
    nowline++;
    exchangeline = nowline; //ここでどちらにしろexchangelineは頭に戻る
 }
 i = 0;

  while( i < element){
    printf("%s",matrix_c[i]);
    if(strcmp(matrix_b[i],matrix_c[i]) != 0) flag = 1;
    if(i != element-1) printf(" ");
    i++;
}
  printf("\n");

  if(flag == 0) printf("Stable\n");
  else printf("Not stable\n");


}

Measured memory_bytes: 624
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
#define YES "YES"
#define NO "NO"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,L;
int main(){
    cin >>N>>L;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    sort(ALL(S));
    string ans = "";
    rep(i,N) ans += S[i];
    pr(ans);
}

Measured memory_bytes: 256
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    string s;
    cin >> s;
    
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else if (s == "Rainy") cout << "Sunny" << endl;
    return 0;
}


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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
      fastio;
      int n;
      cin>>n;
      string s;
      cin>>s;
      int ans=0;
      for(int i=0;i<n-2;i++)
      {
          if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            ans++;
      }
      cout<<ans<<endl;
    }

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


using namespace std;
typedef long long ll;
typedef long double ld;
const int MX=2e3+9;
const long double eps=-0.00000001;
const ll mod = 1e9+7;


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

int get ( string x )
{
    int c=0;
    for ( int i=0  ;i<x.size() ; i++ )
    {
        c = c*10 + x[i]-'0';
    }
    return c;
}

int dx[]={ 0,0,1,-1 };
int dy[]={ -1,1,0,0 };




int  n , arr[MX] , x ;
int dp[2001];
long long ans=0;
int main(){
    scanf("%d %d",&n,&x);
    for(int j=0;j<n;j++){
        scanf("%d",&arr[j]);
        dp[j] = arr[j];
        ans+=arr[j];
    }
    for(int j=1;j<n;j++){
        long long cur = 0;
        for(int i=0;i<n;i++){
            dp[i] = min(dp[i] , arr[(i-j+n)%n] );
            cur += dp[i];
        }
        cur += 1ll * x * j;
        ans = min(ans , cur);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256